This is an archive of the discontinued Mercurial Phabricator instance.

templatekw: choose {latesttag} by len(changes), not date (issue5659)
ClosedPublic

Authored by martinvonz on Aug 18 2017, 4:48 PM.

Details

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    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
|
~

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 1.610s. We can optimize it later.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

martinvonz created this revision.Aug 18 2017, 4:48 PM
yuja requested changes to this revision.Aug 19 2017, 3:11 AM
yuja added a subscriber: yuja.
yuja added inline comments.
mercurial/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.
f04d17912441

This revision now requires changes to proceed.Aug 19 2017, 3:11 AM
martinvonz added inline comments.Aug 19 2017, 11:32 AM
mercurial/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.

f04d17912441

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.

martinvonz edited edge metadata.Aug 19 2017, 11:32 AM
martinvonz updated this revision to Diff 1088.
yuja added inline comments.Aug 19 2017, 11:47 AM
mercurial/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.

martinvonz edited the summary of this revision. (Show Details)Aug 19 2017, 12:07 PM
martinvonz added inline comments.Aug 19 2017, 12:09 PM
mercurial/templatekw.py
222

This should be enabled only if ptags[0][2] != ptags[1][2].

Good point. Done.

Great point, actually! See updated timings in commit message.

martinvonz updated this revision to Diff 1089.Aug 19 2017, 12:29 PM
martinvonz added inline comments.Aug 19 2017, 12:29 PM
mercurial/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.

Ah, right, when the tag is in the common ancestor, we should choose the longest branch. Good catch. See how you like this change.

yuja accepted this revision.Aug 19 2017, 10:51 PM

This one looks good to me, thanks. I leave it to Sean since he said he's queued the previous series.

This revision is now accepted and ready to land.Aug 19 2017, 10:51 PM
martinvonz edited the summary of this revision. (Show Details)Aug 21 2017, 4:37 PM
This revision was automatically updated to reflect the committed changes.