Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » git-blame --contents equivalent(How to specify the contents for the working tree copy)
git-blame --contents equivalent [message #1821344] Tue, 11 February 2020 10:28 Go to next message
Alex Jitianu is currently offline Alex JitianuFriend
Messages: 1
Registered: February 2020
Junior Member

I'm using the JGit API to perform a blame on the working tree copy:

BlameCommand blamer = new BlameCommand(repository);
BlameResult blame =;

Is there a correspondence to the git-blame --contents argument ?

Looking inside org.eclipse.jgit.blame.BlameGenerator.prepareHead(), I'm tempted to believe I can use the BlameGenerator directly and use push() to put a different content for the working tree version, right?

Either way, I would prefer just setting a flag instead of working with low level API that I might not fully understand.

Thank you,
Re: git-blame --contents equivalent [message #1821498 is a reply to message #1821344] Thu, 13 February 2020 16:03 Go to previous messageGo to next message
Tim Wolf is currently offline Tim WolfFriend
Messages: 1
Registered: July 2009
Junior Member
Yes, looks like that should be possible. We'd welcome a change on Gerrit for this. Shouldn't be too complicated:

* BlameGenerator needs a prepareHead() variant that takes a RawText (or a Callable<RawText>) as parameter and that uses that for inTree. In that case checking whether the original path exists at all in the working tree is perhaps also not needed.
* BlameCommand needs some setter to get the contents for the head version. Something like setInitialContents(Callable<RawText>). I wouldn't pass in an InputStream, it might force the client to read the file early, and closing the stream is less obvious. Then use that supplier in the prepareHead() case of call().
* Tests.

Then you could do
BlameCommand blamer = new BlameCommand(repository);
blamer.setInitialContents(() -> {
  // Load from wherever into a RawText, return that
BlameResult blame =;
Re: git-blame --contents equivalent [message #1821536 is a reply to message #1821498] Fri, 14 February 2020 10:50 Go to previous message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 512
Registered: August 2016
Senior Member
Tim Wolf wrote on Thu, 13 February 2020 16:03

That's a mighty strange post. The above was me; but it appears the server crash at the Eclipse Foundation somehow had corrupted my account, and the forum software thought the name was "Tim", not "Thomas", and I didn't have any forum posts yet...

[Updated on: Fri, 14 February 2020 10:51]

Report message to a moderator

Previous Topic:"rejected - non-fast-forward" while pushing a new local branch to remote
Next Topic:EGit 2.3 + Eclipse 3.7.2 cannot communicate with repository
Goto Forum:

Current Time: Fri Dec 09 15:44:45 GMT 2022

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

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

Back to the top