diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2010-10-20 17:39:19 +0200 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2010-10-25 00:36:16 +0200 |
commit | a4f7992dfb7ac1931e89af9035b33604717cb2c9 (patch) | |
tree | c94c462d35dc785b2776fe4e5da6143c642d254b | |
parent | 8067197049a02ad9344199fde2e6b52000c0139c (diff) | |
download | jgit-a4f7992dfb7ac1931e89af9035b33604717cb2c9.tar.gz jgit-a4f7992dfb7ac1931e89af9035b33604717cb2c9.zip |
Add support for special symref FETCH_HEAD and MERGE_HEAD
The RefDirectory class was not returning FETCH_HEAD and
MERGE_HEAD when trying to get all refs via getRefs(RefDatabase.ALL).
This fix adds constants for FETCH_HEAD and ORIG_HEAD and adds a
new getter getAdditionalRefs() to get these additional refs.
To be compatible with c git the getRefs(ALL) method will not return
FETCH_HEAD, MERGE_HEAD and ORIG_HEAD.
Change-Id: Ie114ca92e9d5e7d61d892f4413ade65acdc08c32
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
3 files changed, 40 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java index 2269655cf5..afeaffcc9c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -79,6 +79,9 @@ public final class Constants { /** Special name for the "HEAD" symbolic-ref. */ public static final String HEAD = "HEAD"; + /** Special name for the "FETCH_HEAD" symbolic-ref. */ + public static final String FETCH_HEAD = "FETCH_HEAD"; + /** * Text string that identifies an object as a commit. * <p> @@ -527,6 +530,12 @@ public final class Constants { /** name of the file containing the IDs of the parents of a merge commit */ public static final String MERGE_HEAD = "MERGE_HEAD"; + /** + * name of the ref ORIG_HEAD used by certain commands to store the original + * value of HEAD + */ + public static final String ORIG_HEAD = "ORIG_HEAD"; + /** objectid for the empty blob */ public static final ObjectId EMPTY_BLOB_ID = ObjectId .fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java index 21e7041b32..b2ccf2944a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.lib; import java.io.IOException; +import java.util.List; import java.util.Map; /** @@ -177,6 +178,19 @@ public abstract class RefDatabase { public abstract Map<String, Ref> getRefs(String prefix) throws IOException; /** + * Get the additional reference-like entities from the repository. + * <p> + * The result list includes non-ref items such as MERGE_HEAD and + * FETCH_RESULT cast to be refs. The names of these refs are not returned by + * <code>getRefs(ALL)</code> but are accepted by {@link #getRef(String)} + * + * @return a list of additional refs + * @throws IOException + * the reference space cannot be accessed. + */ + public abstract List<Ref> getAdditionalRefs() throws IOException; + + /** * Peel a possibly unpeeled reference by traversing the annotated tags. * <p> * If the reference cannot be peeled (as it does not refer to an annotated diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java index 0f073b66fd..2e4489cda4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java @@ -69,6 +69,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.text.MessageFormat; import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -123,6 +125,10 @@ public class RefDirectory extends RefDatabase { /** If in the header, denotes the file has peeled data. */ public static final String PACKED_REFS_PEELED = " peeled"; //$NON-NLS-1$ + /** The names of the additional refs supported by this class */ + private static final String[] additionalRefsNames = new String[] { + Constants.MERGE_HEAD, Constants.FETCH_HEAD, Constants.ORIG_HEAD }; + private final FileRepository parent; private final File gitDir; @@ -297,6 +303,17 @@ public class RefDirectory extends RefDatabase { return new RefMap(prefix, packed, upcast(loose), symbolic.toRefList()); } + @Override + public List<Ref> getAdditionalRefs() throws IOException { + List<Ref> ret = new LinkedList<Ref>(); + for (String name : additionalRefsNames) { + Ref r = getRef(name); + if (r != null) + ret.add(r); + } + return ret; + } + @SuppressWarnings("unchecked") private RefList<Ref> upcast(RefList<? extends Ref> loose) { return (RefList<Ref>) loose; |