Submitter | Jordi Gutiérrez Hermoso |
---|---|
Date | Feb. 15, 2019, 8 p.m. |
Message ID | <2aa9472715119f26f2e6.1550260812@chloe> |
Download | mbox | patch |
Permalink | /patch/38766/ |
State | Accepted |
Headers | show |
Comments
On Fri, 15 Feb 2019 15:00:12 -0500, Jordi Gutiérrez Hermoso wrote: > # HG changeset patch > # User Jordi Gutiérrez Hermoso <jordigh@octave.org> > # Date 1550259811 18000 > # Fri Feb 15 14:43:31 2019 -0500 > # Node ID 2aa9472715119f26f2e688dd9130f717113ec518 > # Parent a22321f2b1ee18ea09a70fee9e524d2f0298aaaa > templatekw: add a {negrev} keyword The word "negative revision" isn't correct, but I can't think of any better name, and I like the feature. Queued, thanks. Any naming idea is welcome. > --- a/mercurial/templatekw.py > +++ b/mercurial/templatekw.py > @@ -777,6 +777,14 @@ def showrev(context, mapping): > ctx = context.resource(mapping, 'ctx') > return scmutil.intrev(ctx) > > +@templatekeyword('negrev', requires={'repo', 'ctx'}) Moved this so the functions are roughly sorted lexicographically. > +def shownegrev(context, mapping): > + """Integer. The repository-local changeset negative revision number, > + which counts in the opposite direction.""" > + ctx = context.resource(mapping, 'ctx') > + repo = context.resource(mapping, 'repo') > + return scmutil.intrev(ctx) - len(repo) There are two weird cases: -r 'wdir()' => not negative -r null => unsupported negative integer (out of range) Maybe return None for these?
On Mon, 2019-02-18 at 22:29 +0900, Yuya Nishihara wrote: > The word "negative revision" isn't correct, Why do you think so? The full phrase is "negative revision number", isn't it? > > --- a/mercurial/templatekw.py > > +++ b/mercurial/templatekw.py > > @@ -777,6 +777,14 @@ def showrev(context, mapping): > > ctx = context.resource(mapping, 'ctx') > > return scmutil.intrev(ctx) > > > > +@templatekeyword('negrev', requires={'repo', 'ctx'}) > > Moved this so the functions are roughly sorted lexicographically. Oh, okay. I thought it made sense to have rev and negrev next to each other, but I didn't noticed that there was already a different order. > There are two weird cases: > > -r 'wdir()' => not negative > -r null => unsupported negative integer (out of range) > > Maybe return None for these? Oh, these are also broken for the normal {rev} template keyword. I'll send a separate patch for those two.
On Mon, 18 Feb 2019 14:25:42 -0500, Jordi Gutiérrez Hermoso wrote: > On Mon, 2019-02-18 at 22:29 +0900, Yuya Nishihara wrote: > > The word "negative revision" isn't correct, > > Why do you think so? The full phrase is "negative revision number", > isn't it? I don't think {negrev} is a revision number. It's merely an offset from the tip. The help says "A plain integer is treated as a revision number. Negative integers are treated as sequential offsets from the tip." > > There are two weird cases: > > > > -r 'wdir()' => not negative > > -r null => unsupported negative integer (out of range) > > > > Maybe return None for these? > > Oh, these are also broken for the normal {rev} template keyword. No. {rev} returns a valid revision number. 'rev(-1)' and 'rev(2147483647)' work if these revisions are populated by e.g. 'null:wdir() & ...'.
Patch
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -777,6 +777,14 @@ def showrev(context, mapping): ctx = context.resource(mapping, 'ctx') return scmutil.intrev(ctx) +@templatekeyword('negrev', requires={'repo', 'ctx'}) +def shownegrev(context, mapping): + """Integer. The repository-local changeset negative revision number, + which counts in the opposite direction.""" + ctx = context.resource(mapping, 'ctx') + repo = context.resource(mapping, 'repo') + return scmutil.intrev(ctx) - len(repo) + def showrevslist(context, mapping, name, revs): """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 @@ -2429,6 +2429,23 @@ Check other fatelog implementations date: Thu Jan 01 00:00:00 1970 +0000 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 ============================================== @@ -2639,3 +2656,10 @@ metadata should be converted back to loc |/ Obsfate: rewritten using amend as 2:718c0d00cee1 by test (at 1970-01-01 00:00 +0000); o ea207398892e + $ hg log -G -T "{negrev}\n" + @ -1 + | + o -2 + | + o -5 +