summaryrefslogtreecommitdiff
path: root/builtin-read-tree.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <junkio@cox.net>2006-05-28 23:05:02 -0700
committerLibravatar Junio C Hamano <junkio@cox.net>2006-05-28 23:05:02 -0700
commit52bc0e294c0d5924db0e5e8f25284e467c6d2983 (patch)
tree86f9e8fe89841de0e69e91902865002dffdaa6bf /builtin-read-tree.c
parentMerge branch 'jc/cache-tree' into next (diff)
parentMerge branch 'lt/tree' into jc/lt-tree-n-cache-tree (diff)
downloadtgif-52bc0e294c0d5924db0e5e8f25284e467c6d2983.tar.xz
Merge branch 'jc/lt-tree-n-cache-tree' into next
* jc/lt-tree-n-cache-tree: Remove "tree->entries" tree-entry list from tree parser Switch "read_tree_recursive()" over to tree-walk functionality Make "tree_entry" have a SHA1 instead of a union of object pointers Add raw tree buffer info to "struct tree" Don't use "sscanf()" for tree mode scanning git-fetch: avoid using "case ... in (arm)"
Diffstat (limited to 'builtin-read-tree.c')
-rw-r--r--builtin-read-tree.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 629d151639..6a2ceba9ce 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -10,6 +10,7 @@
#include "object.h"
#include "tree.h"
#include "cache-tree.h"
+#include "tree-walk.h"
#include <sys/time.h>
#include <signal.h>
#include "builtin.h"
@@ -40,7 +41,7 @@ static struct tree_entry_list df_conflict_list = {
typedef int (*merge_fn_t)(struct cache_entry **src);
-static int entcmp(char *name1, int dir1, char *name2, int dir2)
+static int entcmp(const char *name1, int dir1, const char *name2, int dir2)
{
int len1 = strlen(name1);
int len2 = strlen(name2);
@@ -68,7 +69,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
int src_size = len + 1;
do {
int i;
- char *first;
+ const char *first;
int firstdir = 0;
int pathlen;
unsigned ce_size;
@@ -162,9 +163,10 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
}
if (posns[i]->directory) {
+ struct tree *tree = lookup_tree(posns[i]->sha1);
any_dirs = 1;
- parse_tree(posns[i]->item.tree);
- subposns[i] = posns[i]->item.tree->entries;
+ parse_tree(tree);
+ subposns[i] = create_tree_entry_list(tree);
posns[i] = posns[i]->next;
src[i + merge] = &df_conflict_entry;
continue;
@@ -188,7 +190,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
any_files = 1;
- memcpy(ce->sha1, posns[i]->item.any->sha1, 20);
+ memcpy(ce->sha1, posns[i]->sha1, 20);
src[i + merge] = ce;
subposns[i] = &df_conflict_list;
posns[i] = posns[i]->next;
@@ -369,7 +371,7 @@ static int unpack_trees(merge_fn_t fn)
if (len) {
posns = xmalloc(len * sizeof(struct tree_entry_list *));
for (i = 0; i < len; i++) {
- posns[i] = ((struct tree *) posn->item)->entries;
+ posns[i] = create_tree_entry_list((struct tree *) posn->item);
posn = posn->next;
}
if (unpack_trees_rec(posns, len, prefix ? prefix : "",
@@ -800,19 +802,31 @@ static int read_cache_unmerged(void)
static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
{
- struct tree_entry_list *ent;
- int cnt;
+ struct tree_desc desc;
+ int cnt = 0;
memcpy(it->sha1, tree->object.sha1, 20);
- for (cnt = 0, ent = tree->entries; ent; ent = ent->next) {
- if (!ent->directory)
+ desc.buf = tree->buffer;
+ desc.size = tree->size;
+
+ while (desc.size) {
+ unsigned mode;
+ const char *name;
+ const unsigned char *sha1;
+
+ sha1 = tree_entry_extract(&desc, &name, &mode);
+ update_tree_entry(&desc);
+
+ if (!S_ISDIR(mode))
cnt++;
else {
struct cache_tree_sub *sub;
- struct tree *subtree = (struct tree *)ent->item.tree;
+ struct tree *subtree;
+
+ subtree = lookup_tree(sha1);
if (!subtree->object.parsed)
parse_tree(subtree);
- sub = cache_tree_sub(it, ent->name);
+ sub = cache_tree_sub(it, name);
sub->cache_tree = cache_tree();
prime_cache_tree_rec(sub->cache_tree, subtree);
cnt += sub->cache_tree->entry_count;