Patchwork [6,of,7,V3] log: add obsfate by default in changeset printer

login
register
mail settings
Submitter Boris Feld
Date Oct. 17, 2017, 3:14 p.m.
Message ID <f3a67648b948d83038f4.1508253247@FB>
Download mbox | patch
Permalink /patch/25120/
State Accepted
Headers show

Comments

Boris Feld - Oct. 17, 2017, 3:14 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1507209918 -7200
#      Thu Oct 05 15:25:18 2017 +0200
# Node ID f3a67648b948d83038f4b0fe351a81ee042f814f
# Parent  a2bbc21a142b192bde003f8df3adb71e13242ea1
# EXP-Topic obsfatekeyword
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f3a67648b948
log: add obsfate by default in changeset printer

Having an obsfate by default in log will be useful for users to understand why
they have obsolete and unstable changesets. Obsfate will only be shown for
obsolete changesets, which only happens if people opt-in to experimental feature.

But when obsolete changeset are visible, it is very useful to understand where
they are. Having it in log could be sufficient for most people, so they don't
have to learn a new command (like obslog which is itself useful in case of
divergences).

For example, when pulling and working directory parent become obsolete:

  $ hg pull
  ...
  working directory parent is obsolete! (f936c1697205)

This message comes from the Evolve extension.

Obsfate would comes handy:

  $ hg log -G
  o  changeset:   2:6f91013c5136
  |  tag:         tip
  |  parent:      0:4ef7b558f3ec
  |  user:        Boris Feld <boris.feld@octobus.net>
  |  date:        Mon Oct 09 16:00:27 2017 +0200
  |  summary:     A
  |
  | @  changeset:   1:f936c1697205
  |/   user:        Boris Feld <boris.feld@octobus.net>
  |    date:        Mon Oct 09 16:00:27 2017 +0200
  |    obsfate:     rewritten using amend as 2:6f91013c5136
  |    summary:     -A
  |
  o  changeset:   0:feb4dd822b8c
     user:        Boris Feld <boris.feld@octobus.net>
     date:        Tue Oct 09 16:00:00 2017 +0200
     summary:     ROOT

And once we update, we don't have an obsolete changeset in the log anymore so
we don't show obsfate anymore, most users won't see obsfate often if they
don't have obsolete changeset often:

  @  changeset:   2:6f91013c5136
  |  tag:         tip
  |  parent:      0:4ef7b558f3ec
  |  user:        Boris Feld <boris.feld@octobus.net>
  |  date:        Mon Oct 09 16:00:27 2017 +0200
  |  summary:     A
  |
  o  changeset:   0:feb4dd822b8c
     user:        Boris Feld <boris.feld@octobus.net>
     date:        Tue Oct 09 16:00:00 2017 +0200
     summary:     ROOT
Yuya Nishihara - Oct. 18, 2017, 1:15 p.m.
On Tue, 17 Oct 2017 17:14:07 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1507209918 -7200
> #      Thu Oct 05 15:25:18 2017 +0200
> # Node ID f3a67648b948d83038f4b0fe351a81ee042f814f
> # Parent  a2bbc21a142b192bde003f8df3adb71e13242ea1
> # EXP-Topic obsfatekeyword
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f3a67648b948
> log: add obsfate by default in changeset printer

> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -1665,6 +1665,9 @@
>              self.ui.write(_("instability: %s\n") % ', '.join(instabilities),
>                            label='log.instability')
>  
> +        elif ctx.obsolete():
> +            self._showobsfate(ctx)

elif? I don't know if isunstable and obsolete are mutually exclusive.

> +    def _showobsfate(self, ctx):
> +        obsfate = templatekw.showobsfate(repo=self.repo, ctx=ctx, ui=self.ui)

Maybe you know, calling templatekw function here is just a hack. Please send
a follow up after the release.

> +
> +        if obsfate:
> +            for obsfateline in obsfate:
> +                # i18n: column positioning for "hg log"
> +                self.ui.write(_("obsfate:     %s\n") % obsfateline,
> +                              label='log.obsfate')
Boris Feld - Oct. 18, 2017, 2:47 p.m.
On Wed, 2017-10-18 at 22:15 +0900, Yuya Nishihara wrote:
> On Tue, 17 Oct 2017 17:14:07 +0200, Boris Feld wrote:
> > # HG changeset patch
> > # User Boris Feld <boris.feld@octobus.net>
> > # Date 1507209918 -7200
> > #      Thu Oct 05 15:25:18 2017 +0200
> > # Node ID f3a67648b948d83038f4b0fe351a81ee042f814f
> > # Parent  a2bbc21a142b192bde003f8df3adb71e13242ea1
> > # EXP-Topic obsfatekeyword
> > # Available At https://bitbucket.org/octobus/mercurial-devel/
> > #              hg pull https://bitbucket.org/octobus/mercurial-deve
> > l/ -r f3a67648b948
> > log: add obsfate by default in changeset printer
> > diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> > --- a/mercurial/cmdutil.py
> > +++ b/mercurial/cmdutil.py
> > @@ -1665,6 +1665,9 @@
> >              self.ui.write(_("instability: %s\n") % ',
> > '.join(instabilities),
> >                            label='log.instability')
> >  
> > +        elif ctx.obsolete():
> > +            self._showobsfate(ctx)
> 
> elif? I don't know if isunstable and obsolete are mutually exclusive.

You can't be both unstable and obsolete at the same time, I just
rechecked to be sure.

> 
> > +    def _showobsfate(self, ctx):
> > +        obsfate = templatekw.showobsfate(repo=self.repo, ctx=ctx,
> > ui=self.ui)
> 
> Maybe you know, calling templatekw function here is just a hack.
> Please send
> a follow up after the release.

Right, I will have a follow-up ready for cleaning this shortcut.

> 
> > +
> > +        if obsfate:
> > +            for obsfateline in obsfate:
> > +                # i18n: column positioning for "hg log"
> > +                self.ui.write(_("obsfate:     %s\n") %
> > obsfateline,
> > +                              label='log.obsfate')

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1665,6 +1665,9 @@ 
             self.ui.write(_("instability: %s\n") % ', '.join(instabilities),
                           label='log.instability')
 
+        elif ctx.obsolete():
+            self._showobsfate(ctx)
+
         self._exthook(ctx)
 
         if self.ui.debugflag:
@@ -1713,6 +1716,15 @@ 
 
         self.showpatch(ctx, matchfn)
 
+    def _showobsfate(self, ctx):
+        obsfate = templatekw.showobsfate(repo=self.repo, ctx=ctx, ui=self.ui)
+
+        if obsfate:
+            for obsfateline in obsfate:
+                # i18n: column positioning for "hg log"
+                self.ui.write(_("obsfate:     %s\n") % obsfateline,
+                              label='log.obsfate')
+
     def _exthook(self, ctx):
         '''empty method used by extension as a hook point
         '''
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -535,6 +535,7 @@ 
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
+  obsfate:     pruned
   summary:     .
   
   changeset:   0:eff892de26ec
diff --git a/tests/test-obsmarker-template.t b/tests/test-obsmarker-template.t
--- a/tests/test-obsmarker-template.t
+++ b/tests/test-obsmarker-template.t
@@ -58,11 +58,13 @@ 
   |/   parent:      0:ea207398892e
   |    user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 3:d004c8f274b9 by test2
   |    summary:     A1
   |
   | x  changeset:   1:471f378eab4c
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 2:a468dc9b3633
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -103,6 +105,26 @@ 
   |/     Obsfate: rewritten using amend as 3:d004c8f274b9 by test, test2
   o  ea207398892e
   
+
+  $ hg log -G --config ui.logtemplate=
+  o  changeset:   3:d004c8f274b9
+  |  tag:         tip
+  |  parent:      0:ea207398892e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     A2
+  |
+  | @  changeset:   1:471f378eab4c
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 3:d004c8f274b9 by test2
+  |    summary:     A0
+  |
+  o  changeset:   0:ea207398892e
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     ROOT
+  
   $ hg up 'desc(A1)' --hidden
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
@@ -294,6 +316,7 @@ 
   | x  changeset:   1:471597cad322
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     split as 2:337fec4d2edc, 3:f257fde29c7a
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -469,11 +492,13 @@ 
   | x  changeset:   2:0dec01379d3b
   | |  user:        test
   | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  obsfate:     rewritten as 3:eb5a0daa2192
   | |  summary:     B0
   | |
   | x  changeset:   1:471f378eab4c
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten as 3:eb5a0daa2192
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -640,6 +665,7 @@ 
   | x  changeset:   1:471f378eab4c
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 2:fdf9bde5129a
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -669,6 +695,8 @@ 
   | x  changeset:   1:471f378eab4c
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 2:fdf9bde5129a
+  |    obsfate:     rewritten using amend as 3:65b757b745b9
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -690,6 +718,7 @@ 
   |/   parent:      0:ea207398892e
   |    user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 4:019fadeab383
   |    summary:     A2
   |
   | o  changeset:   2:fdf9bde5129a
@@ -702,6 +731,8 @@ 
   | x  changeset:   1:471f378eab4c
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 2:fdf9bde5129a
+  |    obsfate:     rewritten using amend as 3:65b757b745b9
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -880,6 +911,7 @@ 
   | x  changeset:   2:0dec01379d3b
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 3:b7ea6d14e664
   |    summary:     B0
   |
   o  changeset:   1:471f378eab4c
@@ -918,16 +950,19 @@ 
   | |  parent:      1:471f378eab4c
   | |  user:        test
   | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  obsfate:     rewritten as 4:eb5a0daa2192
   | |  summary:     B1
   | |
   | | x  changeset:   2:0dec01379d3b
   | |/   user:        test
   | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    obsfate:     rewritten using amend as 3:b7ea6d14e664
   | |    summary:     B0
   | |
   | x  changeset:   1:471f378eab4c
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten as 4:eb5a0daa2192
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -1166,11 +1201,13 @@ 
   |/   parent:      0:ea207398892e
   |    user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 3:7a230b46bf61
   |    summary:     A1
   |
   | x  changeset:   1:471f378eab4c
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 2:fdf9bde5129a
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -1201,6 +1238,7 @@ 
   | @  changeset:   1:471f378eab4c
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 2:7a230b46bf61
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
@@ -1608,6 +1646,8 @@ 
   | x  changeset:   6:4a004186e638
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     rewritten using amend as 8:b18bc8331526
+  |    obsfate:     rewritten using amend as 9:0b997eb7ceee
   |    summary:     Add A,B,C
   |
   o  changeset:   5:dd800401bd8c
@@ -2051,6 +2091,7 @@ 
   |  tag:         tip
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  obsfate:     pruned
   |  summary:     A2
   |
   o  changeset:   2:617adc3a144c
@@ -2062,6 +2103,7 @@ 
   | x  changeset:   1:471597cad322
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    obsfate:     split as 2:617adc3a144c, 3:0d0ef4bdf70e
   |    summary:     A0
   |
   o  changeset:   0:ea207398892e
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -975,6 +975,7 @@ 
   [log.parent changeset.draft|parent:      3:6f9641995072]
   [log.user|user:        test]
   [log.date|date:        Thu Jan 01 00:00:00 1970 +0000]
+  [log.obsfate|obsfate:     pruned]
   [log.summary|summary:     add obsolete_e]