From 0685d629f86ef27e4b68947f63cb53f2e750d3a7 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Tue, 22 Oct 2019 21:32:58 +0530 Subject: [PATCH 01/11] fixed classmethod argument PYL-C0202 --- AUTHORS | 1 + git/refs/log.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index e91fd78b1..66a4329f9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -34,5 +34,6 @@ Contributors are: -Stefan Stancu -César Izurieta -Arthur Milchior +-Anil Khatri Portions derived from other open source works and are clearly marked. diff --git a/git/refs/log.py b/git/refs/log.py index e8c2d7ada..8d5579021 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -84,7 +84,7 @@ def message(self): return self[4] @classmethod - def new(self, oldhexsha, newhexsha, actor, time, tz_offset, message): + def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) From d52c5783c08f4f9e397c4dad55bbfee2b8c61c5f Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Tue, 22 Oct 2019 21:40:35 +0530 Subject: [PATCH 02/11] fixed unused variable found PYL-W0612 --- git/test/test_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/test/test_docs.py b/git/test/test_docs.py index a1fea4540..a393ded8d 100644 --- a/git/test/test_docs.py +++ b/git/test/test_docs.py @@ -349,7 +349,7 @@ def test_references_and_objects(self, rw_dir): # The index contains all blobs in a flat list assert len(list(index.iter_blobs())) == len([o for o in repo.head.commit.tree.traverse() if o.type == 'blob']) # Access blob objects - for (path, _stage), entry in index.entries.items(): + for (_path, _stage), entry in index.entries.items(): pass new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name') open(new_file_path, 'w').close() From dba01d3738912a59b468b76922642e8983d8995b Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Tue, 22 Oct 2019 21:46:53 +0530 Subject: [PATCH 03/11] silence PYL-W0401 --- git/exc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/exc.py b/git/exc.py index 4865da944..df79747f2 100644 --- a/git/exc.py +++ b/git/exc.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php """ Module containing all exceptions thrown throughout the git package, """ -from gitdb.exc import * # NOQA @UnusedWildImport +from gitdb.exc import * # NOQA @UnusedWildImport skipcq: PYL-W0401 from git.compat import UnicodeMixin, safe_decode, string_types From 607d8aa3461e764cbe008f2878c2ac0fa79cf910 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Tue, 22 Oct 2019 21:50:12 +0530 Subject: [PATCH 04/11] silence PYL-W0614 --- git/exc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/exc.py b/git/exc.py index df79747f2..1c4d50056 100644 --- a/git/exc.py +++ b/git/exc.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php """ Module containing all exceptions thrown throughout the git package, """ -from gitdb.exc import * # NOQA @UnusedWildImport skipcq: PYL-W0401 +from gitdb.exc import * # NOQA @UnusedWildImport skipcq: PYL-W0401, PYL-W0614 from git.compat import UnicodeMixin, safe_decode, string_types From 5eb8289e80c8b9fe48456e769e0421b7f9972af3 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Wed, 23 Oct 2019 23:06:48 +0530 Subject: [PATCH 05/11] fix Loop variable used outside the loop --- git/diff.py | 10 ++++++---- git/objects/submodule/base.py | 2 +- git/refs/log.py | 2 +- git/util.py | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/git/diff.py b/git/diff.py index 10cb9f02c..6a5d51cc1 100644 --- a/git/diff.py +++ b/git/diff.py @@ -415,13 +415,14 @@ def _index_from_patch_format(cls, repo, proc): text = b''.join(text) index = DiffIndex() previous_header = None - for header in cls.re_header.finditer(text): + header = None + for _header in cls.re_header.finditer(text): a_path_fallback, b_path_fallback, \ old_mode, new_mode, \ rename_from, rename_to, \ new_file_mode, deleted_file_mode, \ a_blob_id, b_blob_id, b_mode, \ - a_path, b_path = header.groups() + a_path, b_path = _header.groups() new_file, deleted_file = bool(new_file_mode), bool(deleted_file_mode) @@ -431,7 +432,7 @@ def _index_from_patch_format(cls, repo, proc): # Our only means to find the actual text is to see what has not been matched by our regex, # and then retro-actively assign it to our index if previous_header is not None: - index[-1].diff = text[previous_header.end():header.start()] + index[-1].diff = text[previous_header.end():_header.start()] # end assign actual diff # Make sure the mode is set if the path is set. Otherwise the resulting blob is invalid @@ -450,7 +451,8 @@ def _index_from_patch_format(cls, repo, proc): rename_to, None, None, None)) - previous_header = header + previous_header = _header + header = _header # end for each header we parse if index: index[-1].diff = text[header.end():] diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index bc76bcceb..fe2859c6d 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -846,7 +846,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False): # have to manually delete references as python's scoping is # not existing, they could keep handles open ( on windows this is a problem ) if len(rrefs): - del(rref) + del(rref) # skipcq:PYL-W0631 # END handle remotes del(rrefs) del(remote) diff --git a/git/refs/log.py b/git/refs/log.py index 8d5579021..01673ae0c 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -228,7 +228,7 @@ def entry_at(cls, filepath, index): # END abort on eof # END handle runup - if i != index or not line: + if i != index or not line: # skipcq:PYL-W0631 raise IndexError # END handle exception diff --git a/git/util.py b/git/util.py index 99600e377..974657e6f 100644 --- a/git/util.py +++ b/git/util.py @@ -133,7 +133,7 @@ def join_path(a, *p): '/' instead of possibly '\' on windows.""" path = a for b in p: - if len(b) == 0: + if not b: continue if b.startswith('/'): path += b[1:] @@ -386,7 +386,7 @@ def _parse_progress_line(self, line): # Compressing objects: 100% (2/2) # Compressing objects: 100% (2/2), done. self._cur_line = line = line.decode('utf-8') if isinstance(line, bytes) else line - if len(self.error_lines) > 0 or self._cur_line.startswith(('error:', 'fatal:')): + if self.error_lines or self._cur_line.startswith(('error:', 'fatal:')): self.error_lines.append(self._cur_line) return From 597fb586347bea58403c0d04ece26de5b6d74423 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Wed, 23 Oct 2019 23:12:14 +0530 Subject: [PATCH 06/11] fix File opened without the with statement --- git/refs/log.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/git/refs/log.py b/git/refs/log.py index 01673ae0c..bc6d44865 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -217,23 +217,24 @@ def entry_at(cls, filepath, index): the index is negative """ fp = open(filepath, 'rb') - if index < 0: - return RefLogEntry.from_line(fp.readlines()[index].strip()) - else: - # read until index is reached - for i in xrange(index + 1): - line = fp.readline() - if not line: - break - # END abort on eof - # END handle runup - - if i != index or not line: # skipcq:PYL-W0631 - raise IndexError - # END handle exception - - return RefLogEntry.from_line(line.strip()) - # END handle index + with open(filepath, 'rb') as fp: + if index < 0: + return RefLogEntry.from_line(fp.readlines()[index].strip()) + else: + # read until index is reached + for i in xrange(index + 1): + line = fp.readline() + if not line: + break + # END abort on eof + # END handle runup + + if i != index or not line: # skipcq:PYL-W0631 + 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. From 284f89d768080cb86e0d986bfa1dd503cfe6b682 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Wed, 23 Oct 2019 23:34:05 +0530 Subject: [PATCH 07/11] silenced iter returns a non-iterator --- git/cmd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/git/cmd.py b/git/cmd.py index 2d288b25f..661e9bb7d 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -497,6 +497,7 @@ def readlines(self, size=-1): # END readline loop return out + # skipcq: PYL-E0301 def __iter__(self): return self From 1dc46d735003df8ff928974cb07545f69f8ea411 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Wed, 23 Oct 2019 23:50:31 +0530 Subject: [PATCH 08/11] resolved all minor issues arised by last fix patch --- git/objects/submodule/base.py | 2 +- git/refs/log.py | 45 +++++++++++++++++------------------ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index fe2859c6d..04ca02218 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -846,7 +846,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False): # have to manually delete references as python's scoping is # not existing, they could keep handles open ( on windows this is a problem ) if len(rrefs): - del(rref) # skipcq:PYL-W0631 + del(rref) # skipcq: PYL-W0631 # END handle remotes del(rrefs) del(remote) diff --git a/git/refs/log.py b/git/refs/log.py index bc6d44865..741151458 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -46,13 +46,13 @@ def __repr__(self): def format(self): """:return: a string suitable to be placed in a reflog file""" act = self.actor - time = self.time + time_ = self.time_ return u"{} {} {} <{}> {!s} {}\t{}\n".format(self.oldhexsha, self.newhexsha, act.name, act.email, - time[0], - altz_to_utctz_str(time[1]), + time_[0], + altz_to_utctz_str(time_[1]), self.message) @property @@ -71,7 +71,7 @@ def actor(self): return self[2] @property - def time(self): + def time_(self): """time as tuple: * [0] = int(time) @@ -84,12 +84,12 @@ def message(self): return self[4] @classmethod - def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): + def new(cls, oldhexsha, newhexsha, actor, time_, tz_offset, message): """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) # END check types - return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) + return RefLogEntry((oldhexsha, newhexsha, actor, (time_, tz_offset), message)) @classmethod def from_line(cls, line): @@ -121,9 +121,9 @@ def from_line(cls, line): # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) - time, tz_offset = parse_date(info[email_end + 2:]) + time_, tz_offset = parse_date(info[email_end + 2:]) - return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) + return RefLogEntry((oldhexsha, newhexsha, actor, (time_, tz_offset), msg)) class RefLog(list, Serializable): @@ -220,21 +220,20 @@ def entry_at(cls, filepath, index): with open(filepath, 'rb') as fp: if index < 0: return RefLogEntry.from_line(fp.readlines()[index].strip()) - else: - # read until index is reached - for i in xrange(index + 1): - line = fp.readline() - if not line: - break - # END abort on eof - # END handle runup - - if i != index or not line: # skipcq:PYL-W0631 - raise IndexError - # END handle exception - - return RefLogEntry.from_line(line.strip()) - # END handle index + # read until index is reached + for i in xrange(index + 1): + line = fp.readline() + if not line: + break + # END abort on eof + # END handle runup + + if i != index or not line: # skipcq:PYL-W0631 + 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. From 4dda3cbbd15e7a415c1cbd33f85d7d6d0e3a307a Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Thu, 24 Oct 2019 21:17:54 +0530 Subject: [PATCH 09/11] silance Re-defined variable from outer scope --- git/refs/log.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/git/refs/log.py b/git/refs/log.py index 741151458..243287ad1 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -46,13 +46,13 @@ def __repr__(self): def format(self): """:return: a string suitable to be placed in a reflog file""" act = self.actor - time_ = self.time_ + time = self.time return u"{} {} {} <{}> {!s} {}\t{}\n".format(self.oldhexsha, self.newhexsha, act.name, act.email, - time_[0], - altz_to_utctz_str(time_[1]), + time[0], + altz_to_utctz_str(time[1]), self.message) @property @@ -71,7 +71,7 @@ def actor(self): return self[2] @property - def time_(self): + def time(self): """time as tuple: * [0] = int(time) @@ -83,14 +83,16 @@ def message(self): """Message describing the operation that acted on the reference""" return self[4] + # skipcq: PYL-W0621 @classmethod - def new(cls, oldhexsha, newhexsha, actor, time_, tz_offset, message): + def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) # END check types - return RefLogEntry((oldhexsha, newhexsha, actor, (time_, tz_offset), message)) + return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) + # skipcq: PYL-W0621 @classmethod def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. @@ -121,9 +123,9 @@ def from_line(cls, line): # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) - time_, tz_offset = parse_date(info[email_end + 2:]) + time, tz_offset = parse_date(info[email_end + 2:]) - return RefLogEntry((oldhexsha, newhexsha, actor, (time_, tz_offset), msg)) + return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) class RefLog(list, Serializable): From 225529c8baaa6ee65b1b23fc1d79b99bf49ebfb1 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Thu, 24 Oct 2019 21:22:53 +0530 Subject: [PATCH 10/11] silence PYL-W0621 --- git/refs/log.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/git/refs/log.py b/git/refs/log.py index 243287ad1..ab5d75a35 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -83,16 +83,14 @@ def message(self): """Message describing the operation that acted on the reference""" return self[4] - # skipcq: PYL-W0621 @classmethod - def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): + def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): # skipcq: PYL-W0621 """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) # END check types return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) - # skipcq: PYL-W0621 @classmethod def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. @@ -123,7 +121,7 @@ def from_line(cls, line): # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) - time, tz_offset = parse_date(info[email_end + 2:]) + time, tz_offset = parse_date(info[email_end + 2:]) # skipcq: PYL-W0621 return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) From 9932e647aaaaf6edd3a407b75edd08a96132ef5c Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Mon, 28 Oct 2019 15:34:09 +0530 Subject: [PATCH 11/11] removed extra line as per code review --- git/refs/log.py | 1 - 1 file changed, 1 deletion(-) diff --git a/git/refs/log.py b/git/refs/log.py index ab5d75a35..432232ac7 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -216,7 +216,6 @@ def entry_at(cls, filepath, index): all other lines. Nonetheless, the whole file has to be read if the index is negative """ - fp = open(filepath, 'rb') with open(filepath, 'rb') as fp: if index < 0: return RefLogEntry.from_line(fp.readlines()[index].strip())