Skip to main content

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

On Sat, Nov 15, 2014 at 9:50 PM, <gt6@xxxxxxx> wrote:

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):

within a single repository you may get the information on which branch a commit has been created
from the reflog. Across repositories this question doesn't make sense since branches are local and
only commits travel between different repositories.
// set an entry point to the tree
val revWalk = new RevWalk(repository)
val lastCommitId = repository.resolve(Constants.HEAD)
val lastCommit = revWalk.parseCommit(lastCommitId);
// limit how far to walk
val firstCommitId = repository.resolve(someCommitName)
if (firstCommit.get.getParentCount > 0) {
  val ignoreCommit = firstCommit.get.getParent(0)

val iterator = revWalk.iterator()
while (iterator.hasNext()) {
  val commit =
  // 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.

jgit-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit


Back to the top