Patchwork [1,of,5,V5] template: compute verb in obsfateverb

login
register
mail settings
Submitter Boris Feld
Date Aug. 28, 2017, 7:59 p.m.
Message ID <3aa34cf79eafaf1f3831.1503950389@FB>
Download mbox | patch
Permalink /patch/23442/
State Accepted
Headers show

Comments

Boris Feld - Aug. 28, 2017, 7:59 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499088807 -7200
#      Mon Jul 03 15:33:27 2017 +0200
# Node ID 3aa34cf79eafaf1f3831dbfcc0891e4432df780e
# Parent  e43264525ce513dab1ea23e39d2cf1051975c8ca
# EXP-Topic obsfatetemplate
template: compute verb in obsfateverb

Add a template function obsfateverb which use the markers information to
compute a better obsfate verb.

The current logic behind the obsfate verb is simple for the moment:

- If the successorsets is empty, the changeset has been pruned, for example:

    Obsfate: pruned

- If the successorsets length is 1, the changeset has been rewritten without
  divergence, for example:

    Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a

- If the successorsets length is more than 1, the changeset has diverged, for
  example:

    Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a

As the divergence might occurs on a subset of successors, we might see some
successors twice:

    Obsfate: split as 9:0b997eb7ceee, 5:dd800401bd8c, 10:eceed8f98ffc; split
    as 8:b18bc8331526, 5:dd800401bd8c, 10:eceed8f98ffc
Yuya Nishihara - Aug. 29, 2017, 1:10 p.m.
On Mon, 28 Aug 2017 21:59:49 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1499088807 -7200
> #      Mon Jul 03 15:33:27 2017 +0200
> # Node ID 3aa34cf79eafaf1f3831dbfcc0891e4432df780e
> # Parent  e43264525ce513dab1ea23e39d2cf1051975c8ca
> # EXP-Topic obsfatetemplate
> template: compute verb in obsfateverb

Queued, thanks. I've adjusted docstrings to not break help formatting, and
added missing _() in flight.
via Mercurial-devel - Aug. 30, 2017, 6:13 a.m.
On Mon, Aug 28, 2017 at 12:59 PM, Boris Feld <boris.feld@octobus.net> wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1499088807 -7200
> #      Mon Jul 03 15:33:27 2017 +0200
> # Node ID 3aa34cf79eafaf1f3831dbfcc0891e4432df780e
> # Parent  e43264525ce513dab1ea23e39d2cf1051975c8ca
> # EXP-Topic obsfatetemplate
> template: compute verb in obsfateverb
>
> Add a template function obsfateverb which use the markers information to
> compute a better obsfate verb.
>
> The current logic behind the obsfate verb is simple for the moment:
>
> - If the successorsets is empty, the changeset has been pruned, for example:
>
>     Obsfate: pruned
>
> - If the successorsets length is 1, the changeset has been rewritten without
>   divergence, for example:
>
>     Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a
>
> - If the successorsets length is more than 1, the changeset has diverged, for
>   example:
>
>     Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a

Why do we say "split" and not "diverged"?

>
> As the divergence might occurs on a subset of successors, we might see some
> successors twice:
>
>     Obsfate: split as 9:0b997eb7ceee, 5:dd800401bd8c, 10:eceed8f98ffc; split
>     as 8:b18bc8331526, 5:dd800401bd8c, 10:eceed8f98ffc
>
> diff -r e43264525ce5 -r 3aa34cf79eaf mercurial/obsutil.py
> --- a/mercurial/obsutil.py      Tue Aug 22 23:39:05 2017 -0700
> +++ b/mercurial/obsutil.py      Mon Jul 03 15:33:27 2017 +0200
> @@ -582,3 +582,14 @@
>          values.append({'successors': sset, 'markers': sset.markers})
>
>      return values
> +
> +def successorsetverb(successorset):
> +    """ Return the verb summarizing the successorset
> +    """
> +    if not successorset:
> +        verb = 'pruned'

Should these strings be internationalized?
Yuya Nishihara - Aug. 30, 2017, 3:38 p.m.
On Tue, 29 Aug 2017 23:13:02 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> On Mon, Aug 28, 2017 at 12:59 PM, Boris Feld <boris.feld@octobus.net> wrote:
> > # HG changeset patch
> > # User Boris Feld <boris.feld@octobus.net>
> > # Date 1499088807 -7200
> > #      Mon Jul 03 15:33:27 2017 +0200
> > # Node ID 3aa34cf79eafaf1f3831dbfcc0891e4432df780e
> > # Parent  e43264525ce513dab1ea23e39d2cf1051975c8ca
> > # EXP-Topic obsfatetemplate
> > template: compute verb in obsfateverb

> > +def successorsetverb(successorset):
> > +    """ Return the verb summarizing the successorset
> > +    """
> > +    if not successorset:
> > +        verb = 'pruned'
> 
> Should these strings be internationalized?

Probably no. I think it's kind of an enum. Also, "_('%s by ...') % _('pruned')"
is difficult to translate.
Boris Feld - Aug. 31, 2017, 9:22 a.m.
On Tue, 2017-08-29 at 23:13 -0700, Martin von Zweigbergk wrote:
> On Mon, Aug 28, 2017 at 12:59 PM, Boris Feld <boris.feld@octobus.net>
> wrote:
> > # HG changeset patch
> > # User Boris Feld <boris.feld@octobus.net>
> > # Date 1499088807 -7200
> > #      Mon Jul 03 15:33:27 2017 +0200
> > # Node ID 3aa34cf79eafaf1f3831dbfcc0891e4432df780e
> > # Parent  e43264525ce513dab1ea23e39d2cf1051975c8ca
> > # EXP-Topic obsfatetemplate
> > template: compute verb in obsfateverb
> > 
> > Add a template function obsfateverb which use the markers
> > information to
> > compute a better obsfate verb.
> > 
> > The current logic behind the obsfate verb is simple for the moment:
> > 
> > - If the successorsets is empty, the changeset has been pruned, for
> > example:
> > 
> >     Obsfate: pruned
> > 
> > - If the successorsets length is 1, the changeset has been
> > rewritten without
> >   divergence, for example:
> > 
> >     Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a
> > 
> > - If the successorsets length is more than 1, the changeset has
> > diverged, for
> >   example:
> > 
> >     Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a
> 
> Why do we say "split" and not "diverged"?

The text is wrong, it should have says:

If a successorset has more than one successor, the changeset has been
splitted. So it match this situation:

successorsset = [[A, B]]

And not this situation:

successorsset = [[A], [B]]

The output is good and I just checked the code comments, it's good.

> 
> > 
> > As the divergence might occurs on a subset of successors, we might
> > see some
> > successors twice:
> > 
> >     Obsfate: split as 9:0b997eb7ceee, 5:dd800401bd8c,
> > 10:eceed8f98ffc; split
> >     as 8:b18bc8331526, 5:dd800401bd8c, 10:eceed8f98ffc
> > 
> > diff -r e43264525ce5 -r 3aa34cf79eaf mercurial/obsutil.py
> > --- a/mercurial/obsutil.py      Tue Aug 22 23:39:05 2017 -0700
> > +++ b/mercurial/obsutil.py      Mon Jul 03 15:33:27 2017 +0200
> > @@ -582,3 +582,14 @@
> >          values.append({'successors': sset, 'markers':
> > sset.markers})
> > 
> >      return values
> > +
> > +def successorsetverb(successorset):
> > +    """ Return the verb summarizing the successorset
> > +    """
> > +    if not successorset:
> > +        verb = 'pruned'
> 
> Should these strings be internationalized?

Patch

diff -r e43264525ce5 -r 3aa34cf79eaf mercurial/obsutil.py
--- a/mercurial/obsutil.py	Tue Aug 22 23:39:05 2017 -0700
+++ b/mercurial/obsutil.py	Mon Jul 03 15:33:27 2017 +0200
@@ -582,3 +582,14 @@ 
         values.append({'successors': sset, 'markers': sset.markers})
 
     return values
+
+def successorsetverb(successorset):
+    """ Return the verb summarizing the successorset
+    """
+    if not successorset:
+        verb = 'pruned'
+    elif len(successorset) == 1:
+        verb = 'rewritten'
+    else:
+        verb = 'split'
+    return verb
diff -r e43264525ce5 -r 3aa34cf79eaf mercurial/templater.py
--- a/mercurial/templater.py	Tue Aug 22 23:39:05 2017 -0700
+++ b/mercurial/templater.py	Mon Jul 03 15:33:27 2017 +0200
@@ -18,6 +18,7 @@ 
     encoding,
     error,
     minirst,
+    obsutil,
     parser,
     pycompat,
     registrar,
@@ -849,6 +850,25 @@ 
     func = lambda a, b: a % b
     return runarithmetic(context, mapping, (func, args[0], args[1]))
 
+@templatefunc('obsfateverb(successors)')
+def obsfateverb(context, mapping, args):
+    """ Compute obsfate related information based on successors
+
+    (EXPERIMENTAL)
+    """
+    if len(args) != 1:
+        # i18n: "obsfateverb" is a keyword
+        raise error.ParseError(_("obsfateverb expects one arguments"))
+
+    successors = evalfuncarg(context, mapping, args[0])
+
+    try:
+        return obsutil.successorsetverb(successors)
+    except TypeError:
+        # i18n: "obsfateverb" is a keyword
+        errmsg = _("obsfateverb first argument should be countable")
+        raise error.ParseError(errmsg)
+
 @templatefunc('relpath(path)')
 def relpath(context, mapping, args):
     """Convert a repository-absolute path into a filesystem path relative to
diff -r e43264525ce5 -r 3aa34cf79eaf tests/test-obsmarker-template.t
--- a/tests/test-obsmarker-template.t	Tue Aug 22 23:39:05 2017 -0700
+++ b/tests/test-obsmarker-template.t	Mon Jul 03 15:33:27 2017 +0200
@@ -13,7 +13,8 @@ 
   > stabilization=all
   > [templates]
   > obsfatesuccessors = " as {join(successors, ", ")}"
-  > obsfate = "rewritten{obsfatesuccessors}; "
+  > obsfateverb = "{obsfateverb(successors)}"
+  > obsfate = "{obsfateverb}{obsfatesuccessors}; "
   > [alias]
   > tlog = log -G -T '{node|short}\
   >     {if(predecessors, "\n  Predecessors: {predecessors}")}\
@@ -318,7 +319,7 @@ 
   o  337fec4d2edc
   |
   | @  471597cad322
-  |/     Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a;
+  |/     Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a;
   o  ea207398892e
   
   $ hg up f257fde29c7a
@@ -359,7 +360,7 @@ 
   o  337fec4d2edc
   |
   | x  471597cad322
-  |/     Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a;
+  |/     Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a;
   o  ea207398892e
   
   $ hg fatelogjson --hidden
@@ -1528,7 +1529,7 @@ 
   o  dd800401bd8c
   |
   | x  9bd10a0775e4
-  |/     Obsfate: rewritten as 5:dd800401bd8c, 6:4a004186e638, 7:ba2ed02b0c9a;
+  |/     Obsfate: split as 5:dd800401bd8c, 6:4a004186e638, 7:ba2ed02b0c9a;
   o  f897c6137566
   |
   | x  0dec01379d3b
@@ -1603,7 +1604,7 @@ 
   o  dd800401bd8c
   |
   | @  9bd10a0775e4
-  |/     Obsfate: rewritten as 5:dd800401bd8c, 9:0b997eb7ceee, 10:eceed8f98ffc; rewritten as 5:dd800401bd8c, 8:b18bc8331526, 10:eceed8f98ffc;
+  |/     Obsfate: split as 5:dd800401bd8c, 9:0b997eb7ceee, 10:eceed8f98ffc; split as 5:dd800401bd8c, 8:b18bc8331526, 10:eceed8f98ffc;
   o  f897c6137566
   |
   o  ea207398892e