diff options
author | Junio C Hamano <junkio@cox.net> | 2005-07-11 11:00:55 +0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-07-11 21:13:09 +0400 |
commit | ab90ea5d6e6ef358c8ee5869307c33a939be0e66 (patch) | |
tree | cb5ca0a9593d744fdf12ef5fec122525b0821d71 | |
parent | 013aab8265a806c8d3c9b040485839091bca30f4 (diff) |
[PATCH] Check packs and then files.
This reverses the order of object lookup, to check pack index first and
then go to the filesystem to find .git/objects/??/ hierarchy.
When most of the objects are packed, this saves quite many stat() calls
and negative dcache entries; while the price this approach has to pay is
negligible, even when most of the objects are outside pack, because
checking pack index file is quite cheap.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | sha1_file.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sha1_file.c b/sha1_file.c index 6b9462cfba..5ec5598d7d 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1035,14 +1035,17 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size { unsigned long mapsize; void *map, *buf; + struct pack_entry e; + if (find_pack_entry(sha1, &e)) + return read_packed_sha1(sha1, type, size); map = map_sha1_file_internal(sha1, &mapsize); if (map) { buf = unpack_sha1_file(map, mapsize, type, size); munmap(map, mapsize); return buf; } - return read_packed_sha1(sha1, type, size); + return NULL; } void *read_object_with_reference(const unsigned char *sha1, @@ -1343,9 +1346,9 @@ int has_sha1_file(const unsigned char *sha1) struct stat st; struct pack_entry e; - if (find_sha1_file(sha1, &st)) + if (find_pack_entry(sha1, &e)) return 1; - return find_pack_entry(sha1, &e); + return find_sha1_file(sha1, &st) ? 1 : 0; } int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type) |