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

Commit90e780a

Browse files
committed
log: non-existing logs no longer throw an exception, but are ignored. Fixed critical bug which caused packed-ref files to be written with native line endings, which made git fail to parse it. I wonder why I never noticed this before, or ignored it. Unbelievable \!
1 parent58a930a commit90e780a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

‎git/refs/log.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ def __init__(self, filepath=None):
126126
# END handle filepath
127127

128128
def_read_from_file(self):
129-
fmap=file_contents_ro_filepath(self._path,stream=False,allow_mmap=True)
129+
try:
130+
fmap=file_contents_ro_filepath(self._path,stream=False,allow_mmap=True)
131+
exceptOSError:
132+
# it is possible and allowed that the file doesn't exist !
133+
return
134+
#END handle invalid log
135+
130136
try:
131137
self._deserialize(fmap)
132138
finally:

‎git/refs/symbolic.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _iter_packed_refs(cls, repo):
9393
"""Returns an iterator yielding pairs of sha1/path pairs for the corresponding refs.
9494
:note: The packed refs file will be kept open as long as we iterate"""
9595
try:
96-
fp=open(cls._get_packed_refs_path(repo),'r')
96+
fp=open(cls._get_packed_refs_path(repo),'rb')
9797
forlineinfp:
9898
line=line.strip()
9999
ifnotline:
@@ -423,7 +423,7 @@ def delete(cls, repo, path):
423423
# check packed refs
424424
pack_file_path=cls._get_packed_refs_path(repo)
425425
try:
426-
reader=open(pack_file_path)
426+
reader=open(pack_file_path,'rb')
427427
except (OSError,IOError):
428428
pass# it didnt exist at all
429429
else:
@@ -450,7 +450,10 @@ def delete(cls, repo, path):
450450

451451
# write the new lines
452452
ifmade_change:
453-
open(pack_file_path,'w').writelines(new_lines)
453+
# write-binary is required, otherwise windows will
454+
# open the file in text mode and change LF to CRLF !
455+
open(pack_file_path,'wb').writelines(new_lines)
456+
# END write out file
454457
# END open exception handling
455458
# END handle deletion
456459

@@ -583,7 +586,7 @@ def _iter_items(cls, repo, common_path = None):
583586
# Currently we do not follow links
584587
forroot,dirs,filesinos.walk(join_path_native(repo.git_dir,common_path)):
585588
if'refs/'notinroot:# skip non-refs subfolders
586-
refs_id= [ifori,dinenumerate(dirs)ifd=='refs' ]
589+
refs_id= [dfordindirsifd=='refs' ]
587590
ifrefs_id:
588591
dirs[0:]= ['refs']
589592
# END prune non-refs folders

‎git/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,15 @@ def join_path(a, *p):
249249
'/' instead of possibly '\' on windows."""
250250
path=a
251251
forbinp:
252+
iflen(b)==0:
253+
continue
252254
ifb.startswith('/'):
253255
path+=b[1:]
254256
elifpath==''orpath.endswith('/'):
255257
path+=b
256258
else:
257259
path+='/'+b
260+
# END for each path token to add
258261
returnpath
259262

260263
defto_native_path_windows(path):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp