Search code examples
mercurialmercurial-extension

In mercurial, how to see tags for only a set of revisions instead of all?


hg tags always shows all tags, so how can I get only the tags that point to a specific revision and all its ancestors?

The real-world use case is that if I use local tags to designate features (or bug fixes) on changesets, and I need to find out the cumulative features/bugs up till a specific rev.

One solution would be adding a wrapper command that adds "-r" to tags. Then what's the best way to implement it? Use revsets to get all ancestral revs and filter the tags?


Solution

  • This should do the trick (requires mercurial 1.7):

    hg log -r "ancestors(<rev>) and tag()"
    

    where <rev> is the hash or local revision number. However, tagging every bugfix and feature seems overkill.

    Instead of tagging, you can just follow a convention where you put "bugfix: xyz" or "feature: abc" in your commit messages. You can then extract all bugfixes and features like this:

    hg log -r "ancestors(<rev>) and (keyword(bugfix) or keyword(feature))"
    

    Keep tags for important milestones or other revisions that have some special significance.