tree 44f1ef88a5d0effdf2337f4c72b88b2bdcd9a54b
parent 8a4556bdf5bc847117c840a8fd7fa42f6efb16e1
author Brad Roberts <[EMAIL PROTECTED]> 1114082996 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114082996 -0700
[PATCH] fix up diff-cache.c to use new cache api's
Along the way, rewrite to use a position index rather than pointer math.
Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---
diff-cache.c | 32 +++++++++++++-------------------
1 files changed, 13 insertions(+), 19 deletions(-)
Index: diff-cache.c
===================================================================
--- 8a4556bdf5bc847117c840a8fd7fa42f6efb16e1:1/diff-cache.c (mode:100644
sha1:fcbc4900d32f4ca24f67bb8f0fe344c6c5642ac9)
+++ cc414a188c0e8fefa7bea4f969cc7adfe4265d6f:1/diff-cache.c (mode:100644
sha1:548211944fc00594bfc06b9ab90f0cb476688285)
@@ -4,7 +4,7 @@
static int recursive = 0;
static int line_termination = '\n';
-static int diff_cache(void *tree, unsigned long size, struct cache_entry **ac,
int entries, const char *base);
+static int diff_cache(void *tree, unsigned long size, int pos, const char
*base);
static void update_tree_entry(void **bufp, unsigned long *sizep)
{
@@ -82,10 +82,10 @@
}
static int compare_tree_entry(const char *path1, unsigned int mode1, const
unsigned char *sha1,
- struct cache_entry **ac, int *entries, const char
*base)
+ int *pos, const char *base)
{
int baselen = strlen(base);
- struct cache_entry *ce = *ac;
+ struct cache_entry *ce = get_cache_entry(*pos);
const char *path2 = ce->name + baselen;
unsigned int mode2 = ntohl(ce->ce_mode);
const unsigned char *sha2 = ce->sha1;
@@ -107,7 +107,7 @@
memcpy(newbase + baselen + pathlen1, "/", 2);
if (!tree || strcmp(type, "tree"))
die("unable to read tree object %s",
sha1_to_hex(sha1));
- *entries = diff_cache(tree, size, ac, *entries,
newbase);
+ *pos = diff_cache(tree, size, *pos, newbase);
free(newbase);
free(tree);
return -1;
@@ -158,7 +158,7 @@
return 0;
}
-static int diff_cache(void *tree, unsigned long size, struct cache_entry **ac,
int entries, const char *base)
+static int diff_cache(void *tree, unsigned long size, int pos, const char
*base)
{
int baselen = strlen(base);
@@ -167,15 +167,16 @@
unsigned int mode;
const char *path;
const unsigned char *sha1;
- int left;
/*
* No entries in the cache (with this base)?
* Output the tree contents.
*/
- if (!entries || ce_namelen(ce = *ac) < baselen ||
memcmp(ce->name, base, baselen)) {
+ if ((pos == get_num_cache_entries()) ||
+ ce_namelen(ce = get_cache_entry(pos)) < baselen ||
+ memcmp(ce->name, base, baselen)) {
if (!size)
- return entries;
+ return pos;
sha1 = extract(tree, size, &path, &mode);
show_file("-", path, mode, sha1, base);
update_tree_entry(&tree, &size);
@@ -187,27 +188,20 @@
*/
if (!size) {
show_file("+", ce->name, ntohl(ce->ce_mode), ce->sha1,
"");
- ac++;
- entries--;
+ pos++;
continue;
}
sha1 = extract(tree, size, &path, &mode);
- left = entries;
- switch (compare_tree_entry(path, mode, sha1, ac, &left, base)) {
+ switch (compare_tree_entry(path, mode, sha1, &pos, base)) {
case -1:
update_tree_entry(&tree, &size);
- if (left < entries) {
- ac += (entries - left);
- entries = left;
- }
continue;
case 0:
update_tree_entry(&tree, &size);
/* Fallthrough */
case 1:
- ac++;
- entries--;
+ pos++;
continue;
}
die("diff-cache: internal error");
@@ -263,5 +257,5 @@
if (strcmp(type, "tree"))
die("bad tree object %s (%s)", sha1_to_hex(tree_sha1), type);
- return diff_cache(tree, size, active_cache, active_nr, "");
+ return diff_cache(tree, size, 0, "");
}
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html