Re: [PATCH 2 of 2] templatekw: add a {negrev} keyword

2018-01-19 Thread Yuya Nishihara
On Fri, 19 Jan 2018 14:32:34 -0500, Augie Fackler wrote:
> On Wed, Jan 17, 2018 at 10:14:30PM -0500, Jordi Gutiérrez Hermoso wrote:
> > # HG changeset patch
> > # User Jordi Gutiérrez Hermoso 
> > # Date 1516243120 18000
> > #  Wed Jan 17 21:38:40 2018 -0500
> > # Node ID cbf1d676a938e78d40cd3504dd916f787bcb47ee
> > # Parent  701f8a9defdc09bb63f2596e2fc426f2e78da313
> > templatekw: add a {negrev} keyword
> 
> This is a really interesting idea. It mostly has driven me crazy that
> negative revnums work, but this sort of provides a reason for their
> existence I guess.
> 
> That said, I'm too wary of locking this in on the last day before a
> freeze, so let's plan to discuss this after the freeze sometime in
> early February? Maybe set a calendar reminder to rebase && resend this
> patch then.

Can you rename the keyword to something saying that isn't actually a "rev"?
Negative integers aren't always usable where revision number is expected,
e.g. rev(n), and -1 means either null or tip depending on context.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 2 of 2] templatekw: add a {negrev} keyword

2018-01-19 Thread Augie Fackler
On Wed, Jan 17, 2018 at 10:14:30PM -0500, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso 
> # Date 1516243120 18000
> #  Wed Jan 17 21:38:40 2018 -0500
> # Node ID cbf1d676a938e78d40cd3504dd916f787bcb47ee
> # Parent  701f8a9defdc09bb63f2596e2fc426f2e78da313
> templatekw: add a {negrev} keyword

This is a really interesting idea. It mostly has driven me crazy that
negative revnums work, but this sort of provides a reason for their
existence I guess.

That said, I'm too wary of locking this in on the last day before a
freeze, so let's plan to discuss this after the freeze sometime in
early February? Maybe set a calendar reminder to rebase && resend this
patch then.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 2 of 2] templatekw: add a {negrev} keyword

2018-01-19 Thread Yuya Nishihara
On Thu, 18 Jan 2018 10:35:09 -0500, Jordi Gutiérrez Hermoso wrote:
> On Thu, 2018-01-18 at 21:05 +0900, Yuya Nishihara wrote:
> > On Wed, 17 Jan 2018 22:14:30 -0500, Jordi Gutiérrez Hermoso wrote:
> > > # HG changeset patch
> > > # User Jordi Gutiérrez Hermoso 
> > > # Date 1516243120 18000
> > > #  Wed Jan 17 21:38:40 2018 -0500
> > > # Node ID cbf1d676a938e78d40cd3504dd916f787bcb47ee
> > > # Parent  701f8a9defdc09bb63f2596e2fc426f2e78da313
> > > templatekw: add a {negrev} keyword
> > > 
> > > Revision numbers are getting much maligned for two reasons: they
> > > are
> > > too long in large repos and users get confused by their local-only
> > > nature. It just occurred to me that negative revision numbers avoid
> > > both of those problems. Since negative revision numbers change
> > > whenever the repo changes, it's much more obvious that they are a
> > > local-only convenience. Additionally, for the recent commits that
> > > we
> > > usually care about the most, negative revision numbers are always
> > > near
> > > zero.
> > > 
> > > This commit adds a negrev templatekw to more easily expose negative
> > > revision numbers. It's not easy to reliably produce this output
> > > with
> > > existing keywords due to hidden commits or without a significant
> > > slowdown due to computing a complicated template expression.
> > 
> > Isn't it "{rev - revset("tip")|stringify - 1}" ? Well, the stringify
> > looks strange, but not terrible.
> 
> That's incorrect if tip is hidden.

Good point. Perhaps we'll need to update the help or change the behavior
of negative integer revisions. Currently "help revisions" says "sequential
offsets from the tip, with -1 denoting the tip."

> And much noticeably slower.

What use case do you suppose?

It's slow to run complex template, but in this case, it's just 34.5us per
revision. I don't think it's noticeable while reading log in pager.

  % hg log -T '{rev}\n' --time > /dev/null
  time: real 1.390 secs (user 1.390+0.000 sys 0.000+0.000)
  % hg log -T '{rev - revset("tip")|stringify - 1}\n' --time > /dev/null
  time: real 2.620 secs (user 2.610+0.000 sys 0.010+0.000)

'{desc}' is much slower by the way.

  % hg log -T '{rev} {desc|firstline}\n' --time > /dev/null
  time: real 3.740 secs (user 3.710+0.000 sys 0.010+0.000)
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 2 of 2] templatekw: add a {negrev} keyword

2018-01-18 Thread Jordi Gutiérrez Hermoso
On Thu, 2018-01-18 at 21:05 +0900, Yuya Nishihara wrote:
> On Wed, 17 Jan 2018 22:14:30 -0500, Jordi Gutiérrez Hermoso wrote:
> > # HG changeset patch
> > # User Jordi Gutiérrez Hermoso 
> > # Date 1516243120 18000
> > #  Wed Jan 17 21:38:40 2018 -0500
> > # Node ID cbf1d676a938e78d40cd3504dd916f787bcb47ee
> > # Parent  701f8a9defdc09bb63f2596e2fc426f2e78da313
> > templatekw: add a {negrev} keyword
> > 
> > Revision numbers are getting much maligned for two reasons: they
> > are
> > too long in large repos and users get confused by their local-only
> > nature. It just occurred to me that negative revision numbers avoid
> > both of those problems. Since negative revision numbers change
> > whenever the repo changes, it's much more obvious that they are a
> > local-only convenience. Additionally, for the recent commits that
> > we
> > usually care about the most, negative revision numbers are always
> > near
> > zero.
> > 
> > This commit adds a negrev templatekw to more easily expose negative
> > revision numbers. It's not easy to reliably produce this output
> > with
> > existing keywords due to hidden commits or without a significant
> > slowdown due to computing a complicated template expression.
> 
> Isn't it "{rev - revset("tip")|stringify - 1}" ? Well, the stringify
> looks strange, but not terrible.

That's incorrect if tip is hidden. And much noticeably slower.

___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 2 of 2] templatekw: add a {negrev} keyword

2018-01-18 Thread Yuya Nishihara
On Wed, 17 Jan 2018 22:14:30 -0500, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso 
> # Date 1516243120 18000
> #  Wed Jan 17 21:38:40 2018 -0500
> # Node ID cbf1d676a938e78d40cd3504dd916f787bcb47ee
> # Parent  701f8a9defdc09bb63f2596e2fc426f2e78da313
> templatekw: add a {negrev} keyword
> 
> Revision numbers are getting much maligned for two reasons: they are
> too long in large repos and users get confused by their local-only
> nature. It just occurred to me that negative revision numbers avoid
> both of those problems. Since negative revision numbers change
> whenever the repo changes, it's much more obvious that they are a
> local-only convenience. Additionally, for the recent commits that we
> usually care about the most, negative revision numbers are always near
> zero.
> 
> This commit adds a negrev templatekw to more easily expose negative
> revision numbers. It's not easy to reliably produce this output with
> existing keywords due to hidden commits or without a significant
> slowdown due to computing a complicated template expression.

Isn't it "{rev - revset("tip")|stringify - 1}" ? Well, the stringify
looks strange, but not terrible.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 2 of 2] templatekw: add a {negrev} keyword

2018-01-17 Thread Jordi Gutiérrez Hermoso
# HG changeset patch
# User Jordi Gutiérrez Hermoso 
# Date 1516243120 18000
#  Wed Jan 17 21:38:40 2018 -0500
# Node ID cbf1d676a938e78d40cd3504dd916f787bcb47ee
# Parent  701f8a9defdc09bb63f2596e2fc426f2e78da313
templatekw: add a {negrev} keyword

Revision numbers are getting much maligned for two reasons: they are
too long in large repos and users get confused by their local-only
nature. It just occurred to me that negative revision numbers avoid
both of those problems. Since negative revision numbers change
whenever the repo changes, it's much more obvious that they are a
local-only convenience. Additionally, for the recent commits that we
usually care about the most, negative revision numbers are always near
zero.

This commit adds a negrev templatekw to more easily expose negative
revision numbers. It's not easy to reliably produce this output with
existing keywords due to hidden commits or without a significant
slowdown due to computing a complicated template expression.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -856,6 +856,12 @@ def showrev(repo, ctx, templ, **args):
 def numrevs(repo):
 return len(repo)
 
+@templatekeyword('negrev')
+def showrev(repo, ctx, templ, **args):
+"""Integer. The repository-local changeset negative revision number,
+which counts in the opposite direction."""
+return scmutil.intrev(ctx) - numrevs(repo)
+
 def showrevslist(name, revs, **args):
 """helper to generate a list of revisions in which a mapped template will
 be evaluated"""
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
@@ -2409,6 +2409,23 @@ Check other fatelog implementations
  date:Thu Jan 01 00:00:00 1970 +
  summary: ROOT
   
+Check that {negrev} shows usable negative revisions despite hidden commits
+
+  $ hg log -G -T "{negrev}\n"
+  @  -3
+  |
+  o  -4
+  
+
+  $ hg log -G -T "{negrev}\n" --hidden
+  x  -1
+  |
+  | x  -2
+  |/
+  | @  -3
+  |/
+  o  -4
+  
 
 Test templates with splitted and pruned commit
 ==
@@ -2559,3 +2576,10 @@ Check other fatelog implementations
  date:Thu Jan 01 00:00:00 1970 +
  summary: ROOT
   
+  $ hg log -G -T "{negrev}\n"
+  @  -1
+  |
+  o  -2
+  |
+  o  -4
+  
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel