Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Restrict RevWalk to a particular branch?

Hi,

I'm trying to use a RevWalk to get all ObjectIds of files changed in commits on a particular branch (e.g. the master branch). Something like this (this is Scala):

/////////////////
// set an entry point to the tree
val revWalk = new RevWalk(repository)
val lastCommitId = repository.resolve(Constants.HEAD)
val lastCommit = revWalk.parseCommit(lastCommitId);
revWalk.markStart(lastCommit)
// limit how far to walk
val firstCommitId = repository.resolve(someCommitName)
if (firstCommit.get.getParentCount > 0) {
  val ignoreCommit = firstCommit.get.getParent(0)
  revWalk.markUninteresting(ignoreCommit)
}

val iterator = revWalk.iterator()
while (iterator.hasNext()) {
  val commit = iterator.next
  // do stuff with commit, e.g. use a TreeWalk to extract ObjectIds
  // ...
}
/////////////////

My problem is, that this walk includes commits that occurred on other branches, which had been merged into the master and I can't figure out a way to exclude other branches from the walk or at least detect if a commit originated on another branch. There doesn't appear to be a RevFilter for this.

For example, imagine a log like this:

*   25707dd merged brach X into master <-- want
|\
* | 15cad98 change on master <-- want
| |
| *   1bd830c change on branch X <-- do NOT want
|/
*   2918d11 change on master <-- want

How could I do a RevWalk that includes the three commits on the master (one of which is a merge), but excludes the commit which was done on the merged branch X?

Any help would be greatly appreciated.

Cheers,
Tom


Back to the top