Patchwork [10,of,11,V2] log: add obsfate by default in changeset printer

login
register
mail settings
Submitter Boris Feld
Date Oct. 11, 2017, 12:09 p.m.
Message ID <79dd127e09281ca88332.1507723796@FB>
Download mbox | patch
Permalink /patch/24731/
State Accepted
Headers show

Comments

Boris Feld - Oct. 11, 2017, 12:09 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 79dd127e09281ca88332be9791016cf92936e4e8
# Parent  4162251414fe06aec0bbe559a0262d8fdd49129a
# EXP-Topic obsfatekeyword
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 79dd127e0928
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. 11, 2017, 1:40 p.m.
On Wed, 11 Oct 2017 14:09:56 +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 79dd127e09281ca88332be9791016cf92936e4e8
> # Parent  4162251414fe06aec0bbe559a0262d8fdd49129a
> # EXP-Topic obsfatekeyword
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 79dd127e0928
> log: add obsfate by default in changeset printer

> +        elif ctx.obsolete():
> +            self.showobsfate(ctx)

Nit: could be marked as a private function.

> +    def showobsfate(self, ctx):
> +        obsfate = templatekw.showobsfate(repo=self.repo, ctx=ctx, ui=self.ui)
> +
> +        if obsfate:
> +            for obsfateline in obsfate:
> +                self.ui.write(_("obsfate:     %s\n") % obsfateline,
> +                              label='log.obsfate')

Nit: please add '# i18n: column positioning for "hg log"' comment
(FWIW, I don't know how the word "obsfate" would be translated.)
Boris Feld - Oct. 12, 2017, 1:36 p.m.
On Wed, 2017-10-11 at 22:40 +0900, Yuya Nishihara wrote:
> On Wed, 11 Oct 2017 14:09:56 +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 79dd127e09281ca88332be9791016cf92936e4e8
> > # Parent  4162251414fe06aec0bbe559a0262d8fdd49129a
> > # EXP-Topic obsfatekeyword
> > # Available At https://bitbucket.org/octobus/mercurial-devel/
> > #              hg pull https://bitbucket.org/octobus/mercurial-deve
> > l/ -r 79dd127e0928
> > log: add obsfate by default in changeset printer
> > +        elif ctx.obsolete():
> > +            self.showobsfate(ctx)
> 
> Nit: could be marked as a private function.
> 
> > +    def showobsfate(self, ctx):
> > +        obsfate = templatekw.showobsfate(repo=self.repo, ctx=ctx,
> > ui=self.ui)
> > +
> > +        if obsfate:
> > +            for obsfateline in obsfate:
> > +                self.ui.write(_("obsfate:     %s\n") %
> > obsfateline,
> > +                              label='log.obsfate')
> 
> Nit: please add '# i18n: column positioning for "hg log"' comment
> (FWIW, I don't know how the word "obsfate" would be translated.)

Both nits fixed.

I have no exact idea how it could be translated. Obsolescence fate
don't translate well in french. The french translation for destiny
might works in French.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1684,6 +1684,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:
@@ -1732,6 +1735,14 @@ 
 
         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:
+                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
@@ -1200,6 +1237,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
@@ -1607,6 +1645,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
@@ -2050,6 +2090,7 @@ 
   |  tag:         tip
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  obsfate:     pruned
   |  summary:     A2
   |
   o  changeset:   2:617adc3a144c
@@ -2061,6 +2102,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
@@ -972,6 +972,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]