Skip to content

Commit

Permalink
Merge branch 'lt/tree-2'
Browse files Browse the repository at this point in the history
* lt/tree-2:
  fetch.c: do not call process_tree() from process_tree().
  tree_entry(): new tree-walking helper function
  adjust to the rebased series by Linus.
  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"
  Remove last vestiges of generic tree_entry_list
  Convert fetch.c: process_tree() to raw tree walker
  Convert "mark_tree_uninteresting()" to raw tree walker
  Remove unused "zeropad" entry from tree_list_entry
  fsck-objects: avoid unnecessary tree_entry_list usage
  Remove "tree->entries" tree-entry list from tree parser
  builtin-read-tree.c: avoid tree_entry_list in prime_cache_tree_rec()
  Switch "read_tree_recursive()" over to tree-walk functionality
  Make "tree_entry" have a SHA1 instead of a union of object pointers
  Make "struct tree" contain the pointer to the tree buffer
  • Loading branch information
Junio C Hamano committed Jun 4, 2006
2 parents f0679f4 + 6f9012b commit 16a4c6e
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 216 deletions.
4 changes: 2 additions & 2 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void free_patch(struct patch *p)
free(p);
}

static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
static int get_blob_sha1_internal(const unsigned char *sha1, const char *base,
int baselen, const char *pathname,
unsigned mode, int stage);

Expand Down Expand Up @@ -178,7 +178,7 @@ static int get_blob_sha1(struct tree *t, const char *pathname,
return 0;
}

static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
static int get_blob_sha1_internal(const unsigned char *sha1, const char *base,
int baselen, const char *pathname,
unsigned mode, int stage)
{
Expand Down
26 changes: 10 additions & 16 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,9 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
struct tree_desc *tree,
const char *tree_name, const char *base)
{
unsigned mode;
int len;
int hit = 0;
const char *path;
const unsigned char *sha1;
struct name_entry entry;
char *down;
char *path_buf = xmalloc(PATH_MAX + strlen(tree_name) + 100);

Expand All @@ -597,36 +595,32 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
}
len = strlen(path_buf);

while (tree->size) {
int pathlen;
sha1 = tree_entry_extract(tree, &path, &mode);
pathlen = strlen(path);
strcpy(path_buf + len, path);
while (tree_entry(tree, &entry)) {
strcpy(path_buf + len, entry.path);

if (S_ISDIR(mode))
if (S_ISDIR(entry.mode))
/* Match "abc/" against pathspec to
* decide if we want to descend into "abc"
* directory.
*/
strcpy(path_buf + len + pathlen, "/");
strcpy(path_buf + len + entry.pathlen, "/");

if (!pathspec_matches(paths, down))
;
else if (S_ISREG(mode))
hit |= grep_sha1(opt, sha1, path_buf);
else if (S_ISDIR(mode)) {
else if (S_ISREG(entry.mode))
hit |= grep_sha1(opt, entry.sha1, path_buf);
else if (S_ISDIR(entry.mode)) {
char type[20];
struct tree_desc sub;
void *data;
data = read_sha1_file(sha1, type, &sub.size);
data = read_sha1_file(entry.sha1, type, &sub.size);
if (!data)
die("unable to read tree (%s)",
sha1_to_hex(sha1));
sha1_to_hex(entry.sha1));
sub.buf = data;
hit |= grep_tree(opt, paths, &sub, tree_name, down);
free(data);
}
update_tree_entry(tree);
}
return hit;
}
Expand Down
2 changes: 1 addition & 1 deletion builtin-ls-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
}
}

static int show_tree(unsigned char *sha1, const char *base, int baselen,
static int show_tree(const unsigned char *sha1, const char *base, int baselen,
const char *pathname, unsigned mode, int stage)
{
int retval = 0;
Expand Down
68 changes: 56 additions & 12 deletions builtin-read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "object.h"
#include "tree.h"
#include "tree-walk.h"
#include "cache-tree.h"
#include <sys/time.h>
#include <signal.h>
Expand All @@ -29,7 +30,17 @@ static int merge_size = 0;

static struct object_list *trees = NULL;

static struct cache_entry df_conflict_entry = {
static struct cache_entry df_conflict_entry = {
};

struct tree_entry_list {
struct tree_entry_list *next;
unsigned directory : 1;
unsigned executable : 1;
unsigned symlink : 1;
unsigned int mode;
const char *name;
const unsigned char *sha1;
};

static struct tree_entry_list df_conflict_list = {
Expand All @@ -39,7 +50,35 @@ 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 struct tree_entry_list *create_tree_entry_list(struct tree *tree)
{
struct tree_desc desc;
struct name_entry one;
struct tree_entry_list *ret = NULL;
struct tree_entry_list **list_p = &ret;

desc.buf = tree->buffer;
desc.size = tree->size;

while (tree_entry(&desc, &one)) {
struct tree_entry_list *entry;

entry = xmalloc(sizeof(struct tree_entry_list));
entry->name = one.path;
entry->sha1 = one.sha1;
entry->mode = one.mode;
entry->directory = S_ISDIR(one.mode) != 0;
entry->executable = (one.mode & S_IXUSR) != 0;
entry->symlink = S_ISLNK(one.mode) != 0;
entry->next = NULL;

*list_p = entry;
list_p = &entry->next;
}
return ret;
}

static int entcmp(const char *name1, int dir1, const char *name2, int dir2)
{
int len1 = strlen(name1);
int len2 = strlen(name2);
Expand Down Expand Up @@ -67,7 +106,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;
Expand Down Expand Up @@ -161,9 +200,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;
Expand All @@ -187,7 +227,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;
Expand Down Expand Up @@ -368,7 +408,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, "", fn, &indpos))
Expand Down Expand Up @@ -775,19 +815,23 @@ static int read_cache_unmerged(void)

static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
{
struct tree_entry_list *ent;
struct tree_desc desc;
struct name_entry entry;
int cnt;

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;
cnt = 0;
while (tree_entry(&desc, &entry)) {
if (!S_ISDIR(entry.mode))
cnt++;
else {
struct cache_tree_sub *sub;
struct tree *subtree = (struct tree *)ent->item.tree;
struct tree *subtree = lookup_tree(entry.sha1);
if (!subtree->object.parsed)
parse_tree(subtree);
sub = cache_tree_sub(it, ent->name);
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;
Expand Down
23 changes: 12 additions & 11 deletions builtin-rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ static struct object_list **process_tree(struct tree *tree,
const char *name)
{
struct object *obj = &tree->object;
struct tree_entry_list *entry;
struct tree_desc desc;
struct name_entry entry;
struct name_path me;

if (!revs.tree_objects)
Expand All @@ -128,18 +129,18 @@ static struct object_list **process_tree(struct tree *tree,
me.up = path;
me.elem = name;
me.elem_len = strlen(name);
entry = tree->entries;
tree->entries = NULL;
while (entry) {
struct tree_entry_list *next = entry->next;
if (entry->directory)
p = process_tree(entry->item.tree, p, &me, entry->name);

desc.buf = tree->buffer;
desc.size = tree->size;

while (tree_entry(&desc, &entry)) {
if (S_ISDIR(entry.mode))
p = process_tree(lookup_tree(entry.sha1), p, &me, name);
else
p = process_blob(entry->item.blob, p, &me, entry->name);
free(entry->name);
free(entry);
entry = next;
p = process_blob(lookup_blob(entry.sha1), p, &me, name);
}
free(tree->buffer);
tree->buffer = NULL;
return p;
}

Expand Down
21 changes: 8 additions & 13 deletions builtin-tar-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,30 +271,25 @@ static void write_global_extended_header(const unsigned char *sha1)
static void traverse_tree(struct tree_desc *tree, struct strbuf *path)
{
int pathlen = path->len;
struct name_entry entry;

while (tree->size) {
const char *name;
const unsigned char *sha1;
unsigned mode;
while (tree_entry(tree, &entry)) {
void *eltbuf;
char elttype[20];
unsigned long eltsize;

sha1 = tree_entry_extract(tree, &name, &mode);
update_tree_entry(tree);

eltbuf = read_sha1_file(sha1, elttype, &eltsize);
eltbuf = read_sha1_file(entry.sha1, elttype, &eltsize);
if (!eltbuf)
die("cannot read %s", sha1_to_hex(sha1));
die("cannot read %s", sha1_to_hex(entry.sha1));

path->len = pathlen;
strbuf_append_string(path, name);
if (S_ISDIR(mode))
strbuf_append_string(path, entry.path);
if (S_ISDIR(entry.mode))
strbuf_append_string(path, "/");

write_entry(sha1, path, mode, eltbuf, eltsize);
write_entry(entry.sha1, path, entry.mode, eltbuf, eltsize);

if (S_ISDIR(mode)) {
if (S_ISDIR(entry.mode)) {
struct tree_desc subtree;
subtree.buf = eltbuf;
subtree.size = eltsize;
Expand Down
31 changes: 22 additions & 9 deletions fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "cache.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
#include "tag.h"
#include "blob.h"
#include "refs.h"
Expand Down Expand Up @@ -37,21 +38,33 @@ static int process(struct object *obj);

static int process_tree(struct tree *tree)
{
struct tree_entry_list *entry;
struct tree_desc desc;
struct name_entry entry;

if (parse_tree(tree))
return -1;

entry = tree->entries;
tree->entries = NULL;
while (entry) {
struct tree_entry_list *next = entry->next;
if (process(entry->item.any))
desc.buf = tree->buffer;
desc.size = tree->size;
while (tree_entry(&desc, &entry)) {
struct object *obj = NULL;

if (S_ISDIR(entry.mode)) {
struct tree *tree = lookup_tree(entry.sha1);
if (tree)
obj = &tree->object;
}
else {
struct blob *blob = lookup_blob(entry.sha1);
if (blob)
obj = &blob->object;
}
if (!obj || process(obj))
return -1;
free(entry->name);
free(entry);
entry = next;
}
free(tree->buffer);
tree->buffer = NULL;
tree->size = 0;
return 0;
}

Expand Down
Loading

0 comments on commit 16a4c6e

Please sign in to comment.