Code

log-tree.c: small refactor in show_signature()
[git.git] / refs.c
diff --git a/refs.c b/refs.c
index 9911c97b69a66ba0a4c7d3aff33b9d7b1d006796..026c7ea25dde100c19b5a1edca4280c20c18f7ee 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -393,12 +393,22 @@ static struct ref_array *get_loose_refs(const char *submodule)
 #define MAXDEPTH 5
 #define MAXREFLEN (1024)
 
+/*
+ * Called by resolve_gitlink_ref_recursive() after it failed to read
+ * from "name", which is "module/.git/<refname>". Find <refname> in
+ * the packed-refs file for the submodule.
+ */
 static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refname, unsigned char *result)
 {
        int retval = -1;
        struct ref_entry *ref;
-       struct ref_array *array = get_packed_refs(name);
+       struct ref_array *array;
 
+       /* being defensive: resolve_gitlink_ref() did this for us */
+       if (pathlen < 6 || memcmp(name + pathlen - 6, "/.git/", 6))
+               die("Oops");
+       name[pathlen - 6] = '\0'; /* make it path to the submodule */
+       array = get_packed_refs(name);
        ref = search_ref_array(array, refname);
        if (ref != NULL) {
                memcpy(result, ref->sha1, 20);
@@ -985,13 +995,6 @@ const char *ref_rev_parse_rules[] = {
        NULL
 };
 
-const char *ref_fetch_rules[] = {
-       "%.*s",
-       "refs/%.*s",
-       "refs/heads/%.*s",
-       NULL
-};
-
 int refname_match(const char *abbrev_name, const char *full_name, const char **rules)
 {
        const char **p;