D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
This revision was automatically updated to reflect the committed changes. Closed by commit rHGfb672eac2702: templatekw: choose {latesttag} by len(changes), not date (issue5659) (authored by martinvonz). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D447?vs=1089=1152 REVISION DETAIL https://phab.mercurial-scm.org/D447 AFFECTED FILES mercurial/templatekw.py tests/test-command-template.t CHANGE DETAILS diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -2885,7 +2885,7 @@ o 0: null+1 -One common tag: longest path wins: +One common tag: longest path wins for {latesttagdistance}: $ hg tag -r 1 -m t1 -d '6 0' t1 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2904,7 +2904,7 @@ o 0: null+1 -One ancestor tag: more recent wins: +One ancestor tag: closest wins: $ hg tag -r 2 -m t2 -d '7 0' t2 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2925,7 +2925,7 @@ o 0: null+1 -Two branch tags: more recent wins: +Two branch tags: more recent wins if same number of changes: $ hg tag -r 3 -m t3 -d '8 0' t3 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2948,12 +2948,39 @@ o 0: null+1 +Two branch tags: fewest changes wins: + + $ hg tag -r 4 -m t4 -d '4 0' t4 # older than t2, but should not matter + $ hg log -G --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n" + @ 9: t4+5,6 + | + o 8: t4+4,5 + | + o 7: t4+3,4 + | + o 6: t4+2,3 + | + o5: t4+1,2 + |\ + | o 4: t4+0,0 + | | + | o 3: t3+0,0 + | | + o | 2: t2+0,0 + |/ + o 1: t1+0,0 + | + o 0: null+1,1 + + Merged tag overrides: $ hg tag -r 5 -m t5 -d '9 0' t5 $ hg tag -r 3 -m at3 -d '10 0' at3 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' - @ 10: t5+5 + @ 11: t5+6 + | + o 10: t5+5 | o 9: t5+4 | @@ -2965,7 +2992,7 @@ | o5: t5+0 |\ - | o 4: at3:t3+1 + | o 4: t4+0 | | | o 3: at3:t3+0 | | @@ -2977,7 +3004,9 @@ $ hg log -G --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n" - @ 10: t5+5,5 + @ 11: t5+6,6 + | + o 10: t5+5,5 | o 9: t5+4,4 | @@ -2989,7 +3018,7 @@ | o5: t5+0,0 |\ - | o 4: at3+1,1 t3+1,1 + | o 4: t4+0,0 | | | o 3: at3+0,0 t3+0,0 | | @@ -3001,7 +3030,9 @@ $ hg log -G --template "{rev}: {latesttag('re:^t[13]$') % '{tag}, C: {changes}, D: {distance}'}\n" - @ 10: t3, C: 8, D: 7 + @ 11: t3, C: 9, D: 8 + | + o 10: t3, C: 8, D: 7 | o 9: t3, C: 7, D: 6 | @@ -3044,7 +3075,7 @@ > EOF $ hg -R latesttag tip - test 10:9b4a630e5f5f + test 11:97e5943b523a Test recursive showlist template (issue1989): @@ -3057,7 +3088,7 @@ $ hg -R latesttag log -r tip --style=style1989 M|test - 10,test + 11,test branch: test Test new-style inline templating: @@ -3090,6 +3121,7 @@ $ hg log -R latesttag --template '{desc}\n' at3 t5 + t4 t3 t2 t1 @@ -3103,6 +3135,7 @@ $ hg log -R latesttag --template '{strip(desc, "te")}\n' at3 5 + 4 3 2 1 @@ -3118,6 +3151,7 @@ $ hg log -R latesttag --template 'date: {date(date, "%y %m %d %S %z")}\n' date: 70 01 01 10 + date: 70 01 01 09 + + date: 70 01 01 04 + date: 70 01 01 08 + date: 70 01 01 07 + date: 70 01 01 06 + diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -208,10 +208,22 @@ latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)] continue try: -# The tuples are laid out so the right one can be found by -# comparison. -pdate, pdist, ptag = max( -latesttags[p.rev()] for p in ctx.parents()) +ptags = [latesttags[p.rev()] for p in ctx.parents()] +if len(ptags) > 1: +if ptags[0][2] == ptags[1][2]: +# The tuples are laid out so the right one can be found by +# comparison in this case. +pdate, pdist, ptag = max(ptags) +else: +def key(x): +changessincetag = len(repo.revs('only(%d, %s)', +ctx.rev(), x[2][0])) +# Smallest number of changes since tag wins. Date is +# used as tiebreaker. +return [-changessincetag, x[0]] +pdate, pdist, ptag = max(ptags, key=key) +else: +pdate, pdist, ptag = ptags[0] except KeyError: # Cache miss - recurse todo.append(rev) To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel
Re: D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
yuja (Yuya Nishihara)writes: > yuja accepted this revision. > yuja added a comment. > This revision is now accepted and ready to land. > > > This one looks good to me, thanks. I leave it to Sean since he said he's > queued the previous series. Thanks. I think I figured out out to queue this again. Will test, merge, and push. signature.asc Description: PGP signature ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
yuja accepted this revision. yuja added a comment. This revision is now accepted and ready to land. This one looks good to me, thanks. I leave it to Sean since he said he's queued the previous series. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D447 To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
martinvonz added inline comments. INLINE COMMENTS > yuja wrote in templatekw.py:222 > > I'm not changing latesttagdistance (AFAIK), only the definition of > > latesttag. > > Try `ptags = reversed(...)` and run tests. The largest `pdist` should be > selected > so that `latesttagdistance` returns the longest path. >> I'm not changing latesttagdistance (AFAIK), only the definition of latesttag. > > Try ptags = reversed(...) and run tests. The largest pdist should be selected > so that latesttagdistance returns the longest path. Ah, right, when the tag is in the common ancestor, we should choose the longest branch. Good catch. See how you like this change. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D447 To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
martinvonz updated this revision to Diff 1089. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D447?vs=1088=1089 REVISION DETAIL https://phab.mercurial-scm.org/D447 AFFECTED FILES mercurial/templatekw.py tests/test-command-template.t CHANGE DETAILS diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -2885,7 +2885,7 @@ o 0: null+1 -One common tag: longest path wins: +One common tag: longest path wins for {latesttagdistance}: $ hg tag -r 1 -m t1 -d '6 0' t1 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2904,7 +2904,7 @@ o 0: null+1 -One ancestor tag: more recent wins: +One ancestor tag: closest wins: $ hg tag -r 2 -m t2 -d '7 0' t2 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2925,7 +2925,7 @@ o 0: null+1 -Two branch tags: more recent wins: +Two branch tags: more recent wins if same number of changes: $ hg tag -r 3 -m t3 -d '8 0' t3 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2948,12 +2948,39 @@ o 0: null+1 +Two branch tags: fewest changes wins: + + $ hg tag -r 4 -m t4 -d '4 0' t4 # older than t2, but should not matter + $ hg log -G --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n" + @ 9: t4+5,6 + | + o 8: t4+4,5 + | + o 7: t4+3,4 + | + o 6: t4+2,3 + | + o5: t4+1,2 + |\ + | o 4: t4+0,0 + | | + | o 3: t3+0,0 + | | + o | 2: t2+0,0 + |/ + o 1: t1+0,0 + | + o 0: null+1,1 + + Merged tag overrides: $ hg tag -r 5 -m t5 -d '9 0' t5 $ hg tag -r 3 -m at3 -d '10 0' at3 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' - @ 10: t5+5 + @ 11: t5+6 + | + o 10: t5+5 | o 9: t5+4 | @@ -2965,7 +2992,7 @@ | o5: t5+0 |\ - | o 4: at3:t3+1 + | o 4: t4+0 | | | o 3: at3:t3+0 | | @@ -2977,7 +3004,9 @@ $ hg log -G --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n" - @ 10: t5+5,5 + @ 11: t5+6,6 + | + o 10: t5+5,5 | o 9: t5+4,4 | @@ -2989,7 +3018,7 @@ | o5: t5+0,0 |\ - | o 4: at3+1,1 t3+1,1 + | o 4: t4+0,0 | | | o 3: at3+0,0 t3+0,0 | | @@ -3001,7 +3030,9 @@ $ hg log -G --template "{rev}: {latesttag('re:^t[13]$') % '{tag}, C: {changes}, D: {distance}'}\n" - @ 10: t3, C: 8, D: 7 + @ 11: t3, C: 9, D: 8 + | + o 10: t3, C: 8, D: 7 | o 9: t3, C: 7, D: 6 | @@ -3044,7 +3075,7 @@ > EOF $ hg -R latesttag tip - test 10:9b4a630e5f5f + test 11:97e5943b523a Test recursive showlist template (issue1989): @@ -3057,7 +3088,7 @@ $ hg -R latesttag log -r tip --style=style1989 M|test - 10,test + 11,test branch: test Test new-style inline templating: @@ -3090,6 +3121,7 @@ $ hg log -R latesttag --template '{desc}\n' at3 t5 + t4 t3 t2 t1 @@ -3103,6 +3135,7 @@ $ hg log -R latesttag --template '{strip(desc, "te")}\n' at3 5 + 4 3 2 1 @@ -3118,6 +3151,7 @@ $ hg log -R latesttag --template 'date: {date(date, "%y %m %d %S %z")}\n' date: 70 01 01 10 + date: 70 01 01 09 + + date: 70 01 01 04 + date: 70 01 01 08 + date: 70 01 01 07 + date: 70 01 01 06 + diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -208,10 +208,22 @@ latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)] continue try: -# The tuples are laid out so the right one can be found by -# comparison. -pdate, pdist, ptag = max( -latesttags[p.rev()] for p in ctx.parents()) +ptags = [latesttags[p.rev()] for p in ctx.parents()] +if len(ptags) > 1: +if ptags[0][2] == ptags[1][2]: +# The tuples are laid out so the right one can be found by +# comparison in this case. +pdate, pdist, ptag = max(ptags) +else: +def key(x): +changessincetag = len(repo.revs('only(%d, %s)', +ctx.rev(), x[2][0])) +# Smallest number of changes since tag wins. Date is +# used as tiebreaker. +return [-changessincetag, x[0]] +pdate, pdist, ptag = max(ptags, key=key) +else: +pdate, pdist, ptag = ptags[0] except KeyError: # Cache miss - recurse todo.append(rev) To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
martinvonz added inline comments. INLINE COMMENTS > martinvonz wrote in templatekw.py:222 > > This should be enabled only if ptags[0][2] != ptags[1][2]. > > Good point. Done. > > > The latesttagdistance is documented to return the longest path to the > > latest tag. > > I'm not changing latesttagdistance (AFAIK), only the definition of latesttag. > > > https://phab.mercurial-scm.org/rHGf04d179124410d491a8def230e408c3b6c98cbfc > > Luckily, that's just the commit message and "hg help templates.latesttag" > just says "The global tags on the most recent globally tagged ancestor of > this changeset" and doesn't define what "most recent" is. >> This should be enabled only if ptags[0][2] != ptags[1][2]. > > Good point. Done. Great point, actually! See updated timings in commit message. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D447 To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
yuja added inline comments. INLINE COMMENTS > martinvonz wrote in templatekw.py:222 > > This should be enabled only if ptags[0][2] != ptags[1][2]. > > Good point. Done. > > > The latesttagdistance is documented to return the longest path to the > > latest tag. > > I'm not changing latesttagdistance (AFAIK), only the definition of latesttag. > > > https://phab.mercurial-scm.org/rHGf04d179124410d491a8def230e408c3b6c98cbfc > > Luckily, that's just the commit message and "hg help templates.latesttag" > just says "The global tags on the most recent globally tagged ancestor of > this changeset" and doesn't define what "most recent" is. > I'm not changing latesttagdistance (AFAIK), only the definition of latesttag. Try `ptags = reversed(...)` and run tests. The largest `pdist` should be selected so that `latesttagdistance` returns the longest path. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D447 To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
martinvonz updated this revision to Diff 1088. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D447?vs=1080=1088 REVISION DETAIL https://phab.mercurial-scm.org/D447 AFFECTED FILES mercurial/templatekw.py tests/test-command-template.t CHANGE DETAILS diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -2885,7 +2885,7 @@ o 0: null+1 -One common tag: longest path wins: +One common tag: longest path wins for {latesttagdistance}: $ hg tag -r 1 -m t1 -d '6 0' t1 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2904,7 +2904,7 @@ o 0: null+1 -One ancestor tag: more recent wins: +One ancestor tag: closest wins: $ hg tag -r 2 -m t2 -d '7 0' t2 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2925,7 +2925,7 @@ o 0: null+1 -Two branch tags: more recent wins: +Two branch tags: more recent wins if same number of changes: $ hg tag -r 3 -m t3 -d '8 0' t3 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2948,12 +2948,39 @@ o 0: null+1 +Two branch tags: fewest changes wins: + + $ hg tag -r 4 -m t4 -d '4 0' t4 # older than t2, but should not matter + $ hg log -G --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n" + @ 9: t4+5,6 + | + o 8: t4+4,5 + | + o 7: t4+3,4 + | + o 6: t4+2,3 + | + o5: t4+1,2 + |\ + | o 4: t4+0,0 + | | + | o 3: t3+0,0 + | | + o | 2: t2+0,0 + |/ + o 1: t1+0,0 + | + o 0: null+1,1 + + Merged tag overrides: $ hg tag -r 5 -m t5 -d '9 0' t5 $ hg tag -r 3 -m at3 -d '10 0' at3 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' - @ 10: t5+5 + @ 11: t5+6 + | + o 10: t5+5 | o 9: t5+4 | @@ -2965,7 +2992,7 @@ | o5: t5+0 |\ - | o 4: at3:t3+1 + | o 4: t4+0 | | | o 3: at3:t3+0 | | @@ -2977,7 +3004,9 @@ $ hg log -G --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n" - @ 10: t5+5,5 + @ 11: t5+6,6 + | + o 10: t5+5,5 | o 9: t5+4,4 | @@ -2989,7 +3018,7 @@ | o5: t5+0,0 |\ - | o 4: at3+1,1 t3+1,1 + | o 4: t4+0,0 | | | o 3: at3+0,0 t3+0,0 | | @@ -3001,7 +3030,9 @@ $ hg log -G --template "{rev}: {latesttag('re:^t[13]$') % '{tag}, C: {changes}, D: {distance}'}\n" - @ 10: t3, C: 8, D: 7 + @ 11: t3, C: 9, D: 8 + | + o 10: t3, C: 8, D: 7 | o 9: t3, C: 7, D: 6 | @@ -3044,7 +3075,7 @@ > EOF $ hg -R latesttag tip - test 10:9b4a630e5f5f + test 11:97e5943b523a Test recursive showlist template (issue1989): @@ -3057,7 +3088,7 @@ $ hg -R latesttag log -r tip --style=style1989 M|test - 10,test + 11,test branch: test Test new-style inline templating: @@ -3090,6 +3121,7 @@ $ hg log -R latesttag --template '{desc}\n' at3 t5 + t4 t3 t2 t1 @@ -3103,6 +3135,7 @@ $ hg log -R latesttag --template '{strip(desc, "te")}\n' at3 5 + 4 3 2 1 @@ -3118,6 +3151,7 @@ $ hg log -R latesttag --template 'date: {date(date, "%y %m %d %S %z")}\n' date: 70 01 01 10 + date: 70 01 01 09 + + date: 70 01 01 04 + date: 70 01 01 08 + date: 70 01 01 07 + date: 70 01 01 06 + diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -208,10 +208,18 @@ latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)] continue try: -# The tuples are laid out so the right one can be found by -# comparison. -pdate, pdist, ptag = max( -latesttags[p.rev()] for p in ctx.parents()) +def key(x): +changessincetag = len(repo.revs('only(%d, %s)', +ctx.rev(), x[2][0])) +# Smallest number of changes since tag wins. Date is used +# as tiebreaker. +return [-changessincetag, x[0]] +ptags = [latesttags[p.rev()] for p in ctx.parents()] +if len(ptags) > 1 and ptags[0][2] != ptags[1][2]: +pdate, pdist, ptag = max(ptags, key=key) +else: +# Don't call expensive key function if not necessary +pdate, pdist, ptag = ptags[0] except KeyError: # Cache miss - recurse todo.append(rev) To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
martinvonz added inline comments. INLINE COMMENTS > yuja wrote in templatekw.py:222 > This should be enabled only if `ptags[0][2] != ptags[1][2]`. > > The latesttagdistance is documented to return the longest path to the latest > tag. > https://phab.mercurial-scm.org/rHGf04d179124410d491a8def230e408c3b6c98cbfc > This should be enabled only if ptags[0][2] != ptags[1][2]. Good point. Done. > The latesttagdistance is documented to return the longest path to the latest > tag. I'm not changing latesttagdistance (AFAIK), only the definition of latesttag. > https://phab.mercurial-scm.org/rHGf04d179124410d491a8def230e408c3b6c98cbfc Luckily, that's just the commit message and "hg help templates.latesttag" just says "The global tags on the most recent globally tagged ancestor of this changeset" and doesn't define what "most recent" is. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D447 To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
yuja requested changes to this revision. yuja added inline comments. This revision now requires changes to proceed. INLINE COMMENTS > templatekw.py:222 > +# Don't call expensive key function if not necessary > +pdate, pdist, ptag = ptags[0] > except KeyError: This should be enabled only if `ptags[0][2] != ptags[1][2]`. The latesttagdistance is documented to return the longest path to the latest tag. https://phab.mercurial-scm.org/rHGf04d179124410d491a8def230e408c3b6c98cbfc REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D447 To: martinvonz, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D447: templatekw: choose {latesttag} by len(changes), not date (issue5659)
martinvonz created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY As Augie reported in the bug, the current heuristic of choosing the best tag of a merge commit by taking the one with newest tag (in terms of tagging date) currently fails in the Mercurial repo itself. Copying the example from Yuya: $ hg glog -T '{node|short} {latesttag}+{latesttagdistance}\n' \ -r '4.2.3: & (merge() + parents(merge()) + tag())' o https://phab.mercurial-scm.org/rHG02a745c20121f9add702f0200dc5522e912c2d20 4.2.3+5 | \ | | o https://phab.mercurial-scm.org/rHG86aca74a063bdd3e9627f069568322981f4dee68 4.2.3+4 | || \ | || o https://phab.mercurial-scm.org/rHGe6d8ee3c9ec3b787221365041407e36ac58db75f 4.3-rc+109 | || | || ~ | | o | https://phab.mercurial-scm.org/rHGa3ce07e2dde5737644dd719806b1e52fb1cc1004 4.3.1+2 : | o | https://phab.mercurial-scm.org/rHG3fee7f7d2da04226914c2258cc2884dc27384fd7 4.3.1+0 | / | | o https://phab.mercurial-scm.org/rHG98e990bb733008e2f7589bb7b276c16dd3aad5e4 4.2.3+3 | \ | | ~ | | o https://phab.mercurial-scm.org/rHG506d7e48fbe68d6925a2cbfcafa9baded5f7de14 4.2.3+2 : o https://phab.mercurial-scm.org/rHG943c91326b23954e6e1c6960d0239511f9530258 4.2.3+0 | | ~ It seems to me like the best choice is the tag with the smallest number of changes since it (across all paths, not the longest single path). So that's what this patch does, even though it's costly. Best-of-5 timings for Yuya's command above shows a slowdown from 1.293s to 3.004s. We can optimize it later. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D447 AFFECTED FILES mercurial/templatekw.py tests/test-command-template.t CHANGE DETAILS diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -2885,7 +2885,7 @@ o 0: null+1 -One common tag: longest path wins: +One common tag: longest path wins for {latesttagdistance}: $ hg tag -r 1 -m t1 -d '6 0' t1 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2904,7 +2904,7 @@ o 0: null+1 -One ancestor tag: more recent wins: +One ancestor tag: closest wins: $ hg tag -r 2 -m t2 -d '7 0' t2 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2925,7 +2925,7 @@ o 0: null+1 -Two branch tags: more recent wins: +Two branch tags: more recent wins if same number of changes: $ hg tag -r 3 -m t3 -d '8 0' t3 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' @@ -2948,12 +2948,39 @@ o 0: null+1 +Two branch tags: fewest changes wins: + + $ hg tag -r 4 -m t4 -d '4 0' t4 # older than t2, but should not matter + $ hg log -G --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n" + @ 9: t4+5,6 + | + o 8: t4+4,5 + | + o 7: t4+3,4 + | + o 6: t4+2,3 + | + o5: t4+1,2 + |\ + | o 4: t4+0,0 + | | + | o 3: t3+0,0 + | | + o | 2: t2+0,0 + |/ + o 1: t1+0,0 + | + o 0: null+1,1 + + Merged tag overrides: $ hg tag -r 5 -m t5 -d '9 0' t5 $ hg tag -r 3 -m at3 -d '10 0' at3 $ hg log -G --template '{rev}: {latesttag}+{latesttagdistance}\n' - @ 10: t5+5 + @ 11: t5+6 + | + o 10: t5+5 | o 9: t5+4 | @@ -2965,7 +2992,7 @@ | o5: t5+0 |\ - | o 4: at3:t3+1 + | o 4: t4+0 | | | o 3: at3:t3+0 | | @@ -2977,7 +3004,9 @@ $ hg log -G --template "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n" - @ 10: t5+5,5 + @ 11: t5+6,6 + | + o 10: t5+5,5 | o 9: t5+4,4 | @@ -2989,7 +3018,7 @@ | o5: t5+0,0 |\ - | o 4: at3+1,1 t3+1,1 + | o 4: t4+0,0 | | | o 3: at3+0,0 t3+0,0 | | @@ -3001,7 +3030,9 @@ $ hg log -G --template "{rev}: {latesttag('re:^t[13]$') % '{tag}, C: {changes}, D: {distance}'}\n" - @ 10: t3, C: 8, D: 7 + @ 11: t3, C: 9, D: 8 + | + o 10: t3, C: 8, D: 7 | o 9: t3, C: 7, D: 6 | @@ -3044,7 +3075,7 @@ > EOF $ hg -R latesttag tip - test 10:9b4a630e5f5f + test 11:97e5943b523a Test recursive showlist template (issue1989): @@ -3057,7 +3088,7 @@ $ hg -R latesttag log -r tip --style=style1989 M|test - 10,test + 11,test branch: test Test new-style inline templating: @@ -3090,6 +3121,7 @@ $ hg log -R latesttag --template '{desc}\n' at3 t5 + t4 t3 t2 t1 @@ -3103,6 +3135,7 @@ $ hg log -R latesttag --template '{strip(desc, "te")}\n' at3 5 + 4 3 2 1 @@ -3118,6 +3151,7 @@ $ hg log -R latesttag --template 'date: {date(date, "%y %m %d %S %z")}\n' date: 70 01 01 10 + date: 70 01 01 09 + + date: 70 01 01 04 + date: 70 01 01 08 + date: 70 01 01