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?

I thought you were trying to recreate something like the git command line --first-parent argument.  There is a commit to the Jenkins git plugin which uses the --first-parent argument.  Unfortunately, the submitter did not include a JGit implementation in the submission, only a command line git call.

Maybe the command line git source code could offer some hints how they implemented --first-parent?

Mark Waite

On Sat, Nov 15, 2014 at 3:33 PM, Matthias Sohn <matthias.sohn@xxxxxxxxx> wrote:
On Sat, Nov 15, 2014 at 9:50 PM, <gt6@xxxxxxx> wrote:
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):


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);
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
_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jgit-dev

--
Matthias

_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jgit-dev



--
Thanks!
Mark Waite

Back to the top