Search code examples
javamercurialbundlejavahg

How can I operate on a Mercurial bundle with JavaHg?


I have a x.hg bundle file that I would like to inspect with JavaHg. I could of course unbundle it onto my repository, but I would like to open it and see the changesets inside instead. Is this possible?


Solution

  • You should use the Bundle class to open the bundle. It constructs a bundle repository where the bundle has been overlaid on top of a base repository.

    In normal Mercurial you do this with the --repository flag:

    $ cd your-base-repository
    $ hg log --repository x.hg
    

    In JavaHg you first open the base repository and then construct a Bundle using that:

    Repository repo = Repository.open(new File("your-base-repository"));
    Bundle bundle = new Bundle(repo, new File("x.hg"));
    

    You can then get the changesets from the bundle:

    List<Changeset> changesets = bundle.getChangesets();