Ref: Add constant for undefined update index

Code that creates references and wants to support ref dbs with and
without update indexes needs to set this value. This leds to a
proliferation of "-1" in the code base.

Make the "undefined" value a constant in the ref interface.

Change-Id: I2622a37536a84b4a4036dd55792e185486fa0628
Signed-off-by: Ivan Frade <ifrade@google.com>
This commit is contained in:
Ivan Frade 2019-03-27 15:21:50 -07:00 committed by Matthias Sohn
parent bbff3ff008
commit cab35b2865
3 changed files with 13 additions and 6 deletions

View File

@ -67,7 +67,7 @@ public static class Unpeeled extends ObjectIdRef {
*/
public Unpeeled(@NonNull Storage st, @NonNull String name,
@Nullable ObjectId id) {
super(st, name, id, -1);
super(st, name, id, UNDEFINED_UPDATE_INDEX);
}
/**
@ -119,7 +119,7 @@ public static class PeeledTag extends ObjectIdRef {
*/
public PeeledTag(@NonNull Storage st, @NonNull String name,
@Nullable ObjectId id, @NonNull ObjectId p) {
super(st, name, id, -1);
super(st, name, id, UNDEFINED_UPDATE_INDEX);
peeledObjectId = p;
}
@ -172,7 +172,7 @@ public static class PeeledNonTag extends ObjectIdRef {
*/
public PeeledNonTag(@NonNull Storage st, @NonNull String name,
@Nullable ObjectId id) {
super(st, name, id, -1);
super(st, name, id, UNDEFINED_UPDATE_INDEX);
}
/**
@ -284,7 +284,7 @@ public Storage getStorage() {
*/
@Override
public long getUpdateIndex() {
if (updateIndex == -1) {
if (updateIndex == UNDEFINED_UPDATE_INDEX) {
throw new UnsupportedOperationException();
}
return updateIndex;

View File

@ -125,6 +125,13 @@ public boolean isPacked() {
}
}
/**
* Update index value when a reference doesn't have one
*
* @since 5.4
*/
long UNDEFINED_UPDATE_INDEX = -1L;
/**
* What this ref is called within the repository.
*

View File

@ -71,7 +71,7 @@ public class SymbolicRef implements Ref {
public SymbolicRef(@NonNull String refName, @NonNull Ref target) {
this.name = refName;
this.target = target;
this.updateIndex = -1;
this.updateIndex = UNDEFINED_UPDATE_INDEX;
}
/**
@ -155,7 +155,7 @@ public boolean isPeeled() {
*/
@Override
public long getUpdateIndex() {
if (updateIndex == -1) {
if (updateIndex == UNDEFINED_UPDATE_INDEX) {
throw new UnsupportedOperationException();
}
return updateIndex;