RefTree: Change peel suffix to " ^" (space carrot)

Using ^{} as the peel suffix has caused problems when projects used
tags like v2.1 and then v2.1.1, v2.2.2, etc.  The peeled value for
v2.1 was stored very far away in the tree relative to v2.1 itself as
^ sorts in the ASCII/UTF-8 encoding after all other common tag
characters like digits and dots.

Use " ^" instead as space is not valid in a reference name, sorts
before all other valid reference characters (thus forcing next entry
locality) and this looks like a peeled marker for the prior tag.

Change-Id: I26d2247a0428dfe26a9c319c02159502b3a67455
This commit is contained in:
Shawn Pearce 2016-01-09 17:27:25 -08:00
parent 088c2fc6e3
commit 398d8e877f
2 changed files with 6 additions and 6 deletions

View File

@ -100,15 +100,15 @@
* blob storing the name of the target reference.
* <p>
* Annotated tags also store the peeled object using a {@code GITLINK} entry
* with the suffix <code>"^{}"</code>, for example {@code "tags/v1.0"} stores
* the annotated tag object, while <code>"tags/v1.0^{}"</code> stores the commit
* the tag annotates.
* with the suffix <code>" ^"</code> (space carrot), for example
* {@code "tags/v1.0"} stores the annotated tag object, while
* <code>"tags/v1.0 ^"</code> stores the commit the tag annotates.
* <p>
* {@code HEAD} is a special case and stored as {@code "..HEAD"}.
*/
public class RefTree {
/** Suffix applied to GITLINK to indicate its the peeled value of a tag. */
public static final String PEELED_SUFFIX = "^{}"; //$NON-NLS-1$
public static final String PEELED_SUFFIX = " ^"; //$NON-NLS-1$
static final String ROOT_DOTDOT = ".."; //$NON-NLS-1$
/**

View File

@ -230,7 +230,7 @@ private static RevTree toTree(ObjectReader reader, AnyObjectId id)
private static boolean curElementHasPeelSuffix(AbstractTreeIterator itr) {
int n = itr.getEntryPathLength();
byte[] c = itr.getEntryPathBuffer();
return n > 3 && c[n - 3] == '^' && c[n - 2] == '{' && c[n - 1] == '}';
return n > 2 && c[n - 2] == ' ' && c[n - 1] == '^';
}
private static void peel(RefList.Builder<Ref> all, CanonicalTreeParser p) {
@ -272,7 +272,7 @@ private static String refName(CanonicalTreeParser p, boolean peel) {
byte[] buf = p.getEntryPathBuffer();
int len = p.getEntryPathLength();
if (peel) {
len -= 3;
len -= 2;
}
int ptr = 0;
if (RawParseUtils.match(buf, ptr, REFS_DOT_DOT) > 0) {