From cab35b28650c73f4ecb8ce5c054bf72628b22034 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Wed, 27 Mar 2019 15:21:50 -0700 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/lib/ObjectIdRef.java | 8 ++++---- org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java | 7 +++++++ .../src/org/eclipse/jgit/lib/SymbolicRef.java | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdRef.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdRef.java index b791c64552..d65c1bdf1a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdRef.java +++ b/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, @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, @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 abstract class ObjectIdRef implements Ref { */ 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 abstract class ObjectIdRef implements Ref { */ @Override public long getUpdateIndex() { - if (updateIndex == -1) { + if (updateIndex == UNDEFINED_UPDATE_INDEX) { throw new UnsupportedOperationException(); } return updateIndex; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java index 32c8b06c91..4082d21c2e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java +++ b/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. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/SymbolicRef.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/SymbolicRef.java index 00fcf52037..9f0568f0c2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/SymbolicRef.java +++ b/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) { this.name = refName; this.target = target; - this.updateIndex = -1; + this.updateIndex = UNDEFINED_UPDATE_INDEX; } /** @@ -155,7 +155,7 @@ public class SymbolicRef implements Ref { */ @Override public long getUpdateIndex() { - if (updateIndex == -1) { + if (updateIndex == UNDEFINED_UPDATE_INDEX) { throw new UnsupportedOperationException(); } return updateIndex; -- 2.39.5