From 20bdcf9ea82c390ee70180c3edb51888e7d237bc Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 5 Jan 2022 18:21:33 +0100 Subject: Introduce a constant for the length of an abbreviated hash string Signed-off-by: Sebastian Schuberth Change-Id: I196d58a813f7caa1965af4cf8e2f977ed4cdc350 --- org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java | 9 +++++++++ org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java index 92367ebd0c..cf2e69dbb5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -48,6 +48,15 @@ public final class Constants { */ public static final int OBJECT_ID_STRING_LENGTH = OBJECT_ID_LENGTH * 2; + /** + * The historic length of an abbreviated Git object hash string. Git 2.11 + * changed this static number to a dynamically calculated one that scales + * as the repository grows. + * + * @since 6.1 + */ + public static final int OBJECT_ID_ABBREV_STRING_LENGTH = 7; + /** Special name for the "HEAD" symbolic-ref. */ public static final String HEAD = "HEAD"; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java index a2c7381ce7..26c3ff6718 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java @@ -10,6 +10,8 @@ package org.eclipse.jgit.lib; +import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH; + import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -76,7 +78,7 @@ public abstract class ObjectReader implements AutoCloseable { */ public AbbreviatedObjectId abbreviate(AnyObjectId objectId) throws IOException { - return abbreviate(objectId, 7); + return abbreviate(objectId, OBJECT_ID_ABBREV_STRING_LENGTH); } /** -- cgit v1.2.3