From f5d11b750ecc982541d1f936488248f0b42d75d3 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:15:50 +0100 Subject: pep8 linting (whitespaces) W191 indentation contains tabs E221 multiple spaces before operator E222 multiple spaces after operator E225 missing whitespace around operator E271 multiple spaces after keyword W292 no newline at end of file W293 blank line contains whitespace W391 blank line at end of file --- git/refs/log.py | 80 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index 9a719ec0..d5d8d7d4 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -32,42 +32,42 @@ class RefLogEntry(tuple): _fmt = "%s %s %s <%s> %i %s\t%s\n" _re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$') __slots__ = tuple() - + def __repr__(self): """Representation of ourselves in git reflog format""" act = self.actor time = self.time return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email, time[0], altz_to_utctz_str(time[1]), self.message) - + @property def oldhexsha(self): """The hexsha to the commit the ref pointed to before the change""" return self[0] - + @property def newhexsha(self): """The hexsha to the commit the ref now points to, after the change""" return self[1] - + @property def actor(self): """Actor instance, providing access""" return self[2] - + @property def time(self): """time as tuple: - + * [0] = int(time) * [1] = int(timezone_offset) in time.altzone format """ return self[3] - + @property def message(self): """Message describing the operation that acted on the reference""" return self[4] - + @classmethod def new(self, oldhexsha, newhexsha, actor, time, tz_offset, message): """:return: New instance of a RefLogEntry""" @@ -75,7 +75,7 @@ class RefLogEntry(tuple): raise ValueError("Need actor instance, got %s" % actor) # END check types return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) - + @classmethod def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. @@ -93,32 +93,32 @@ class RefLogEntry(tuple): raise ValueError("Invalid hexsha: %s" % hexsha) # END if hexsha re doesn't match #END for each hexsha - + email_end = info.find('>', 82) if email_end == -1: raise ValueError("Missing token: >") #END handle missing end brace - + actor = Actor._from_string(info[82:email_end+1]) time, tz_offset = parse_date(info[email_end+2:]) - + return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) - + class RefLog(list, Serializable): """A reflog contains reflog entries, each of which defines a certain state of the head in question. Custom query methods allow to retrieve log entries by date or by other criteria. - + Reflog entries are orded, the first added entry is first in the list, the last entry, i.e. the last change of the head or reference, is last in the list.""" - + __slots__ = ('_path', ) - + def __new__(cls, filepath=None): inst = super(RefLog, cls).__new__(cls) return inst - + def __init__(self, filepath=None): """Initialize this instance with an optional filepath, from which we will initialize our data. The path is also used to write changes back using @@ -127,7 +127,7 @@ class RefLog(list, Serializable): if filepath is not None: self._read_from_file() # END handle filepath - + def _read_from_file(self): try: fmap = file_contents_ro_filepath(self._path, stream=True, allow_mmap=True) @@ -135,15 +135,15 @@ class RefLog(list, Serializable): # it is possible and allowed that the file doesn't exist ! return #END handle invalid log - + try: self._deserialize(fmap) finally: fmap.close() #END handle closing of handle - + #{ Interface - + @classmethod def from_file(cls, filepath): """ @@ -152,7 +152,7 @@ class RefLog(list, Serializable): :param filepath: path to reflog :raise ValueError: If the file could not be read or was corrupted in some way""" return cls(filepath) - + @classmethod def path(cls, ref): """ @@ -161,7 +161,7 @@ class RefLog(list, Serializable): file though. :param ref: SymbolicReference instance""" return join(ref.repo.git_dir, "logs", to_native_path(ref.path)) - + @classmethod def iter_entries(cls, stream): """ @@ -179,16 +179,16 @@ class RefLog(list, Serializable): return yield new_entry(line.strip()) #END endless loop - + @classmethod def entry_at(cls, filepath, index): """:return: RefLogEntry at the given index :param filepath: full path to the index file from which to read the entry :param index: python list compatible index, i.e. it may be negative to specifiy an entry counted from the end of the list - + :raise IndexError: If the entry didn't exist - + .. note:: This method is faster as it only parses the entry at index, skipping all other lines. Nonetheless, the whole file has to be read if the index is negative @@ -204,20 +204,20 @@ class RefLog(list, Serializable): break #END abort on eof #END handle runup - + if i != index or not line: raise IndexError #END handle exception - + return RefLogEntry.from_line(line.strip()) #END handle index - + def to_file(self, filepath): """Write the contents of the reflog instance to a file at the given filepath. :param filepath: path to file, parent directories are assumed to exist""" lfd = LockedFD(filepath) assure_directory_exists(filepath, is_file=True) - + fp = lfd.open(write=True, stream=True) try: self._serialize(fp) @@ -227,11 +227,11 @@ class RefLog(list, Serializable): lfd.rollback() raise #END handle change - + @classmethod def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message): """Append a new log entry to the revlog at filepath. - + :param config_reader: configuration reader of the repository - used to obtain user information. May be None :param filepath: full path to the log file @@ -248,10 +248,10 @@ class RefLog(list, Serializable): #END handle sha type assure_directory_exists(filepath, is_file=True) entry = RefLogEntry((bin_to_hex(oldbinsha), bin_to_hex(newbinsha), Actor.committer(config_reader), (int(time.time()), time.altzone), message)) - + lf = LockFile(filepath) lf._obtain_lock_or_raise() - + fd = open(filepath, 'a') try: fd.write(repr(entry)) @@ -259,9 +259,9 @@ class RefLog(list, Serializable): fd.close() lf._release_lock() #END handle write operation - + return entry - + def write(self): """Write this instance's data to the file we are originating from :return: self""" @@ -270,19 +270,19 @@ class RefLog(list, Serializable): #END assert path self.to_file(self._path) return self - + #} END interface - + #{ Serializable Interface def _serialize(self, stream): lm1 = len(self) - 1 write = stream.write - + # write all entries for e in self: write(repr(e)) #END for each entry - + def _deserialize(self, stream): self.extend(self.iter_entries(stream)) #} END serializable interface -- cgit v1.2.1 From be34ec23c48d6d5d8fd2ef4491981f6fb4bab8e6 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:51:04 +0100 Subject: pep8 linting (blank lines expectations) E301 expected 1 blank line, found 0 E302 expected 2 blank lines, found 1 E303 too many blank lines (n) --- git/refs/log.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index d5d8d7d4..8917f3fa 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -28,6 +28,7 @@ __all__ = ["RefLog", "RefLogEntry"] class RefLogEntry(tuple): + """Named tuple allowing easy access to the revlog data fields""" _fmt = "%s %s %s <%s> %i %s\t%s\n" _re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$') @@ -106,6 +107,7 @@ class RefLogEntry(tuple): class RefLog(list, Serializable): + """A reflog contains reflog entries, each of which defines a certain state of the head in question. Custom query methods allow to retrieve log entries by date or by other criteria. -- cgit v1.2.1 From 614907b7445e2ed8584c1c37df7e466e3b56170f Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:56:53 +0100 Subject: pep8 linting (whitespace before/after) E201 whitespace after '(' E202 whitespace before ')' E203 whitespace before ':' E225 missing whitespace around operator E226 missing whitespace around arithmetic operator E227 missing whitespace around bitwise or shift operator E228 missing whitespace around modulo operator E231 missing whitespace after ',' E241 multiple spaces after ',' E251 unexpected spaces around keyword / parameter equals --- git/refs/log.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index 8917f3fa..c075e7a0 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -100,8 +100,8 @@ class RefLogEntry(tuple): raise ValueError("Missing token: >") #END handle missing end brace - actor = Actor._from_string(info[82:email_end+1]) - time, tz_offset = parse_date(info[email_end+2:]) + actor = Actor._from_string(info[82:email_end + 1]) + time, tz_offset = parse_date(info[email_end + 2:]) return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) @@ -200,7 +200,7 @@ class RefLog(list, Serializable): return RefLogEntry.from_line(fp.readlines()[index].strip()) else: # read until index is reached - for i in xrange(index+1): + for i in xrange(index + 1): line = fp.readline() if not line: break -- cgit v1.2.1 From c8e70749887370a99adeda972cc3503397b5f9a7 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 21:09:47 +0100 Subject: pep8 linting (trailing whitespace) W291 trailing whitespace --- git/refs/log.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index c075e7a0..7249aec5 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -15,7 +15,7 @@ from gitdb.util import ( from git.objects.util import ( parse_date, - Serializable, + Serializable, utctz_to_altz, altz_to_utctz_str, ) @@ -38,12 +38,12 @@ class RefLogEntry(tuple): """Representation of ourselves in git reflog format""" act = self.actor time = self.time - return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email, + return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email, time[0], altz_to_utctz_str(time[1]), self.message) @property def oldhexsha(self): - """The hexsha to the commit the ref pointed to before the change""" + """The hexsha to the commit the ref pointed to before the change""" return self[0] @property @@ -74,7 +74,7 @@ class RefLogEntry(tuple): """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) - # END check types + # END check types return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) @classmethod @@ -109,7 +109,7 @@ class RefLogEntry(tuple): class RefLog(list, Serializable): """A reflog contains reflog entries, each of which defines a certain state - of the head in question. Custom query methods allow to retrieve log entries + of the head in question. Custom query methods allow to retrieve log entries by date or by other criteria. Reflog entries are orded, the first added entry is first in the list, the last @@ -123,7 +123,7 @@ class RefLog(list, Serializable): def __init__(self, filepath=None): """Initialize this instance with an optional filepath, from which we will - initialize our data. The path is also used to write changes back using + initialize our data. The path is also used to write changes back using the write() method""" self._path = filepath if filepath is not None: @@ -149,17 +149,17 @@ class RefLog(list, Serializable): @classmethod def from_file(cls, filepath): """ - :return: a new RefLog instance containing all entries from the reflog + :return: a new RefLog instance containing all entries from the reflog at the given filepath - :param filepath: path to reflog + :param filepath: path to reflog :raise ValueError: If the file could not be read or was corrupted in some way""" return cls(filepath) @classmethod def path(cls, ref): """ - :return: string to absolute path at which the reflog of the given ref - instance would be found. The path is not guaranteed to point to a valid + :return: string to absolute path at which the reflog of the given ref + instance would be found. The path is not guaranteed to point to a valid file though. :param ref: SymbolicReference instance""" return join(ref.repo.git_dir, "logs", to_native_path(ref.path)) @@ -167,7 +167,7 @@ class RefLog(list, Serializable): @classmethod def iter_entries(cls, stream): """ - :return: Iterator yielding RefLogEntry instances, one for each line read + :return: Iterator yielding RefLogEntry instances, one for each line read sfrom the given stream. :param stream: file-like object containing the revlog in its native format or basestring instance pointing to a file to read""" @@ -186,13 +186,13 @@ class RefLog(list, Serializable): def entry_at(cls, filepath, index): """:return: RefLogEntry at the given index :param filepath: full path to the index file from which to read the entry - :param index: python list compatible index, i.e. it may be negative to + :param index: python list compatible index, i.e. it may be negative to specifiy an entry counted from the end of the list :raise IndexError: If the entry didn't exist .. note:: This method is faster as it only parses the entry at index, skipping - all other lines. Nonetheless, the whole file has to be read if + all other lines. Nonetheless, the whole file has to be read if the index is negative """ fp = open(filepath, 'rb') @@ -243,7 +243,7 @@ class RefLog(list, Serializable): :param write: If True, the changes will be written right away. Otherwise the change will not be written :return: RefLogEntry objects which was appended to the log - :note: As we are append-only, concurrent access is not a problem as we + :note: As we are append-only, concurrent access is not a problem as we do not interfere with readers.""" if len(oldbinsha) != 20 or len(newbinsha) != 20: raise ValueError("Shas need to be given in binary format") -- cgit v1.2.1