2

I want to fetch all the commits with their changeset after a particular commit id or time. Is there any straight way to do that using Mercurial API?

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
sra
  • 71
  • 1
  • 5

1 Answers1

1

As you probably know, there's no stable Python-level API for Mercurial. The command line is really the only supported API (unless you use a wrapper library like JavaHg or python-hglib).

So on the command line you would run

$ hg log -r "ID::"

to get all changesets after ID. The :: operator gives you descendents, use ID: if you simply want changesets with a higher revision number, even if they're not a descendent of ID.

Using JavaHg, you would instantiate a Repository object and use LogCommand:

List<Changeset> changesets = LogCommand.on(repo).rev(id + "::").execute();

You can then iterate through the changesets list. With python-hglib it looks like

changesets = client.log(id + "::")

Finally, if you import the Mercurial code directly you can do

ctxs = repo.set(id + "::")

to get an iterator yielding changectx objects. While we give no guarantees about the Python API, I would expect this to be very stable too.

The above focused on looking up by a changeset ID or revision number. If you want to lookup by date, then you'll need to call the equivalent of

$ hg log -d '>YOUR-DATE'

In JavaHg you can just use the date(String date) method on LogCommand, in python-hglib you set the date keyword argument, and internally you use the date revset predicate — see hg help revsets.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229