diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2011-06-08 01:27:28 +0200 |
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2011-06-08 01:35:16 +0200 |
| commit | 90e780a3e16d0c3e4d7288728f6ba36e9c18d736 (patch) | |
| tree | de5988fc3bb6a39b91cc652e9f6cc51f7015087f /git | |
| parent | 58a930a632c867b65b9a3802e2f4190cf32e33ee (diff) | |
| download | GitPython-90e780a3e16d0c3e4d7288728f6ba36e9c18d736.tar.gz GitPython-90e780a3e16d0c3e4d7288728f6ba36e9c18d736.zip | |
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 \!
Diffstat (limited to 'git')
| -rw-r--r-- | git/refs/log.py | 8 | ||||
| -rw-r--r-- | git/refs/symbolic.py | 11 | ||||
| -rw-r--r-- | git/util.py | 3 |
3 files changed, 17 insertions, 5 deletions
diff --git a/git/refs/log.py b/git/refs/log.py index 3b9d8514..562c6caa 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -126,7 +126,13 @@ class RefLog(list, Serializable): # END handle filepath def _read_from_file(self): - fmap = file_contents_ro_filepath(self._path, stream=False, allow_mmap=True) + try: + fmap = file_contents_ro_filepath(self._path, stream=False, allow_mmap=True) + except OSError: + # it is possible and allowed that the file doesn't exist ! + return + #END handle invalid log + try: self._deserialize(fmap) finally: diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index ddee3809..8c3689b4 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -93,7 +93,7 @@ class SymbolicReference(object): """Returns an iterator yielding pairs of sha1/path pairs for the corresponding refs. :note: The packed refs file will be kept open as long as we iterate""" try: - fp = open(cls._get_packed_refs_path(repo), 'r') + fp = open(cls._get_packed_refs_path(repo), 'rb') for line in fp: line = line.strip() if not line: @@ -423,7 +423,7 @@ class SymbolicReference(object): # check packed refs pack_file_path = cls._get_packed_refs_path(repo) try: - reader = open(pack_file_path) + reader = open(pack_file_path, 'rb') except (OSError,IOError): pass # it didnt exist at all else: @@ -450,7 +450,10 @@ class SymbolicReference(object): # write the new lines if made_change: - open(pack_file_path, 'w').writelines(new_lines) + # write-binary is required, otherwise windows will + # open the file in text mode and change LF to CRLF ! + open(pack_file_path, 'wb').writelines(new_lines) + # END write out file # END open exception handling # END handle deletion @@ -583,7 +586,7 @@ class SymbolicReference(object): # Currently we do not follow links for root, dirs, files in os.walk(join_path_native(repo.git_dir, common_path)): if 'refs/' not in root: # skip non-refs subfolders - refs_id = [ i for i,d in enumerate(dirs) if d == 'refs' ] + refs_id = [ d for d in dirs if d == 'refs' ] if refs_id: dirs[0:] = ['refs'] # END prune non-refs folders diff --git a/git/util.py b/git/util.py index 6009e158..d248b1ee 100644 --- a/git/util.py +++ b/git/util.py @@ -249,12 +249,15 @@ def join_path(a, *p): '/' instead of possibly '\' on windows.""" path = a for b in p: + if len(b) == 0: + continue if b.startswith('/'): path += b[1:] elif path == '' or path.endswith('/'): path += b else: path += '/' + b + # END for each path token to add return path def to_native_path_windows(path): |
