[PATCH 2 of 2] templatekw: introduce the changessincelatesttag keyword
Matt Harbison
mharbison72 at gmail.com
Sat Jun 27 11:50:48 CDT 2015
On Sat, 27 Jun 2015 09:15:33 -0400, Yuya Nishihara <yuya at tcha.org> wrote:
> On Sat, 27 Jun 2015 00:01:24 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1435374665 14400
>> # Fri Jun 26 23:11:05 2015 -0400
>> # Node ID 7391298f5b4d78e7d6e56eb2e9ebaf61dbd98be9
>> # Parent c673a9cb5668ed84c13d69505cd6523a5469e385
>> templatekw: introduce the changessincelatesttag keyword
>>
>> Archive is putting a value with the same name in the metadata file, to
>> count all
>> of the changes not covered by the latest tag, instead of just along the
>> longest
>> path. It seems that this would be useful to have on the command line
>> as well.
>> It might be nice for the name to start with 'latesttag' so that it is
>> grouped
>> with the other tag keywords, but I can't think of a better name.
>>
>> Using p1() instead of wdir() is partially for practicality- wctx.rev()
>> returns
>> None, which crashes %d, and repo[ff..ff] doesn't currently work.
>> There's also
>> a correctness factor- if you update to a tag and change nothing, there
>> are 0
>> changes since the latest tag. A change without a commit (dirty) is 1
>> change.
>>
>> Current precedent for wdir() mascarading as p1() is the fact that
>> wctx.tags()
>> reports whatever tags the parents have. Maybe that's not a good idea
>> (at least
>> for non virtual tags like 'tip'), because a side effect of that is
>> '-r wdir() -T {latesttagdistance}' after updating to a tag is 0,
>> whether or not
>> wdir() is dirty. Committing once then jumps the value to 2, and it
>> continues
>> sequentially from there.
>>
>> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
>> --- a/mercurial/templatekw.py
>> +++ b/mercurial/templatekw.py
>> @@ -334,6 +334,18 @@
>> """:latesttagdistance: Integer. Longest path to the latest tag."""
>> return getlatesttags(repo, ctx, cache)[1]
>>
>> +def showchangessincelatesttag(repo, ctx, templ, cache, **args):
>> + """:changessincelatesttag: Integer. All ancestors not in the
>> latest tag."""
>> + latesttag = getlatesttags(repo, ctx, cache)[2][0]
>> + offset = 0
>> +
>> + if ctx.rev() is None:
>> + if ctx.dirty(missing=True):
>> + offset = 1
>
> IMHO, offset is always 1 because the wdir revision exists no matter if
> it is
> dirty or not.
Is there an ease of coding something factor? It seems a bit surprising to
me if you clean update to a tag, that immediately the change count is 1.
I added something like this to a build script:
hg log -r "wdir()" -T
"{latesttag}+{changessincelatesttag}-{p1node|short}{if(files,'+')}\n"
and cut on the first '+' if the value between '+' and '-' is zero.
Treating a change count of 1 as the tagged release is why it seems weird.
Certainly I could change that from 0 to 1 and put a comment in. I'm more
worried about this keyword and {latesttagdistance} agreeing when given a
few linear commits on a tagged revision:
T -- o -- o -- wdir()
Currently they do not (except a clean wdir() on T), because
committablectx.tags() returns the parents' tags. I commented that out,
and the 'identify' tests fail. Maybe identify can be fixed up to manually
look at the parent's tags. Since wdir() isn't documented, I don't think
that's a breaking change. I didn't try because I found this at work when
dealing with something else, and didn't get back to it.
If you always consider wdir() to be a distinct change or "commit", it
really can't have the same tags as it's parents without violating the 1:1
relationship between tag and cset. (Not that a user is likely to notice
or care.)
>> + ctx = ctx.p1()
>> +
>> + return len(repo.revs('only(%d, %s)', ctx.rev(), latesttag)) +
>> offset
>
> Perhaps repo.revs('only(%ld, %s)', [p.rev() for p in wctx.parents()]) is
> more correct.
You're right. I'll wait for more feedback on the first point before
resending.
More information about the Mercurial-devel
mailing list