changeset 2336:93a37e13424f

obshistory: add a debugobshistory command to show obs history of a revs Add the debugobshistory command that accept a revision range and display the obsolescence containing each revision in the range. For the moment, it only displays the predecessors.
author Boris Feld <boris.feld@octobus.net>
date Wed, 10 May 2017 12:26:33 +0200
parents f7ce3b9167d6
children c0ed4adf965e
files hgext3rd/evolve/__init__.py tests/test-evolve-obshistory.t
diffstat 2 files changed, 243 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py	Wed May 10 12:16:01 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Wed May 10 12:26:33 2017 +0200
@@ -3249,3 +3249,62 @@
                 f.write(orig.topic())
 
     return merge.graft(repo, orig, pctx, ['local', 'graft'], True)
+
+@eh.command(
+    '^debugobshistory',
+    [('r', 'rev', [], _("revision to debug"))],
+    _('hg debugobshistory [OPTION]... [-r] [REV]'))
+def debugobshistory(ui, repo, *revs, **opts):
+    revs = scmutil.revrange(repo, revs)
+
+    for rev in revs:
+        _debugobshistorysingle(ui, repo, rev)
+
+def _debugobshistorysingle(ui, repo, rev):
+    """ Display the obsolescence history for a single revision
+    """
+    precursors = repo.obsstore.precursors
+    successors = repo.obsstore.successors
+    nodec = repo.changelog.node
+    nodes = [nodec(rev)]
+
+    while nodes:
+        ctxnode = nodes.pop()
+        _debugobshistorydisplaynode(ui, repo, ctxnode)
+
+        succs = successors.get(ctxnode, ())
+
+        for successor in sorted(succs):
+            _debugobshistorydisplaymarker(ui, repo, successor)
+
+        precs = precursors.get(ctxnode, ())
+        nodes.extend(precursor[0] for precursor in sorted(precs))
+
+def _debugobshistorydisplaynode(ui, repo, node):
+    ctx = repo.unfiltered()[node]
+    shortdescription = ctx.description().splitlines()[0]
+
+    args = (ui.label(str(ctx), "evolve.short_node"),
+            ui.label(str(int(ctx)), "evolve.rev"),
+            ui.label(shortdescription, "evolve.short_description"))
+
+    ui.write("%s (%s) %s\n" % args)
+
+def _debugobshistorydisplaymarker(ui, repo, marker):
+    succnodes = marker[1]
+    date = marker[4]
+    metadata = dict(marker[3])
+
+    msgargs = (ui.label(metadata['user'], "evolve.user"),
+               ui.label(util.datestr(date), "evolve.date"))
+    # If no successors with a marker, the commit has been pruned
+    if len(succnodes) == 0:
+        msgargs = (ui.label("pruned", "evolve.verb"),) + msgargs
+        msg = "  %s by %s (%s)\n"
+    else:
+        shortsnodes = (node.short(succnode) for succnode in sorted(succnodes))
+        labelednodes = (ui.label(node, "evolve.short_node") for node in shortsnodes)
+        msgargs = (ui.label("rewritten", "evolve.verb"),) + msgargs + (", ".join(labelednodes),)
+        msg = "  %s by %s (%s) as %s\n"
+
+    ui.write(msg % msgargs)
--- a/tests/test-evolve-obshistory.t	Wed May 10 12:16:01 2017 +0200
+++ b/tests/test-evolve-obshistory.t	Wed May 10 12:26:33 2017 +0200
@@ -25,9 +25,11 @@
   $ mkcommit ROOT
   $ mkcommit A0
   $ echo 42 >> A0
-  $ hg amend -m "A1"
+  $ hg amend -m "A1
+  > 
+  > Better commit message"
   $ hg log --hidden -G
-  @  changeset:   3:a468dc9b3633
+  @  changeset:   3:4ae3a4151de9
   |  tag:         tip
   |  parent:      0:ea207398892e
   |  user:        test
@@ -51,15 +53,21 @@
   
 Actual test
 -----------
-
+  $ hg debugobshistory 4ae3a4151de9
+  4ae3a4151de9 (3) A1
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as 4ae3a4151de9 (glob)
+  $ hg debugobshistory --hidden 471f378eab4c
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as 4ae3a4151de9 (glob)
   $ hg update 471f378eab4c
   abort: hidden revision '471f378eab4c'!
-  (use --hidden to access hidden revisions; successor: a468dc9b3633)
+  (use --hidden to access hidden revisions; successor: 4ae3a4151de9)
   [255]
   $ hg update --hidden "desc(A0)"
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   working directory parent is obsolete! (471f378eab4c)
-  (use 'hg evolve' to update to its successor: a468dc9b3633)
+  (use 'hg evolve' to update to its successor: 4ae3a4151de9)
 
 Test output with pruned commit
 ==============================
@@ -93,10 +101,32 @@
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   working directory now at 471f378eab4c
   1 changesets pruned
+  $ hg log --hidden -G
+  x  changeset:   2:0dec01379d3b
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     B0
+  |
+  @  changeset:   1:471f378eab4c
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     A0
+  |
+  o  changeset:   0:ea207398892e
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     ROOT
+  
 
 Actual test
 -----------
 
+  $ hg debugobshistory 'desc(B0)' --hidden
+  0dec01379d3b (2) B0
+    pruned by test (*20*) (glob)
+  $ hg debugobshistory 'desc(A0)'
+  471f378eab4c (1) A0
   $ hg up 1
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg up 0dec01379d3b
@@ -195,6 +225,17 @@
 Actual test
 -----------
 
+  $ hg debugobshistory 471597cad322 --hidden
+  471597cad322 (1) A0
+    rewritten by test (*20*) as 337fec4d2edc, f257fde29c7a (glob)
+  $ hg debugobshistory 337fec4d2edc
+  337fec4d2edc (2) A0
+  471597cad322 (1) A0
+    rewritten by test (*20*) as 337fec4d2edc, f257fde29c7a (glob)
+  $ hg debugobshistory f257fde29c7a
+  f257fde29c7a (3) A0
+  471597cad322 (1) A0
+    rewritten by test (*20*) as 337fec4d2edc, f257fde29c7a (glob)
   $ hg update 471597cad322
   abort: hidden revision '471597cad322'!
   (use --hidden to access hidden revisions; successors: 337fec4d2edc, f257fde29c7a)
@@ -357,6 +398,13 @@
 Actual test
 -----------
 
+  $ hg debugobshistory de7290d8b885 --hidden
+  de7290d8b885 (1) A0
+    rewritten by test (*20*) as 1ae8bc733a14, 337fec4d2edc, c7f044602e9b, f257fde29c7a (glob)
+  $ hg debugobshistory c7f044602e9b
+  c7f044602e9b (5) A0
+  de7290d8b885 (1) A0
+    rewritten by test (*20*) as 1ae8bc733a14, 337fec4d2edc, c7f044602e9b, f257fde29c7a (glob)
   $ hg update de7290d8b885
   abort: hidden revision 'de7290d8b885'!
   (use --hidden to access hidden revisions; successors: 337fec4d2edc, f257fde29c7a and 2 more)
@@ -423,6 +471,18 @@
  Actual test
  -----------
 
+  $ hg debugobshistory --hidden 471f378eab4c
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as eb5a0daa2192 (glob)
+  $ hg debugobshistory --hidden 0dec01379d3b
+  0dec01379d3b (2) B0
+    rewritten by test (*20*) as eb5a0daa2192 (glob)
+  $ hg debugobshistory eb5a0daa2192
+  eb5a0daa2192 (3) C0
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as eb5a0daa2192 (glob)
+  0dec01379d3b (2) B0
+    rewritten by test (*20*) as eb5a0daa2192 (glob)
   $ hg update 471f378eab4c
   abort: hidden revision '471f378eab4c'!
   (use --hidden to access hidden revisions; successor: eb5a0daa2192)
@@ -506,6 +566,20 @@
 Actual test
 -----------
 
+  $ hg debugobshistory --hidden 471f378eab4c
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as 65b757b745b9 (glob)
+    rewritten by test (*20*) as fdf9bde5129a (glob)
+  $ hg debugobshistory fdf9bde5129a
+  fdf9bde5129a (2) A1
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as 65b757b745b9 (glob)
+    rewritten by test (*20*) as fdf9bde5129a (glob)
+  $ hg debugobshistory 65b757b745b9
+  65b757b745b9 (3) A2
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as 65b757b745b9 (glob)
+    rewritten by test (*20*) as fdf9bde5129a (glob)
   $ hg update 471f378eab4c
   abort: hidden revision '471f378eab4c'!
   (use --hidden to access hidden revisions; diverged)
@@ -514,3 +588,108 @@
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   working directory parent is obsolete! (471f378eab4c)
   (471f378eab4c has diverged, use 'hg evolve -list --divergent' to resolve the issue)
+
+Test output with amended + folded commit
+========================================
+
+Test setup
+----------
+
+  $ hg init $TESTTMP/local-amend-fold
+  $ cd $TESTTMP/local-amend-fold
+  $ mkcommit ROOT
+  $ mkcommit A0
+  $ mkcommit B0
+  $ hg amend -m "B1"
+  $ hg log --hidden -G
+  @  changeset:   3:b7ea6d14e664
+  |  tag:         tip
+  |  parent:      1:471f378eab4c
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     B1
+  |
+  | x  changeset:   2:0dec01379d3b
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     B0
+  |
+  o  changeset:   1:471f378eab4c
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     A0
+  |
+  o  changeset:   0:ea207398892e
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     ROOT
+  
+  $ hg fold --exact -r 'desc(A0) + desc(B1)' --date "0 0" -m "C0"
+  2 changesets folded
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg log --hidden -G
+  @  changeset:   4:eb5a0daa2192
+  |  tag:         tip
+  |  parent:      0:ea207398892e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     C0
+  |
+  | x  changeset:   3:b7ea6d14e664
+  | |  parent:      1:471f378eab4c
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     B1
+  | |
+  | | x  changeset:   2:0dec01379d3b
+  | |/   user:        test
+  | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    summary:     B0
+  | |
+  | x  changeset:   1:471f378eab4c
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     A0
+  |
+  o  changeset:   0:ea207398892e
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     ROOT
+  
+ Actual test
+ -----------
+
+  $ hg debugobshistory --hidden 471f378eab4c
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as eb5a0daa2192 (glob)
+  $ hg debugobshistory --hidden 0dec01379d3b
+  0dec01379d3b (2) B0
+    rewritten by test (*20*) as b7ea6d14e664 (glob)
+  $ hg debugobshistory eb5a0daa2192
+  eb5a0daa2192 (4) C0
+  b7ea6d14e664 (3) B1
+    rewritten by test (*20*) as eb5a0daa2192 (glob)
+  0dec01379d3b (2) B0
+    rewritten by test (*20*) as b7ea6d14e664 (glob)
+  471f378eab4c (1) A0
+    rewritten by test (*20*) as eb5a0daa2192 (glob)
+  $ hg update 471f378eab4c
+  abort: hidden revision '471f378eab4c'!
+  (use --hidden to access hidden revisions; successor: eb5a0daa2192)
+  [255]
+  $ hg update --hidden 'desc(A0)'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  working directory parent is obsolete! (471f378eab4c)
+  (use 'hg evolve' to update to its successor: eb5a0daa2192)
+  $ hg update --hidden 0dec01379d3b
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  working directory parent is obsolete! (0dec01379d3b)
+  (use 'hg evolve' to update to its successor: eb5a0daa2192)
+  $ hg update 0dec01379d3b
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  working directory parent is obsolete! (0dec01379d3b)
+  (use 'hg evolve' to update to its successor: eb5a0daa2192)
+  $ hg update --hidden 'desc(B0)'
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  working directory parent is obsolete! (0dec01379d3b)
+  (use 'hg evolve' to update to its successor: eb5a0daa2192)