diff options
Diffstat (limited to 'git/refs')
-rw-r--r-- | git/refs/head.py | 2 | ||||
-rw-r--r-- | git/refs/log.py | 69 | ||||
-rw-r--r-- | git/refs/reference.py | 20 | ||||
-rw-r--r-- | git/refs/symbolic.py | 64 |
4 files changed, 79 insertions, 76 deletions
diff --git a/git/refs/head.py b/git/refs/head.py index 2ef7c23e..6f36a956 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -30,7 +30,7 @@ class HEAD(SymbolicReference): return SymbolicReference(self.repo, self._ORIG_HEAD_NAME) def reset(self, commit='HEAD', index=True, working_tree=False, - paths=None, **kwargs): + paths=None, **kwargs): """Reset our HEAD to the given commit optionally synchronizing the index and working tree. The reference we refer to will be set to commit as well. diff --git a/git/refs/log.py b/git/refs/log.py index 3bc42801..43441884 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -1,24 +1,24 @@ from git.util import ( - join_path, - Actor, - LockedFD, - LockFile, - assure_directory_exists, - to_native_path, - ) + join_path, + Actor, + LockedFD, + LockFile, + assure_directory_exists, + to_native_path, +) from gitdb.util import ( - bin_to_hex, - join, - file_contents_ro_filepath, - ) + bin_to_hex, + join, + file_contents_ro_filepath, +) from git.objects.util import ( - parse_date, - Serializable, - utctz_to_altz, - altz_to_utctz_str, - ) + parse_date, + Serializable, + utctz_to_altz, + altz_to_utctz_str, +) import time import os @@ -86,19 +86,19 @@ class RefLogEntry(tuple): info, msg = line.split('\t', 2) except ValueError: raise ValueError("line is missing tab separator") - #END handle first plit + # END handle first plit oldhexsha = info[:40] newhexsha = info[41:81] for hexsha in (oldhexsha, newhexsha): if not cls._re_hexsha_only.match(hexsha): raise ValueError("Invalid hexsha: %s" % hexsha) # END if hexsha re doesn't match - #END for each hexsha + # END for each hexsha email_end = info.find('>', 82) if email_end == -1: raise ValueError("Missing token: >") - #END handle missing end brace + # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) time, tz_offset = parse_date(info[email_end + 2:]) @@ -136,13 +136,13 @@ class RefLog(list, Serializable): except OSError: # it is possible and allowed that the file doesn't exist ! return - #END handle invalid log + # END handle invalid log try: self._deserialize(fmap) finally: fmap.close() - #END handle closing of handle + # END handle closing of handle #{ Interface @@ -174,13 +174,13 @@ class RefLog(list, Serializable): new_entry = RefLogEntry.from_line if isinstance(stream, basestring): stream = file_contents_ro_filepath(stream) - #END handle stream type + # END handle stream type while True: line = stream.readline() if not line: return yield new_entry(line.strip()) - #END endless loop + # END endless loop @classmethod def entry_at(cls, filepath, index): @@ -204,15 +204,15 @@ class RefLog(list, Serializable): line = fp.readline() if not line: break - #END abort on eof - #END handle runup + # END abort on eof + # END handle runup if i != index or not line: raise IndexError - #END handle exception + # END handle exception return RefLogEntry.from_line(line.strip()) - #END handle index + # END handle index def to_file(self, filepath): """Write the contents of the reflog instance to a file at the given filepath. @@ -228,7 +228,7 @@ class RefLog(list, Serializable): # on failure it rolls back automatically, but we make it clear lfd.rollback() raise - #END handle change + # END handle change @classmethod def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message): @@ -248,11 +248,12 @@ class RefLog(list, Serializable): do not interfere with readers.""" if len(oldbinsha) != 20 or len(newbinsha) != 20: raise ValueError("Shas need to be given in binary format") - #END handle sha type + # END handle sha type assure_directory_exists(filepath, is_file=True) committer = isinstance(config_reader, Actor) and config_reader or Actor.committer(config_reader) - entry = RefLogEntry((bin_to_hex(oldbinsha), bin_to_hex(newbinsha), committer, (int(time.time()), time.altzone), message)) - + entry = RefLogEntry( + (bin_to_hex(oldbinsha), bin_to_hex(newbinsha), committer, (int(time.time()), time.altzone), message)) + lf = LockFile(filepath) lf._obtain_lock_or_raise() @@ -262,7 +263,7 @@ class RefLog(list, Serializable): finally: fd.close() lf._release_lock() - #END handle write operation + # END handle write operation return entry @@ -271,7 +272,7 @@ class RefLog(list, Serializable): :return: self""" if self._path is None: raise ValueError("Instance was not initialized with a path, use to_file(...) instead") - #END assert path + # END assert path self.to_file(self._path) return self @@ -285,7 +286,7 @@ class RefLog(list, Serializable): # write all entries for e in self: write(repr(e)) - #END for each entry + # END for each entry def _deserialize(self, stream): self.extend(self.iter_entries(stream)) diff --git a/git/refs/reference.py b/git/refs/reference.py index 72494e0a..f71ded72 100644 --- a/git/refs/reference.py +++ b/git/refs/reference.py @@ -1,13 +1,13 @@ from symbolic import SymbolicReference from git.util import ( - LazyMixin, - Iterable, - ) + LazyMixin, + Iterable, +) from gitdb.util import ( - isfile, - hex_to_bin - ) + isfile, + hex_to_bin +) __all__ = ["Reference"] @@ -21,7 +21,7 @@ def require_remote_ref_path(func): if not self.is_remote(): raise ValueError("ref path does not point to a remote reference: %s" % self.path) return func(self, *args) - #END wrapper + # END wrapper wrapper.__name__ = func.__name__ return wrapper #}END utilites @@ -61,8 +61,8 @@ class Reference(SymbolicReference, LazyMixin, Iterable): head = self.repo.head if not head.is_detached and head.ref == self: oldbinsha = self.commit.binsha - #END handle commit retrieval - #END handle message is set + # END handle commit retrieval + # END handle message is set super(Reference, self).set_object(object, logmsg) @@ -80,7 +80,7 @@ class Reference(SymbolicReference, LazyMixin, Iterable): # * scenarios (even 100% of the default ones). # */ self.repo.head.log_append(oldbinsha, logmsg) - #END check if the head + # END check if the head # NOTE: Don't have to overwrite properties as the will only work without a the log diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index fcb1336e..1470c879 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -1,23 +1,23 @@ import os from git.objects import Object, Commit from git.util import ( - join_path, - join_path_native, - to_native_path_linux, - assure_directory_exists - ) + join_path, + join_path_native, + to_native_path_linux, + assure_directory_exists +) from gitdb.exc import BadObject from gitdb.util import ( - join, - dirname, - isdir, - exists, - isfile, - rename, - hex_to_bin, - LockedFD - ) + join, + dirname, + isdir, + exists, + isfile, + rename, + hex_to_bin, + LockedFD +) from log import RefLog @@ -135,7 +135,8 @@ class SymbolicReference(object): # NOTE: We are not a symbolic ref if we are in a packed file, as these # are excluded explictly for sha, path in cls._iter_packed_refs(repo): - if path != ref_path: continue + if path != ref_path: + continue tokens = (sha, path) break # END for each packed ref @@ -170,11 +171,11 @@ class SymbolicReference(object): obj = self._get_object() if obj.type == 'tag': obj = obj.object - #END dereference tag + # END dereference tag if obj.type != Commit.type: raise TypeError("Symbolic Reference pointed to object %r, commit was required" % obj) - #END handle type + # END handle type return obj def set_commit(self, commit, logmsg=None): @@ -194,12 +195,12 @@ class SymbolicReference(object): invalid_type = self.repo.rev_parse(commit).type != Commit.type except BadObject: raise ValueError("Invalid object: %s" % commit) - #END handle exception + # END handle exception # END verify type if invalid_type: raise ValueError("Need commit, got %r" % commit) - #END handle raise + # END handle raise # we leave strings to the rev-parse method below self.set_object(commit, logmsg) @@ -218,7 +219,7 @@ class SymbolicReference(object): :return: self""" if isinstance(object, SymbolicReference): object = object.object - #END resolve references + # END resolve references is_detached = True try: @@ -284,7 +285,7 @@ class SymbolicReference(object): # typecheck if obj is not None and self._points_to_commits_only and obj.type != Commit.type: raise TypeError("Require commit, got %r" % obj) - #END verify type + # END verify type oldbinsha = None if logmsg is not None: @@ -292,8 +293,8 @@ class SymbolicReference(object): oldbinsha = self.commit.binsha except ValueError: oldbinsha = Commit.NULL_BIN_SHA - #END handle non-existing - #END retrieve old hexsha + # END handle non-existing + # END retrieve old hexsha fpath = self.abspath assure_directory_exists(fpath, is_file=True) @@ -306,7 +307,7 @@ class SymbolicReference(object): # Adjust the reflog if logmsg is not None: self.log_append(oldbinsha, logmsg) - #END handle reflog + # END handle reflog return self @@ -355,7 +356,7 @@ class SymbolicReference(object): :param newbinsha: The sha the ref points to now. If None, our current commit sha will be used :return: added RefLogEntry instance""" - # NOTE: we use the committer of the currently active commit - this should be + # NOTE: we use the committer of the currently active commit - this should be # correct to allow overriding the committer on a per-commit level. # See https://github.com/gitpython-developers/GitPython/pull/146 try: @@ -363,9 +364,9 @@ class SymbolicReference(object): except ValueError: committer_or_reader = self.repo.config_reader() # end handle newly cloned repositories - return RefLog.append_entry(committer_or_reader, RefLog.path(self), oldbinsha, - (newbinsha is None and self.commit.binsha) or newbinsha, - message) + return RefLog.append_entry(committer_or_reader, RefLog.path(self), oldbinsha, + (newbinsha is None and self.commit.binsha) or newbinsha, + message) def log_entry(self, index): """:return: RefLogEntry at the given index @@ -422,7 +423,7 @@ class SymbolicReference(object): # If we deleted the last line and this one is a tag-reference object, # we drop it as well if ( line.startswith('#') or full_ref_path not in line ) and \ - (not dropped_last_line or dropped_last_line and not line.startswith('^')): + (not dropped_last_line or dropped_last_line and not line.startswith('^')): new_lines.append(line) dropped_last_line = False continue @@ -447,7 +448,7 @@ class SymbolicReference(object): reflog_path = RefLog.path(cls(repo, full_ref_path)) if os.path.isfile(reflog_path): os.remove(reflog_path) - #END remove reflog + # END remove reflog @classmethod def _create(cls, repo, path, resolve, reference, force, logmsg=None): @@ -472,7 +473,8 @@ class SymbolicReference(object): target_data = "ref: " + target_data existing_data = open(abs_ref_path, 'rb').read().strip() if existing_data != target_data: - raise OSError("Reference at %r does already exist, pointing to %r, requested was %r" % (full_ref_path, existing_data, target_data)) + raise OSError("Reference at %r does already exist, pointing to %r, requested was %r" % + (full_ref_path, existing_data, target_data)) # END no force handling ref = cls(repo, full_ref_path) |