Patchwork [7,of,9,V3] template: compute dates in obsfatedate

login
register
mail settings
Submitter Boris Feld
Date Aug. 21, 2017, 8:43 a.m.
Message ID <faad6d683f7a30996007.1503305039@FB>
Download mbox | patch
Permalink /patch/23174/
State Superseded
Headers show

Comments

Boris Feld - Aug. 21, 2017, 8:43 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499088850 -7200
#      Mon Jul 03 15:34:10 2017 +0200
# Node ID faad6d683f7a30996007116d296df9ebf853c44d
# Parent  2fee3b06f7b09f35dcfa312b645cf94090c11fb9
# EXP-Topic obsfatetemplate
template: compute dates in obsfatedate

Extract the dates from obsmarkers. Compute the min and max date from the
obsmarker range list.
Yuya Nishihara - Aug. 22, 2017, 3:10 p.m.
On Mon, 21 Aug 2017 10:43:59 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1499088850 -7200
> #      Mon Jul 03 15:34:10 2017 +0200
> # Node ID faad6d683f7a30996007116d296df9ebf853c44d
> # Parent  2fee3b06f7b09f35dcfa312b645cf94090c11fb9
> # EXP-Topic obsfatetemplate
> template: compute dates in obsfatedate
> 
> Extract the dates from obsmarkers. Compute the min and max date from the
> obsmarker range list.
> 
> diff -r 2fee3b06f7b0 -r faad6d683f7a mercurial/obsutil.py
> --- a/mercurial/obsutil.py	Mon Jul 03 15:34:00 2017 +0200
> +++ b/mercurial/obsutil.py	Mon Jul 03 15:34:10 2017 +0200
> @@ -591,6 +591,20 @@
>  
>      return {'users': sorted(users)}
>  
> +def _successorsetdates(successorset, markers):
> +    """returns the max date and the min date of the markers list
> +    """
> +
> +    if not markers:
> +        return {}
> +
> +    dates = [m[4] for m in markers]
> +
> +    return {
> +        'min_date': min(dates),
> +        'max_date': max(dates)
> +    }

Perhaps we'll want a list of dates, min(), and max() functions?

  "{min(markers % date)}"
               ^^^^^^^
               not work currently, so we'll probably need a function to
               extract 'date' fields from markers.
Boris Feld - Aug. 23, 2017, 2:32 p.m.
On Wed, 2017-08-23 at 00:10 +0900, Yuya Nishihara wrote:
> On Mon, 21 Aug 2017 10:43:59 +0200, Boris Feld wrote:
> > # HG changeset patch
> > # User Boris Feld <boris.feld@octobus.net>
> > # Date 1499088850 -7200
> > #      Mon Jul 03 15:34:10 2017 +0200
> > # Node ID faad6d683f7a30996007116d296df9ebf853c44d
> > # Parent  2fee3b06f7b09f35dcfa312b645cf94090c11fb9
> > # EXP-Topic obsfatetemplate
> > template: compute dates in obsfatedate
> > 
> > Extract the dates from obsmarkers. Compute the min and max date
> > from the
> > obsmarker range list.
> > 
> > diff -r 2fee3b06f7b0 -r faad6d683f7a mercurial/obsutil.py
> > --- a/mercurial/obsutil.py	Mon Jul 03 15:34:00 2017 +0200
> > +++ b/mercurial/obsutil.py	Mon Jul 03 15:34:10 2017 +0200
> > @@ -591,6 +591,20 @@
> >  
> >      return {'users': sorted(users)}
> >  
> > +def _successorsetdates(successorset, markers):
> > +    """returns the max date and the min date of the markers list
> > +    """
> > +
> > +    if not markers:
> > +        return {}
> > +
> > +    dates = [m[4] for m in markers]
> > +
> > +    return {
> > +        'min_date': min(dates),
> > +        'max_date': max(dates)
> > +    }
> 
> Perhaps we'll want a list of dates, min(), and max() functions?
> 
>   "{min(markers % date)}"
>                ^^^^^^^
>                not work currently, so we'll probably need a function
> to
>                extract 'date' fields from markers.

Good idea, I will send a V4 with these modifications.

Patch

diff -r 2fee3b06f7b0 -r faad6d683f7a mercurial/obsutil.py
--- a/mercurial/obsutil.py	Mon Jul 03 15:34:00 2017 +0200
+++ b/mercurial/obsutil.py	Mon Jul 03 15:34:10 2017 +0200
@@ -591,6 +591,20 @@ 
 
     return {'users': sorted(users)}
 
+def _successorsetdates(successorset, markers):
+    """returns the max date and the min date of the markers list
+    """
+
+    if not markers:
+        return {}
+
+    dates = [m[4] for m in markers]
+
+    return {
+        'min_date': min(dates),
+        'max_date': max(dates)
+    }
+
 def successorsandmarkers(repo, ctx):
     """compute the raw data needed for computing obsfate
     Returns a list of dict, one dict per successors set
diff -r 2fee3b06f7b0 -r faad6d683f7a mercurial/templater.py
--- a/mercurial/templater.py	Mon Jul 03 15:34:00 2017 +0200
+++ b/mercurial/templater.py	Mon Jul 03 15:34:10 2017 +0200
@@ -877,6 +877,22 @@ 
 
     return _hybrid(None, [data], makemap, joinfmt)
 
+@templatefunc('obsfatedate(successors, markers)')
+def obsfatedate(context, mapping, args):
+    """ Compute obsfate related information based on successors and markers
+    """
+    successors = evalfuncarg(context, mapping, args[0])
+    markers = evalfuncarg(context, mapping, args[1])
+    data = obsutil._successorsetdates(successors, markers)
+
+    def makemap(x):
+        return x
+
+    def joinfmt(d):
+        return d
+
+    return templatekw._hybrid(None, [data], makemap, joinfmt)
+
 @templatefunc('relpath(path)')
 def relpath(context, mapping, args):
     """Convert a repository-absolute path into a filesystem path relative to
diff -r 2fee3b06f7b0 -r faad6d683f7a tests/test-obsmarker-template.t
--- a/tests/test-obsmarker-template.t	Mon Jul 03 15:34:00 2017 +0200
+++ b/tests/test-obsmarker-template.t	Mon Jul 03 15:34:10 2017 +0200
@@ -16,7 +16,9 @@ 
   > obsfateverb = "{obsfateverb(successors, markers)}"
   > obsfateuserstmpl = "{if(users, " by {join(users, ", ")}")}"
   > obsfateusers = "{obsfateusers(successors, markers) % "{obsfateuserstmpl}"}"
-  > obsfate = "{obsfateverb}{obsfatesuccessors}{obsfateusers}; "
+  > obsfatedatetmpl = "{if(max_date, "{ifeq(min_date, max_date, " (at {min_date|isodate})", " (between {min_date|isodate} and {max_date|isodate})")}")}"
+  > obsfatedate = "{obsfatedate(successors, markers) % "{obsfatedatetmpl}"}"
+  > obsfate = "{obsfateverb}{obsfatesuccessors}{obsfateusers}{obsfatedate}; "
   > [alias]
   > tlog = log -G -T '{node|short}\
   >     {if(predecessors, "\n  Predecessors: {predecessors}")}\
@@ -95,21 +97,21 @@ 
   o  d004c8f274b9
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 4:d004c8f274b9 by test1, test2;
+  |/     Obsfate: rewritten as 4:d004c8f274b9 by test1, test2 (between 2001-04-19 04:25 +0000 and 2009-02-13 23:31 +0000);
   o  ea207398892e
   
   $ hg fatelog
   o  d004c8f274b9
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 4:d004c8f274b9 by test1, test2;
+  |/     Obsfate: rewritten as 4:d004c8f274b9 by test1, test2 (between 2001-04-19 04:25 +0000 and 2009-02-13 23:31 +0000);
   o  ea207398892e
   
   $ hg fatelog -v
   o  d004c8f274b9
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 4:d004c8f274b9 by test1, test2;
+  |/     Obsfate: rewritten as 4:d004c8f274b9 by test1, test2 (between 2001-04-19 04:25 +0000 and 2009-02-13 23:31 +0000);
   o  ea207398892e
   
   $ hg up 'desc(A1)' --hidden
@@ -132,7 +134,7 @@ 
   o  d004c8f274b9
   |
   | @  a468dc9b3633
-  |/     Obsfate: rewritten as 4:d004c8f274b9 by test2;
+  |/     Obsfate: rewritten as 4:d004c8f274b9 by test2 (at 2001-04-19 04:25 +0000);
   o  ea207398892e
   
 Predecessors template should show all the predecessors as we force their display
@@ -163,11 +165,11 @@ 
   o  d004c8f274b9
   |
   | @  a468dc9b3633
-  |/     Obsfate: rewritten as 4:d004c8f274b9 by test2;
+  |/     Obsfate: rewritten as 4:d004c8f274b9 by test2 (at 2001-04-19 04:25 +0000);
   | x  f137d23bb3e1
   | |
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 3:a468dc9b3633 by test1;
+  |/     Obsfate: rewritten as 3:a468dc9b3633 by test1 (at 2009-02-13 23:31 +0000);
   o  ea207398892e
   
 
@@ -212,11 +214,11 @@ 
   @  d004c8f274b9
   |
   | x  a468dc9b3633
-  |/     Obsfate: rewritten as 4:d004c8f274b9 by test2;
+  |/     Obsfate: rewritten as 4:d004c8f274b9 by test2 (at 2001-04-19 04:25 +0000);
   | x  f137d23bb3e1
   | |
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 3:a468dc9b3633 by test1;
+  |/     Obsfate: rewritten as 3:a468dc9b3633 by test1 (at 2009-02-13 23:31 +0000);
   o  ea207398892e
   
   $ hg fatelogjson --hidden
@@ -320,7 +322,7 @@ 
   o  337fec4d2edc
   |
   | @  471597cad322
-  |/     Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a by test;
+  |/     Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg up f257fde29c7a
@@ -361,7 +363,7 @@ 
   o  337fec4d2edc
   |
   | x  471597cad322
-  |/     Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a by test;
+  |/     Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg fatelogjson --hidden
@@ -462,7 +464,7 @@ 
   o  eb5a0daa2192
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 3:eb5a0daa2192 by test;
+  |/     Obsfate: rewritten as 3:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg up 'desc(B0)' --hidden
@@ -491,9 +493,9 @@ 
   o  eb5a0daa2192
   |
   | @  0dec01379d3b
-  | |    Obsfate: rewritten as 3:eb5a0daa2192 by test;
+  | |    Obsfate: rewritten as 3:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 3:eb5a0daa2192 by test;
+  |/     Obsfate: rewritten as 3:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg up 'desc(C0)'
@@ -529,9 +531,9 @@ 
   @  eb5a0daa2192
   |
   | x  0dec01379d3b
-  | |    Obsfate: rewritten as 3:eb5a0daa2192 by test;
+  | |    Obsfate: rewritten as 3:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 3:eb5a0daa2192 by test;
+  |/     Obsfate: rewritten as 3:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
 
@@ -668,7 +670,7 @@ 
   | o  fdf9bde5129a
   |/
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 2:fdf9bde5129a by test; rewritten as 4:019fadeab383 by test;
+  |/     Obsfate: rewritten as 2:fdf9bde5129a by test (at 1970-01-01 00:00 +0000); rewritten as 4:019fadeab383 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg up 'desc(A1)'
@@ -724,11 +726,11 @@ 
   o  019fadeab383
   |
   | x  65b757b745b9
-  |/     Obsfate: rewritten as 4:019fadeab383 by test;
+  |/     Obsfate: rewritten as 4:019fadeab383 by test (at 1970-01-01 00:00 +0000);
   | @  fdf9bde5129a
   |/
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 2:fdf9bde5129a by test; rewritten as 3:65b757b745b9 by test;
+  |/     Obsfate: rewritten as 2:fdf9bde5129a by test (at 1970-01-01 00:00 +0000); rewritten as 3:65b757b745b9 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
 
@@ -846,7 +848,7 @@ 
   o  eb5a0daa2192
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 4:eb5a0daa2192 by test;
+  |/     Obsfate: rewritten as 4:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg up 'desc(B0)' --hidden
@@ -874,9 +876,9 @@ 
   o  eb5a0daa2192
   |
   | @  0dec01379d3b
-  | |    Obsfate: rewritten as 4:eb5a0daa2192 by test;
+  | |    Obsfate: rewritten as 4:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 4:eb5a0daa2192 by test;
+  |/     Obsfate: rewritten as 4:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg up 'desc(B1)' --hidden
@@ -904,9 +906,9 @@ 
   o  eb5a0daa2192
   |
   | @  b7ea6d14e664
-  | |    Obsfate: rewritten as 4:eb5a0daa2192 by test;
+  | |    Obsfate: rewritten as 4:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 4:eb5a0daa2192 by test;
+  |/     Obsfate: rewritten as 4:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg up 'desc(C0)'
@@ -955,11 +957,11 @@ 
   @  eb5a0daa2192
   |
   | x  b7ea6d14e664
-  | |    Obsfate: rewritten as 4:eb5a0daa2192 by test;
+  | |    Obsfate: rewritten as 4:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   | | x  0dec01379d3b
-  | |/     Obsfate: rewritten as 3:b7ea6d14e664 by test;
+  | |/     Obsfate: rewritten as 3:b7ea6d14e664 by test (at 1970-01-01 00:00 +0000);
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 4:eb5a0daa2192 by test;
+  |/     Obsfate: rewritten as 4:eb5a0daa2192 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
 
@@ -1083,7 +1085,7 @@ 
   o  7a230b46bf61
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 2:7a230b46bf61 by test;
+  |/     Obsfate: rewritten as 2:7a230b46bf61 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg up 'desc(A2)'
@@ -1120,7 +1122,7 @@ 
   @  7a230b46bf61
   |
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 2:7a230b46bf61 by test;
+  |/     Obsfate: rewritten as 2:7a230b46bf61 by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
 
@@ -1195,9 +1197,9 @@ 
   o  f897c6137566
   |
   | @  0dec01379d3b
-  | |    Obsfate: rewritten as 3:f897c6137566 by test; rewritten as 1:471f378eab4c by test;
+  | |    Obsfate: rewritten as 3:f897c6137566 by test (at 1970-01-01 00:00 +0000); rewritten as 1:471f378eab4c by test (at 1970-01-01 00:00 +0000);
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 2:0dec01379d3b by test;
+  |/     Obsfate: rewritten as 2:0dec01379d3b by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
 
@@ -1453,7 +1455,7 @@ 
   | o  ba2ed02b0c9a
   | |
   | x  4a004186e638
-  |/     Obsfate: rewritten as 8:b18bc8331526 by test; rewritten as 9:0b997eb7ceee by test;
+  |/     Obsfate: rewritten as 8:b18bc8331526 by test (at 1970-01-01 00:00 +0000); rewritten as 9:0b997eb7ceee by test (at 1970-01-01 00:00 +0000);
   o  dd800401bd8c
   |
   o  f897c6137566
@@ -1526,17 +1528,17 @@ 
   | o  ba2ed02b0c9a
   | |
   | x  4a004186e638
-  |/     Obsfate: rewritten as 8:b18bc8331526 by test; rewritten as 9:0b997eb7ceee by test;
+  |/     Obsfate: rewritten as 8:b18bc8331526 by test (at 1970-01-01 00:00 +0000); rewritten as 9:0b997eb7ceee by test (at 1970-01-01 00:00 +0000);
   o  dd800401bd8c
   |
   | x  9bd10a0775e4
-  |/     Obsfate: split as 5:dd800401bd8c, 6:4a004186e638, 7:ba2ed02b0c9a by test;
+  |/     Obsfate: split as 5:dd800401bd8c, 6:4a004186e638, 7:ba2ed02b0c9a by test (at 1970-01-01 00:00 +0000);
   o  f897c6137566
   |
   | x  0dec01379d3b
-  | |    Obsfate: rewritten as 3:f897c6137566 by test; rewritten as 1:471f378eab4c by test;
+  | |    Obsfate: rewritten as 3:f897c6137566 by test (at 1970-01-01 00:00 +0000); rewritten as 1:471f378eab4c by test (at 1970-01-01 00:00 +0000);
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 2:0dec01379d3b by test;
+  |/     Obsfate: rewritten as 2:0dec01379d3b by test (at 1970-01-01 00:00 +0000);
   o  ea207398892e
   
   $ hg fatelogjson --hidden
@@ -1605,7 +1607,7 @@ 
   o  dd800401bd8c
   |
   | @  9bd10a0775e4
-  |/     Obsfate: split as 5:dd800401bd8c, 9:0b997eb7ceee, 10:eceed8f98ffc by test; split as 5:dd800401bd8c, 8:b18bc8331526, 10:eceed8f98ffc by test;
+  |/     Obsfate: split as 5:dd800401bd8c, 9:0b997eb7ceee, 10:eceed8f98ffc by test (at 1970-01-01 00:00 +0000); split as 5:dd800401bd8c, 8:b18bc8331526, 10:eceed8f98ffc by test (at 1970-01-01 00:00 +0000);
   o  f897c6137566
   |
   o  ea207398892e