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 11/16/14 00:34, Mark Waite wrote:
I thought you were trying to recreate something like the git command
line --first-parent argument.  There is a commit to the Jenkins git ...

Actually I just discovered that `git rev-list master` does exactly what I'd need - retrieving the names of all commits on the master branch. But JGit does not have a rev-list command.

... 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
<mailto:matthias.sohn@xxxxxxxxx>> wrote:

    On Sat, Nov 15, 2014 at 9:50 PM, <gt6@xxxxxxx <mailto: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.

I'm not sure how the reflog can help me. I read man git-reflog and tried to figure out what to do with the jgit ReflogCommand but I don't see how it can tell me which branch a commit resides on.


        /////////////////
        // 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 <mailto: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
        <https://dev.eclipse.org/mailman/listinfo/jgit-dev>


    --
    Matthias

    _______________________________________________
    jgit-dev mailing list
    jgit-dev@xxxxxxxxxxx <mailto: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