Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Store raw path bytes in Diff instances#474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 1 commit intomasterfromkeep-raw-bytes-on-diffs
Jun 20, 2016
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletionsdoc/source/changes.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,9 @@ Changelog
2.0.6 - Fixes and Features
==========================

* API: Diffs now have `a_rawpath`, `b_rawpath`, `raw_rename_from`,
`raw_rename_to` properties, which are the raw-bytes equivalents of their
unicode path counterparts.
* Fix: TypeError about passing keyword argument to string decode() on
Python 2.6.
* Feature: `setUrl API on Remotes<https://github.com/gitpython-developers/GitPython/pull/446#issuecomment-224670539>`_
Expand Down
2 changes: 2 additions & 0 deletionsgit/compat.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,7 @@ def mviter(d):
returnd.values()
range=xrange
unicode=str
binary_type=bytes
else:
FileType=file
# usually, this is just ascii, which might not enough for our encoding needs
Expand All@@ -44,6 +45,7 @@ def mviter(d):
byte_ord=ord
bchr=chr
unicode=unicode
binary_type=str
range=xrange
defmviter(d):
returnd.itervalues()
Expand Down
58 changes: 41 additions & 17 deletionsgit/diff.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@

fromgitdb.utilimporthex_to_bin

from .compatimportbinary_type
from .objects.blobimportBlob
from .objects.utilimportmode_str_to_int

Expand DownExpand Up@@ -245,18 +246,20 @@ class Diff(object):
NULL_HEX_SHA="0"*40
NULL_BIN_SHA=b"\0"*20

__slots__= ("a_blob","b_blob","a_mode","b_mode","a_path","b_path",
"new_file","deleted_file","rename_from","rename_to","diff")
__slots__= ("a_blob","b_blob","a_mode","b_mode","a_rawpath","b_rawpath",
"new_file","deleted_file","raw_rename_from","raw_rename_to","diff")

def__init__(self,repo,a_path,b_path,a_blob_id,b_blob_id,a_mode,
b_mode,new_file,deleted_file,rename_from,
rename_to,diff):
def__init__(self,repo,a_rawpath,b_rawpath,a_blob_id,b_blob_id,a_mode,
b_mode,new_file,deleted_file,raw_rename_from,
raw_rename_to,diff):

self.a_mode=a_mode
self.b_mode=b_mode

self.a_path=a_path
self.b_path=b_path
asserta_rawpathisNoneorisinstance(a_rawpath,binary_type)
assertb_rawpathisNoneorisinstance(b_rawpath,binary_type)
self.a_rawpath=a_rawpath
self.b_rawpath=b_rawpath

ifself.a_mode:
self.a_mode=mode_str_to_int(self.a_mode)
Expand All@@ -266,19 +269,21 @@ def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode,
ifa_blob_idisNoneora_blob_id==self.NULL_HEX_SHA:
self.a_blob=None
else:
self.a_blob=Blob(repo,hex_to_bin(a_blob_id),mode=self.a_mode,path=a_path)
self.a_blob=Blob(repo,hex_to_bin(a_blob_id),mode=self.a_mode,path=self.a_path)

ifb_blob_idisNoneorb_blob_id==self.NULL_HEX_SHA:
self.b_blob=None
else:
self.b_blob=Blob(repo,hex_to_bin(b_blob_id),mode=self.b_mode,path=b_path)
self.b_blob=Blob(repo,hex_to_bin(b_blob_id),mode=self.b_mode,path=self.b_path)

self.new_file=new_file
self.deleted_file=deleted_file

# be clear and use None instead of empty strings
self.rename_from=rename_fromorNone
self.rename_to=rename_toorNone
assertraw_rename_fromisNoneorisinstance(raw_rename_from,binary_type)
assertraw_rename_toisNoneorisinstance(raw_rename_to,binary_type)
self.raw_rename_from=raw_rename_fromorNone
self.raw_rename_to=raw_rename_toorNone

self.diff=diff

Expand DownExpand Up@@ -344,6 +349,22 @@ def __str__(self):
# end
returnres

@property
defa_path(self):
returnself.a_rawpath.decode(defenc,'replace')ifself.a_rawpathelseNone

@property
defb_path(self):
returnself.b_rawpath.decode(defenc,'replace')ifself.b_rawpathelseNone

@property
defrename_from(self):
returnself.raw_rename_from.decode(defenc,'replace')ifself.raw_rename_fromelseNone

@property
defrename_to(self):
returnself.raw_rename_to.decode(defenc,'replace')ifself.raw_rename_toelseNone

@property
defrenamed(self):
""":returns: True if the blob of our diff has been renamed
Expand DownExpand Up@@ -388,6 +409,7 @@ def _index_from_patch_format(cls, repo, stream):
new_file_mode,deleted_file_mode, \
a_blob_id,b_blob_id,b_mode, \
a_path,b_path=header.groups()

new_file,deleted_file=bool(new_file_mode),bool(deleted_file_mode)

a_path=cls._pick_best_path(a_path,rename_from,a_path_fallback)
Expand All@@ -404,15 +426,15 @@ def _index_from_patch_format(cls, repo, stream):
a_mode=old_modeordeleted_file_modeor (a_pathand (b_modeornew_modeornew_file_mode))
b_mode=b_modeornew_modeornew_file_modeor (b_pathanda_mode)
index.append(Diff(repo,
a_pathanda_path.decode(defenc,'replace'),
b_pathandb_path.decode(defenc,'replace'),
a_path,
b_path,
a_blob_idanda_blob_id.decode(defenc),
b_blob_idandb_blob_id.decode(defenc),
a_modeanda_mode.decode(defenc),
b_modeandb_mode.decode(defenc),
new_file,deleted_file,
rename_fromandrename_from.decode(defenc,'replace'),
rename_toandrename_to.decode(defenc,'replace'),
rename_from,
rename_to,
None))

previous_header=header
Expand All@@ -438,8 +460,8 @@ def _index_from_raw_format(cls, repo, stream):
meta,_,path=line[1:].partition('\t')
old_mode,new_mode,a_blob_id,b_blob_id,change_type=meta.split(None,4)
path=path.strip()
a_path=path
b_path=path
a_path=path.encode(defenc)
b_path=path.encode(defenc)
deleted_file=False
new_file=False
rename_from=None
Expand All@@ -455,6 +477,8 @@ def _index_from_raw_format(cls, repo, stream):
new_file=True
elifchange_type[0]=='R':# parses RXXX, where XXX is a confidence value
a_path,b_path=path.split('\t',1)
a_path=a_path.encode(defenc)
b_path=b_path.encode(defenc)
rename_from,rename_to=a_path,b_path
# END add/remove handling

Expand Down
6 changes: 5 additions & 1 deletiongit/test/test_diff.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,6 +90,8 @@ def test_diff_with_rename(self):
assert_true(diff.renamed)
assert_equal(diff.rename_from,u'Jérôme')
assert_equal(diff.rename_to,u'müller')
assert_equal(diff.raw_rename_from,b'J\xc3\xa9r\xc3\xb4me')
assert_equal(diff.raw_rename_to,b'm\xc3\xbcller')
assertisinstance(str(diff),str)

output=StringProcessAdapter(fixture('diff_rename_raw'))
Expand DownExpand Up@@ -129,7 +131,7 @@ def test_diff_index_raw_format(self):
output=StringProcessAdapter(fixture('diff_index_raw'))
res=Diff._index_from_raw_format(None,output.stdout)
assertres[0].deleted_file
assertres[0].b_path==''
assertres[0].b_pathisNone

deftest_diff_initial_commit(self):
initial_commit=self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781')
Expand DownExpand Up@@ -162,7 +164,9 @@ def test_diff_unsafe_paths(self):
self.assertEqual(res[7].b_path,u'path/with-question-mark?')
self.assertEqual(res[8].b_path,u'path/¯\\_(ツ)_|¯')
self.assertEqual(res[9].b_path,u'path/💩.txt')
self.assertEqual(res[9].b_rawpath,b'path/\xf0\x9f\x92\xa9.txt')
self.assertEqual(res[10].b_path,u'path/�-invalid-unicode-path.txt')
self.assertEqual(res[10].b_rawpath,b'path/\x80-invalid-unicode-path.txt')

# The "Moves"
# NOTE: The path prefixes a/ and b/ here are legit! We're actually
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp