changeset 8114:2c224062eba7

vcs: fix get_file_annotate - consistently bind sha so it has the right value when executing The Git implementation did *not* save the sha value in the lambda expression for the "changeset lazy loader". Thus, if the generator had moved on and assigned a different value to sha when the expression was executed, it would use the "wrong" sha. Fixed by doing as the Hg implementation: bind the sha value as value of a default parameter when defining the lambda expression. The Hg implementation did however also save the line - it is not used, and there is no need for that.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 25 Dec 2019 15:30:11 +0100
parents c78fd87d362b
children 2c7308652445
files kallithea/lib/vcs/backends/git/changeset.py kallithea/lib/vcs/backends/hg/changeset.py
diffstat 2 files changed, 6 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/git/changeset.py	Sat Dec 28 23:01:23 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/changeset.py	Wed Dec 25 15:30:11 2019 +0100
@@ -321,11 +321,10 @@
         """
         Returns a generator of four element tuples with
             lineno, sha, changeset lazy loader and line
-
-        TODO: This function now uses os underlying 'git' command which is
-        generally not good. Should be replaced with algorithm iterating
-        commits.
         """
+        # TODO: This function now uses os underlying 'git' command which is
+        # generally not good. Should be replaced with algorithm iterating
+        # commits.
         cmd = ['blame', '-l', '--root', '-r', self.id, '--', path]
         # -l     ==> outputs long shas (and we need all 40 characters)
         # --root ==> doesn't put '^' character for boundaries
@@ -333,9 +332,8 @@
         so = self.repository.run_git_command(cmd)
 
         for i, blame_line in enumerate(so.split('\n')[:-1]):
-            ln_no = i + 1
             sha, line = re.split(r' ', blame_line, 1)
-            yield (ln_no, sha, lambda: self.repository.get_changeset(sha), line)
+            yield (i + 1, sha, lambda sha=sha: self.repository.get_changeset(sha), line)
 
     def fill_archive(self, stream=None, kind='tgz', prefix=None,
                      subrepos=False):
--- a/kallithea/lib/vcs/backends/hg/changeset.py	Sat Dec 28 23:01:23 2019 +0100
+++ b/kallithea/lib/vcs/backends/hg/changeset.py	Wed Dec 25 15:30:11 2019 +0100
@@ -287,9 +287,9 @@
         """
         annotations = self._get_filectx(path).annotate()
         annotation_lines = [(annotateline.fctx, annotateline.text) for annotateline in annotations]
-        for i, (fctx, l) in enumerate(annotation_lines):
+        for i, (fctx, line) in enumerate(annotation_lines):
             sha = ascii_str(fctx.hex())
-            yield (i + 1, sha, lambda sha=sha, l=l: self.repository.get_changeset(sha), l)
+            yield (i + 1, sha, lambda sha=sha: self.repository.get_changeset(sha), line)
 
     def fill_archive(self, stream=None, kind='tgz', prefix=None,
                      subrepos=False):