Search code examples
mercurialjavahg

Get latest revision of the remote repository with javahg


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!


Solution

  • 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