Start moving unpack-trees to "struct tree_desc"

This doesn't actually change any real code, but it changes the interface
to unpack_trees() to take an array of "struct tree_desc" entries, the same
way the tree-walk.c functions do.

The reason for this is that we would be much better off if we can do the
tree-unpacking using the generic "traverse_trees()" functionality instead
of having to the special "unpack" infrastructure.

This really is a pretty minimal diff, just to change the calling
convention. It passes all the tests, and looks sane. There were only two
users of "unpack_trees()": builtin-read-tree and merge-recursive, and I
tried to keep the changes minimal.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Linus Torvalds 2007-08-09 22:21:29 -07:00 коммит произвёл Junio C Hamano
Родитель 7efeb8f098
Коммит 933bf40a5c
4 изменённых файлов: 39 добавлений и 30 удалений

Просмотреть файл

@ -13,14 +13,19 @@
#include "dir.h" #include "dir.h"
#include "builtin.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) 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) if (!tree)
return -1; return -1;
object_list_append(&tree->object, &trees); trees[nr_trees++] = tree;
return 0; 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) static void prime_cache_tree(void)
{ {
struct tree *tree = (struct tree *)trees->item; if (!nr_trees)
if (!tree)
return; return;
active_cache_tree = cache_tree(); 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; int i, newfd, stage = 0;
unsigned char sha1[20]; unsigned char sha1[20];
struct tree_desc t[3];
struct unpack_trees_options opts; struct unpack_trees_options opts;
memset(&opts, 0, sizeof(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; 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, * 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 * valid cache-tree because the index must match exactly
* what came from the tree. * 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); cache_tree_free(&active_cache_tree);
prime_cache_tree(); prime_cache_tree();
} }

Просмотреть файл

@ -216,13 +216,19 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
*/ */
static int index_only = 0; 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, static int git_merge_trees(int index_only,
struct tree *common, struct tree *common,
struct tree *head, struct tree *head,
struct tree *merge) struct tree *merge)
{ {
int rc; int rc;
struct object_list *trees = NULL; struct tree_desc t[3];
struct unpack_trees_options opts; struct unpack_trees_options opts;
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
@ -234,11 +240,11 @@ static int git_merge_trees(int index_only,
opts.head_idx = 2; opts.head_idx = 2;
opts.fn = threeway_merge; opts.fn = threeway_merge;
object_list_append(&common->object, &trees); init_tree_desc_from_tree(t+0, common);
object_list_append(&head->object, &trees); init_tree_desc_from_tree(t+1, head);
object_list_append(&merge->object, &trees); 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); cache_tree_free(&active_cache_tree);
return rc; return rc;
} }

Просмотреть файл

@ -16,19 +16,13 @@ struct tree_entry_list {
const unsigned char *sha1; 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 name_entry one;
struct tree_entry_list *ret = NULL; struct tree_entry_list *ret = NULL;
struct tree_entry_list **list_p = &ret; struct tree_entry_list **list_p = &ret;
if (!tree->object.parsed) while (tree_entry(desc, &one)) {
parse_tree(tree);
init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &one)) {
struct tree_entry_list *entry; struct tree_entry_list *entry;
entry = xmalloc(sizeof(struct tree_entry_list)); 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)) { if (S_ISDIR(posns[i]->mode)) {
struct tree *tree = lookup_tree(posns[i]->sha1); struct tree *tree = lookup_tree(posns[i]->sha1);
struct tree_desc t;
any_dirs = 1; any_dirs = 1;
parse_tree(tree); 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; posns[i] = posns[i]->next;
src[i + o->merge] = o->df_conflict_entry; src[i + o->merge] = o->df_conflict_entry;
continue; continue;
@ -331,12 +327,10 @@ static void check_updates(struct cache_entry **src, int nr,
stop_progress(&progress);; 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; struct tree_entry_list **posns;
int i; int i;
struct object_list *posn = trees;
struct tree_entry_list df_conflict_list; struct tree_entry_list df_conflict_list;
static struct cache_entry *dfc; static struct cache_entry *dfc;
@ -356,10 +350,9 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
if (len) { if (len) {
posns = xmalloc(len * sizeof(struct tree_entry_list *)); posns = xmalloc(len * sizeof(struct tree_entry_list *));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++)
posns[i] = create_tree_entry_list((struct tree *) posn->item); posns[i] = create_tree_entry_list(t+i);
posn = posn->next;
}
if (unpack_trees_rec(posns, len, o->prefix ? o->prefix : "", if (unpack_trees_rec(posns, len, o->prefix ? o->prefix : "",
o, &df_conflict_list)) o, &df_conflict_list))
return -1; return -1;

Просмотреть файл

@ -26,7 +26,7 @@ struct unpack_trees_options {
struct cache_entry *df_conflict_entry; 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); struct unpack_trees_options *options);
int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o); int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o);