How do I make a revset alias for tags whose names follow a pattern?

642 views Asked by At

In my repository, I have tags of the form version-1.2.3. I would like to make a revset alias new() that is called like this:

hg log -r 'new(1.2.3, 1.2.4)'

...and expands to this:

hg log -r '::version-1.2.4 - ::version-1.2.3'  # What's new in 1.2.4?

When I tried to do this:

[revsetalias]
new($1, $2) = ::version-$2 - ::version-$1

...Mercurial interpreted it as subtracting the revision $2 (e.g. 1.2.3) from the revision version, which was not my intent.

I also tried this, using the ## concatenation operator:

new($1, $2) = ::"version-" ## $2 - ::"version-" ## $1

But then hg log -r 'new(1.2.3, 1.2.4)' gives me this error:

hg: parse error at 13: syntax error

I also tried using ancestors() instead of the :: syntax, but still got the syntax error. Is this possible to do?

2

There are 2 answers

9
lc2817 On BEST ANSWER

I tested the following that works:

new($1, $2) = (::"version-" ## $2) - (::"version-" ## $1)

For reference $1::$2 won't give you the same thing, it means the revision between $1 and $2 An equivalent revset that I would prefer is:

new($1, $2) = only("version-" ## $2, "version-" ## $1)

According to the doc it is strictly equivalent to what you want:

"only(set, [set])"
      Changesets that are ancestors of the first set that are not ancestors of
      any other head in the repo. If a second set is specified, the result is
      ancestors of the first set that are not ancestors of the second set
      (i.e. ::<set1> - ::<set2>).
0
Lazy Badger On

Side note: $1::$2 will be more readable and give you the same part of DAGOnly only() provides correct result in all cases, DAG may fail according to discussion in @lc2817 answer)

I was almost successful in getting answer, but have some troubles (and know no ways to debug) at last step: aggregating all in [revsetalias]

Preface

Because parameters are tags and tag() predicate allow to use regexps in parameter - I'll use they

Revset tag("re:version\-") show all tags, started with "version-"

Revset with hardcoded number as string show single changeset

hg log -r "tag('re:version\-1.7$')
changeset:   2912:454a12f024f3

(trailing $ is mandatory, otherwise it will be all 1.7* tags)

My best attempt in revsetalias was tag('re:version\-\$1$') - with no errors and no output: I can't get fully expanded command in order to see all processings and substitutions and detect my mistakes with parametrized revsetalias

HTH