diff options
author | Nicolas Pitre <nico@cam.org> | 2007-04-04 16:49:04 -0400 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-04-05 14:59:47 -0700 |
commit | d72308e01c5977177cda0aed06cfeee9192e1247 (patch) | |
tree | c42895d515c9bdae4d429ddd93c74b2f082fe09d /sha1_name.c | |
parent | d5ad36fe3584551a09160edce3e76d559d412ae5 (diff) | |
download | git-d72308e01c5977177cda0aed06cfeee9192e1247.tar.gz |
clean up and optimize nth_packed_object_sha1() usage
Let's avoid the open coded pack index reference in pack-object and use
nth_packed_object_sha1() instead. This will help encapsulating index
format differences in one place.
And while at it there is no reason to copy SHA1's over and over while a
direct pointer to it in the index will do just fine.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sha1_name.c b/sha1_name.c index bede0e5b06..267ea3f3ed 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -71,7 +71,7 @@ static int match_sha(unsigned len, const unsigned char *a, const unsigned char * static int find_short_packed_object(int len, const unsigned char *match, unsigned char *sha1) { struct packed_git *p; - unsigned char found_sha1[20]; + const unsigned char *found_sha1 = NULL; int found = 0; prepare_packed_git(); @@ -80,10 +80,10 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne uint32_t first = 0, last = num; while (first < last) { uint32_t mid = (first + last) / 2; - unsigned char now[20]; + const unsigned char *now; int cmp; - nth_packed_object_sha1(p, mid, now); + now = nth_packed_object_sha1(p, mid); cmp = hashcmp(match, now); if (!cmp) { first = mid; @@ -96,14 +96,14 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne last = mid; } if (first < num) { - unsigned char now[20], next[20]; - nth_packed_object_sha1(p, first, now); + const unsigned char *now, *next; + now = nth_packed_object_sha1(p, first); if (match_sha(len, match, now)) { - if (nth_packed_object_sha1(p, first+1, next) || - !match_sha(len, match, next)) { + next = nth_packed_object_sha1(p, first+1); + if (!next|| !match_sha(len, match, next)) { /* unique within this pack */ if (!found) { - hashcpy(found_sha1, now); + found_sha1 = now; found++; } else if (hashcmp(found_sha1, now)) { |