Patchwork [2,of,4,hyperblame] annotate: make pair take all parents to pair against

login
register
mail settings
Submitter Siddharth Agarwal
Date May 25, 2017, 2:39 a.m.
Message ID <6e8ec82c40f311e7aa5f0002c991e86a-964d56b0@7511894063d3764ff01ea8111f5a004d7dd700ed078797c204a24e620ddb965c>
Download mbox | patch
Permalink /patch/20892/
State Accepted
Headers show

Comments

Siddharth Agarwal - May 25, 2017, 2:39 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1495672808 25200
#      Wed May 24 17:40:08 2017 -0700
# Node ID 0f28e90b0fb95733de10f8d1524c345fe5949315
# Parent  de6d23b18ea0e4e6eb46b509639c63b2318ac979
annotate: make pair take all parents to pair against

In upcoming patches we'll need to be aware of all parents at the same time.

This also exposes a potential bug: if a line can be annotated with both parents
of a merge commit, it'll always be annotated with p2, not p1. I'm not sure if
that's what we want, but at least the code makes it clear now.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1044,8 +1044,8 @@  class basefilectx(object):
             if ready:
                 visit.pop()
                 curr = decorate(f.data(), f)
+                curr = _annotatepair([hist[p] for p in pl], curr, diffopts)
                 for p in pl:
-                    curr = _annotatepair(hist[p], curr, diffopts)
                     if needed[p] == 1:
                         del hist[p]
                         del needed[p]
@@ -1073,13 +1073,17 @@  class basefilectx(object):
             c = visit.pop(max(visit))
             yield c
 
-def _annotatepair(parent, child, diffopts):
-    blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts)
-    for (a1, a2, b1, b2), t in blocks:
-        # Changed blocks ('!') or blocks made only of blank lines ('~')
-        # belong to the child.
-        if t == '=':
-            child[0][b1:b2] = parent[0][a1:a2]
+def _annotatepair(parents, child, diffopts):
+    pblocks = [(parent, mdiff.allblocks(parent[1], child[1], opts=diffopts))
+               for parent in parents]
+    # Mercurial currently prefers p2 over p1 for annotate.
+    # TODO: change this?
+    for parent, blocks in pblocks:
+        for (a1, a2, b1, b2), t in blocks:
+            # Changed blocks ('!') or blocks made only of blank lines ('~')
+            # belong to the child.
+            if t == '=':
+                child[0][b1:b2] = parent[0][a1:a2]
     return child
 
 class filectx(basefilectx):