{"thread":{"id":"28783","subject":"[PATCH v3 00/14] Tidying up references code","startedAt":"2011-10-28T11:14:27Z","lastAt":"2011-10-28T11:14:41Z","messageCount":15,"participants":["mhagger@alum.mit.edu"],"isPatch":true,"patchVersion":3,"patchTotal":14},"messages":[{"id":"178404","messageId":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":null,"subject":"[PATCH v3 00/14] Tidying up references code","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:27Z","receivedAt":"2011-10-28T11:14:27Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nI have re-rolled this patch series against gitster/master for your\nmerging enjoyment.\n\nOriginal description of patch series:\n\nThis is the next installment of the reference changes that I have been\nworking on.  This batch includes a lot of tidying up in preparation\nfor the real changes.\n\nThe last few patches have a little bit of meat on them.  They start\nchanging the innards of refs.c to work less with strings and more with\nobjects.  This work will continue in later patches with the ultimate\ngoal of swapping the data structure used to store cached references\nout from under the module--changing it from a sorted array of pointers\ninto a hierarchical tree shaped like the reference namespace tree.\n\nMichael Haggerty (14):\n  cache.h: add comments for git_path() and git_path_submodule()\n  struct ref_entry: document name member\n  refs: rename \"refname\" variables\n  refs: rename parameters result -> sha1\n  clear_ref_array(): rename from free_ref_array()\n  is_refname_available(): remove the \"quiet\" argument\n  parse_ref_line(): add docstring\n  add_ref(): add docstring\n  is_dup_ref(): extract function from sort_ref_array()\n  refs: change signatures of get_packed_refs() and get_loose_refs()\n  get_ref_dir(): change signature\n  resolve_gitlink_ref(): improve docstring\n  Pass a (ref_cache *) to the resolve_gitlink_*() helper functions\n  resolve_gitlink_ref_recursive(): change to work with struct ref_cache\n\n cache.h |   18 +++\n refs.c  |  434 +++++++++++++++++++++++++++++++++------------------------------\n refs.h  |   34 +++--\n 3 files changed, 266 insertions(+), 220 deletions(-)\n\n-- \n1.7.7\n"},{"id":"178409","messageId":"1319800481-15138-2-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 01/14] cache.h: add comments for git_path() and git_path_submodule()","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:28Z","receivedAt":"2011-10-28T11:14:28Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n cache.h |   18 ++++++++++++++++++\n 1 files changed, 18 insertions(+), 0 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 2e6ad36..5e807b9 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -662,7 +662,25 @@ extern char *git_pathdup(const char *fmt, ...)\n \n /* Return a statically allocated filename matching the sha1 signature */\n extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));\n+\n+/*\n+ * Return the path of a file within get_git_dir().  The arguments\n+ * should be printf-like arguments that produce the filename relative\n+ * to get_git_dir().  Return the resulting path, or \"/bad-path/\" if\n+ * there is an error.  The return value is a pointer into a temporary\n+ * buffer that will be overwritten without notice.\n+ */\n extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));\n+\n+/*\n+ * Return the path of a file within the git_dir of the submodule\n+ * located at path.  The other arguments should be printf-like\n+ * arguments that produce the filename relative to \"<path>/.git\".  If\n+ * \"<path>/.git\" is a gitlink file, follow it to find the actual\n+ * submodule git_dir.  Return the resulting path, or \"/bad-path/\" if\n+ * there is an error.  The return value is a pointer into a temporary\n+ * buffer that will be overwritten without notice.\n+ */\n extern char *git_path_submodule(const char *path, const char *fmt, ...)\n \t__attribute__((format (printf, 2, 3)));\n \n-- \n1.7.7\n"},{"id":"178408","messageId":"1319800481-15138-3-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 02/14] struct ref_entry: document name member","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:29Z","receivedAt":"2011-10-28T11:14:29Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex e69ba26..5fa880b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -11,6 +11,7 @@ struct ref_entry {\n \tunsigned char flag; /* ISSYMREF? ISPACKED? */\n \tunsigned char sha1[20];\n \tunsigned char peeled[20];\n+\t/* The full name of the reference (e.g., \"refs/heads/master\"): */\n \tchar name[FLEX_ARRAY];\n };\n \n-- \n1.7.7\n"},{"id":"178406","messageId":"1319800481-15138-4-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 03/14] refs: rename \"refname\" variables","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:30Z","receivedAt":"2011-10-28T11:14:30Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nTry to consistently use the variable name \"refname\" when referring to\na string that names a reference.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |  276 +++++++++++++++++++++++++++++++++-------------------------------\n refs.h |   26 ++++---\n 2 files changed, 157 insertions(+), 145 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 5fa880b..7a34e4b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -48,7 +48,7 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)\n \treturn line;\n }\n \n-static void add_ref(const char *name, const unsigned char *sha1,\n+static void add_ref(const char *refname, const unsigned char *sha1,\n \t\t    int flag, struct ref_array *refs,\n \t\t    struct ref_entry **new_entry)\n {\n@@ -56,13 +56,13 @@ static void add_ref(const char *name, const unsigned char *sha1,\n \tstruct ref_entry *entry;\n \n \t/* Allocate it and add it in.. */\n-\tlen = strlen(name) + 1;\n+\tlen = strlen(refname) + 1;\n \tentry = xmalloc(sizeof(struct ref_entry) + len);\n \thashcpy(entry->sha1, sha1);\n \thashclr(entry->peeled);\n-\tif (check_refname_format(name, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))\n-\t\tdie(\"Reference has invalid format: '%s'\", name);\n-\tmemcpy(entry->name, name, len);\n+\tif (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))\n+\t\tdie(\"Reference has invalid format: '%s'\", refname);\n+\tmemcpy(entry->name, refname, len);\n \tentry->flag = flag;\n \tif (new_entry)\n \t\t*new_entry = entry;\n@@ -105,20 +105,20 @@ static void sort_ref_array(struct ref_array *array)\n \tarray->nr = i + 1;\n }\n \n-static struct ref_entry *search_ref_array(struct ref_array *array, const char *name)\n+static struct ref_entry *search_ref_array(struct ref_array *array, const char *refname)\n {\n \tstruct ref_entry *e, **r;\n \tint len;\n \n-\tif (name == NULL)\n+\tif (refname == NULL)\n \t\treturn NULL;\n \n \tif (!array->nr)\n \t\treturn NULL;\n \n-\tlen = strlen(name) + 1;\n+\tlen = strlen(refname) + 1;\n \te = xmalloc(sizeof(struct ref_entry) + len);\n-\tmemcpy(e->name, name, len);\n+\tmemcpy(e->name, refname, len);\n \n \tr = bsearch(&e, array->refs, array->nr, sizeof(*array->refs), ref_entry_cmp);\n \n@@ -222,7 +222,7 @@ static void read_packed_refs(FILE *f, struct ref_array *array)\n \n \twhile (fgets(refline, sizeof(refline), f)) {\n \t\tunsigned char sha1[20];\n-\t\tconst char *name;\n+\t\tconst char *refname;\n \t\tstatic const char header[] = \"# pack-refs with:\";\n \n \t\tif (!strncmp(refline, header, sizeof(header)-1)) {\n@@ -233,9 +233,9 @@ static void read_packed_refs(FILE *f, struct ref_array *array)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tname = parse_ref_line(refline, sha1);\n-\t\tif (name) {\n-\t\t\tadd_ref(name, sha1, flag, array, &last);\n+\t\trefname = parse_ref_line(refline, sha1);\n+\t\tif (refname) {\n+\t\t\tadd_ref(refname, sha1, flag, array, &last);\n \t\t\tcontinue;\n \t\t}\n \t\tif (last &&\n@@ -248,9 +248,9 @@ static void read_packed_refs(FILE *f, struct ref_array *array)\n \tsort_ref_array(array);\n }\n \n-void add_extra_ref(const char *name, const unsigned char *sha1, int flag)\n+void add_extra_ref(const char *refname, const unsigned char *sha1, int flag)\n {\n-\tadd_ref(name, sha1, flag, &extra_refs, NULL);\n+\tadd_ref(refname, sha1, flag, &extra_refs, NULL);\n }\n \n void clear_extra_refs(void)\n@@ -401,7 +401,8 @@ static struct ref_array *get_loose_refs(const char *submodule)\n  * from \"name\", which is \"module/.git/<refname>\". Find <refname> in\n  * the packed-refs file for the submodule.\n  */\n-static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refname, unsigned char *result)\n+static int resolve_gitlink_packed_ref(char *name, int pathlen,\n+\t\t\t\t      const char *refname, unsigned char *result)\n {\n \tint retval = -1;\n \tstruct ref_entry *ref;\n@@ -420,7 +421,9 @@ static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refna\n \treturn retval;\n }\n \n-static int resolve_gitlink_ref_recursive(char *name, int pathlen, const char *refname, unsigned char *result, int recursion)\n+static int resolve_gitlink_ref_recursive(char *name, int pathlen,\n+\t\t\t\t\t const char *refname, unsigned char *result,\n+\t\t\t\t\t int recursion)\n {\n \tint fd, len = strlen(refname);\n \tchar buffer[128], *p;\n@@ -487,10 +490,10 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *re\n  * Try to read ref from the packed references.  On success, set sha1\n  * and return 0; otherwise, return -1.\n  */\n-static int get_packed_ref(const char *ref, unsigned char *sha1)\n+static int get_packed_ref(const char *refname, unsigned char *sha1)\n {\n \tstruct ref_array *packed = get_packed_refs(NULL);\n-\tstruct ref_entry *entry = search_ref_array(packed, ref);\n+\tstruct ref_entry *entry = search_ref_array(packed, refname);\n \tif (entry) {\n \t\thashcpy(sha1, entry->sha1);\n \t\treturn 0;\n@@ -498,17 +501,17 @@ static int get_packed_ref(const char *ref, unsigned char *sha1)\n \treturn -1;\n }\n \n-const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag)\n+const char *resolve_ref(const char *refname, unsigned char *sha1, int reading, int *flag)\n {\n \tint depth = MAXDEPTH;\n \tssize_t len;\n \tchar buffer[256];\n-\tstatic char ref_buffer[256];\n+\tstatic char refname_buffer[256];\n \n \tif (flag)\n \t\t*flag = 0;\n \n-\tif (check_refname_format(ref, REFNAME_ALLOW_ONELEVEL))\n+\tif (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))\n \t\treturn NULL;\n \n \tfor (;;) {\n@@ -520,7 +523,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *\n \t\tif (--depth < 0)\n \t\t\treturn NULL;\n \n-\t\tgit_snpath(path, sizeof(path), \"%s\", ref);\n+\t\tgit_snpath(path, sizeof(path), \"%s\", refname);\n \n \t\tif (lstat(path, &st) < 0) {\n \t\t\tif (errno != ENOENT)\n@@ -529,17 +532,17 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *\n \t\t\t * The loose reference file does not exist;\n \t\t\t * check for a packed reference.\n \t\t\t */\n-\t\t\tif (!get_packed_ref(ref, sha1)) {\n+\t\t\tif (!get_packed_ref(refname, sha1)) {\n \t\t\t\tif (flag)\n \t\t\t\t\t*flag |= REF_ISPACKED;\n-\t\t\t\treturn ref;\n+\t\t\t\treturn refname;\n \t\t\t}\n \t\t\t/* The reference is not a packed reference, either. */\n \t\t\tif (reading) {\n \t\t\t\treturn NULL;\n \t\t\t} else {\n \t\t\t\thashclr(sha1);\n-\t\t\t\treturn ref;\n+\t\t\t\treturn refname;\n \t\t\t}\n \t\t}\n \n@@ -551,8 +554,8 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *\n \t\t\tbuffer[len] = 0;\n \t\t\tif (!prefixcmp(buffer, \"refs/\") &&\n \t\t\t\t\t!check_refname_format(buffer, 0)) {\n-\t\t\t\tstrcpy(ref_buffer, buffer);\n-\t\t\t\tref = ref_buffer;\n+\t\t\t\tstrcpy(refname_buffer, buffer);\n+\t\t\t\trefname = refname_buffer;\n \t\t\t\tif (flag)\n \t\t\t\t\t*flag |= REF_ISSYMREF;\n \t\t\t\tcontinue;\n@@ -595,7 +598,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *\n \t\t\t\t*flag |= REF_ISBROKEN;\n \t\t\treturn NULL;\n \t\t}\n-\t\tref = strcpy(ref_buffer, buf);\n+\t\trefname = strcpy(refname_buffer, buf);\n \t}\n \t/* Please note that FETCH_HEAD has a second line containing other data. */\n \tif (get_sha1_hex(buffer, sha1) || (buffer[40] != '\\0' && !isspace(buffer[40]))) {\n@@ -603,7 +606,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *\n \t\t\t*flag |= REF_ISBROKEN;\n \t\treturn NULL;\n \t}\n-\treturn ref;\n+\treturn refname;\n }\n \n /* The argument to filter_refs */\n@@ -613,9 +616,9 @@ struct ref_filter {\n \tvoid *cb_data;\n };\n \n-int read_ref(const char *ref, unsigned char *sha1)\n+int read_ref(const char *refname, unsigned char *sha1)\n {\n-\tif (resolve_ref(ref, sha1, 1, NULL))\n+\tif (resolve_ref(refname, sha1, 1, NULL))\n \t\treturn 0;\n \treturn -1;\n }\n@@ -639,23 +642,23 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,\n \treturn fn(entry->name + trim, entry->sha1, entry->flag, cb_data);\n }\n \n-static int filter_refs(const char *ref, const unsigned char *sha, int flags,\n+static int filter_refs(const char *refname, const unsigned char *sha, int flags,\n \tvoid *data)\n {\n \tstruct ref_filter *filter = (struct ref_filter *)data;\n-\tif (fnmatch(filter->pattern, ref, 0))\n+\tif (fnmatch(filter->pattern, refname, 0))\n \t\treturn 0;\n-\treturn filter->fn(ref, sha, flags, filter->cb_data);\n+\treturn filter->fn(refname, sha, flags, filter->cb_data);\n }\n \n-int peel_ref(const char *ref, unsigned char *sha1)\n+int peel_ref(const char *refname, unsigned char *sha1)\n {\n \tint flag;\n \tunsigned char base[20];\n \tstruct object *o;\n \n-\tif (current_ref && (current_ref->name == ref\n-\t\t|| !strcmp(current_ref->name, ref))) {\n+\tif (current_ref && (current_ref->name == refname\n+\t\t|| !strcmp(current_ref->name, refname))) {\n \t\tif (current_ref->flag & REF_KNOWS_PEELED) {\n \t\t\thashcpy(sha1, current_ref->peeled);\n \t\t\treturn 0;\n@@ -664,12 +667,12 @@ int peel_ref(const char *ref, unsigned char *sha1)\n \t\tgoto fallback;\n \t}\n \n-\tif (!resolve_ref(ref, base, 1, &flag))\n+\tif (!resolve_ref(refname, base, 1, &flag))\n \t\treturn -1;\n \n \tif ((flag & REF_ISPACKED)) {\n \t\tstruct ref_array *array = get_packed_refs(NULL);\n-\t\tstruct ref_entry *r = search_ref_array(array, ref);\n+\t\tstruct ref_entry *r = search_ref_array(array, refname);\n \n \t\tif (r != NULL && r->flag & REF_KNOWS_PEELED) {\n \t\t\thashcpy(sha1, r->peeled);\n@@ -680,7 +683,7 @@ int peel_ref(const char *ref, unsigned char *sha1)\n fallback:\n \to = parse_object(base);\n \tif (o && o->type == OBJ_TAG) {\n-\t\to = deref_tag(o, ref, 0);\n+\t\to = deref_tag(o, refname, 0);\n \t\tif (o) {\n \t\t\thashcpy(sha1, o->sha1);\n \t\t\treturn 0;\n@@ -910,16 +913,16 @@ static inline int bad_ref_char(int ch)\n }\n \n /*\n- * Try to read one refname component from the front of ref.  Return\n+ * Try to read one refname component from the front of refname.  Return\n  * the length of the component found, or -1 if the component is not\n  * legal.\n  */\n-static int check_refname_component(const char *ref, int flags)\n+static int check_refname_component(const char *refname, int flags)\n {\n \tconst char *cp;\n \tchar last = '\\0';\n \n-\tfor (cp = ref; ; cp++) {\n+\tfor (cp = refname; ; cp++) {\n \t\tchar ch = *cp;\n \t\tif (ch == '\\0' || ch == '/')\n \t\t\tbreak;\n@@ -931,34 +934,34 @@ static int check_refname_component(const char *ref, int flags)\n \t\t\treturn -1; /* Refname contains \"@{\". */\n \t\tlast = ch;\n \t}\n-\tif (cp == ref)\n+\tif (cp == refname)\n \t\treturn -1; /* Component has zero length. */\n-\tif (ref[0] == '.') {\n+\tif (refname[0] == '.') {\n \t\tif (!(flags & REFNAME_DOT_COMPONENT))\n \t\t\treturn -1; /* Component starts with '.'. */\n \t\t/*\n \t\t * Even if leading dots are allowed, don't allow \".\"\n \t\t * as a component (\"..\" is prevented by a rule above).\n \t\t */\n-\t\tif (ref[1] == '\\0')\n+\t\tif (refname[1] == '\\0')\n \t\t\treturn -1; /* Component equals \".\". */\n \t}\n-\tif (cp - ref >= 5 && !memcmp(cp - 5, \".lock\", 5))\n+\tif (cp - refname >= 5 && !memcmp(cp - 5, \".lock\", 5))\n \t\treturn -1; /* Refname ends with \".lock\". */\n-\treturn cp - ref;\n+\treturn cp - refname;\n }\n \n-int check_refname_format(const char *ref, int flags)\n+int check_refname_format(const char *refname, int flags)\n {\n \tint component_len, component_count = 0;\n \n \twhile (1) {\n \t\t/* We are at the start of a path component. */\n-\t\tcomponent_len = check_refname_component(ref, flags);\n+\t\tcomponent_len = check_refname_component(refname, flags);\n \t\tif (component_len < 0) {\n \t\t\tif ((flags & REFNAME_REFSPEC_PATTERN) &&\n-\t\t\t\t\tref[0] == '*' &&\n-\t\t\t\t\t(ref[1] == '\\0' || ref[1] == '/')) {\n+\t\t\t\t\trefname[0] == '*' &&\n+\t\t\t\t\t(refname[1] == '\\0' || refname[1] == '/')) {\n \t\t\t\t/* Accept one wildcard as a full refname component. */\n \t\t\t\tflags &= ~REFNAME_REFSPEC_PATTERN;\n \t\t\t\tcomponent_len = 1;\n@@ -967,13 +970,13 @@ int check_refname_format(const char *ref, int flags)\n \t\t\t}\n \t\t}\n \t\tcomponent_count++;\n-\t\tif (ref[component_len] == '\\0')\n+\t\tif (refname[component_len] == '\\0')\n \t\t\tbreak;\n \t\t/* Skip to next component. */\n-\t\tref += component_len + 1;\n+\t\trefname += component_len + 1;\n \t}\n \n-\tif (ref[component_len - 1] == '.')\n+\tif (refname[component_len - 1] == '.')\n \t\treturn -1; /* Refname ends with '.'. */\n \tif (!(flags & REFNAME_ALLOW_ONELEVEL) && component_count < 2)\n \t\treturn -1; /* Refname has only one component. */\n@@ -1056,22 +1059,22 @@ static int remove_empty_directories(const char *file)\n \treturn result;\n }\n \n-static int is_refname_available(const char *ref, const char *oldref,\n+static int is_refname_available(const char *refname, const char *oldrefname,\n \t\t\t\tstruct ref_array *array, int quiet)\n {\n-\tint i, namlen = strlen(ref); /* e.g. 'foo/bar' */\n+\tint i, namlen = strlen(refname); /* e.g. 'foo/bar' */\n \tfor (i = 0; i < array->nr; i++ ) {\n \t\tstruct ref_entry *entry = array->refs[i];\n \t\t/* entry->name could be 'foo' or 'foo/bar/baz' */\n-\t\tif (!oldref || strcmp(oldref, entry->name)) {\n+\t\tif (!oldrefname || strcmp(oldrefname, entry->name)) {\n \t\t\tint len = strlen(entry->name);\n \t\t\tint cmplen = (namlen < len) ? namlen : len;\n-\t\t\tconst char *lead = (namlen < len) ? entry->name : ref;\n-\t\t\tif (!strncmp(ref, entry->name, cmplen) &&\n+\t\t\tconst char *lead = (namlen < len) ? entry->name : refname;\n+\t\t\tif (!strncmp(refname, entry->name, cmplen) &&\n \t\t\t    lead[cmplen] == '/') {\n \t\t\t\tif (!quiet)\n \t\t\t\t\terror(\"'%s' exists; cannot create '%s'\",\n-\t\t\t\t\t      entry->name, ref);\n+\t\t\t\t\t      entry->name, refname);\n \t\t\t\treturn 0;\n \t\t\t}\n \t\t}\n@@ -1167,10 +1170,12 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)\n \treturn logs_found;\n }\n \n-static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char *old_sha1, int flags, int *type_p)\n+static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n+\t\t\t\t\t    const unsigned char *old_sha1,\n+\t\t\t\t\t    int flags, int *type_p)\n {\n \tchar *ref_file;\n-\tconst char *orig_ref = ref;\n+\tconst char *orig_refname = refname;\n \tstruct ref_lock *lock;\n \tint last_errno = 0;\n \tint type, lflags;\n@@ -1180,27 +1185,27 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char\n \tlock = xcalloc(1, sizeof(struct ref_lock));\n \tlock->lock_fd = -1;\n \n-\tref = resolve_ref(ref, lock->old_sha1, mustexist, &type);\n-\tif (!ref && errno == EISDIR) {\n+\trefname = resolve_ref(refname, lock->old_sha1, mustexist, &type);\n+\tif (!refname && errno == EISDIR) {\n \t\t/* we are trying to lock foo but we used to\n \t\t * have foo/bar which now does not exist;\n \t\t * it is normal for the empty directory 'foo'\n \t\t * to remain.\n \t\t */\n-\t\tref_file = git_path(\"%s\", orig_ref);\n+\t\tref_file = git_path(\"%s\", orig_refname);\n \t\tif (remove_empty_directories(ref_file)) {\n \t\t\tlast_errno = errno;\n-\t\t\terror(\"there are still refs under '%s'\", orig_ref);\n+\t\t\terror(\"there are still refs under '%s'\", orig_refname);\n \t\t\tgoto error_return;\n \t\t}\n-\t\tref = resolve_ref(orig_ref, lock->old_sha1, mustexist, &type);\n+\t\trefname = resolve_ref(orig_refname, lock->old_sha1, mustexist, &type);\n \t}\n \tif (type_p)\n \t    *type_p = type;\n-\tif (!ref) {\n+\tif (!refname) {\n \t\tlast_errno = errno;\n \t\terror(\"unable to resolve reference %s: %s\",\n-\t\t\torig_ref, strerror(errno));\n+\t\t\torig_refname, strerror(errno));\n \t\tgoto error_return;\n \t}\n \tmissing = is_null_sha1(lock->old_sha1);\n@@ -1210,7 +1215,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char\n \t * name is a proper prefix of our refname.\n \t */\n \tif (missing &&\n-\t     !is_refname_available(ref, NULL, get_packed_refs(NULL), 0)) {\n+\t     !is_refname_available(refname, NULL, get_packed_refs(NULL), 0)) {\n \t\tlast_errno = ENOTDIR;\n \t\tgoto error_return;\n \t}\n@@ -1219,12 +1224,12 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char\n \n \tlflags = LOCK_DIE_ON_ERROR;\n \tif (flags & REF_NODEREF) {\n-\t\tref = orig_ref;\n+\t\trefname = orig_refname;\n \t\tlflags |= LOCK_NODEREF;\n \t}\n-\tlock->ref_name = xstrdup(ref);\n-\tlock->orig_ref_name = xstrdup(orig_ref);\n-\tref_file = git_path(\"%s\", ref);\n+\tlock->ref_name = xstrdup(refname);\n+\tlock->orig_ref_name = xstrdup(orig_refname);\n+\tref_file = git_path(\"%s\", refname);\n \tif (missing)\n \t\tlock->force_write = 1;\n \tif ((flags & REF_NODEREF) && (type & REF_ISSYMREF))\n@@ -1245,20 +1250,21 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char\n \treturn NULL;\n }\n \n-struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)\n+struct ref_lock *lock_ref_sha1(const char *refname, const unsigned char *old_sha1)\n {\n \tchar refpath[PATH_MAX];\n-\tif (check_refname_format(ref, 0))\n+\tif (check_refname_format(refname, 0))\n \t\treturn NULL;\n-\tstrcpy(refpath, mkpath(\"refs/%s\", ref));\n+\tstrcpy(refpath, mkpath(\"refs/%s\", refname));\n \treturn lock_ref_sha1_basic(refpath, old_sha1, 0, NULL);\n }\n \n-struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int flags)\n+struct ref_lock *lock_any_ref_for_update(const char *refname,\n+\t\t\t\t\t const unsigned char *old_sha1, int flags)\n {\n-\tif (check_refname_format(ref, REFNAME_ALLOW_ONELEVEL))\n+\tif (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))\n \t\treturn NULL;\n-\treturn lock_ref_sha1_basic(ref, old_sha1, flags, NULL);\n+\treturn lock_ref_sha1_basic(refname, old_sha1, flags, NULL);\n }\n \n static struct lock_file packlock;\n@@ -1344,96 +1350,96 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)\n  */\n #define TMP_RENAMED_LOG  \"logs/refs/.tmp-renamed-log\"\n \n-int rename_ref(const char *oldref, const char *newref, const char *logmsg)\n+int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)\n {\n \tunsigned char sha1[20], orig_sha1[20];\n \tint flag = 0, logmoved = 0;\n \tstruct ref_lock *lock;\n \tstruct stat loginfo;\n-\tint log = !lstat(git_path(\"logs/%s\", oldref), &loginfo);\n+\tint log = !lstat(git_path(\"logs/%s\", oldrefname), &loginfo);\n \tconst char *symref = NULL;\n \n \tif (log && S_ISLNK(loginfo.st_mode))\n-\t\treturn error(\"reflog for %s is a symlink\", oldref);\n+\t\treturn error(\"reflog for %s is a symlink\", oldrefname);\n \n-\tsymref = resolve_ref(oldref, orig_sha1, 1, &flag);\n+\tsymref = resolve_ref(oldrefname, orig_sha1, 1, &flag);\n \tif (flag & REF_ISSYMREF)\n \t\treturn error(\"refname %s is a symbolic ref, renaming it is not supported\",\n-\t\t\toldref);\n+\t\t\toldrefname);\n \tif (!symref)\n-\t\treturn error(\"refname %s not found\", oldref);\n+\t\treturn error(\"refname %s not found\", oldrefname);\n \n-\tif (!is_refname_available(newref, oldref, get_packed_refs(NULL), 0))\n+\tif (!is_refname_available(newrefname, oldrefname, get_packed_refs(NULL), 0))\n \t\treturn 1;\n \n-\tif (!is_refname_available(newref, oldref, get_loose_refs(NULL), 0))\n+\tif (!is_refname_available(newrefname, oldrefname, get_loose_refs(NULL), 0))\n \t\treturn 1;\n \n-\tif (log && rename(git_path(\"logs/%s\", oldref), git_path(TMP_RENAMED_LOG)))\n+\tif (log && rename(git_path(\"logs/%s\", oldrefname), git_path(TMP_RENAMED_LOG)))\n \t\treturn error(\"unable to move logfile logs/%s to \"TMP_RENAMED_LOG\": %s\",\n-\t\t\toldref, strerror(errno));\n+\t\t\toldrefname, strerror(errno));\n \n-\tif (delete_ref(oldref, orig_sha1, REF_NODEREF)) {\n-\t\terror(\"unable to delete old %s\", oldref);\n+\tif (delete_ref(oldrefname, orig_sha1, REF_NODEREF)) {\n+\t\terror(\"unable to delete old %s\", oldrefname);\n \t\tgoto rollback;\n \t}\n \n-\tif (resolve_ref(newref, sha1, 1, &flag) && delete_ref(newref, sha1, REF_NODEREF)) {\n+\tif (resolve_ref(newrefname, sha1, 1, &flag) && delete_ref(newrefname, sha1, REF_NODEREF)) {\n \t\tif (errno==EISDIR) {\n-\t\t\tif (remove_empty_directories(git_path(\"%s\", newref))) {\n-\t\t\t\terror(\"Directory not empty: %s\", newref);\n+\t\t\tif (remove_empty_directories(git_path(\"%s\", newrefname))) {\n+\t\t\t\terror(\"Directory not empty: %s\", newrefname);\n \t\t\t\tgoto rollback;\n \t\t\t}\n \t\t} else {\n-\t\t\terror(\"unable to delete existing %s\", newref);\n+\t\t\terror(\"unable to delete existing %s\", newrefname);\n \t\t\tgoto rollback;\n \t\t}\n \t}\n \n-\tif (log && safe_create_leading_directories(git_path(\"logs/%s\", newref))) {\n-\t\terror(\"unable to create directory for %s\", newref);\n+\tif (log && safe_create_leading_directories(git_path(\"logs/%s\", newrefname))) {\n+\t\terror(\"unable to create directory for %s\", newrefname);\n \t\tgoto rollback;\n \t}\n \n  retry:\n-\tif (log && rename(git_path(TMP_RENAMED_LOG), git_path(\"logs/%s\", newref))) {\n+\tif (log && rename(git_path(TMP_RENAMED_LOG), git_path(\"logs/%s\", newrefname))) {\n \t\tif (errno==EISDIR || errno==ENOTDIR) {\n \t\t\t/*\n \t\t\t * rename(a, b) when b is an existing\n \t\t\t * directory ought to result in ISDIR, but\n \t\t\t * Solaris 5.8 gives ENOTDIR.  Sheesh.\n \t\t\t */\n-\t\t\tif (remove_empty_directories(git_path(\"logs/%s\", newref))) {\n-\t\t\t\terror(\"Directory not empty: logs/%s\", newref);\n+\t\t\tif (remove_empty_directories(git_path(\"logs/%s\", newrefname))) {\n+\t\t\t\terror(\"Directory not empty: logs/%s\", newrefname);\n \t\t\t\tgoto rollback;\n \t\t\t}\n \t\t\tgoto retry;\n \t\t} else {\n \t\t\terror(\"unable to move logfile \"TMP_RENAMED_LOG\" to logs/%s: %s\",\n-\t\t\t\tnewref, strerror(errno));\n+\t\t\t\tnewrefname, strerror(errno));\n \t\t\tgoto rollback;\n \t\t}\n \t}\n \tlogmoved = log;\n \n-\tlock = lock_ref_sha1_basic(newref, NULL, 0, NULL);\n+\tlock = lock_ref_sha1_basic(newrefname, NULL, 0, NULL);\n \tif (!lock) {\n-\t\terror(\"unable to lock %s for update\", newref);\n+\t\terror(\"unable to lock %s for update\", newrefname);\n \t\tgoto rollback;\n \t}\n \tlock->force_write = 1;\n \thashcpy(lock->old_sha1, orig_sha1);\n \tif (write_ref_sha1(lock, orig_sha1, logmsg)) {\n-\t\terror(\"unable to write current sha1 into %s\", newref);\n+\t\terror(\"unable to write current sha1 into %s\", newrefname);\n \t\tgoto rollback;\n \t}\n \n \treturn 0;\n \n  rollback:\n-\tlock = lock_ref_sha1_basic(oldref, NULL, 0, NULL);\n+\tlock = lock_ref_sha1_basic(oldrefname, NULL, 0, NULL);\n \tif (!lock) {\n-\t\terror(\"unable to lock %s for rollback\", oldref);\n+\t\terror(\"unable to lock %s for rollback\", oldrefname);\n \t\tgoto rollbacklog;\n \t}\n \n@@ -1441,17 +1447,17 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)\n \tflag = log_all_ref_updates;\n \tlog_all_ref_updates = 0;\n \tif (write_ref_sha1(lock, orig_sha1, NULL))\n-\t\terror(\"unable to write current sha1 into %s\", oldref);\n+\t\terror(\"unable to write current sha1 into %s\", oldrefname);\n \tlog_all_ref_updates = flag;\n \n  rollbacklog:\n-\tif (logmoved && rename(git_path(\"logs/%s\", newref), git_path(\"logs/%s\", oldref)))\n+\tif (logmoved && rename(git_path(\"logs/%s\", newrefname), git_path(\"logs/%s\", oldrefname)))\n \t\terror(\"unable to restore logfile %s from %s: %s\",\n-\t\t\toldref, newref, strerror(errno));\n+\t\t\toldrefname, newrefname, strerror(errno));\n \tif (!logmoved && log &&\n-\t    rename(git_path(TMP_RENAMED_LOG), git_path(\"logs/%s\", oldref)))\n+\t    rename(git_path(TMP_RENAMED_LOG), git_path(\"logs/%s\", oldrefname)))\n \t\terror(\"unable to restore logfile %s from \"TMP_RENAMED_LOG\": %s\",\n-\t\t\toldref, strerror(errno));\n+\t\t\toldrefname, strerror(errno));\n \n \treturn 1;\n }\n@@ -1508,16 +1514,16 @@ static int copy_msg(char *buf, const char *msg)\n \treturn cp - buf;\n }\n \n-int log_ref_setup(const char *ref_name, char *logfile, int bufsize)\n+int log_ref_setup(const char *refname, char *logfile, int bufsize)\n {\n \tint logfd, oflags = O_APPEND | O_WRONLY;\n \n-\tgit_snpath(logfile, bufsize, \"logs/%s\", ref_name);\n+\tgit_snpath(logfile, bufsize, \"logs/%s\", refname);\n \tif (log_all_ref_updates &&\n-\t    (!prefixcmp(ref_name, \"refs/heads/\") ||\n-\t     !prefixcmp(ref_name, \"refs/remotes/\") ||\n-\t     !prefixcmp(ref_name, \"refs/notes/\") ||\n-\t     !strcmp(ref_name, \"HEAD\"))) {\n+\t    (!prefixcmp(refname, \"refs/heads/\") ||\n+\t     !prefixcmp(refname, \"refs/remotes/\") ||\n+\t     !prefixcmp(refname, \"refs/notes/\") ||\n+\t     !strcmp(refname, \"HEAD\"))) {\n \t\tif (safe_create_leading_directories(logfile) < 0)\n \t\t\treturn error(\"unable to create directory for %s\",\n \t\t\t\t     logfile);\n@@ -1547,7 +1553,7 @@ int log_ref_setup(const char *ref_name, char *logfile, int bufsize)\n \treturn 0;\n }\n \n-static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,\n+static int log_ref_write(const char *refname, const unsigned char *old_sha1,\n \t\t\t const unsigned char *new_sha1, const char *msg)\n {\n \tint logfd, result, written, oflags = O_APPEND | O_WRONLY;\n@@ -1560,7 +1566,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,\n \tif (log_all_ref_updates < 0)\n \t\tlog_all_ref_updates = !is_bare_repository();\n \n-\tresult = log_ref_setup(ref_name, log_file, sizeof(log_file));\n+\tresult = log_ref_setup(refname, log_file, sizeof(log_file));\n \tif (result)\n \t\treturn result;\n \n@@ -1731,7 +1737,9 @@ static char *ref_msg(const char *line, const char *endp)\n \treturn xmemdupz(line, ep - line);\n }\n \n-int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)\n+int read_ref_at(const char *refname, unsigned long at_time, int cnt,\n+\t\tunsigned char *sha1, char **msg,\n+\t\tunsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)\n {\n \tconst char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec;\n \tchar *tz_c;\n@@ -1742,7 +1750,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *\n \tvoid *log_mapped;\n \tsize_t mapsz;\n \n-\tlogfile = git_path(\"logs/%s\", ref);\n+\tlogfile = git_path(\"logs/%s\", refname);\n \tlogfd = open(logfile, O_RDONLY, 0);\n \tif (logfd < 0)\n \t\tdie_errno(\"Unable to read log '%s'\", logfile);\n@@ -1835,14 +1843,14 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *\n \treturn 1;\n }\n \n-int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs, void *cb_data)\n+int for_each_recent_reflog_ent(const char *refname, each_reflog_ent_fn fn, long ofs, void *cb_data)\n {\n \tconst char *logfile;\n \tFILE *logfp;\n \tstruct strbuf sb = STRBUF_INIT;\n \tint ret = 0;\n \n-\tlogfile = git_path(\"logs/%s\", ref);\n+\tlogfile = git_path(\"logs/%s\", refname);\n \tlogfp = fopen(logfile, \"r\");\n \tif (!logfp)\n \t\treturn -1;\n@@ -1893,9 +1901,9 @@ int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs,\n \treturn ret;\n }\n \n-int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)\n+int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data)\n {\n-\treturn for_each_recent_reflog_ent(ref, fn, 0, cb_data);\n+\treturn for_each_recent_reflog_ent(refname, fn, 0, cb_data);\n }\n \n static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)\n@@ -2015,7 +2023,7 @@ static void gen_scanf_fmt(char *scanf_fmt, const char *rule)\n \treturn;\n }\n \n-char *shorten_unambiguous_ref(const char *ref, int strict)\n+char *shorten_unambiguous_ref(const char *refname, int strict)\n {\n \tint i;\n \tstatic char **scanf_fmts;\n@@ -2044,10 +2052,10 @@ char *shorten_unambiguous_ref(const char *ref, int strict)\n \n \t/* bail out if there are no rules */\n \tif (!nr_rules)\n-\t\treturn xstrdup(ref);\n+\t\treturn xstrdup(refname);\n \n-\t/* buffer for scanf result, at most ref must fit */\n-\tshort_name = xstrdup(ref);\n+\t/* buffer for scanf result, at most refname must fit */\n+\tshort_name = xstrdup(refname);\n \n \t/* skip first rule, it will always match */\n \tfor (i = nr_rules - 1; i > 0 ; --i) {\n@@ -2055,7 +2063,7 @@ char *shorten_unambiguous_ref(const char *ref, int strict)\n \t\tint rules_to_fail = i;\n \t\tint short_name_len;\n \n-\t\tif (1 != sscanf(ref, scanf_fmts[i], short_name))\n+\t\tif (1 != sscanf(refname, scanf_fmts[i], short_name))\n \t\t\tcontinue;\n \n \t\tshort_name_len = strlen(short_name);\n@@ -2100,5 +2108,5 @@ char *shorten_unambiguous_ref(const char *ref, int strict)\n \t}\n \n \tfree(short_name);\n-\treturn xstrdup(ref);\n+\treturn xstrdup(refname);\n }\ndiff --git a/refs.h b/refs.h\nindex 3fd5536..e36bd03 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -60,14 +60,16 @@ extern void add_extra_ref(const char *refname, const unsigned char *sha1, int fl\n extern void clear_extra_refs(void);\n extern int ref_exists(const char *);\n \n-extern int peel_ref(const char *, unsigned char *);\n+extern int peel_ref(const char *refname, unsigned char *sha1);\n \n /** Locks a \"refs/\" ref returning the lock on success and NULL on failure. **/\n-extern struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1);\n+extern struct ref_lock *lock_ref_sha1(const char *refname, const unsigned char *old_sha1);\n \n /** Locks any ref (for 'HEAD' type refs). */\n #define REF_NODEREF\t0x01\n-extern struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int flags);\n+extern struct ref_lock *lock_any_ref_for_update(const char *refname,\n+\t\t\t\t\t\tconst unsigned char *old_sha1,\n+\t\t\t\t\t\tint flags);\n \n /** Close the file descriptor owned by a lock and return the status */\n extern int close_ref(struct ref_lock *lock);\n@@ -93,12 +95,14 @@ extern void invalidate_ref_cache(const char *submodule);\n int log_ref_setup(const char *ref_name, char *logfile, int bufsize);\n \n /** Reads log for the value of ref during at_time. **/\n-extern int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt);\n+extern int read_ref_at(const char *refname, unsigned long at_time, int cnt,\n+\t\t       unsigned char *sha1, char **msg,\n+\t\t       unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt);\n \n /* iterate over reflog entries */\n typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *);\n-int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data);\n-int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long, void *cb_data);\n+int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data);\n+int for_each_recent_reflog_ent(const char *refname, each_reflog_ent_fn fn, long, void *cb_data);\n \n /*\n  * Calls the specified function for each reflog file until it returns nonzero,\n@@ -111,9 +115,9 @@ extern int for_each_reflog(each_ref_fn, void *);\n #define REFNAME_DOT_COMPONENT 4\n \n /*\n- * Return 0 iff ref has the correct format for a refname according to\n- * the rules described in Documentation/git-check-ref-format.txt.  If\n- * REFNAME_ALLOW_ONELEVEL is set in flags, then accept one-level\n+ * Return 0 iff refname has the correct format for a refname according\n+ * to the rules described in Documentation/git-check-ref-format.txt.\n+ * If REFNAME_ALLOW_ONELEVEL is set in flags, then accept one-level\n  * reference names.  If REFNAME_REFSPEC_PATTERN is set in flags, then\n  * allow a \"*\" wildcard character in place of one of the name\n  * components.  No leading or repeated slashes are accepted.  If\n@@ -121,10 +125,10 @@ extern int for_each_reflog(each_ref_fn, void *);\n  * components to start with \".\" (but not a whole component equal to\n  * \".\" or \"..\").\n  */\n-extern int check_refname_format(const char *ref, int flags);\n+extern int check_refname_format(const char *refname, int flags);\n \n extern const char *prettify_refname(const char *refname);\n-extern char *shorten_unambiguous_ref(const char *ref, int strict);\n+extern char *shorten_unambiguous_ref(const char *refname, int strict);\n \n /** rename ref, return 0 on success **/\n extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);\n-- \n1.7.7\n"},{"id":"178413","messageId":"1319800481-15138-5-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 04/14] refs: rename parameters result -> sha1","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:31Z","receivedAt":"2011-10-28T11:14:31Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nTry consistently to use the name \"sha1\" for parameters to which a SHA1\nwill be stored.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |   16 ++++++++--------\n refs.h |    2 +-\n 2 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 7a34e4b..564070c 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -402,7 +402,7 @@ static struct ref_array *get_loose_refs(const char *submodule)\n  * the packed-refs file for the submodule.\n  */\n static int resolve_gitlink_packed_ref(char *name, int pathlen,\n-\t\t\t\t      const char *refname, unsigned char *result)\n+\t\t\t\t      const char *refname, unsigned char *sha1)\n {\n \tint retval = -1;\n \tstruct ref_entry *ref;\n@@ -415,14 +415,14 @@ static int resolve_gitlink_packed_ref(char *name, int pathlen,\n \tarray = get_packed_refs(name);\n \tref = search_ref_array(array, refname);\n \tif (ref != NULL) {\n-\t\tmemcpy(result, ref->sha1, 20);\n+\t\tmemcpy(sha1, ref->sha1, 20);\n \t\tretval = 0;\n \t}\n \treturn retval;\n }\n \n static int resolve_gitlink_ref_recursive(char *name, int pathlen,\n-\t\t\t\t\t const char *refname, unsigned char *result,\n+\t\t\t\t\t const char *refname, unsigned char *sha1,\n \t\t\t\t\t int recursion)\n {\n \tint fd, len = strlen(refname);\n@@ -433,7 +433,7 @@ static int resolve_gitlink_ref_recursive(char *name, int pathlen,\n \tmemcpy(name + pathlen, refname, len+1);\n \tfd = open(name, O_RDONLY);\n \tif (fd < 0)\n-\t\treturn resolve_gitlink_packed_ref(name, pathlen, refname, result);\n+\t\treturn resolve_gitlink_packed_ref(name, pathlen, refname, sha1);\n \n \tlen = read(fd, buffer, sizeof(buffer)-1);\n \tclose(fd);\n@@ -444,7 +444,7 @@ static int resolve_gitlink_ref_recursive(char *name, int pathlen,\n \tbuffer[len] = 0;\n \n \t/* Was it a detached head or an old-fashioned symlink? */\n-\tif (!get_sha1_hex(buffer, result))\n+\tif (!get_sha1_hex(buffer, sha1))\n \t\treturn 0;\n \n \t/* Symref? */\n@@ -454,10 +454,10 @@ static int resolve_gitlink_ref_recursive(char *name, int pathlen,\n \twhile (isspace(*p))\n \t\tp++;\n \n-\treturn resolve_gitlink_ref_recursive(name, pathlen, p, result, recursion+1);\n+\treturn resolve_gitlink_ref_recursive(name, pathlen, p, sha1, recursion+1);\n }\n \n-int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *result)\n+int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1)\n {\n \tint len = strlen(path), retval;\n \tchar *gitdir;\n@@ -481,7 +481,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *re\n \t}\n \tgitdir[len] = '/';\n \tgitdir[++len] = '\\0';\n-\tretval = resolve_gitlink_ref_recursive(gitdir, len, refname, result, 0);\n+\tretval = resolve_gitlink_ref_recursive(gitdir, len, refname, sha1, 0);\n \tfree(gitdir);\n \treturn retval;\n }\ndiff --git a/refs.h b/refs.h\nindex e36bd03..4c5d570 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -134,7 +134,7 @@ extern char *shorten_unambiguous_ref(const char *refname, int strict);\n extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);\n \n /** resolve ref in nested \"gitlink\" repository */\n-extern int resolve_gitlink_ref(const char *name, const char *refname, unsigned char *result);\n+extern int resolve_gitlink_ref(const char *name, const char *refname, unsigned char *sha1);\n \n /** lock a ref and then write its file */\n enum action_on_err { MSG_ON_ERR, DIE_ON_ERR, QUIET_ON_ERR };\n-- \n1.7.7\n"},{"id":"178410","messageId":"1319800481-15138-6-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 05/14] clear_ref_array(): rename from free_ref_array()","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:32Z","receivedAt":"2011-10-28T11:14:32Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nRename the function since it doesn't actually free the array object\nthat is passed to it.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 564070c..c9e14fd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -148,7 +148,7 @@ static struct ref_entry *current_ref;\n \n static struct ref_array extra_refs;\n \n-static void free_ref_array(struct ref_array *array)\n+static void clear_ref_array(struct ref_array *array)\n {\n \tint i;\n \tfor (i = 0; i < array->nr; i++)\n@@ -161,14 +161,14 @@ static void free_ref_array(struct ref_array *array)\n static void clear_packed_ref_cache(struct ref_cache *refs)\n {\n \tif (refs->did_packed)\n-\t\tfree_ref_array(&refs->packed);\n+\t\tclear_ref_array(&refs->packed);\n \trefs->did_packed = 0;\n }\n \n static void clear_loose_ref_cache(struct ref_cache *refs)\n {\n \tif (refs->did_loose)\n-\t\tfree_ref_array(&refs->loose);\n+\t\tclear_ref_array(&refs->loose);\n \trefs->did_loose = 0;\n }\n \n@@ -255,7 +255,7 @@ void add_extra_ref(const char *refname, const unsigned char *sha1, int flag)\n \n void clear_extra_refs(void)\n {\n-\tfree_ref_array(&extra_refs);\n+\tclear_ref_array(&extra_refs);\n }\n \n static struct ref_array *get_packed_refs(const char *submodule)\n-- \n1.7.7\n"},{"id":"178407","messageId":"1319800481-15138-7-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 06/14] is_refname_available(): remove the \"quiet\" argument","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:33Z","receivedAt":"2011-10-28T11:14:33Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nquiet was always set to 0, so get rid of it.  Add a function docstring\nfor good measure.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |   20 +++++++++++++-------\n 1 files changed, 13 insertions(+), 7 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex c9e14fd..d3dcb3c 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1059,8 +1059,15 @@ static int remove_empty_directories(const char *file)\n \treturn result;\n }\n \n+/*\n+ * Return true iff a reference named refname could be created without\n+ * conflicting with the name of an existing reference.  If oldrefname\n+ * is non-NULL, ignore potential conflicts with oldrefname (e.g.,\n+ * because oldrefname is scheduled for deletion in the same\n+ * operation).\n+ */\n static int is_refname_available(const char *refname, const char *oldrefname,\n-\t\t\t\tstruct ref_array *array, int quiet)\n+\t\t\t\tstruct ref_array *array)\n {\n \tint i, namlen = strlen(refname); /* e.g. 'foo/bar' */\n \tfor (i = 0; i < array->nr; i++ ) {\n@@ -1072,9 +1079,8 @@ static int is_refname_available(const char *refname, const char *oldrefname,\n \t\t\tconst char *lead = (namlen < len) ? entry->name : refname;\n \t\t\tif (!strncmp(refname, entry->name, cmplen) &&\n \t\t\t    lead[cmplen] == '/') {\n-\t\t\t\tif (!quiet)\n-\t\t\t\t\terror(\"'%s' exists; cannot create '%s'\",\n-\t\t\t\t\t      entry->name, refname);\n+\t\t\t\terror(\"'%s' exists; cannot create '%s'\",\n+\t\t\t\t      entry->name, refname);\n \t\t\t\treturn 0;\n \t\t\t}\n \t\t}\n@@ -1215,7 +1221,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n \t * name is a proper prefix of our refname.\n \t */\n \tif (missing &&\n-\t     !is_refname_available(refname, NULL, get_packed_refs(NULL), 0)) {\n+\t     !is_refname_available(refname, NULL, get_packed_refs(NULL))) {\n \t\tlast_errno = ENOTDIR;\n \t\tgoto error_return;\n \t}\n@@ -1369,10 +1375,10 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \tif (!symref)\n \t\treturn error(\"refname %s not found\", oldrefname);\n \n-\tif (!is_refname_available(newrefname, oldrefname, get_packed_refs(NULL), 0))\n+\tif (!is_refname_available(newrefname, oldrefname, get_packed_refs(NULL)))\n \t\treturn 1;\n \n-\tif (!is_refname_available(newrefname, oldrefname, get_loose_refs(NULL), 0))\n+\tif (!is_refname_available(newrefname, oldrefname, get_loose_refs(NULL)))\n \t\treturn 1;\n \n \tif (log && rename(git_path(\"logs/%s\", oldrefname), git_path(TMP_RENAMED_LOG)))\n-- \n1.7.7\n"},{"id":"178405","messageId":"1319800481-15138-8-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 07/14] parse_ref_line(): add docstring","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:34Z","receivedAt":"2011-10-28T11:14:34Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex d3dcb3c..963291f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -20,6 +20,11 @@ struct ref_array {\n \tstruct ref_entry **refs;\n };\n \n+/*\n+ * Parse one line from a packed-refs file.  Write the SHA1 to sha1.\n+ * Return a pointer to the refname within the line (null-terminated),\n+ * or NULL if there was a problem.\n+ */\n static const char *parse_ref_line(char *line, unsigned char *sha1)\n {\n \t/*\n-- \n1.7.7\n"},{"id":"178411","messageId":"1319800481-15138-9-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 08/14] add_ref(): add docstring","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:35Z","receivedAt":"2011-10-28T11:14:35Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 963291f..a94af1d 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -53,6 +53,7 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)\n \treturn line;\n }\n \n+/* Add a ref_entry to the end of the ref_array (unsorted). */\n static void add_ref(const char *refname, const unsigned char *sha1,\n \t\t    int flag, struct ref_array *refs,\n \t\t    struct ref_entry **new_entry)\n-- \n1.7.7\n"},{"id":"178412","messageId":"1319800481-15138-10-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 09/14] is_dup_ref(): extract function from sort_ref_array()","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:36Z","receivedAt":"2011-10-28T11:14:36Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nGiving it a name makes the code easier to understand.  And the new\nfunction will be convenient later when it has to be called from\nmultiple places.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |   25 ++++++++++++++++++++-----\n 1 files changed, 20 insertions(+), 5 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex a94af1d..50fc567 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -83,6 +83,25 @@ static int ref_entry_cmp(const void *a, const void *b)\n \treturn strcmp(one->name, two->name);\n }\n \n+/*\n+ * Emit a warning and return true iff ref1 and ref2 have the same name\n+ * and the same sha1.  Die if they have the same name but different\n+ * sha1s.\n+ */\n+static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2)\n+{\n+\tif (!strcmp(ref1->name, ref2->name)) {\n+\t\t/* Duplicate name; make sure that the SHA1s match: */\n+\t\tif (hashcmp(ref1->sha1, ref2->sha1))\n+\t\t\tdie(\"Duplicated ref, and SHA1s don't match: %s\",\n+\t\t\t    ref1->name);\n+\t\twarning(\"Duplicated ref: %s\", ref1->name);\n+\t\treturn 1;\n+\t} else {\n+\t\treturn 0;\n+\t}\n+}\n+\n static void sort_ref_array(struct ref_array *array)\n {\n \tint i = 0, j = 1;\n@@ -97,11 +116,7 @@ static void sort_ref_array(struct ref_array *array)\n \tfor (; j < array->nr; j++) {\n \t\tstruct ref_entry *a = array->refs[i];\n \t\tstruct ref_entry *b = array->refs[j];\n-\t\tif (!strcmp(a->name, b->name)) {\n-\t\t\tif (hashcmp(a->sha1, b->sha1))\n-\t\t\t\tdie(\"Duplicated ref, and SHA1s don't match: %s\",\n-\t\t\t\t    a->name);\n-\t\t\twarning(\"Duplicated ref: %s\", a->name);\n+\t\tif (is_dup_ref(a, b)) {\n \t\t\tfree(b);\n \t\t\tcontinue;\n \t\t}\n-- \n1.7.7\n"},{"id":"178417","messageId":"1319800481-15138-11-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 10/14] refs: change signatures of get_packed_refs() and get_loose_refs()","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:37Z","receivedAt":"2011-10-28T11:14:37Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nChange get_packed_refs() and get_loose_refs() to take a (struct\nref_cache *) instead of the name of the submodule.\n\nChange get_ref_dir() to take a submodule name (i.e., \"\" for the main\nmodule) rather than a submodule pointer (i.e., NULL for the main\nmodule) so that refs->name can be used as its argument.  (In a moment\nthis function will also be changed to take a (struct ref_cache *),\ntoo.)\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |   36 +++++++++++++++++-------------------\n 1 files changed, 17 insertions(+), 19 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 50fc567..4131d53 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -279,16 +279,14 @@ void clear_extra_refs(void)\n \tclear_ref_array(&extra_refs);\n }\n \n-static struct ref_array *get_packed_refs(const char *submodule)\n+static struct ref_array *get_packed_refs(struct ref_cache *refs)\n {\n-\tstruct ref_cache *refs = get_ref_cache(submodule);\n-\n \tif (!refs->did_packed) {\n \t\tconst char *packed_refs_file;\n \t\tFILE *f;\n \n-\t\tif (submodule)\n-\t\t\tpacked_refs_file = git_path_submodule(submodule, \"packed-refs\");\n+\t\tif (*refs->name)\n+\t\t\tpacked_refs_file = git_path_submodule(refs->name, \"packed-refs\");\n \t\telse\n \t\t\tpacked_refs_file = git_path(\"packed-refs\");\n \t\tf = fopen(packed_refs_file, \"r\");\n@@ -307,7 +305,7 @@ static void get_ref_dir(const char *submodule, const char *base,\n \tDIR *dir;\n \tconst char *path;\n \n-\tif (submodule)\n+\tif (*submodule)\n \t\tpath = git_path_submodule(submodule, \"%s\", base);\n \telse\n \t\tpath = git_path(\"%s\", base);\n@@ -401,12 +399,10 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)\n \tfor_each_rawref(warn_if_dangling_symref, &data);\n }\n \n-static struct ref_array *get_loose_refs(const char *submodule)\n+static struct ref_array *get_loose_refs(struct ref_cache *refs)\n {\n-\tstruct ref_cache *refs = get_ref_cache(submodule);\n-\n \tif (!refs->did_loose) {\n-\t\tget_ref_dir(submodule, \"refs\", &refs->loose);\n+\t\tget_ref_dir(refs->name, \"refs\", &refs->loose);\n \t\tsort_ref_array(&refs->loose);\n \t\trefs->did_loose = 1;\n \t}\n@@ -433,7 +429,7 @@ static int resolve_gitlink_packed_ref(char *name, int pathlen,\n \tif (pathlen < 6 || memcmp(name + pathlen - 6, \"/.git/\", 6))\n \t\tdie(\"Oops\");\n \tname[pathlen - 6] = '\\0'; /* make it path to the submodule */\n-\tarray = get_packed_refs(name);\n+\tarray = get_packed_refs(get_ref_cache(name));\n \tref = search_ref_array(array, refname);\n \tif (ref != NULL) {\n \t\tmemcpy(sha1, ref->sha1, 20);\n@@ -513,7 +509,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh\n  */\n static int get_packed_ref(const char *refname, unsigned char *sha1)\n {\n-\tstruct ref_array *packed = get_packed_refs(NULL);\n+\tstruct ref_array *packed = get_packed_refs(get_ref_cache(NULL));\n \tstruct ref_entry *entry = search_ref_array(packed, refname);\n \tif (entry) {\n \t\thashcpy(sha1, entry->sha1);\n@@ -692,7 +688,7 @@ int peel_ref(const char *refname, unsigned char *sha1)\n \t\treturn -1;\n \n \tif ((flag & REF_ISPACKED)) {\n-\t\tstruct ref_array *array = get_packed_refs(NULL);\n+\t\tstruct ref_array *array = get_packed_refs(get_ref_cache(NULL));\n \t\tstruct ref_entry *r = search_ref_array(array, refname);\n \n \t\tif (r != NULL && r->flag & REF_KNOWS_PEELED) {\n@@ -717,8 +713,9 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn\n \t\t\t   int trim, int flags, void *cb_data)\n {\n \tint retval = 0, i, p = 0, l = 0;\n-\tstruct ref_array *packed = get_packed_refs(submodule);\n-\tstruct ref_array *loose = get_loose_refs(submodule);\n+\tstruct ref_cache *refs = get_ref_cache(submodule);\n+\tstruct ref_array *packed = get_packed_refs(refs);\n+\tstruct ref_array *loose = get_loose_refs(refs);\n \n \tstruct ref_array *extra = &extra_refs;\n \n@@ -1242,7 +1239,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n \t * name is a proper prefix of our refname.\n \t */\n \tif (missing &&\n-\t     !is_refname_available(refname, NULL, get_packed_refs(NULL))) {\n+\t     !is_refname_available(refname, NULL, get_packed_refs(get_ref_cache(NULL)))) {\n \t\tlast_errno = ENOTDIR;\n \t\tgoto error_return;\n \t}\n@@ -1302,7 +1299,7 @@ static int repack_without_ref(const char *refname)\n \tstruct ref_entry *ref;\n \tint fd, i;\n \n-\tpacked = get_packed_refs(NULL);\n+\tpacked = get_packed_refs(get_ref_cache(NULL));\n \tref = search_ref_array(packed, refname);\n \tif (ref == NULL)\n \t\treturn 0;\n@@ -1385,6 +1382,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \tstruct stat loginfo;\n \tint log = !lstat(git_path(\"logs/%s\", oldrefname), &loginfo);\n \tconst char *symref = NULL;\n+\tstruct ref_cache *refs = get_ref_cache(NULL);\n \n \tif (log && S_ISLNK(loginfo.st_mode))\n \t\treturn error(\"reflog for %s is a symlink\", oldrefname);\n@@ -1396,10 +1394,10 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \tif (!symref)\n \t\treturn error(\"refname %s not found\", oldrefname);\n \n-\tif (!is_refname_available(newrefname, oldrefname, get_packed_refs(NULL)))\n+\tif (!is_refname_available(newrefname, oldrefname, get_packed_refs(refs)))\n \t\treturn 1;\n \n-\tif (!is_refname_available(newrefname, oldrefname, get_loose_refs(NULL)))\n+\tif (!is_refname_available(newrefname, oldrefname, get_loose_refs(refs)))\n \t\treturn 1;\n \n \tif (log && rename(git_path(\"logs/%s\", oldrefname), git_path(TMP_RENAMED_LOG)))\n-- \n1.7.7\n"},{"id":"178416","messageId":"1319800481-15138-12-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 11/14] get_ref_dir(): change signature","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:38Z","receivedAt":"2011-10-28T11:14:38Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nChange get_ref_dir() to take a (struct ref_cache *) in place of the\nsubmodule name.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |   18 +++++++++---------\n 1 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 4131d53..7d58ef9 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -299,14 +299,14 @@ static struct ref_array *get_packed_refs(struct ref_cache *refs)\n \treturn &refs->packed;\n }\n \n-static void get_ref_dir(const char *submodule, const char *base,\n+static void get_ref_dir(struct ref_cache *refs, const char *base,\n \t\t\tstruct ref_array *array)\n {\n \tDIR *dir;\n \tconst char *path;\n \n-\tif (*submodule)\n-\t\tpath = git_path_submodule(submodule, \"%s\", base);\n+\tif (*refs->name)\n+\t\tpath = git_path_submodule(refs->name, \"%s\", base);\n \telse\n \t\tpath = git_path(\"%s\", base);\n \n@@ -337,19 +337,19 @@ static void get_ref_dir(const char *submodule, const char *base,\n \t\t\tif (has_extension(de->d_name, \".lock\"))\n \t\t\t\tcontinue;\n \t\t\tmemcpy(ref + baselen, de->d_name, namelen+1);\n-\t\t\trefdir = submodule\n-\t\t\t\t? git_path_submodule(submodule, \"%s\", ref)\n+\t\t\trefdir = *refs->name\n+\t\t\t\t? git_path_submodule(refs->name, \"%s\", ref)\n \t\t\t\t: git_path(\"%s\", ref);\n \t\t\tif (stat(refdir, &st) < 0)\n \t\t\t\tcontinue;\n \t\t\tif (S_ISDIR(st.st_mode)) {\n-\t\t\t\tget_ref_dir(submodule, ref, array);\n+\t\t\t\tget_ref_dir(refs, ref, array);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (submodule) {\n+\t\t\tif (*refs->name) {\n \t\t\t\thashclr(sha1);\n \t\t\t\tflag = 0;\n-\t\t\t\tif (resolve_gitlink_ref(submodule, ref, sha1) < 0) {\n+\t\t\t\tif (resolve_gitlink_ref(refs->name, ref, sha1) < 0) {\n \t\t\t\t\thashclr(sha1);\n \t\t\t\t\tflag |= REF_ISBROKEN;\n \t\t\t\t}\n@@ -402,7 +402,7 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)\n static struct ref_array *get_loose_refs(struct ref_cache *refs)\n {\n \tif (!refs->did_loose) {\n-\t\tget_ref_dir(refs->name, \"refs\", &refs->loose);\n+\t\tget_ref_dir(refs, \"refs\", &refs->loose);\n \t\tsort_ref_array(&refs->loose);\n \t\trefs->did_loose = 1;\n \t}\n-- \n1.7.7\n"},{"id":"178418","messageId":"1319800481-15138-13-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 12/14] resolve_gitlink_ref(): improve docstring","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:39Z","receivedAt":"2011-10-28T11:14:39Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.h |    8 ++++++--\n 1 files changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/refs.h b/refs.h\nindex 4c5d570..d498291 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -133,8 +133,12 @@ extern char *shorten_unambiguous_ref(const char *refname, int strict);\n /** rename ref, return 0 on success **/\n extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);\n \n-/** resolve ref in nested \"gitlink\" repository */\n-extern int resolve_gitlink_ref(const char *name, const char *refname, unsigned char *sha1);\n+/**\n+ * Resolve refname in the nested \"gitlink\" repository that is located\n+ * at path.  If the resolution is successful, return 0 and set sha1 to\n+ * the name of the object; otherwise, return a non-zero value.\n+ */\n+extern int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1);\n \n /** lock a ref and then write its file */\n enum action_on_err { MSG_ON_ERR, DIE_ON_ERR, QUIET_ON_ERR };\n-- \n1.7.7\n"},{"id":"178414","messageId":"1319800481-15138-14-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 13/14] Pass a (ref_cache *) to the resolve_gitlink_*() helper functions","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:40Z","receivedAt":"2011-10-28T11:14:40Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nAnd remove some redundant arguments from resolve_gitlink_packed_ref().\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |   40 ++++++++++++++++++++--------------------\n 1 files changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 7d58ef9..1867ff0 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -415,30 +415,25 @@ static struct ref_array *get_loose_refs(struct ref_cache *refs)\n \n /*\n  * Called by resolve_gitlink_ref_recursive() after it failed to read\n- * from \"name\", which is \"module/.git/<refname>\". Find <refname> in\n- * the packed-refs file for the submodule.\n+ * from the loose refs in ref_cache refs. Find <refname> in the\n+ * packed-refs file for the submodule.\n  */\n-static int resolve_gitlink_packed_ref(char *name, int pathlen,\n+static int resolve_gitlink_packed_ref(struct ref_cache *refs,\n \t\t\t\t      const char *refname, unsigned char *sha1)\n {\n-\tint retval = -1;\n \tstruct ref_entry *ref;\n-\tstruct ref_array *array;\n+\tstruct ref_array *array = get_packed_refs(refs);\n \n-\t/* being defensive: resolve_gitlink_ref() did this for us */\n-\tif (pathlen < 6 || memcmp(name + pathlen - 6, \"/.git/\", 6))\n-\t\tdie(\"Oops\");\n-\tname[pathlen - 6] = '\\0'; /* make it path to the submodule */\n-\tarray = get_packed_refs(get_ref_cache(name));\n \tref = search_ref_array(array, refname);\n-\tif (ref != NULL) {\n-\t\tmemcpy(sha1, ref->sha1, 20);\n-\t\tretval = 0;\n-\t}\n-\treturn retval;\n+\tif (ref == NULL)\n+\t\treturn -1;\n+\n+\tmemcpy(sha1, ref->sha1, 20);\n+\treturn 0;\n }\n \n-static int resolve_gitlink_ref_recursive(char *name, int pathlen,\n+static int resolve_gitlink_ref_recursive(struct ref_cache *refs,\n+\t\t\t\t\t char *name, int pathlen,\n \t\t\t\t\t const char *refname, unsigned char *sha1,\n \t\t\t\t\t int recursion)\n {\n@@ -450,7 +445,7 @@ static int resolve_gitlink_ref_recursive(char *name, int pathlen,\n \tmemcpy(name + pathlen, refname, len+1);\n \tfd = open(name, O_RDONLY);\n \tif (fd < 0)\n-\t\treturn resolve_gitlink_packed_ref(name, pathlen, refname, sha1);\n+\t\treturn resolve_gitlink_packed_ref(refs, refname, sha1);\n \n \tlen = read(fd, buffer, sizeof(buffer)-1);\n \tclose(fd);\n@@ -471,19 +466,24 @@ static int resolve_gitlink_ref_recursive(char *name, int pathlen,\n \twhile (isspace(*p))\n \t\tp++;\n \n-\treturn resolve_gitlink_ref_recursive(name, pathlen, p, sha1, recursion+1);\n+\treturn resolve_gitlink_ref_recursive(refs, name, pathlen, p, sha1, recursion+1);\n }\n \n int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1)\n {\n \tint len = strlen(path), retval;\n-\tchar *gitdir;\n+\tchar *submodule, *gitdir;\n+\tstruct ref_cache *refs;\n \tconst char *tmp;\n \n \twhile (len && path[len-1] == '/')\n \t\tlen--;\n \tif (!len)\n \t\treturn -1;\n+\tsubmodule = xstrndup(path, len);\n+\trefs = get_ref_cache(submodule);\n+\tfree(submodule);\n+\n \tgitdir = xmalloc(len + MAXREFLEN + 8);\n \tmemcpy(gitdir, path, len);\n \tmemcpy(gitdir + len, \"/.git\", 6);\n@@ -498,7 +498,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh\n \t}\n \tgitdir[len] = '/';\n \tgitdir[++len] = '\\0';\n-\tretval = resolve_gitlink_ref_recursive(gitdir, len, refname, sha1, 0);\n+\tretval = resolve_gitlink_ref_recursive(refs, gitdir, len, refname, sha1, 0);\n \tfree(gitdir);\n \treturn retval;\n }\n-- \n1.7.7\n"},{"id":"178415","messageId":"1319800481-15138-15-git-send-email-mhagger@alum.mit.edu","threadId":"28783","inReplyTo":"1319800481-15138-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v3 14/14] resolve_gitlink_ref_recursive(): change to work with struct ref_cache","fromName":"","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-10-28T11:14:41Z","receivedAt":"2011-10-28T11:14:41Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Michael Haggerty <mhagger@alum.mit.edu>\n\nresolve_gitlink_ref() and resolve_gitlink_ref_recursive(), together,\nbasically duplicated the code in git_path_submodule().  So use that\nfunction instead.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n refs.c |   34 ++++++++++------------------------\n 1 files changed, 10 insertions(+), 24 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 1867ff0..1c6de61 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -433,17 +433,19 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,\n }\n \n static int resolve_gitlink_ref_recursive(struct ref_cache *refs,\n-\t\t\t\t\t char *name, int pathlen,\n \t\t\t\t\t const char *refname, unsigned char *sha1,\n \t\t\t\t\t int recursion)\n {\n-\tint fd, len = strlen(refname);\n+\tint fd, len;\n \tchar buffer[128], *p;\n+\tchar *path;\n \n-\tif (recursion > MAXDEPTH || len > MAXREFLEN)\n+\tif (recursion > MAXDEPTH || strlen(refname) > MAXREFLEN)\n \t\treturn -1;\n-\tmemcpy(name + pathlen, refname, len+1);\n-\tfd = open(name, O_RDONLY);\n+\tpath = *refs->name\n+\t\t? git_path_submodule(refs->name, \"%s\", refname)\n+\t\t: git_path(\"%s\", refname);\n+\tfd = open(path, O_RDONLY);\n \tif (fd < 0)\n \t\treturn resolve_gitlink_packed_ref(refs, refname, sha1);\n \n@@ -466,15 +468,14 @@ static int resolve_gitlink_ref_recursive(struct ref_cache *refs,\n \twhile (isspace(*p))\n \t\tp++;\n \n-\treturn resolve_gitlink_ref_recursive(refs, name, pathlen, p, sha1, recursion+1);\n+\treturn resolve_gitlink_ref_recursive(refs, p, sha1, recursion+1);\n }\n \n int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1)\n {\n \tint len = strlen(path), retval;\n-\tchar *submodule, *gitdir;\n+\tchar *submodule;\n \tstruct ref_cache *refs;\n-\tconst char *tmp;\n \n \twhile (len && path[len-1] == '/')\n \t\tlen--;\n@@ -484,22 +485,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh\n \trefs = get_ref_cache(submodule);\n \tfree(submodule);\n \n-\tgitdir = xmalloc(len + MAXREFLEN + 8);\n-\tmemcpy(gitdir, path, len);\n-\tmemcpy(gitdir + len, \"/.git\", 6);\n-\tlen += 5;\n-\n-\ttmp = read_gitfile(gitdir);\n-\tif (tmp) {\n-\t\tfree(gitdir);\n-\t\tlen = strlen(tmp);\n-\t\tgitdir = xmalloc(len + MAXREFLEN + 3);\n-\t\tmemcpy(gitdir, tmp, len);\n-\t}\n-\tgitdir[len] = '/';\n-\tgitdir[++len] = '\\0';\n-\tretval = resolve_gitlink_ref_recursive(refs, gitdir, len, refname, sha1, 0);\n-\tfree(gitdir);\n+\tretval = resolve_gitlink_ref_recursive(refs, refname, sha1, 0);\n \treturn retval;\n }\n \n-- \n1.7.7\n"}]}