Cap describe abbrev option
- minimum is 4 [1] - maximum is length of a full ObjectId [1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreabbrev Change-Id: I145bde1a218f71b87b8d8260761dd0853770bb76
This commit is contained in:
parent
a2d5650b8f
commit
85d8b31cb2
|
@ -14,7 +14,6 @@
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertThrows;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
@ -104,6 +103,10 @@ public void testDescribe() throws Exception {
|
||||||
assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*"));
|
assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*"));
|
||||||
|
|
||||||
assertEquals("bob-t2", describe(c4, false, true, 0));
|
assertEquals("bob-t2", describe(c4, false, true, 0));
|
||||||
|
assertEquals("bob-t2-1-g3e56", describe(c4, false, true, 1));
|
||||||
|
assertEquals("bob-t2-1-g3e56", describe(c4, false, true, -10));
|
||||||
|
assertEquals("bob-t2-1-g3e563c55927905f21e3bc7c00a3d83a31bf4ed3a",
|
||||||
|
describe(c4, false, true, 50));
|
||||||
} else {
|
} else {
|
||||||
assertEquals(null, describe(c2));
|
assertEquals(null, describe(c2));
|
||||||
assertEquals(null, describe(c3));
|
assertEquals(null, describe(c3));
|
||||||
|
@ -117,16 +120,13 @@ public void testDescribe() throws Exception {
|
||||||
assertEquals("44579ebe7f", describe(c3, false, true, 10));
|
assertEquals("44579ebe7f", describe(c3, false, true, 10));
|
||||||
assertEquals("3e563c5592", describe(c4, false, true, 10));
|
assertEquals("3e563c5592", describe(c4, false, true, 10));
|
||||||
|
|
||||||
assertEquals("3e", describe(c4, false, true, 2));
|
assertEquals("3e56", describe(c4, false, true, -10));
|
||||||
|
assertEquals("3e56", describe(c4, false, true, 0));
|
||||||
|
assertEquals("3e56", describe(c4, false, true, 2));
|
||||||
assertEquals("3e563c55927905f21e3bc7c00a3d83a31bf4ed3a",
|
assertEquals("3e563c55927905f21e3bc7c00a3d83a31bf4ed3a",
|
||||||
describe(c4, false, true, 40));
|
describe(c4, false, true, 40));
|
||||||
|
assertEquals("3e563c55927905f21e3bc7c00a3d83a31bf4ed3a",
|
||||||
assertThrows(StringIndexOutOfBoundsException.class,
|
describe(c4, false, true, 42));
|
||||||
() -> describe(c4, false, true, -10));
|
|
||||||
assertThrows(StringIndexOutOfBoundsException.class,
|
|
||||||
() -> describe(c4, false, true, 1));
|
|
||||||
assertThrows(StringIndexOutOfBoundsException.class,
|
|
||||||
() -> describe(c4, false, true, 41));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test default target
|
// test default target
|
||||||
|
|
|
@ -232,7 +232,13 @@ private String longDescription(Ref tag, int depth, ObjectId tip)
|
||||||
}
|
}
|
||||||
return String.format("%s-%d-g%s", formatRefName(tag.getName()), //$NON-NLS-1$
|
return String.format("%s-%d-g%s", formatRefName(tag.getName()), //$NON-NLS-1$
|
||||||
Integer.valueOf(depth),
|
Integer.valueOf(depth),
|
||||||
w.getObjectReader().abbreviate(tip, abbrev).name());
|
w.getObjectReader().abbreviate(tip, getCappedAbbrev()).name());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCappedAbbrev() {
|
||||||
|
int len = Math.max(abbrev, 4);
|
||||||
|
len = Math.min(len, Constants.OBJECT_ID_STRING_LENGTH);
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -436,7 +442,9 @@ String describe(ObjectId tip) throws IOException {
|
||||||
// if all the nodes are dominated by all the tags, the walk stops
|
// if all the nodes are dominated by all the tags, the walk stops
|
||||||
if (candidates.isEmpty()) {
|
if (candidates.isEmpty()) {
|
||||||
return always
|
return always
|
||||||
? w.getObjectReader().abbreviate(target, abbrev).name()
|
? w.getObjectReader()
|
||||||
|
.abbreviate(target, getCappedAbbrev())
|
||||||
|
.name()
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue