mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
Make "tree_entry" have a SHA1 instead of a union of object pointers
This is preparatory work for further cleanups, where we try to make tree_entry look more like the more efficient tree-walk descriptor. Instead of having a union of pointers to blob/tree/objects, this just makes "struct tree_entry" have the raw SHA1, and makes all the users use that instead (often that implies adding a "lookup_tree(..)" on the sha1, but sometimes the user just wanted the SHA1 in the first place, and it just avoids an unnecessary indirection). Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
d2eafb7661
commit
a755dfe45c
9 changed files with 30 additions and 29 deletions
4
blame.c
4
blame.c
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -160,9 +160,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] = tree->entries;
|
||||
posns[i] = posns[i]->next;
|
||||
src[i + merge] = &df_conflict_entry;
|
||||
continue;
|
||||
|
@ -186,7 +187,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;
|
||||
|
|
|
@ -133,9 +133,9 @@ static struct object_list **process_tree(struct tree *tree,
|
|||
while (entry) {
|
||||
struct tree_entry_list *next = entry->next;
|
||||
if (entry->directory)
|
||||
p = process_tree(entry->item.tree, p, &me, entry->name);
|
||||
p = process_tree(lookup_tree(entry->sha1), p, &me, entry->name);
|
||||
else
|
||||
p = process_blob(entry->item.blob, p, &me, entry->name);
|
||||
p = process_blob(lookup_blob(entry->sha1), p, &me, entry->name);
|
||||
free(entry);
|
||||
entry = next;
|
||||
}
|
||||
|
|
|
@ -441,6 +441,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
int i, heads;
|
||||
|
||||
track_object_refs = 1;
|
||||
setup_git_directory();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
|
|
|
@ -1733,9 +1733,9 @@ static struct object_list **process_tree(struct tree *tree,
|
|||
while (entry) {
|
||||
struct tree_entry_list *next = entry->next;
|
||||
if (entry->directory)
|
||||
p = process_tree(entry->item.tree, p, &me, entry->name);
|
||||
p = process_tree(lookup_tree(entry->sha1), p, &me, entry->name);
|
||||
else
|
||||
p = process_blob(entry->item.blob, p, &me, entry->name);
|
||||
p = process_blob(lookup_blob(entry->sha1), p, &me, entry->name);
|
||||
free(entry);
|
||||
entry = next;
|
||||
}
|
||||
|
|
2
object.c
2
object.c
|
@ -9,7 +9,7 @@ struct object **objs;
|
|||
static int nr_objs;
|
||||
int obj_allocs;
|
||||
|
||||
int track_object_refs = 1;
|
||||
int track_object_refs = 0;
|
||||
|
||||
static int hashtable_index(const unsigned char *sha1)
|
||||
{
|
||||
|
|
|
@ -68,9 +68,9 @@ void mark_tree_uninteresting(struct tree *tree)
|
|||
while (entry) {
|
||||
struct tree_entry_list *next = entry->next;
|
||||
if (entry->directory)
|
||||
mark_tree_uninteresting(entry->item.tree);
|
||||
mark_tree_uninteresting(lookup_tree(entry->sha1));
|
||||
else
|
||||
mark_blob_uninteresting(entry->item.blob);
|
||||
mark_blob_uninteresting(lookup_blob(entry->sha1));
|
||||
free(entry);
|
||||
entry = next;
|
||||
}
|
||||
|
|
25
tree.c
25
tree.c
|
@ -8,7 +8,7 @@
|
|||
|
||||
const char *tree_type = "tree";
|
||||
|
||||
static int read_one_entry(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
|
||||
static int read_one_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
|
||||
{
|
||||
int len;
|
||||
unsigned int size;
|
||||
|
@ -89,7 +89,7 @@ int read_tree_recursive(struct tree *tree,
|
|||
current->mode, match))
|
||||
continue;
|
||||
|
||||
switch (fn(current->item.any->sha1, base, baselen,
|
||||
switch (fn(current->sha1, base, baselen,
|
||||
current->name, current->mode, stage)) {
|
||||
case 0:
|
||||
continue;
|
||||
|
@ -107,7 +107,7 @@ int read_tree_recursive(struct tree *tree,
|
|||
memcpy(newbase, base, baselen);
|
||||
memcpy(newbase + baselen, current->name, pathlen);
|
||||
newbase[baselen + pathlen] = '/';
|
||||
retval = read_tree_recursive(current->item.tree,
|
||||
retval = read_tree_recursive(lookup_tree(current->sha1),
|
||||
newbase,
|
||||
baselen + pathlen + 1,
|
||||
stage, match, fn);
|
||||
|
@ -170,6 +170,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
|
|||
|
||||
entry = xmalloc(sizeof(struct tree_entry_list));
|
||||
entry->name = path;
|
||||
entry->sha1 = sha1;
|
||||
entry->mode = mode;
|
||||
entry->directory = S_ISDIR(mode) != 0;
|
||||
entry->executable = (mode & S_IXUSR) != 0;
|
||||
|
@ -178,12 +179,6 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
|
|||
entry->next = NULL;
|
||||
|
||||
update_tree_entry(&desc);
|
||||
|
||||
if (entry->directory) {
|
||||
entry->item.tree = lookup_tree(sha1);
|
||||
} else {
|
||||
entry->item.blob = lookup_blob(sha1);
|
||||
}
|
||||
n_refs++;
|
||||
*list_p = entry;
|
||||
list_p = &entry->next;
|
||||
|
@ -193,8 +188,16 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
|
|||
struct tree_entry_list *entry;
|
||||
unsigned i = 0;
|
||||
struct object_refs *refs = alloc_object_refs(n_refs);
|
||||
for (entry = item->entries; entry; entry = entry->next)
|
||||
refs->ref[i++] = entry->item.any;
|
||||
for (entry = item->entries; entry; entry = entry->next) {
|
||||
struct object *obj;
|
||||
|
||||
if (entry->directory)
|
||||
obj = &lookup_tree(entry->sha1)->object;
|
||||
else
|
||||
obj = &lookup_blob(entry->sha1)->object;
|
||||
refs->ref[i++] = obj;
|
||||
}
|
||||
|
||||
set_object_refs(&item->object, refs);
|
||||
}
|
||||
|
||||
|
|
8
tree.h
8
tree.h
|
@ -13,11 +13,7 @@ struct tree_entry_list {
|
|||
unsigned zeropad : 1;
|
||||
unsigned int mode;
|
||||
const char *name;
|
||||
union {
|
||||
struct object *any;
|
||||
struct tree *tree;
|
||||
struct blob *blob;
|
||||
} item;
|
||||
const unsigned char *sha1;
|
||||
};
|
||||
|
||||
struct tree {
|
||||
|
@ -37,7 +33,7 @@ int parse_tree(struct tree *tree);
|
|||
struct tree *parse_tree_indirect(const unsigned char *sha1);
|
||||
|
||||
#define READ_TREE_RECURSIVE 1
|
||||
typedef int (*read_tree_fn_t)(unsigned char *, const char *, int, const char *, unsigned int, int);
|
||||
typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int);
|
||||
|
||||
extern int read_tree_recursive(struct tree *tree,
|
||||
const char *base, int baselen,
|
||||
|
|
Loading…
Reference in a new issue