obslog: also display description patch with --patch
authorBoris Feld <boris.feld@octobus.net>
Tue, 20 Jun 2017 16:22:16 +0200
changeset 2639 a5d8062f55ba
parent 2638 9290f985868c
child 2640 e278271d2391
obslog: also display description patch with --patch When activating the --patch option, also display the description patch.
hgext3rd/evolve/obshistory.py
tests/test-evolve-obshistory.t
--- a/hgext3rd/evolve/obshistory.py	Wed Jun 21 11:11:37 2017 +0200
+++ b/hgext3rd/evolve/obshistory.py	Tue Jun 20 16:22:16 2017 +0200
@@ -14,6 +14,7 @@
     commands,
     error,
     graphmod,
+    mdiff,
     patch,
     obsolete,
     node as nodemod,
@@ -145,7 +146,7 @@
     extra = ' ' * indent
     return "".join(extra + line for line in content.splitlines(True))
 
-def getmarkerpatch(repo, node, succ):
+def getmarkercontentpatch(repo, node, succ):
     # Todo get the ops from the cmd
     diffopts = patch.diffallopts(repo.ui, {})
     matchfn = scmutil.matchall(repo)
@@ -157,6 +158,24 @@
 
     return _indent(buffer)
 
+def getmarkerdescriptionpatch(repo, base, succ):
+    basectx = repo[base]
+    succctx = repo[succ]
+    basedesc = basectx.description() + '\n'
+    succdesc = succctx.description() + '\n'
+
+    # fake file name
+    basename = "%s-changeset-description" % basectx
+    succname = "%s-changeset-description" % succctx
+
+    d = mdiff.unidiff(basedesc, '', succdesc, '', basename, succname)
+    uheaders, hunks = d
+
+    # Copied from patch.diff
+    text = ''.join(sum((list(hlines) for hrange, hlines in hunks), []))
+    patch = "\n".join(uheaders + [text])
+    return _indent(patch)
+
 class missingchangectx(object):
     ''' a minimal object mimicking changectx for change contexts
     references by obs markers but not available locally '''
@@ -455,13 +474,24 @@
     if opts.get('patch'):
         _patchavailable = patchavailable(node, repo, marker)
 
-        if _patchavailable[0]:
-            patch = getmarkerpatch(repo, node, _patchavailable[1])
+        if _patchavailable[0] is True:
+            succ = _patchavailable[1]
+
+            # Description patch
+            descriptionpatch = getmarkerdescriptionpatch(repo, node, succ)
+            if descriptionpatch:
+                fm.plain("\n")
+                fm.plain(descriptionpatch)
+
+            # Content patch
+            contentpatch = getmarkercontentpatch(repo, node, succ)
+            if contentpatch:
+                fm.plain("\n")
+                fm.plain(contentpatch)
         else:
             patch = "    (No patch available yet, %s)" % _patchavailable[1]
-        if patch:
             fm.plain("\n")
-            # should be in json too
+            # TODO: should be in json too
             fm.plain(patch)
 
     fm.plain("\n")
--- a/tests/test-evolve-obshistory.t	Wed Jun 21 11:11:37 2017 +0200
+++ b/tests/test-evolve-obshistory.t	Tue Jun 20 16:22:16 2017 +0200
@@ -60,6 +60,14 @@
   |
   x  471f378eab4c (1) A0
        rewritten(description, content) by test (Thu Jan 01 00:00:00 1970 +0000) as 4ae3a4151de9
+         --- a/471f378eab4c-changeset-description
+         +++ b/4ae3a4151de9-changeset-description
+         @@ -1,1 +1,3 @@
+         -A0
+         +A1
+         +
+         +Better commit message
+  
          diff -r 471f378eab4c -r 4ae3a4151de9 A0
          --- a/A0	Thu Jan 01 00:00:00 1970 +0000
          +++ b/A0	Thu Jan 01 00:00:00 1970 +0000
@@ -102,6 +110,14 @@
   $ hg obslog --hidden --patch 471f378eab4c
   x  471f378eab4c (1) A0
        rewritten(description, content) by test (*) as 4ae3a4151de9 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/4ae3a4151de9-changeset-description
+         @@ -1,1 +1,3 @@
+         -A0
+         +A1
+         +
+         +Better commit message
+  
          diff -r 471f378eab4c -r 4ae3a4151de9 A0
          --- a/A0	Thu Jan 01 00:00:00 1970 +0000
          +++ b/A0	Thu Jan 01 00:00:00 1970 +0000
@@ -768,6 +784,12 @@
   $ hg obslog --hidden 471f378eab4c --patch
   x  471f378eab4c (1) A0
        rewritten(description, content) by test (*) as eb5a0daa2192 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/eb5a0daa2192-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +C0
+  
          diff -r 471f378eab4c -r eb5a0daa2192 B0
          --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
          +++ b/B0	Thu Jan 01 00:00:00 1970 +0000
@@ -785,6 +807,12 @@
   |
   x  471f378eab4c (1) A0
        rewritten(description, content) by test (*) as eb5a0daa2192 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/eb5a0daa2192-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +C0
+  
          diff -r 471f378eab4c -r eb5a0daa2192 B0
          --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
          +++ b/B0	Thu Jan 01 00:00:00 1970 +0000
@@ -809,6 +837,12 @@
   |
   x  471f378eab4c (1) A0
        rewritten(description, content) by test (*) as eb5a0daa2192 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/eb5a0daa2192-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +C0
+  
          diff -r 471f378eab4c -r eb5a0daa2192 B0
          --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
          +++ b/B0	Thu Jan 01 00:00:00 1970 +0000
@@ -827,6 +861,12 @@
   |
   x  471f378eab4c (1) A0
        rewritten(description, content) by test (*) as eb5a0daa2192 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/eb5a0daa2192-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +C0
+  
          diff -r 471f378eab4c -r eb5a0daa2192 B0
          --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
          +++ b/B0	Thu Jan 01 00:00:00 1970 +0000
@@ -975,7 +1015,19 @@
   $ hg obslog --hidden 471f378eab4c --patch
   x  471f378eab4c (1) A0
        rewritten(description) by test (*) as 65b757b745b9 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/65b757b745b9-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A2
+  
        rewritten(description) by test (*) as fdf9bde5129a (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/fdf9bde5129a-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A1
+  
   
 
 Check that with all option, every changeset is shown
@@ -986,7 +1038,19 @@
   |/
   x  471f378eab4c (1) A0
        rewritten(description) by test (*) as 65b757b745b9 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/65b757b745b9-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A2
+  
        rewritten(description) by test (*) as fdf9bde5129a (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/fdf9bde5129a-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A1
+  
   
   $ hg obslog --hidden 471f378eab4c --no-graph -Tjson | python -m json.tool
   [
@@ -1033,7 +1097,19 @@
   |
   x  471f378eab4c (1) A0
        rewritten(description) by test (*) as 65b757b745b9 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/65b757b745b9-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A2
+  
        rewritten(description) by test (*) as fdf9bde5129a (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/fdf9bde5129a-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A1
+  
   
 
 Check that all option show all of them
@@ -1044,7 +1120,19 @@
   |/
   x  471f378eab4c (1) A0
        rewritten(description) by test (*) as 65b757b745b9 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/65b757b745b9-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A2
+  
        rewritten(description) by test (*) as fdf9bde5129a (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/fdf9bde5129a-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A1
+  
   
 Check that debugobshistory on the second diverged revision show the revision
 and the diverent one
@@ -1053,7 +1141,19 @@
   |
   x  471f378eab4c (1) A0
        rewritten(description) by test (*) as 65b757b745b9 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/65b757b745b9-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A2
+  
        rewritten(description) by test (*) as fdf9bde5129a (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/fdf9bde5129a-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A1
+  
   
 Check that all option show all of them
   $ hg obslog 65b757b745b9 -a --patch
@@ -1063,7 +1163,19 @@
   |/
   x  471f378eab4c (1) A0
        rewritten(description) by test (*) as 65b757b745b9 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/65b757b745b9-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A2
+  
        rewritten(description) by test (*) as fdf9bde5129a (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/fdf9bde5129a-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A1
+  
   
 Check that debugobshistory on the both diverged revision show a coherent
 graph
@@ -1074,7 +1186,19 @@
   |/
   x  471f378eab4c (1) A0
        rewritten(description) by test (*) as 65b757b745b9 (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/65b757b745b9-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A2
+  
        rewritten(description) by test (*) as fdf9bde5129a (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/fdf9bde5129a-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A1
+  
   
   $ hg obslog '65b757b745b9+fdf9bde5129a' --no-graph -Tjson | python -m json.tool
   [
@@ -1211,6 +1335,12 @@
   |\
   x |  471f378eab4c (1) A0
    /     rewritten(description, content) by test (*) as eb5a0daa2192 (glob)
+  |        --- a/471f378eab4c-changeset-description
+  |        +++ b/eb5a0daa2192-changeset-description
+  |        @@ -1,1 +1,1 @@
+  |        -A0
+  |        +C0
+  |
   |        diff -r 471f378eab4c -r eb5a0daa2192 B0
   |        --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   |        +++ b/B0	Thu Jan 01 00:00:00 1970 +0000
@@ -1224,6 +1354,12 @@
   |
   x  0dec01379d3b (2) B0
        rewritten(description) by test (*) as b7ea6d14e664 (glob)
+         --- a/0dec01379d3b-changeset-description
+         +++ b/b7ea6d14e664-changeset-description
+         @@ -1,1 +1,1 @@
+         -B0
+         +B1
+  
   
 Check that obslog on ROOT with all option show everything
   $ hg obslog 1 --hidden --all --patch
@@ -1231,6 +1367,12 @@
   |\
   x |  471f378eab4c (1) A0
    /     rewritten(description, content) by test (*) as eb5a0daa2192 (glob)
+  |        --- a/471f378eab4c-changeset-description
+  |        +++ b/eb5a0daa2192-changeset-description
+  |        @@ -1,1 +1,1 @@
+  |        -A0
+  |        +C0
+  |
   |        diff -r 471f378eab4c -r eb5a0daa2192 B0
   |        --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   |        +++ b/B0	Thu Jan 01 00:00:00 1970 +0000
@@ -1244,6 +1386,12 @@
   |
   x  0dec01379d3b (2) B0
        rewritten(description) by test (*) as b7ea6d14e664 (glob)
+         --- a/0dec01379d3b-changeset-description
+         +++ b/b7ea6d14e664-changeset-description
+         @@ -1,1 +1,1 @@
+         -B0
+         +B1
+  
   
   $ hg obslog eb5a0daa2192 --no-graph -Tjson | python -m json.tool
   [
@@ -1414,9 +1562,21 @@
   |
   x  fdf9bde5129a (2) A1
   |    rewritten(description) by test (*) as 7a230b46bf61 (glob)
+  |      --- a/fdf9bde5129a-changeset-description
+  |      +++ b/7a230b46bf61-changeset-description
+  |      @@ -1,1 +1,1 @@
+  |      -A1
+  |      +A2
+  |
   |
   x  471f378eab4c (1) A0
        rewritten(description) by test (*) as fdf9bde5129a (glob)
+         --- a/471f378eab4c-changeset-description
+         +++ b/fdf9bde5129a-changeset-description
+         @@ -1,1 +1,1 @@
+         -A0
+         +A1
+  
   
   $ cd $TESTTMP/local-remote-markers-2
   $ hg pull