Commits

Hidetaka Iwata  committed 3990e5a

graph: fix problem about `showgraftsource` and `branch`

when specifying `showgraftsource` and `branch` to revision_grapher,
source revisions are always shown even if they belong to another branch.

  • Participants
  • Parent commits 0ea9c6b
  • Branches stable

Comments (0)

Files changed (2)

File tests/graph_test.py

     5 [source=1]
     4
     | 3
-    | 2
+    | 2 [branch=foo]
     | 1
     |/
     0
     }
     assert_equal(expectedtable, actualtable)
 
+def test_grapher_showgraftsource_with_branch():
+    repo = openrepo('bulkgraft')
+    grapher = graph.revision_grapher(
+        repo, {"showgraftsource": True, "branch": "default"})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                            # wt
+        None: ['0-0'],      # |
+                            # 7
+        7: ['0-0'],         # |
+                            # 6
+        6: ['0-0'],         # |
+                            # 5
+        5: ['0-0', '0-1G'], # |\
+                            # 4 :
+        4: ['0-0', '1-1G'], # | :
+                            # | 1
+        1: ['0-0', '1-0'],  # |/
+                            # 0
+        0: [],
+    }
+    assert_equal(expectedtable, actualtable)
+
 def test_grapher_hidegraftsource():
     repo = openrepo('bulkgraft')
     grapher = graph.revision_grapher(repo, {})

File tortoisehg/hgqt/graph.py

     activeedges = []  # order is not important
 
     if opts.get('allparents') or not branch:
-        def getparents(ctx):
-            return [x for x in ctx.parents() if x]
+        def hiddenctx(ctx):
+            return not ctx
     else:
-        def getparents(ctx):
-            return [x for x in ctx.parents()
-                    if x and x.branch() == branch]
+        def hiddenctx(ctx):
+            return not ctx or ctx.branch() != branch
+
+    def getparents(ctx):
+        return [x for x in ctx.parents() if not hiddenctx(x)]
 
     rev_color = RevColorPalette(getparents)
 
             if src_rev_str is not None and src_rev_str in repo:
                 src = repo[src_rev_str]
                 src_rev = src.rev()
-                if stop_rev <= src_rev < curr_rev and not hidden(src_rev):
+                if stop_rev <= src_rev < curr_rev and \
+                        not hidden(src_rev) and not hiddenctx(src):
                     parents.append((src, LINE_TYPE_GRAFT, False))
             for octx in obsoleteutil.first_known_precursors(ctx):
                 src_rev = octx.rev()
-                if stop_rev <= src_rev < curr_rev and not hidden(src_rev):
+                if stop_rev <= src_rev < curr_rev and \
+                        not hidden(src_rev) and not hiddenctx(octx):
                     parents.append((octx, LINE_TYPE_OBSOLETE, False))
         parents_to_add = []
         for pctx, link_type, is_p1 in parents: