Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [egit-dev] EGit PDE - help with EGit/JGit

On Wed, Oct 27, 2010 at 12:23 PM, Chris Aniszczyk <caniszczyk@xxxxxxxxx> wrote:
> On Wed, Oct 27, 2010 at 12:54 PM, Paul Webster
> <pwebster@xxxxxxxxxxxxxxxxxxx> wrote:
>> 4) git tag --contains $LAST_COMMIT :to get the list of tags that contain the
>> commit
>
> Not sure how to do this one yet using the API. May have to drop down
> to using RevWalk's

This isn't implemented yet.  `git tag --contains` is implemented in
terms of `git name-rev`, which JGit hasn't provided an implementation
of yet.

You can approximate this by performing the tests yourself with a
RevWalk.  Its ugly but:

  RevWalk rw = new RevWalk(repo);
  RevCommit lastCommit = rw.parseCommit(lastCommitSHA1);
  RevTag inTag = null;

  for (Ref ref : repo.getTags().valueSet()) {
    RevTag tag;
    try {
      tag = rw.parseTag(ref.getObjectId());
    } catch (IncorrectObjectException notTag) {
      continue;
    }

    RevCommit c;
    try {
      c = rw.parseCommit(tag.getObject());
    } catch (IncorrectObjectException notCommit) {
      continue;
    }

    if (rw.isMergedInto(lastCommit, c)) {
      // The commit is contained in this tag.  But this tag may
      // be contained inside of another tag.

      if (inTag == null || rw.isMergedInto(c, (RevCommit)inTag.getObject()))
        inTag = tag;
    }
  }

  if (inTag != null)
    name = inTag.getName();

If you have a lot of tags or a lot of history, this won't be fast,
because it is very brute-force.  We need a better implementation
inside of JGit, one that understands how to dig back through history
and match up tags as it goes.

-- 
Shawn.


Back to the top