{"thread":{"id":"216","subject":"[PATCH 12/19] fix up diff-cache.c to use new cache api's","startedAt":"2005-04-21T18:37:34Z","lastAt":"2005-04-21T18:37:34Z","messageCount":1,"participants":["Brad Roberts"],"isPatch":true,"patchVersion":1,"patchTotal":19},"messages":[{"id":"1165","messageId":"200504211837.j3LIbYRQ027685@gameboy2.puremagic.com","threadId":"216","inReplyTo":null,"subject":"[PATCH 12/19] fix up diff-cache.c to use new cache api's","fromName":"Brad Roberts","fromEmail":"braddr@gameboy2.puremagic.com","sentAt":"2005-04-21T18:37:34Z","receivedAt":"2005-04-21T18:37:34Z","isPatch":true,"sender":{"key":"braddr@gameboy2.puremagic.com","avatar":null},"body":"tree 44f1ef88a5d0effdf2337f4c72b88b2bdcd9a54b\nparent 8a4556bdf5bc847117c840a8fd7fa42f6efb16e1\nauthor Brad Roberts <braddr@puremagic.com> 1114082996 -0700\ncommitter Brad Roberts <braddr@gameboy2.puremagic.com> 1114082996 -0700\n\n[PATCH] fix up diff-cache.c to use new cache api's\n\nAlong the way, rewrite to use a position index rather than pointer math.\n\nSigned-off-by: Brad Roberts <braddr@puremagic.com>\n---\n\n diff-cache.c |   32 +++++++++++++-------------------\n 1 files changed, 13 insertions(+), 19 deletions(-)\n\nIndex: diff-cache.c\n===================================================================\n--- 8a4556bdf5bc847117c840a8fd7fa42f6efb16e1:1/diff-cache.c  (mode:100644 sha1:fcbc4900d32f4ca24f67bb8f0fe344c6c5642ac9)\n+++ cc414a188c0e8fefa7bea4f969cc7adfe4265d6f:1/diff-cache.c  (mode:100644 sha1:548211944fc00594bfc06b9ab90f0cb476688285)\n@@ -4,7 +4,7 @@\n static int recursive = 0;\n static int line_termination = '\\n';\n \n-static int diff_cache(void *tree, unsigned long size, struct cache_entry **ac, int entries, const char *base);\n+static int diff_cache(void *tree, unsigned long size, int pos, const char *base);\n \n static void update_tree_entry(void **bufp, unsigned long *sizep)\n {\n@@ -82,10 +82,10 @@\n }\n \n static int compare_tree_entry(const char *path1, unsigned int mode1, const unsigned char *sha1,\n-\t\t\t      struct cache_entry **ac, int *entries, const char *base)\n+\t\t\t      int *pos, const char *base)\n {\n \tint baselen = strlen(base);\n-\tstruct cache_entry *ce = *ac;\n+\tstruct cache_entry *ce = get_cache_entry(*pos);\n \tconst char *path2 = ce->name + baselen;\n \tunsigned int mode2 = ntohl(ce->ce_mode);\n \tconst unsigned char *sha2 = ce->sha1;\n@@ -107,7 +107,7 @@\n \t\t\tmemcpy(newbase + baselen + pathlen1, \"/\", 2);\n \t\t\tif (!tree || strcmp(type, \"tree\"))\n \t\t\t\tdie(\"unable to read tree object %s\", sha1_to_hex(sha1));\n-\t\t\t*entries = diff_cache(tree, size, ac, *entries, newbase);\n+\t\t\t*pos = diff_cache(tree, size, *pos, newbase);\n \t\t\tfree(newbase);\n \t\t\tfree(tree);\n \t\t\treturn -1;\n@@ -158,7 +158,7 @@\n \treturn 0;\n }\n \n-static int diff_cache(void *tree, unsigned long size, struct cache_entry **ac, int entries, const char *base)\n+static int diff_cache(void *tree, unsigned long size, int pos, const char *base)\n {\n \tint baselen = strlen(base);\n \n@@ -167,15 +167,16 @@\n \t\tunsigned int mode;\n \t\tconst char *path;\n \t\tconst unsigned char *sha1;\n-\t\tint left;\n \n \t\t/*\n \t\t * No entries in the cache (with this base)?\n \t\t * Output the tree contents.\n \t\t */\n-\t\tif (!entries || ce_namelen(ce = *ac) < baselen || memcmp(ce->name, base, baselen)) {\n+\t\tif ((pos == get_num_cache_entries()) ||\n+\t\t    ce_namelen(ce = get_cache_entry(pos)) < baselen ||\n+\t\t    memcmp(ce->name, base, baselen)) {\n \t\t\tif (!size)\n-\t\t\t\treturn entries;\n+\t\t\t\treturn pos;\n \t\t\tsha1 = extract(tree, size, &path, &mode);\n \t\t\tshow_file(\"-\", path, mode, sha1, base);\n \t\t\tupdate_tree_entry(&tree, &size);\n@@ -187,27 +188,20 @@\n \t\t */\n \t\tif (!size) {\n \t\t\tshow_file(\"+\", ce->name, ntohl(ce->ce_mode), ce->sha1, \"\");\n-\t\t\tac++;\n-\t\t\tentries--;\n+\t\t\tpos++;\n \t\t\tcontinue;\n \t\t}\n \n \t\tsha1 = extract(tree, size, &path, &mode);\n-\t\tleft = entries;\n-\t\tswitch (compare_tree_entry(path, mode, sha1, ac, &left, base)) {\n+\t\tswitch (compare_tree_entry(path, mode, sha1, &pos, base)) {\n \t\tcase -1:\n \t\t\tupdate_tree_entry(&tree, &size);\n-\t\t\tif (left < entries) {\n-\t\t\t\tac += (entries - left);\n-\t\t\t\tentries = left;\n-\t\t\t}\n \t\t\tcontinue;\n \t\tcase 0:\n \t\t\tupdate_tree_entry(&tree, &size);\n \t\t\t/* Fallthrough */\n \t\tcase 1:\n-\t\t\tac++;\n-\t\t\tentries--;\n+\t\t\tpos++;\n \t\t\tcontinue;\n \t\t}\n \t\tdie(\"diff-cache: internal error\");\n@@ -263,5 +257,5 @@\n \tif (strcmp(type, \"tree\"))\n \t\tdie(\"bad tree object %s (%s)\", sha1_to_hex(tree_sha1), type);\n \n-\treturn diff_cache(tree, size, active_cache, active_nr, \"\");\n+\treturn diff_cache(tree, size, 0, \"\");\n }\n\n"}]}