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

Commit7ab12b4

Browse files
committed
fix(index):allow adding non-unicode paths to index
This issue only surfaced in python 2, in case paths containing unicodecharacters were not actual unicode objects.In python 3, this was never the issue.Closesgitpython-developers#331
1 parent8324c4b commit7ab12b4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

‎git/index/fun.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
fromgitdb.typimportstr_tree_type
4242
fromgit.compatimport (
4343
defenc,
44-
force_text
44+
force_text,
45+
force_bytes
4546
)
4647

4748
S_IFGITLINK=S_IFLNK|S_IFDIR# a submodule
@@ -124,7 +125,7 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
124125
write(entry[4])# ctime
125126
write(entry[5])# mtime
126127
path=entry[3]
127-
path=path.encode(defenc)
128+
path=force_bytes(path,encoding=defenc)
128129
plen=len(path)&CE_NAMEMASK# path length
129130
assertplen==len(path),"Path %s too long to fit into index"%entry[3]
130131
flags=plen| (entry[2]&CE_NAMEMASK_INV)# clear possible previous values

‎git/test/test_index.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919
fromgitimport (
2020
IndexFile,
21+
Repo,
2122
BlobFilter,
2223
UnmergedEntriesError,
2324
Tree,
@@ -45,6 +46,7 @@
4546
IndexEntry
4647
)
4748
fromgit.index.funimporthook_path
49+
fromgitdb.test.libimportwith_rw_directory
4850

4951

5052
classTestIndex(TestBase):
@@ -780,3 +782,14 @@ def test_index_bare_add(self, rw_bare_repo):
780782
exceptInvalidGitRepositoryError:
781783
asserted=True
782784
assertasserted,"Adding using a filename is not correctly asserted."
785+
786+
@with_rw_directory
787+
deftest_add_utf8P_path(self,rw_dir):
788+
# NOTE: fp is not a Unicode object in python 2 (which is the source of the problem)
789+
fp=os.path.join(rw_dir,'ø.txt')
790+
withopen(fp,'w')asfs:
791+
fs.write('content of ø')
792+
793+
r=Repo.init(rw_dir)
794+
r.index.add([fp])
795+
r.index.commit('Added orig and prestable')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp