Browse Source

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>
stable-5.4
Ivan Frade 6 years ago committed by Matthias Sohn
parent
commit
cab35b2865
  1. 8
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdRef.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java
  3. 4
      org.eclipse.jgit/src/org/eclipse/jgit/lib/SymbolicRef.java

8
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdRef.java

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

7
org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java

@ -125,6 +125,13 @@ public interface Ref {
} }
} }
/**
* 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. * What this ref is called within the repository.
* *

4
org.eclipse.jgit/src/org/eclipse/jgit/lib/SymbolicRef.java

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

Loading…
Cancel
Save