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
+  |
+  o    5: 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 @@
   |
   o    5: 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 @@
   |
   o    5: 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 +0000
   date: 70 01 01 09 +0000
+  date: 70 01 01 04 +0000
   date: 70 01 01 08 +0000
   date: 70 01 01 07 +0000
   date: 70 01 01 06 +0000
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:
+                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
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to