-1

I need the last commit with affected the path something similar to git log -1 -- path.

Currently, I am doing this

TreeWalk.forPath(repo, filepath, rootCommit.getTree()).getObjectId(0)

Is there any faster way to achieve this?

RĂ¼diger Herrmann
  • 20,512
  • 11
  • 62
  • 79

1 Answers1

0

Another option would be to use the Porcelain command for "log", it uses a RevWalk internally, so it might run with different timings, however I am not sure which one will be faster, it may also depend on the repository size and structure to some degree...

    Iterable<RevCommit> logs = new Git(repository).log()
            .addPath("README.md")
            .setMaxCount(1)
            .call();
    for(RevCommit rev : logs) {
        System.out.println("Commit: " + rev);
    }
centic
  • 15,565
  • 9
  • 68
  • 125