{"thread":{"id":"826","subject":"[PATCH] diff.c: locate_size_cache() fix.","startedAt":"2005-06-04T06:02:23Z","lastAt":"2005-06-04T06:02:23Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4526","messageId":"7vekbik6c0.fsf@assigned-by-dhcp.cox.net","threadId":"826","inReplyTo":null,"subject":"[PATCH] diff.c: locate_size_cache() fix.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-06-04T06:02:23Z","receivedAt":"2005-06-04T06:02:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This fixes two bugs.\n\n - declaration of auto variable \"cmp\" was preceeded by a\n   statement, causing compilation error on real C compilers;\n   noticed and patch given by Yoichi Yuasa.\n\n - the function's calling convention was overloading its size\n   parameter to mean \"largest possible value means do not add\n   entry\", which was a bad taste.  Brought up during a\n   discussion with Peter Baudis.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n diff.c |   11 ++++++-----\n 1 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\n--- a/diff.c\n+++ b/diff.c\n@@ -236,6 +236,7 @@ static struct sha1_size_cache {\n static int sha1_size_cache_nr, sha1_size_cache_alloc;\n \n static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,\n+\t\t\t\t\t\t int find_only,\n \t\t\t\t\t\t unsigned long size)\n {\n \tint first, last;\n@@ -244,9 +245,9 @@ static struct sha1_size_cache *locate_si\n \tfirst = 0;\n \tlast = sha1_size_cache_nr;\n \twhile (last > first) {\n-\t\tint next = (last + first) >> 1;\n+\t\tint cmp, next = (last + first) >> 1;\n \t\te = sha1_size_cache[next];\n-\t\tint cmp = memcmp(e->sha1, sha1, 20);\n+\t\tcmp = memcmp(e->sha1, sha1, 20);\n \t\tif (!cmp)\n \t\t\treturn e;\n \t\tif (cmp < 0) {\n@@ -256,7 +257,7 @@ static struct sha1_size_cache *locate_si\n \t\tfirst = next+1;\n \t}\n \t/* not found */\n-\tif (size == UINT_MAX)\n+\tif (find_only)\n \t\treturn NULL;\n \t/* insert to make it at \"first\" */\n \tif (sha1_size_cache_alloc <= sha1_size_cache_nr) {\n@@ -337,13 +338,13 @@ int diff_populate_filespec(struct diff_f\n \t\tstruct sha1_size_cache *e;\n \n \t\tif (size_only) {\n-\t\t\te = locate_size_cache(s->sha1, UINT_MAX);\n+\t\t\te = locate_size_cache(s->sha1, 1, 0);\n \t\t\tif (e) {\n \t\t\t\ts->size = e->size;\n \t\t\t\treturn 0;\n \t\t\t}\n \t\t\tif (!sha1_file_size(s->sha1, &s->size))\n-\t\t\t\tlocate_size_cache(s->sha1, s->size);\n+\t\t\t\tlocate_size_cache(s->sha1, 0, s->size);\n \t\t}\n \t\telse {\n \t\t\ts->data = read_sha1_file(s->sha1, type, &s->size);\n------------\n\n"}]}