0

In our current Java project we want to compare the local with the remote revision number of an alreay cloned mercurial repository, especially we want to get the latest revision number from the server. We are using javahg to access mercurial functions. But we can't find any command in the javahg library to achieve that.

Normally, you would use the identity command, but this is not supported in this library. Another way could be to use the incoming command, which is supported, but it seems not to work for us. We tried to execute the following code line:

IncomingCommand.on(localRepo).execute(serverURL)

and the resulting bundle returns "-1". After a quick look into the source code of the execution function we found out that this method operates only on local repositories.

Has anybody an idea how the incoming command could be used to get the latest revision from the remote repository? Or is there another way to do this?

Any help is appreciated. Thanks!

1 Answers1

0

The incoming command downloads a 'bundle file' containing the remote changesets not present locally. From the Bundle instance you can use getOverlayRepository() to get a Repository instance that any other command can be invoked on.

Here's an example of using Incoming with a remote repository:

Repository repoB = ..;
Bundle bundle = IncomingCommand.on(repoB).execute("http://localhost:" + port);
List<Changeset> changesets = bundle.getChangesets();
List<Changeset> heads = bundle.getOverlayRepository().heads();

I'm not sure the precise semantics of 'identify' but maybe a similar effect could be achieved by listing heads of the bundle overlay repository.

Identify seems much more efficient if you're just interested in the node id and not the changes themselves. Feel free to post a feature request here: https://bitbucket.org/aragost/javahg

johnpeb
  • 406
  • 2
  • 7
  • Thanks! But we don't get the remote changeset, only the local changeset. The IncomingComand operates on two different repositories ("IncomingCommand.on(repo1).execute(repo2)"). The execute method accepts a String or a File, not the remote repository URL. We think the method is designed to use it in a way that the remote repository is cloned and compared with the other previously cloned repository. Right? If yes, how we can avoid the second clone in order to compare the local repository with the remote repo directly? The identity command seems more suited. I have created a feature request. – Mike Nagora Jun 11 '13 at 14:16
  • Which version of JavaHg are you using? The latest definitely support invoking incoming on remote repositories. Take a look at MercurialEclipse to to see how JavaHg is used in practice: https://bitbucket.org/mercurialeclipse/main . You might also be interested in: http://stackoverflow.com/questions/16899356/getting-javahg-0-6-snapshot-from-maven?rq=1 – johnpeb Jun 12 '13 at 15:11
  • We are using a Maven generated JavaHg jar file in version 0.6. But I still don't get the remote changeset. Probably, I'm doing something wrong. Could you please give me a code example of the IncomingComand how to achieve that? Thanks a lot! – Mike Nagora Jun 14 '13 at 10:10
  • I've added a test case for invoking incoming over http and edited above to link to it – johnpeb Jun 14 '13 at 19:50