21

I'm attempting to use the hg log command to show a series of revisions, x through y.

When I do this:

hg log -r 1+5

I get this:

changeset:   1:7320d2a9baa5
user:        Tim Post <tpost@whereiwork.com>
date:        Fri Sep 30 20:38:29 2011 +0800
summary:     Foo foo everywhere is foo

changeset:   5:8d6bea76ce60
user:        Tim Post <tpost@whereiwork.com>
date:        Fri Sep 30 20:51:42 2011 +0800
summary:     Blah blah blah

Which is Mercurial understanding that I want to see revisions one and five instead of one through five.

Oddly enough, this works:

hg log -r 1+2+3+4+5

But, that gets extremely cumbersome, especially when trying to get a summary between revisions that are +500 away from each other.

Is there a way to get logs for revisions x through y instead of x and y without concatenating every revision in the series?

I'm using the output in order to determine how many commitments each developer made in a given series. If I simply can't do that using the hg command, I'm more than open to using the Mercurial API. I resorted to the hg command because I did not see an obvious way of doing it via the API.

By API, I mean just using Python via a hook or extension.

Tim Post
  • 33,371
  • 15
  • 110
  • 174
  • Which API are you referring to? The last I heard, the only "stable" way of using Mercurial programmatically _is_ through the command line, which is why the [command server](http://mercurial.selenic.com/wiki/CommandServer) mode was recently added - basically a way of using the command line but only having to spawn one process for as many commands as you need. – anton.burger Oct 17 '11 at 10:17
  • @Anton The [internal](http://mercurial.selenic.com/wiki/MercurialApi) one. – Tim Post Oct 17 '11 at 10:23
  • Ah, I see. Unless you're writing a hook or extension, I'd go with the advice on that page and use either the command line or the command server. – anton.burger Oct 17 '11 at 10:26
  • @Anton Well, part of what I'm writing is a hook, which is why I was open to getting that specific data using it (but really hoped not to, as I'd be doing something in the hook that I wanted a simple script to do later). – Tim Post Oct 17 '11 at 10:31

1 Answers1

27

hg log -r1:5.

Mercurial has an entire mini-language devoted to selecting revisions for commands (not just for logs). For more information, see hg help revsets (needs Mercurial 1.6+).

anton.burger
  • 5,637
  • 32
  • 48
  • 1
    Thank you. Strange that they don't include breadcrumbs to that in the output of `hg log --help`. – Tim Post Oct 17 '11 at 10:28
  • Definitely one of the most enlightened features I've ever seen in any software :) A more recent version (1.9? Not sure) adds the [equivalent capability anywhere a list of _files_ (rather than changesets) is expected as an argument](http://www.selenic.com/mercurial/hg.1.html#filesets "Mercurial filesets"). – anton.burger Oct 17 '11 at 10:32
  • 1
    I think I'm going to re-subscribe to the user's list, so I don't miss neat stuff like this coming in. Over the years I've come up with 'interesting' ways to do things with Mercurial, mostly working around features it didn't have. This particular feature gets rid of a few clumsy kludges :) – Tim Post Oct 17 '11 at 10:41
  • Quote from `hg help log` "If no revision range is specified, the default is "tip:0" unless --follow is set, in which case the working directory parent is used as the starting revision. You can specify a revision set for log, *see "hg help revsets"* for more information. " – Lazy Badger Oct 17 '11 at 11:44