Patchwork [8,of,8] template: better prune support in obsfate

login
register
mail settings
Submitter Boris Feld
Date Aug. 7, 2017, 2:56 p.m.
Message ID <1d6509b36d5e03608e16.1502117787@FB>
Download mbox | patch
Permalink /patch/22732/
State Changes Requested
Headers show

Comments

Boris Feld - Aug. 7, 2017, 2:56 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499096336 -7200
#      Mon Jul 03 17:38:56 2017 +0200
# Node ID 1d6509b36d5e03608e160c0c0453c129a373dacd
# Parent  274933e813ada051cba2e0d193ad098d0d0b28b6
# EXP-Topic obsfatetemplate
template: better prune support in obsfate

successorssets don't returns good results for pruned commit, add a workaround
for simple cases.

A proper fix would require a large rework of successorssets algorithm, I will
send a separate series for this refactoring.

Patch

diff -r 274933e813ad -r 1d6509b36d5e mercurial/obsutil.py
--- a/mercurial/obsutil.py	Mon Jul 03 15:34:10 2017 +0200
+++ b/mercurial/obsutil.py	Mon Jul 03 17:38:56 2017 +0200
@@ -636,8 +636,32 @@ 
 
     ssets = successorssets(repo, ctx.node(), closest=True)
 
+    # closestsuccessors returns an empty list for pruned revisions, remap it
+    # into a list containing en empty list for future processing
+    if ssets == []:
+        ssets = [[]]
+
+    # Try to recover pruned markers
+    succsmap = repo.obsstore.successors
+    fullsuccessorsets = [] # successor set + markers
+    for sset in ssets:
+        if sset:
+            fullsuccessorsets.append(sset)
+        else:
+            # XXX we do not catch all prune markers (eg rewritten then pruned)
+            # (fix me later)
+            foundany = False
+            for mark in succsmap.get(ctx.node(), ()):
+                if not mark[1]:
+                    foundany = True
+                    sset = _succs()
+                    sset.markers.add(mark)
+                    fullsuccessorsets.append(sset)
+            if not foundany:
+                fullsuccessorsets.append(_succs())
+
     values = []
-    for sset in ssets:
+    for sset in fullsuccessorsets:
         values.append({'successors': sset, 'markers': sset.markers})
 
     return values
diff -r 274933e813ad -r 1d6509b36d5e tests/test-obsmarker-template.t
--- a/tests/test-obsmarker-template.t	Mon Jul 03 15:34:10 2017 +0200
+++ b/tests/test-obsmarker-template.t	Mon Jul 03 17:38:56 2017 +0200
@@ -20,7 +20,7 @@ 
   >     {if(successorssets, "\n  Successors: {successorssets}")}\
   >     {if(successorssets, "\n  multi-line: {join(successorssets, "\n  multi-line: ")}")}\
   >     {if(successorssets, "\n  json: {successorssets|json}")}\n'
-  > fatelog = log -G -T '{node|short}\n{if(succsandmarkers, "  Obsfate: {succsandmarkers % "{obsfate(succsandmarkers) % "{verb} as {join(successors, ", ")}{if(users, " by {join(users, ", ")}")}{if(max_date, "{ifeq(min_date, max_date, " (at {min_date|isodate})", " (between {min_date|isodate} and {max_date|isodate})")}")}; "}"} \n" )}'
+  > fatelog = log -G -T '{node|short}\n{if(succsandmarkers, "  Obsfate: {succsandmarkers % "{obsfate(succsandmarkers) % "{verb}{if(successors, " as ")}{join(successors, ", ")}{if(users, " by {join(users, ", ")}")}{if(max_date, "{ifeq(min_date, max_date, " (at {min_date|isodate})", " (between {min_date|isodate} and {max_date|isodate})")}")}; "}"} \n" )}'
   > fatelogjson = log -G -T '{node|short}\n{if(succsandmarkers, "  Obsfate: {succsandmarkers|json}\n")}'
   > EOF
 
@@ -159,7 +159,7 @@ 
   | @  a468dc9b3633
   |/     Obsfate: rewritten as 4:d004c8f274b9 by test2 (at 2001-04-19 04:25 +0000);
   | x  f137d23bb3e1
-  | |
+  | |    Obsfate: pruned by test1 (at 2009-02-13 23:31 +0000);
   | x  471f378eab4c
   |/     Obsfate: rewritten as 3:a468dc9b3633 by test1 (at 2009-02-13 23:31 +0000);
   o  ea207398892e
@@ -208,7 +208,7 @@ 
   | x  a468dc9b3633
   |/     Obsfate: rewritten as 4:d004c8f274b9 by test2 (at 2001-04-19 04:25 +0000);
   | x  f137d23bb3e1
-  | |
+  | |    Obsfate: pruned by test1 (at 2009-02-13 23:31 +0000);
   | x  471f378eab4c
   |/     Obsfate: rewritten as 3:a468dc9b3633 by test1 (at 2009-02-13 23:31 +0000);
   o  ea207398892e
@@ -219,7 +219,7 @@ 
   | x  a468dc9b3633
   |/     Obsfate: [{"markers": [["\udca4h\u071b63\udc8b\u0014\udcfd\udcb7\udc82_U\udcce=\udcf4\udce7\u0015\u0017\udcad", ["\udcd0\u0004\udcc8\udcf2t\udcb9\udcecH\nG\udca9\u003c\u0010\udcda\udcc5\udcee\udce6:\udcdbx"], 0, [["user", "test2"]], [987654321.0, 0], null]], "successors": ["\udcd0\u0004\udcc8\udcf2t\udcb9\udcecH\nG\udca9\u003c\u0010\udcda\udcc5\udcee\udce6:\udcdbx"]}]
   | x  f137d23bb3e1
-  | |
+  | |    Obsfate: [{"markers": [["\udcf17\udcd2;\udcb3\udce1\u001d\udcc1\udcda\udcebbd\udcfa\udcc9\udccb$3x.\u0015", [], 0, [["user", "test1"]], [1234567890.0, 0], ["G\u001f7\udc8e\udcabL^%\udcf6\udcc7\u007fx['\udcc96\udcef\udcb2(t"]]], "successors": []}]
   | x  471f378eab4c
   |/     Obsfate: [{"markers": [["G\u001f7\udc8e\udcabL^%\udcf6\udcc7\u007fx['\udcc96\udcef\udcb2(t", ["\udca4h\u071b63\udc8b\u0014\udcfd\udcb7\udc82_U\udcce=\udcf4\udce7\u0015\u0017\udcad"], 0, [["user", "test1"]], [1234567890.0, 0], null]], "successors": ["\udca4h\u071b63\udc8b\u0014\udcfd\udcb7\udc82_U\udcce=\udcf4\udce7\u0015\u0017\udcad"]}]
   o  ea207398892e
@@ -1212,7 +1212,7 @@ 
   o  f897c6137566
   |
   | @  471f378eab4c
-  |/
+  |/     Obsfate: pruned;
   o  ea207398892e
   
 
@@ -1629,11 +1629,11 @@ 
   
   $ hg fatelog
   @  471f378eab4c
-  |
+  |    Obsfate: pruned by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg fatelog -v
   @  471f378eab4c
-  |
+  |    Obsfate: pruned by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e