changeset 12951:101366ad816c stable

graphmod: safer code when a changeset has two identical parents While this situation should never under normal use, some real life repos sometimes contain such changesets (older hg versions, broken rebases, etc...) hgweb was displaying an "Internal error" in this case, and graphlog displayed a redundant branch all the way to null: it does not cost us much to just ignore this extra parent when constructing the DAG.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Mon, 08 Nov 2010 22:45:56 +0900
parents 2405b4a5964a
children f6b88f3bcc03 f3183932c487
files mercurial/graphmod.py tests/test-glog.t
diffstat 2 files changed, 39 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/graphmod.py	Sun Nov 07 18:23:48 2010 +0900
+++ b/mercurial/graphmod.py	Mon Nov 08 22:45:56 2010 +0900
@@ -32,7 +32,7 @@
     cur = start
     while cur >= stop:
         ctx = repo[cur]
-        parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev]
+        parents = set([p.rev() for p in ctx.parents() if p.rev() != nullrev])
         yield (cur, CHANGESET, ctx, sorted(parents))
         cur -= 1
 
@@ -47,7 +47,7 @@
     count = 0
     while filerev >= 0 and rev > stop:
         fctx = repo.filectx(path, fileid=filerev)
-        parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
+        parents = set([f.linkrev() for f in fctx.parents() if f.path() == path])
         rev = fctx.rev()
         if rev <= start:
             yield (rev, CHANGESET, fctx.changectx(), sorted(parents))
@@ -65,7 +65,7 @@
     include = set(nodes)
     for node in nodes:
         ctx = repo[node]
-        parents = [p.rev() for p in ctx.parents() if p.node() in include]
+        parents = set([p.rev() for p in ctx.parents() if p.node() in include])
         yield (ctx.rev(), CHANGESET, ctx, sorted(parents))
 
 def colored(dag):
--- a/tests/test-glog.t	Sun Nov 07 18:23:48 2010 +0900
+++ b/tests/test-glog.t	Mon Nov 08 22:45:56 2010 +0900
@@ -887,3 +887,39 @@
   | |  summary:     (33) head
   | |
 
+Do not crash or produce strange graphs if history is buggy
+
+  $ commit 36 "buggy merge: identical parents" 35 35
+  $ hg glog -l5
+  @  changeset:   36:95fa8febd08a
+  |  tag:         tip
+  |  parent:      35:9159c3644c5e
+  |  parent:      35:9159c3644c5e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:36 1970 +0000
+  |  summary:     (36) buggy merge: identical parents
+  |
+  o  changeset:   35:9159c3644c5e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     0
+  |
+  o  changeset:   34:fea3ac5810e0
+  |  parent:      32:d06dffa21a31
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:34 1970 +0000
+  |  summary:     (34) head
+  |
+  | o  changeset:   33:68608f5145f9
+  | |  parent:      18:1aa84d96232a
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:33 1970 +0000
+  | |  summary:     (33) head
+  | |
+  o |    changeset:   32:d06dffa21a31
+  |\ \   parent:      27:886ed638191b
+  | | |  parent:      31:621d83e11f67
+  | | |  user:        test
+  | | |  date:        Thu Jan 01 00:00:32 1970 +0000
+  | | |  summary:     (32) expand
+  | | |