summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin-read-tree.c26
-rw-r--r--merge-recursive.c16
-rw-r--r--unpack-trees.c25
-rw-r--r--unpack-trees.h2
4 files changed, 39 insertions, 30 deletions
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index a3b17a3bd9..1967d100f2 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -13,14 +13,19 @@
#include "dir.h"
#include "builtin.h"
-static struct object_list *trees;
+static int nr_trees;
+static struct tree *trees[4];
static int list_tree(unsigned char *sha1)
{
- struct tree *tree = parse_tree_indirect(sha1);
+ struct tree *tree;
+
+ if (nr_trees >= 4)
+ return -1;
+ tree = parse_tree_indirect(sha1);
if (!tree)
return -1;
- object_list_append(&tree->object, &trees);
+ trees[nr_trees++] = tree;
return 0;
}
@@ -76,11 +81,10 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
static void prime_cache_tree(void)
{
- struct tree *tree = (struct tree *)trees->item;
- if (!tree)
+ if (!nr_trees)
return;
active_cache_tree = cache_tree();
- prime_cache_tree_rec(active_cache_tree, tree);
+ prime_cache_tree_rec(active_cache_tree, trees[0]);
}
@@ -92,6 +96,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
{
int i, newfd, stage = 0;
unsigned char sha1[20];
+ struct tree_desc t[3];
struct unpack_trees_options opts;
memset(&opts, 0, sizeof(opts));
@@ -258,7 +263,12 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
opts.head_idx = 1;
}
- unpack_trees(trees, &opts);
+ for (i = 0; i < nr_trees; i++) {
+ struct tree *tree = trees[i];
+ parse_tree(tree);
+ init_tree_desc(t+i, tree->buffer, tree->size);
+ }
+ unpack_trees(nr_trees, t, &opts);
/*
* When reading only one tree (either the most basic form,
@@ -266,7 +276,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
* valid cache-tree because the index must match exactly
* what came from the tree.
*/
- if (trees && trees->item && !opts.prefix && (!opts.merge || (stage == 2))) {
+ if (nr_trees && !opts.prefix && (!opts.merge || (stage == 2))) {
cache_tree_free(&active_cache_tree);
prime_cache_tree();
}
diff --git a/merge-recursive.c b/merge-recursive.c
index c8539ec0ba..f7d1b84999 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -216,13 +216,19 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
*/
static int index_only = 0;
+static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
+{
+ parse_tree(tree);
+ init_tree_desc(desc, tree->buffer, tree->size);
+}
+
static int git_merge_trees(int index_only,
struct tree *common,
struct tree *head,
struct tree *merge)
{
int rc;
- struct object_list *trees = NULL;
+ struct tree_desc t[3];
struct unpack_trees_options opts;
memset(&opts, 0, sizeof(opts));
@@ -234,11 +240,11 @@ static int git_merge_trees(int index_only,
opts.head_idx = 2;
opts.fn = threeway_merge;
- object_list_append(&common->object, &trees);
- object_list_append(&head->object, &trees);
- object_list_append(&merge->object, &trees);
+ init_tree_desc_from_tree(t+0, common);
+ init_tree_desc_from_tree(t+1, head);
+ init_tree_desc_from_tree(t+2, merge);
- rc = unpack_trees(trees, &opts);
+ rc = unpack_trees(3, t, &opts);
cache_tree_free(&active_cache_tree);
return rc;
}
diff --git a/unpack-trees.c b/unpack-trees.c
index dfd985b0ef..5d1ffd1a32 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -16,19 +16,13 @@ struct tree_entry_list {
const unsigned char *sha1;
};
-static struct tree_entry_list *create_tree_entry_list(struct tree *tree)
+static struct tree_entry_list *create_tree_entry_list(struct tree_desc *desc)
{
- struct tree_desc desc;
struct name_entry one;
struct tree_entry_list *ret = NULL;
struct tree_entry_list **list_p = &ret;
- if (!tree->object.parsed)
- parse_tree(tree);
-
- init_tree_desc(&desc, tree->buffer, tree->size);
-
- while (tree_entry(&desc, &one)) {
+ while (tree_entry(desc, &one)) {
struct tree_entry_list *entry;
entry = xmalloc(sizeof(struct tree_entry_list));
@@ -173,9 +167,11 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
if (S_ISDIR(posns[i]->mode)) {
struct tree *tree = lookup_tree(posns[i]->sha1);
+ struct tree_desc t;
any_dirs = 1;
parse_tree(tree);
- subposns[i] = create_tree_entry_list(tree);
+ init_tree_desc(&t, tree->buffer, tree->size);
+ subposns[i] = create_tree_entry_list(&t);
posns[i] = posns[i]->next;
src[i + o->merge] = o->df_conflict_entry;
continue;
@@ -331,12 +327,10 @@ static void check_updates(struct cache_entry **src, int nr,
stop_progress(&progress);;
}
-int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
+int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)
{
- unsigned len = object_list_length(trees);
struct tree_entry_list **posns;
int i;
- struct object_list *posn = trees;
struct tree_entry_list df_conflict_list;
static struct cache_entry *dfc;
@@ -356,10 +350,9 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
if (len) {
posns = xmalloc(len * sizeof(struct tree_entry_list *));
- for (i = 0; i < len; i++) {
- posns[i] = create_tree_entry_list((struct tree *) posn->item);
- posn = posn->next;
- }
+ for (i = 0; i < len; i++)
+ posns[i] = create_tree_entry_list(t+i);
+
if (unpack_trees_rec(posns, len, o->prefix ? o->prefix : "",
o, &df_conflict_list))
return -1;
diff --git a/unpack-trees.h b/unpack-trees.h
index fee7da4382..9cd39a28a9 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -26,7 +26,7 @@ struct unpack_trees_options {
struct cache_entry *df_conflict_entry;
};
-extern int unpack_trees(struct object_list *trees,
+extern int unpack_trees(unsigned n, struct tree_desc *t,
struct unpack_trees_options *options);
int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o);