Skip to main content



      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 05:28 Go to next message
Eclipse UserFriend
Hello,

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

BlameCommand blamer = new BlameCommand(repository);
blamer.setFilePath(filePath);
BlameResult blame = blamer.call();


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,
Alex
Re: git-blame --contents equivalent [message #1821498 is a reply to message #1821344] Thu, 13 February 2020 11:03 Go to previous messageGo to next message
Eclipse UserFriend
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.setFilePath(filePath);
blamer.setInitialContents(() -> {
  // Load from wherever into a RawText, return that
});
BlameResult blame = blamer.call();
Re: git-blame --contents equivalent [message #1821536 is a reply to message #1821498] Fri, 14 February 2020 05:50 Go to previous message
Eclipse UserFriend
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 05:51] by 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: Thu Nov 06 15:17:36 EST 2025

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

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

Back to the top