17

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?

c2knaps
  • 1,707
  • 16
  • 22
  • 1
    I've never used Java before but I typed "jgit revcommit" into Google and found http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/revwalk/RevCommit.html then http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/lib/AnyObjectId.html#getName() – ta.speot.is Mar 08 '14 at 23:31

2 Answers2

18

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.

Community
  • 1
  • 1
ta.speot.is
  • 26,445
  • 8
  • 64
  • 94
2

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.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755