aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorSebastian Schuberth <sebastian.schuberth@bosch.io>2022-01-05 18:07:48 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2022-02-19 22:04:28 +0100
commita7386ffe3aada6d1e0f73536f985dbe21cebadc2 (patch)
tree46f0e2b12a3e0177fc8eb8946a4a47a363343470 /org.eclipse.jgit/src/org/eclipse/jgit
parent69ef598bd933dda36ff852700e5ff7853e7ae04e (diff)
downloadjgit-a7386ffe3aada6d1e0f73536f985dbe21cebadc2.tar.gz
jgit-a7386ffe3aada6d1e0f73536f985dbe21cebadc2.zip
DescribeCommand: Support configuring the hash abbreviation
Bug: 537883 Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io> Change-Id: Ic52dcebc564bbb0d934cc3a6205704b7aeaee30e
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java31
1 files changed, 26 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
index 1e524fadab..e572773e43 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
@@ -9,6 +9,7 @@
*/
package org.eclipse.jgit.api;
+import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH;
import static org.eclipse.jgit.lib.Constants.R_REFS;
import static org.eclipse.jgit.lib.Constants.R_TAGS;
@@ -89,6 +90,11 @@ public class DescribeCommand extends GitCommand<String> {
private boolean always;
/**
+ * The prefix length to use when abbreviating a commit hash.
+ */
+ private int abbrev = OBJECT_ID_ABBREV_STRING_LENGTH;
+
+ /**
* Constructor for DescribeCommand.
*
* @param repo
@@ -205,12 +211,25 @@ public class DescribeCommand extends GitCommand<String> {
return this;
}
+ /**
+ * Sets the prefix length to use when abbreviating an object SHA-1.
+ *
+ * @param abbrev
+ * minimum length of the abbreviated string. Must be in the range
+ * [2, {@value Constants#OBJECT_ID_STRING_LENGTH}].
+ * @return {@code this}
+ * @since 6.1
+ */
+ public DescribeCommand setAbbrev(int abbrev) {
+ this.abbrev = abbrev;
+ return this;
+ }
+
private String longDescription(Ref tag, int depth, ObjectId tip)
throws IOException {
- return String.format(
- "%s-%d-g%s", formatRefName(tag.getName()), //$NON-NLS-1$
- Integer.valueOf(depth), w.getObjectReader().abbreviate(tip)
- .name());
+ return String.format("%s-%d-g%s", formatRefName(tag.getName()), //$NON-NLS-1$
+ Integer.valueOf(depth),
+ w.getObjectReader().abbreviate(tip, abbrev).name());
}
/**
@@ -413,7 +432,9 @@ public class DescribeCommand extends GitCommand<String> {
// if all the nodes are dominated by all the tags, the walk stops
if (candidates.isEmpty()) {
- return always ? w.getObjectReader().abbreviate(target).name() : null;
+ return always
+ ? w.getObjectReader().abbreviate(target, abbrev).name()
+ : null;
}
Candidate best = Collections.min(candidates,