Git development
 help / color / mirror / Atom feed
From: Brad Roberts <braddr@gameboy2.puremagic.com>
To: git@vger.kernel.org
Subject: [PATCH 12/19] fix up diff-cache.c to use new cache api's
Date: Thu, 21 Apr 2005 11:37:34 -0700	[thread overview]
Message-ID: <200504211837.j3LIbYRQ027685@gameboy2.puremagic.com> (raw)

tree 44f1ef88a5d0effdf2337f4c72b88b2bdcd9a54b
parent 8a4556bdf5bc847117c840a8fd7fa42f6efb16e1
author Brad Roberts <braddr@puremagic.com> 1114082996 -0700
committer Brad Roberts <braddr@gameboy2.puremagic.com> 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 <braddr@puremagic.com>
---

 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, "");
 }


                 reply	other threads:[~2005-04-21 18:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200504211837.j3LIbYRQ027685@gameboy2.puremagic.com \
    --to=braddr@gameboy2.puremagic.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox