Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JGit how do i get the SHA1 from a RevCommit?

Tags:

jgit

This seems like an idiotic question, but I can't find documentation on it anywhere.

How do I get a the SHA1 of a RevCommit object?

like image 974
c2knaps Avatar asked Mar 08 '14 23:03

c2knaps


2 Answers

RevCommit inherits from AnyObjectId which has a getName function.

getName

public final String getName()

Returns:

string form of the SHA-1, in lower case hexadecimal.

like image 183
ta.speot.is Avatar answered Sep 29 '22 16:09

ta.speot.is


Do note that getName()only works with SHA-1 repositories: JGit does not yet work with SHA-256 repositories.

That is why, for instance, Git 2.30 (Q1 2021) does mark the tests that uses JGit not to run unless we are testing with ShA-1 repositories.

See commit ea699b4 (13 Nov 2020) by SZEDER Gábor (szeder).
(Merged by Junio C Hamano -- gitster -- in commit d302170, 25 Nov 2020)

t5310-pack-bitmaps: skip JGit tests with SHA256

Signed-off-by: SZEDER Gábor
Reviewed-by: Taylor Blau

In 't5310-pack-bitmaps.sh' two tests make sure that our pack bitmaps are compatible with JGit's bitmaps.
Alas, not even the most recent JGit version (5.9.0.202009080501-r) supports SHA256 yet, so when this test script is run with GIT_TEST_DEFAULT_HASH=sha256 on a setup with JGit installed in PATH, then these two tests fail.

Protect these two tests with the SHA1 prereq in order to skip them when testing with SHA256.

like image 43
VonC Avatar answered Sep 29 '22 16:09

VonC