diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2011-12-12 06:38:57 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-12-12 09:08:57 -0800 |
commit | 6a871b0a34230a977534d341b2e10182a0565b19 (patch) | |
tree | 3bb3a9a35bc7db89887195ab63b4a105a4db4765 | |
parent | bce637326daf875b27f370c23e00ffb2c8354d76 (diff) | |
download | git-6a871b0a34230a977534d341b2e10182a0565b19.tar.gz |
read_packed_refs(): keep track of the directory being worked in
Packed references are stored in $GIT_DIR/packed-refs sorted, so
adjacent ones are pretty likely to be in the same directory. So while
reading them, keep track of the last directory used, and reuse it if
possible to avoid searching the reference namespace from the root each
time.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | refs.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -780,6 +780,7 @@ static const char *parse_ref_line(char *line, unsigned char *sha1) static void read_packed_refs(FILE *f, struct ref_entry *direntry) { struct ref_entry *last = NULL; + struct ref_entry *current_direntry = NULL; char refline[PATH_MAX]; int flag = REF_ISPACKED; @@ -799,8 +800,21 @@ static void read_packed_refs(FILE *f, struct ref_entry *direntry) refname = parse_ref_line(refline, sha1); if (refname) { + if (current_direntry) { + char *slash = strrchr(refname, '/'); + if (!slash + || strncmp(current_direntry->name, refname, + slash - refname + 1) + || current_direntry->name[slash - refname + 1] != '\0') + /* The new refname does not go in current_direntry */ + current_direntry = NULL; + } + if (!current_direntry) + current_direntry = find_containing_direntry( + direntry, refname, 1); + last = create_ref_entry(refname, sha1, flag, 1); - add_ref(direntry, last); + add_entry(current_direntry, last); continue; } if (last && |