Bug 5659 - latesttag et al pick wrong tag when on current hg default
Summary: latesttag et al pick wrong tag when on current hg default
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: 4.3
Hardware: PC Mac OS
: wish feature
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-14 18:55 UTC by Augie Fackler
Modified: 2019-01-30 00:00 UTC (History)
3 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Augie Fackler 2017-08-14 18:55 UTC
I just got

Mercurial Distributed SCM (version 4.2.3+1605-fa3aa6c98bb7)

but 4.3.1 should really be the tag that was picked (I think I should get something like 4.3.1+53!)

I'm not sure what the problem is, but there's definitely something rotten here.
Comment 1 Yuya Nishihara 2017-08-15 02:35 UTC
This is because the tagged revisions (at 4.2.3 and 4.3.1) have exactly
the same commit date.

We could adjust the strategy to take the tag of the shortest distance
(or the tipmost revision), but that wouldn't always work.

$ hg glog -T '{node|short} {latesttag}+{latesttagdistance}\n' \
  -r '4.2.3: & (merge() + parents(merge()) + tag())'
o    02a745c20121 4.2.3+5
|\
| o    86aca74a063b 4.2.3+4
| |\
| | o  e6d8ee3c9ec3 4.3-rc+109
| | |
| | ~
o |  a3ce07e2dde5 4.3.1+2
: |
o |  3fee7f7d2da0 4.3.1+0
|/
o    98e990bb7330 4.2.3+3
|\
| ~
o  506d7e48fbe6 4.2.3+2
:
o  943c91326b23 4.2.3+0
|
~
Comment 2 Martin von Zweigbergk 2017-08-16 01:41 UTC
I'm tired and haven't thought much about it, but this seems to produce better results in the case Augie reported and it's much faster too (even though it may not look like it). I'll leave this for now.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -210,8 +210,13 @@ def getlatesttags(repo, ctx, cache, patt
         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())
+            if len(ctx.parents()) == 1:
+                pctx = ctx.parents()[0]
+            else:
+                anc = ctx.parents()[0].ancestor(ctx.parents()[1])
+                key = lambda pctx: repo.set('%n::%n', anc, pctx)
+                pctx = max(ctx.parents(), key=key)
+            pdate, pdist, ptag = latesttags[pctx.rev()]
         except KeyError:
             # Cache miss - recurse
             todo.append(rev)
Comment 3 Martin von Zweigbergk 2017-08-16 02:54 UTC
Wow, that patch just accidentally worked in my repo. What I meant was more like the following. I'm still not sure if it's a good idea:

--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -210,8 +210,13 @@
         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())
+            if len(ctx.parents()) == 1:
+                pctx = ctx.parents()[0]
+            else:
+                anc = ctx.parents()[0].ancestor(ctx.parents()[1])
+                key = lambda pctx: len(repo.revs('%d::%d', anc.rev(), pctx.rev()))
+                pctx = max(ctx.parents(), key=key)
+            pdate, pdist, ptag = latesttags[pctx.rev()]
         except KeyError:
             # Cache miss - recurse
             todo.append(rev)
Comment 4 Martin von Zweigbergk 2017-08-24 11:39 UTC
Fixed in commit fb672eac2702
Comment 5 HG Bot 2019-01-22 10:55 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/ff1222a7d714
Yuya Nishihara <yuya@tcha.org>
test-template-keywords: add test for {latesttag} of wdir() revision

It's probably broken since fb672eac2702, "templatekw: choose {latesttag}
by len(changes), not date (issue5659)". only() doesn't support wdir.

(please test the fix)
Comment 6 Bugzilla 2019-01-30 00:00 UTC
Bug was set to TESTING for 7 days, resolving