Mercurial API for Java?

前端 未结 5 743
灰色年华
灰色年华 2021-01-01 10:20

Is there a plain API to access Mercurial repositories from Java?

There are plugins for Netbeans and Eclipse, but unlike their Subversion counterparts, they do not us

5条回答
  •  梦谈多话
    2021-01-01 10:50

    A new option is JavaHg, which gives you a high-level Java API. The unit tests give a good example of how it is to program with it (as of JavaHg 0.1):

    public void commitTest() throws IOException {
        Repository repo = getTestRepository();
        writeFile("x", "abc");
    
        CommitCommand commit = CommitCommand.on(repo);
        StatusCommand status = StatusCommand.on(repo);
    
        List statusLines = status.lines();
        Assert.assertEquals(1, statusLines.size());
        Assert.assertEquals(StatusLine.Type.UNKNOWN, statusLines.get(0).getType());
    
        AddCommand.on(repo).execute();
        statusLines = status.lines();
        Assert.assertEquals(1, statusLines.size());
        Assert.assertEquals(StatusLine.Type.ADDED, statusLines.get(0).getType());
    
        commit.message("Add a file").user("Martin Geisler");
        Changeset cset = commit.execute();
        Assert.assertEquals("Martin Geisler", cset.getUser());
        statusLines = status.lines();
        Assert.assertEquals(0, statusLines.size());
    }
    

    It interacts with the Mercurial command server present in version 1.9 and later. This means that there will be a persistent Mercurial process around that accepts multiple commands and so you avoid the startup overhead normally associated with launching Mercurial. We expect that it will be used in a coming version of MercurialEclipse. (I'm one of the authors of JavaHg.)

提交回复
热议问题