Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » JGit TagCommand(Having trouble making a tag via JGit)
JGit TagCommand [message #1004827] Thu, 24 January 2013 00:06 Go to next message
Gurce Isikyildiz is currently offline Gurce IsikyildizFriend
Messages: 6
Registered: April 2012
Junior Member
Hi,

I'm using JGit to build a tailored GUI app. I'm currently experiencing problems with the TagCommand, I use it as follows:

- In my GUI, I have a list of past commits, generated via calling git.log().all().call() which returns a List<RevCommit> collection.

I want to allow the user to tag any one of these prior commits by right-clicking it and entering a tag name.

Once provided a name, I then execute the following JGit code to try apply the requested tag.

            Git git = new Git(gitrepo);
            org.eclipse.jgit.api.TagCommand tagcmd = git.tag();
            tagcmd. setObjectId(revcmt);
            tagcmd.setName(strTag);
            System.out.println("revid = " + tagcmd.getObjectId().getId().toString());
            try
            {
                Ref ref = tagcmd.call();
                System.out.println("refid = " + ref.getObjectId().toString());
            } catch (Exception ex)
            {
                parent.setErrMsg(ex);
                return;
            }


The only problem here is that when I refresh my list of commits (via git.log().all().call() again), I get the following exception:

SEVERE: null
org.eclipse.jgit.errors.IncorrectObjectTypeException: Object b7607418fae91345b3941532ad3ce2e94907a9d8 is not a commit.
        at org.eclipse.jgit.storage.file.WindowCursor.open(WindowCursor.java:130)
        at org.eclipse.jgit.revwalk.RevWalk.getCachedBytes(RevWalk.java:861)
        at org.eclipse.jgit.revwalk.RevCommit.parseHeaders(RevCommit.java:142)
        at org.eclipse.jgit.revwalk.RevWalk.markStart(RevWalk.java:284)
        at org.eclipse.jgit.api.LogCommand.add(LogCommand.java:297)
        at org.eclipse.jgit.api.LogCommand.add(LogCommand.java:172)
        at org.eclipse.jgit.api.LogCommand.all(LogCommand.java:245)


I think the object it is complaining about is the newly created tag, which I called "test1" in this example.

My two debug println's in the above code show the following:

revid = commit a7c533ff99c2b34b42991bccf6b901f4b6b8875a 1357769853 ----sp
refid = AnyObjectId[b7607418fae91345b3941532ad3ce2e94907a9d8]

Ie, "refid" is the id of tag, which equates to the id the exception is complaining about.

I found the tag object within the ".git/" sub-folder of the project in the following location:

.git/refs/tags/test1

Its contents is: b7607418fae91345b3941532ad3ce2e94907a9d8

Hmm, but now, I try something from the command-line as a test:

git tag -d test1 (to remove the tag)

git tag test1 a7c533ff99c2b34b42991bccf6b901f4b6b8875a (ie, make a tag called "test1" on the rev-id I intended it for)

This time, when I edit ".git/refs/tags/test1", it contains: a7c533ff99c2b34b42991bccf6b901f4b6b8875a

Ie:


  • When I add a tag via JGit, this ".git/refs/tags/test1" file contains the Id of the tag itself
  • When I add a tag via command-line git, this ".git/refs/tags/test1" file contains the Id of the commit that the tag is associated with


Anyone know what's going on here? Is it a bug? Or am I making use of JGit in the wrong way?
Re: JGit TagCommand [message #1005336 is a reply to message #1004827] Thu, 24 January 2013 22:24 Go to previous messageGo to next message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Gurce Isikyildiz skrev 2013-01-24 01.06:
> hen I add a tag via JGit, this ".git/refs/tags/test1" file contains the Id of the tag itself
> When I add a tag via command-line git, this ".git/refs/tags/test1" file contains the Id of the commit that the tag is associated with
>
>
> Anyone know what's going on here? Is it a bug? Or am I making use of JGit in the wrong way?

Git creates unannotated tags by default (no tag object), while JGit creates annotated tags (not convinced it should...).

-- robin
Re: JGit TagCommand [message #1005513 is a reply to message #1005336] Fri, 25 January 2013 19:44 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Slightly off-topic -- does JGit support the creation of simple tags? If so, does EGit provide a hook to that support? I haven't found it in EGit,

Re: JGit TagCommand [message #1005521 is a reply to message #1005513] Fri, 25 January 2013 21:37 Go to previous messageGo to next message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
R Shapiro skrev 2013-01-25 20.44:
> Slightly off-topic -- does JGit support the creation of simple tags?

No, but I think it should.

-- robin
Re: JGit TagCommand [message #1005539 is a reply to message #1004827] Sat, 26 January 2013 11:23 Go to previous messageGo to next message
Gurce Isikyildiz is currently offline Gurce IsikyildizFriend
Messages: 6
Registered: April 2012
Junior Member
Thanks for the explanation Robin. I'm trying to take this on-board, and gathering that the "log().all().call()" isn't working due to these annotated tags.

I tried to avoid the exception above by making the log command only add all "refs/heads" and "refs/remotes" (skipping "refs/tags") with code something like this:

            try
            {
                org.eclipse.jgit.api.LogCommand logcmd = git.log();
                Map<String, Ref> mapRefs =repo.getRefDatabase().getRefs("refs/heads");
                mapRefs.putAll(repo.getRefDatabase().getRefs("refs/remotes"));

                Set<String> names = mapRefs.keySet();
                Iterator<String> it = names.iterator();
                while (it.hasNext())
                {
                    String name = it.next();
                    Ref ref = mapRefs.get(name);
                    logcmd.add(ref.getObjectId());
                }

                Iterable<RevCommit> iter_gitlog = logcmd.call();


No more exception, nice... But now I'd like to display the tags I find with ListTagCommand within my tree.

            Git git = new Git(gitrepo);
            ListTagCommand taglistcmd = git.tagList();
            lstTags = taglistcmd.call();
            for (Ref tag : lstTags)
            {
                mapObjIdToRefTag.put(tag.getTarget().getObjectId(), tag);
            }


As I iterate through my RevCommits, I try and match them against each tag's tag.getTarget().getObjectId(). This technique seems to work for un-annotated tags, but not for these JGit annotated tags (for me).

I did notice there was a mention of tag.getPeeledObjectId() returning the RevCommit that an annotated tag points to, but when I try that on this "test1" tag in my example, it is returning null (tag.isPeeled() is false too).

What's up here? Am I going about this the wrong way?
Re: JGit TagCommand [message #1005592 is a reply to message #1005539] Sat, 26 January 2013 21:48 Go to previous messageGo to next message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Gurce Isikyildiz skrev 2013-01-26 12.23:>
> As I iterate through my RevCommits, I try and match them against each tag's tag.getTarget().getObjectId(). This technique seems to work for un-annotated tags, but not for
> these JGit annotated tags (for me).
>
> I did notice there was a mention of tag.getPeeledObjectId() returning the RevCommit that an annotated tag points to, but when I try that on this "test1" tag in my example,
> it is returning null (tag.isPeeled() is false too).
>
> What's up here? Am I going about this the wrong way?

Determining the target is costly, so it's not done by default.

Use the code below peel the tag. After that you can get the peeled object.

ref = repository.peel(ref)

-- robin
Re: JGit TagCommand [message #1005595 is a reply to message #1005592] Sun, 27 January 2013 01:07 Go to previous message
Gurce Isikyildiz is currently offline Gurce IsikyildizFriend
Messages: 6
Registered: April 2012
Junior Member
Ah great, with that tip, it's now working for me, thanks Robin.
Previous Topic:crash during install of EGit plugin in Eclipse Indigo
Next Topic:quick diff with index as baseline?
Goto Forum:
  


Current Time: Fri Apr 19 19:33:30 GMT 2024

Powered by FUDForum. Page generated in 0.04098 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top