Bug 6055 - {latesttags} and friends raise a revspec parse error for uncommitted merges
Summary: {latesttags} and friends raise a revspec parse error for uncommitted merges
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: templater (show other bugs)
Version: default branch
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-18 10:53 UTC by Matt Harbison
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 Matt Harbison 2019-01-18 10:53 UTC
It works fine for committed merges and normal commits.  But:

$ hg merge
$ hg id -T '{latesttag}+{changessincelatesttag}-{p1node}{dirty}' --traceback
Traceback (most recent call last):
  File "d:\mercurial\mercurial\scmutil.py", line 165, in callcatch
    return func()
  File "d:\mercurial\mercurial\dispatch.py", line 367, in _runcatchfunc
    return _dispatch(req)
  File "d:\mercurial\mercurial\dispatch.py", line 1021, in _dispatch
    cmdpats, cmdoptions)
  File "d:\mercurial\mercurial\dispatch.py", line 756, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "d:\mercurial\mercurial\dispatch.py", line 1030, in _runcommand
    return cmdfunc()
  File "d:\mercurial\mercurial\dispatch.py", line 1018, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
  File "d:\mercurial\mercurial\util.py", line 1670, in check
    return func(*args, **kwargs)
  File "d:\mercurial\mercurial\commands.py", line 3311, in identify
    fm.end()
  File "d:\mercurial\mercurial\formatter.py", line 435, in end
    baseformatter.end(self)
  File "d:\mercurial\mercurial\formatter.py", line 239, in end
    self._showitem()
  File "d:\mercurial\mercurial\formatter.py", line 418, in _showitem
    self._renderitem(self._tref, item)
  File "d:\mercurial\mercurial\formatter.py", line 424, in _renderitem
    self._out.write(self._t.render(ref, item))
  File "d:\mercurial\mercurial\templater.py", line 937, in render
    return b''.join(self.generate(t, mapping))
  File "d:\mercurial\mercurial\util.py", line 1581, in increasingchunks
    for chunk in source:
  File "d:\mercurial\mercurial\templateutil.py", line 721, in flatten
    for i in thing:
  File "d:\mercurial\mercurial\templateutil.py", line 915, in runtemplate
    yield evalrawexp(context, mapping, arg)
  File "d:\mercurial\mercurial\templateutil.py", line 769, in evalrawexp
    return func(context, mapping, data)
  File "d:\mercurial\mercurial\templateutil.py", line 907, in runsymbol
    return v(context, mapping)
  File "d:\mercurial\mercurial\templatekw.py", line 428, in showlatesttag
    return showlatesttags(context, mapping, None)
  File "d:\mercurial\mercurial\templatekw.py", line 432, in showlatesttags
    latesttags = getlatesttags(context, mapping, pattern)
  File "d:\mercurial\mercurial\templatekw.py", line 89, in getlatesttags
    pdate, pdist, ptag = max(ptags, key=key)
  File "d:\mercurial\mercurial\templatekw.py", line 85, in key
    ctx.rev(), x[2][0]))
  File "d:\mercurial\mercurial\localrepo.py", line 1365, in revs
    tree = revsetlang.spectree(expr, *args)
  File "d:\mercurial\mercurial\revsetlang.py", line 697, in spectree
    parsed = _parseargs(expr, args)
  File "d:\mercurial\mercurial\revsetlang.py", line 775, in _parseargs
    raise error.ParseError(_('invalid argument for revspec'))
ParseError: invalid argument for revspec
hg: parse error: invalid argument for revspec

This was with 4.8.2+810-593f6359681d.  I didn't go back to see where it broke.
Comment 1 Boris Feld 2019-01-18 14:53 UTC
We didn't reproduced, does it happens on all of your repositories?
Comment 2 Matt Harbison 2019-01-18 17:10 UTC
I hit it on the mercurial repo (I had some old junk heads laying around), as well as a private repo.
Comment 3 Matt Harbison 2019-01-18 22:29 UTC
Here's a quick and dirty reproduction on 4.9-rc:

diff --git a/tests/test-merge-commit.t b/tests/test-merge-commit.t
--- a/tests/test-merge-commit.t
+++ b/tests/test-merge-commit.t
@@ -33,6 +33,7 @@ Test with the merge on 3 having the rena
   line2

   $ hg ci -m '3: merge with local rename'
+  $ hg tag foo

   $ hg debugindex bar
      rev linkrev nodeid       p1           p2
@@ -85,6 +86,8 @@ This should use bar@rev2 as the ancestor
   line1
   line2

+  $ hg id -T '{latesttag}+{changessincelatesttag}-{p1node}{dirty}' --traceback
+
   $ hg ci -m '5: merge'

   $ hg debugindex bar
Comment 4 HG Bot 2019-01-22 10:56 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/66102f6fa10a
Yuya Nishihara <yuya@tcha.org>
templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)

It appears not easy to fix only() to support wdir(), so this patch works
around the issue by getlatesttags(). The "+1" after len(changes) doesn't
matter since ctx never changes while sorting. It's just for clarity.

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