git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 2/4] Move prime_cache_tree() to cache-tree.c
Date: Mon, 20 Apr 2009 03:58:18 -0700	[thread overview]
Message-ID: <1240225100-29960-3-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1240225100-29960-2-git-send-email-gitster@pobox.com>

The interface to build cache-tree belongs there.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-checkout.c  |    1 +
 builtin-read-tree.c |   37 +------------------------------------
 cache-tree.c        |   34 ++++++++++++++++++++++++++++++++++
 cache-tree.h        |    4 ++++
 4 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/builtin-checkout.c b/builtin-checkout.c
index b121fe5..ffdb33a 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -5,6 +5,7 @@
 #include "commit.h"
 #include "tree.h"
 #include "tree-walk.h"
+#include "cache-tree.h"
 #include "unpack-trees.h"
 #include "dir.h"
 #include "run-command.h"
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index e4e0e71..9cd7d07 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -29,41 +29,6 @@ static int list_tree(unsigned char *sha1)
 	return 0;
 }
 
-static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
-{
-	struct tree_desc desc;
-	struct name_entry entry;
-	int cnt;
-
-	hashcpy(it->sha1, tree->object.sha1);
-	init_tree_desc(&desc, tree->buffer, tree->size);
-	cnt = 0;
-	while (tree_entry(&desc, &entry)) {
-		if (!S_ISDIR(entry.mode))
-			cnt++;
-		else {
-			struct cache_tree_sub *sub;
-			struct tree *subtree = lookup_tree(entry.sha1);
-			if (!subtree->object.parsed)
-				parse_tree(subtree);
-			sub = cache_tree_sub(it, entry.path);
-			sub->cache_tree = cache_tree();
-			prime_cache_tree_rec(sub->cache_tree, subtree);
-			cnt += sub->cache_tree->entry_count;
-		}
-	}
-	it->entry_count = cnt;
-}
-
-static void prime_cache_tree(void)
-{
-	if (!nr_trees)
-		return;
-	active_cache_tree = cache_tree();
-	prime_cache_tree_rec(active_cache_tree, trees[0]);
-
-}
-
 static const char read_tree_usage[] = "git read-tree (<sha> | [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
 
 static struct lock_file lock_file;
@@ -236,7 +201,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 	 * what came from the tree.
 	 */
 	if (nr_trees == 1 && !opts.prefix)
-		prime_cache_tree();
+		prime_cache_tree(&active_cache_tree, trees[0]);
 
 	if (write_cache(newfd, active_cache, active_nr) ||
 	    commit_locked_index(&lock_file))
diff --git a/cache-tree.c b/cache-tree.c
index 3d8f218..37bf35e 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tree.h"
+#include "tree-walk.h"
 #include "cache-tree.h"
 
 #ifndef DEBUG
@@ -591,3 +592,36 @@ int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix)
 
 	return 0;
 }
+
+static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
+{
+	struct tree_desc desc;
+	struct name_entry entry;
+	int cnt;
+
+	hashcpy(it->sha1, tree->object.sha1);
+	init_tree_desc(&desc, tree->buffer, tree->size);
+	cnt = 0;
+	while (tree_entry(&desc, &entry)) {
+		if (!S_ISDIR(entry.mode))
+			cnt++;
+		else {
+			struct cache_tree_sub *sub;
+			struct tree *subtree = lookup_tree(entry.sha1);
+			if (!subtree->object.parsed)
+				parse_tree(subtree);
+			sub = cache_tree_sub(it, entry.path);
+			sub->cache_tree = cache_tree();
+			prime_cache_tree_rec(sub->cache_tree, subtree);
+			cnt += sub->cache_tree->entry_count;
+		}
+	}
+	it->entry_count = cnt;
+}
+
+void prime_cache_tree(struct cache_tree **it, struct tree *tree)
+{
+	cache_tree_free(it);
+	*it = cache_tree();
+	prime_cache_tree_rec(*it, tree);
+}
diff --git a/cache-tree.h b/cache-tree.h
index cf8b790..e958835 100644
--- a/cache-tree.h
+++ b/cache-tree.h
@@ -1,6 +1,8 @@
 #ifndef CACHE_TREE_H
 #define CACHE_TREE_H
 
+#include "tree.h"
+
 struct cache_tree;
 struct cache_tree_sub {
 	struct cache_tree *cache_tree;
@@ -33,4 +35,6 @@ int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int)
 #define WRITE_TREE_PREFIX_ERROR (-3)
 
 int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix);
+void prime_cache_tree(struct cache_tree **, struct tree *);
+
 #endif
-- 
1.6.3.rc1.18.g66996

  reply	other threads:[~2009-04-20 11:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-20 10:58 [PATCH 0/4] Revisiting cache-tree Junio C Hamano
2009-04-20 10:58 ` [PATCH 1/4] read-tree A B: do not corrupt cache-tree Junio C Hamano
2009-04-20 10:58   ` Junio C Hamano [this message]
2009-04-20 10:58     ` [PATCH 3/4] read-tree -m A B: prime cache-tree from the switched-to tree Junio C Hamano
2009-04-20 10:58       ` [PATCH 4/4] checkout branch: prime cache-tree fully Junio C Hamano
2009-04-20 13:08 ` [PATCH 0/4] Revisiting cache-tree Alex Riesen

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=1240225100-29960-3-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.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;
as well as URLs for NNTP newsgroup(s).