Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » How to do "git log --oneline --decorate" in JGit
How to do "git log --oneline --decorate" in JGit [message #1586413] Mon, 26 January 2015 21:15 Go to next message
Martin Lichtin is currently offline Martin LichtinFriend
Messages: 3
Registered: September 2013
Junior Member
Wanted to ask how to get the information returned by

git log --oneline --decorate

with JGit?

Using Iterable<RevCommit> commits = git.log().call(); is obvious, but how to do what "--decorate" does?

Thanks
Martin
Re: How to do "git log --oneline --decorate" in JGit [message #1587185 is a reply to message #1586413] Tue, 27 January 2015 07:32 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior Member
That's a functionality exposed by the pgm package. The org.eclipse.jgit.pgm.Log class exposes the "decorate" option. You can lookup there [1] how it is done.

[1] https://github.com/eclipse/jgit/blob/master/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java


Ciao
Chris
Re: How to do "git log --oneline --decorate" in JGit [message #1588067 is a reply to message #1587185] Tue, 27 January 2015 18:35 Go to previous messageGo to next message
Martin Lichtin is currently offline Martin LichtinFriend
Messages: 3
Registered: September 2013
Junior Member
Thanks much!
It's something like:

    Map<AnyObjectId, Set<Ref>> allsRefs = git.getRepository().getAllRefsByPeeledObjectId();
    Iterable<RevCommit> commits = git.log().call();
    for (RevCommit commit : commits) {
      log.info("commit msg={}", commit.getShortMessage());
      Set<Ref> commitRefs = allsRefs.get(commit);
      if (commitRefs == null)
        continue;
      for (Ref ref : commitRefs) {
        String name = ref.getName();
        log.info("    rev={}", name);
      }
    }
Re: How to do "git log --oneline --decorate" in JGit [message #1715141 is a reply to message #1588067] Thu, 19 November 2015 14:54 Go to previous messageGo to next message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

I have a similar question. How to call log with "--merges" option?
I have tried to extract such info from the answer above with no success.
Re: How to do "git log --oneline --decorate" in JGit [message #1715168 is a reply to message #1715141] Thu, 19 November 2015 18:14 Go to previous messageGo to next message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

I have just managed to get the merge commits using the following method:
/**
	 * Returns the commits returned by the <code>git log --merges</code> command call.
	 * Commits with 2 or more parents are considered merges, as says the 'git-log' mannual .
	 * 
	 * @return
	 */
	public List<RevCommit> call() {
		ArrayList<RevCommit> commits = new ArrayList<RevCommit>();
		
		try {
			git = new Git(repository);
			
			Iterable<RevCommit> logs = git.log().all().call();
			for (RevCommit aCommit : logs) {
				count++;
				if (aCommit.getParentCount() >= 2) {
					commits.add(aCommit);
				}else continue;
			}	
		} catch (GitAPIException e) {
			// TODO treat GitAPIException
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
		return commits;
	}


Is there any better way to do it?
Re: How to do "git log --oneline --decorate" in JGit [message #1715201 is a reply to message #1715168] Fri, 20 November 2015 08:00 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior Member
That looks ok. You can skip the "count++" and "} else continue;" lines but other than that its ok. If you need more control you can directly use RevWalk. There we have a NoMerges Filter which does the opposite of what you want (report only non-merges). Writing a MergesFilter is very easy. Adding "setNoMerges()" and "setMerges()" to LogCommand would also be easy. You want to contribute?


Ciao
Chris
Re: How to do "git log --oneline --decorate" in JGit [message #1715577 is a reply to message #1715201] Tue, 24 November 2015 12:50 Go to previous messageGo to next message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

Thanks for the answer. And about your question...

Christian Halstrick wrote on Fri, 20 November 2015 03:00
Adding "setNoMerges()" and "setMerges()" to LogCommand would also be easy. You want to contribute?


What should I do? Unfortunately, I never contribute to OSS, maybe now it is a good opportunity to start. Smile
Re: How to do "git log --oneline --decorate" in JGit [message #1715595 is a reply to message #1715577] Tue, 24 November 2015 14:54 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior Member
The first contribution is the hardest. You should follow our https://wiki.eclipse.org/EGit/Contributor_Guide. You should have at least a green (no errors) jgit project in your workspace. Your work would probably mostly in LogCommand.java and in the addition of the new class MergesFilter as a sibling of NoMergesFilter.

Ciao
Chris
Re: How to do "git log --oneline --decorate" in JGit [message #1729017 is a reply to message #1715595] Sat, 09 April 2016 14:45 Go to previous messageGo to next message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

I finally took a time to implement the additions. I tried to follow the guide but Gerrit ended up by refusing my push.
After adding my ssh pub key to my account in Gerrit and commit my changes to my local 'origin/master' i tried to push with

git push ssh://username@git.eclipse.org:29418/jgit/jgit.git HEAD:origin/master


After added the server to my known hosts, I've got the following error message:
Quote:

Counting objects: 12, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (12/12), 1.35 KiB | 0 bytes/s, done.
Total 12 (delta 8 ), reused 0 (delta 0)
remote: Resolving deltas: 100% (8/8)
remote: Processing changes: refs: 1, done
To ssh://username@git.eclipse.org:29418/jgit/jgit.git
! [remote rejected] HEAD -> origin/master (prohibited by Gerrit)
error: failed to push some refs to 'ssh://username@git.eclipse.org:29418/jgit/jgit.git'


What am I missing?
Re: How to do "git log --oneline --decorate" in JGit [message #1729094 is a reply to message #1729017] Mon, 11 April 2016 07:32 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior Member
See http://wiki.eclipse.org/EGit/Contributor_Guide#Using_Gerrit_with_git_command_line:

You have to use "git push ... HEAD:refs/for/master"


Ciao
Chris
Re: How to do "git log --oneline --decorate" in JGit [message #1729276 is a reply to message #1729094] Tue, 12 April 2016 14:00 Go to previous messageGo to next message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

What exactly "refs/for/master" means? I managed to found the find command and then I ran the following:
$ find .git/refs

and given the following answer:
Quote:

.git/refs
.git/refs/heads
.git/refs/heads/master
.git/refs/remotes
.git/refs/remotes/origin
.git/refs/remotes/origin/HEAD
.git/refs/tags


i used the bold path and tried these 2 different pushes, as follows (one at a time)

$ git push ssh://username@git.eclipse.org:29418/jgit/jgit.git HEAD:refs/heads/master
$ git push ssh://username@git.eclipse.org:29418/jgit/jgit.git HEAD:heads/master


but the answer was the same:

Quote:

Counting objects: 12, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (12/12), 1.35 KiB | 0 bytes/s, done.
Total 12 (delta 8 ), reused 0 (delta 0)
remote: Resolving deltas: 100% (8/8)
remote: Branch refs/heads/master:
remote: You are not allowed to perform this operation.
remote: To push into this reference you need 'Push' rights.
remote: User: username
remote: Please read the documentation and contact an administrator
remote: if you feel the configuration is incorrect
remote: Processing changes: refs: 1, done
To ssh://username@git.eclipse.org:29418/jgit/jgit.git
! [remote rejected] HEAD -> master (prohibited by Gerrit)
error: failed to push some refs to 'ssh://username@git.eclipse.org:29418/jgit/jgit.git'


Is not the public ssh key enough for authentication?
Re: How to do "git log --oneline --decorate" in JGit [message #1729279 is a reply to message #1729276] Tue, 12 April 2016 14:16 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior Member
have you tried "refs/for/master"? If you push to a gerrit server and you want that your push goes into the review queue for branch x , then you have to push to "refs/for/x". That's how gerrit detects that you want to push for review.

It doesn't help if you search with the find command for refs you have locally. When you push to a git server then what you specify to the right of the colon is a ref which is interpreted only by the server. So the server has to know the ref. And our git server knows how to handle refs/for/x.



Ciao
Chris
Re: How to do "git log --oneline --decorate" in JGit [message #1729306 is a reply to message #1729279] Tue, 12 April 2016 18:19 Go to previous message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

It worked for "refs/for/master". \o/
=)

I was the whole time thinking that it was a "generic" reference to the mast Ref. It took also a bit longer because I had committed without the Change-Id than I got some errors, but i managed to solve than. Many thanks for the help.

Previous Topic:Lock Fail
Next Topic:Eclipse upgrade to 4.5.2
Goto Forum:
  


Current Time: Fri Mar 29 13:06:55 GMT 2024

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

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

Back to the top