18

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,817
  • 17
  • 23
  • 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,914
  • 8
  • 68
  • 96
3

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,262,500
  • 529
  • 4,410
  • 5,250
  • does this stay true in 2022? – shabunc Dec 01 '22 at 15:38
  • 1
    @shabunc Yes, recent commit [shows the skip is still in place](https://github.com/git/git/blame/93eb41e2403788fa9105211956e87b6b2c22c68c/t/t5310-pack-bitmaps.sh#L189). – VonC Dec 01 '22 at 16:19