This patch move Linus' packed refs resolving code from "resolve_ref" into a new "resolve_packed_ref" extern function so that it can be reused when needed. Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- cache.h | 2 ++ refs.c | 34 ++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cache.h b/cache.h index 4e01a74..f37bc18 100644 --- a/cache.h +++ b/cache.h @@ -296,6 +296,8 @@ extern int get_sha1_hex(const char *hex, extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ extern int read_ref(const char *filename, unsigned char *sha1); extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *); +extern const char *resolve_packed_ref(const char *ref, unsigned char *sha1, int, int *); + extern int create_symref(const char *ref, const char *refs_heads_master); extern int validate_symref(const char *ref); diff --git a/refs.c b/refs.c index 3d4cdd1..5e3988b 100644 --- a/refs.c +++ b/refs.c @@ -148,6 +148,25 @@ static struct ref_list *get_loose_refs(v return refs; } +const char *resolve_packed_ref(const char *ref, unsigned char *sha1, + int reading, int *flag) +{ + struct ref_list *list = get_packed_refs(); + while (list) { + if (!strcmp(ref, list->name)) { + hashcpy(sha1, list->sha1); + if (flag) + *flag |= REF_ISPACKED; + return ref; + } + list = list->next; + } + if (reading || errno != ENOENT) + return NULL; + hashclr(sha1); + return ref; +} + /* We allow "recursive" symbolic refs. Only within reason, though */ #define MAXDEPTH 5 @@ -177,20 +196,7 @@ const char *resolve_ref(const char *ref, * reading. */ if (lstat(path, &st) < 0) { - struct ref_list *list = get_packed_refs(); - while (list) { - if (!strcmp(ref, list->name)) { - hashcpy(sha1, list->sha1); - if (flag) - *flag |= REF_ISPACKED; - return ref; - } - list = list->next; - } - if (reading || errno != ENOENT) - return NULL; - hashclr(sha1); - return ref; + return resolve_packed_ref(ref, sha1, reading, flag); } /* Follow "normalized" - ie "refs/.." symlinks by hand */ -- 1.4.2.1.g7cf04 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html