From a4f7992dfb7ac1931e89af9035b33604717cb2c9 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Wed, 20 Oct 2010 17:39:19 +0200 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/lib/Constants.java | 9 +++++++++ .../src/org/eclipse/jgit/lib/RefDatabase.java | 14 ++++++++++++++ .../eclipse/jgit/storage/file/RefDirectory.java | 17 +++++++++++++++++ 3 files changed, 40 insertions(+) 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. *

@@ -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; /** @@ -176,6 +177,19 @@ public abstract class RefDatabase { */ public abstract Map getRefs(String prefix) throws IOException; + /** + * Get the additional reference-like entities from the repository. + *

+ * 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 + * getRefs(ALL) but are accepted by {@link #getRef(String)} + * + * @return a list of additional refs + * @throws IOException + * the reference space cannot be accessed. + */ + public abstract List getAdditionalRefs() throws IOException; + /** * Peel a possibly unpeeled reference by traversing the annotated tags. *

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 getAdditionalRefs() throws IOException { + List ret = new LinkedList(); + for (String name : additionalRefsNames) { + Ref r = getRef(name); + if (r != null) + ret.add(r); + } + return ret; + } + @SuppressWarnings("unchecked") private RefList upcast(RefList loose) { return (RefList) loose; -- 2.39.5