Search code examples
mercurial

Use Mercurial in build to generate a change log between the last releases


Currently I am trying to figure out how to automatically produce a changelog. The plan was to use the default branch and mark commits with a label as "delivered to customer" the Label should have the version number.

So I added 3 Labels (Version0,Version1,Version2) to branch "default". Now I want to generate a hg log for

"Current Tag" of branch=default to "Current Tag -1"

But .. I cant figure out the right syntax.

I tried things similar to:

hg log --branch=default --rev="tag()" --template=Changelog => no Error but no result
hg log --branch=default --rev="tag(Version0):tag(Version1)" --template=Changelog => Errors Version0 does not exist.

Can someone give/or point me to correct syntax. I would prefer a solution where I don't need to know the tag names.

Something like: Log for branch=default where from last to last -1 where Tag exists.

Optional: I found the "tag Part" also without --rev used like "tag()::tag()" but I cant figure out which part of hg Documentation (function name) I have to look into...


Solution

  • I'll show the whole process on local clone of hg-git repo with a lot of tags as version-numbers, but you have to read hg help revisions carefully after all.

    • Starting point (almost identical to your command)hg log -r "tag() & branch(default)" --style compact (output truncated for readability)

      253[0.1.0] 505d7cdca198 2009-09-30 14:39 -0500 kbullock package with distutils

      269[0.2.0] 77d6c9eb02fb 2009-12-26 12:42 -0600 durin42 setup: bump to 0.2.0

      278[0.2.1] 21ead8190d9c 2009-12-26 13:46 -0600 durin42 setup: bump to 0.2.1

      322[0.2.2] a222399a59d7 2010-05-22 22:12 -0500 durin42 Bump version 0.2.2

      348[0.2.3] 5d39b98e5083 2010-07-05 11:56 -0500 durin42 Bump version to 0.2.3

      358[0.2.4] b53421918a89 2010-08-25 15:45 -0500 durin42 setup: bump version number

      ...

      1698[0.9.0] c17c6c915646 2020-08-06 16:31 +0200 georges Setting version for 0.9.0

      1814[0.10.0] d3af25aa2864 2021-01-11 15:58 +0100 danchr setup: bump version to 0.10.0

    OK, I got

    1. all (only) tagged revisions without revisions in range
    2. newest revisions are on bottom

    and I'll fix noted problems now

    • hg log -r "limit(reverse(tag() & branch(default)),2)" --style compact

      1814[0.10.0] d3af25aa2864 2021-01-11 15:58 +0100 danchr setup: bump version to 0.10.0

      1698[0.9.0] c17c6c915646 2020-08-06 16:31 +0200 georges Setting version for 0.9.0

    Not bad, but

    • Now I have to reference to first and second revisions in hg log for range SECOND::FIRST and use limit() predicate twice with some magic

    Last release (one first changeset in list) hg log -r "limit(reverse(tag() & branch(default)),1)" --style compact

    1814[0.10.0]   d3af25aa2864   2021-01-11 15:58 +0100   danchr
      setup: bump version to 0.10.0
    

    Previous release (second changeset in list - one changeset with offset 1 from list) hg log -r "limit(reverse(tag() & branch(default)),1,1)" --style compact

    1698[0.9.0]   c17c6c915646   2020-08-06 16:31 +0200   georges
      Setting version for 0.9.0
    
    • Revset for range, first iteration hg log -r "limit(reverse(tag() & branch(default)),1,1)::limit(reverse(tag() & branch(default)),1)" --style compact

      1698[0.9.0] c17c6c915646 2020-08-06 16:31 +0200 georges Setting version for 0.9.0

      1699 940082ab0f8a 2020-08-06 17:08 +0200 georges Added tag 0.9.0 for changeset c17c6c915646

      1700 746310cba0a3 2020-08-06 17:10 +0200 georges Added signature for changeset c17c6c915646

      1701 8b51b82cfb48 2020-08-06 14:53 +0200 a tests: demostrate crash on nonempty hg incoming when gitnode() is in template

      ...

      1813 635107c4ad3a 2021-02-01 18:12 +0100 danchr setup: adjust homepage to heptapod

      1814[0.10.0] d3af25aa2864 2021-01-11 15:58 +0100 danchr setup: bump version to 0.10.0

    • Revset is good, but string is too long and not-bulletproof for typing, polish it with revsetalias and after adding to .hgrc for repo into existing or created now [revsetalias] section something like

      rcl = limit(reverse(tag() & branch(default)),1,1)::limit(reverse(tag() & branch(default)),1)

    command hg log -r "rcl" --style compact will produce the same result as previous long version, but it's at least more compact and memorable

    HTH

    Some notes:

    1. You can|have to use any other style instead of used in testing compact
    2. You can convert full hg log ... command into new hg-alias and use it as (f.e) hg rcl