@matheusbsbs / matheus-bagliano / commits / a755dfe45c
Fork 0

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>

Linus Torvalds committed May 28, 2006 at 15:10 UTC a755dfe45c10ccd9f180d3c267602ad18d127d6a
9 files changed +30 -29
blame.c
+2 -2
@@ -149,7 +149,7 @@ static void free_patch(struct patch *p)
149 free(p);
150 }
151
152 -static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
152 +static int get_blob_sha1_internal(const unsigned char *sha1, const char *base,
153 int baselen, const char *pathname,
154 unsigned mode, int stage);
155
@@ -178,7 +178,7 @@ static int get_blob_sha1(struct tree *t, const char *pathname,
178 return 0;
179 }
180
181 -static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
181 +static int get_blob_sha1_internal(const unsigned char *sha1, const char *base,
182 int baselen, const char *pathname,
183 unsigned mode, int stage)
184 {
builtin-read-tree.c
+4 -3
@@ -160,9 +160,10 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
160 }
161
162 if (posns[i]->directory) {
163 + struct tree *tree = lookup_tree(posns[i]->sha1);
164 any_dirs = 1;
164 - parse_tree(posns[i]->item.tree);
165 - subposns[i] = posns[i]->item.tree->entries;
165 + parse_tree(tree);
166 + subposns[i] = tree->entries;
167 posns[i] = posns[i]->next;
168 src[i + merge] = &df_conflict_entry;
169 continue;
@@ -186,7 +187,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
187
188 any_files = 1;
189
189 - memcpy(ce->sha1, posns[i]->item.any->sha1, 20);
190 + memcpy(ce->sha1, posns[i]->sha1, 20);
191 src[i + merge] = ce;
192 subposns[i] = &df_conflict_list;
193 posns[i] = posns[i]->next;
builtin-rev-list.c
+2 -2
@@ -133,9 +133,9 @@ static struct object_list **process_tree(struct tree *tree,
133 while (entry) {
134 struct tree_entry_list *next = entry->next;
135 if (entry->directory)
136 - p = process_tree(entry->item.tree, p, &me, entry->name);
136 + p = process_tree(lookup_tree(entry->sha1), p, &me, entry->name);
137 else
138 - p = process_blob(entry->item.blob, p, &me, entry->name);
138 + p = process_blob(lookup_blob(entry->sha1), p, &me, entry->name);
139 free(entry);
140 entry = next;
141 }
fsck-objects.c
+1
@@ -441,6 +441,7 @@ int main(int argc, char **argv)
441 {
442 int i, heads;
443
444 + track_object_refs = 1;
445 setup_git_directory();
446
447 for (i = 1; i < argc; i++) {
http-push.c
+2 -2
@@ -1733,9 +1733,9 @@ static struct object_list **process_tree(struct tree *tree,
1733 while (entry) {
1734 struct tree_entry_list *next = entry->next;
1735 if (entry->directory)
1736 - p = process_tree(entry->item.tree, p, &me, entry->name);
1736 + p = process_tree(lookup_tree(entry->sha1), p, &me, entry->name);
1737 else
1738 - p = process_blob(entry->item.blob, p, &me, entry->name);
1738 + p = process_blob(lookup_blob(entry->sha1), p, &me, entry->name);
1739 free(entry);
1740 entry = next;
1741 }
object.c
+1 -1
@@ -9,7 +9,7 @@ struct object **objs;
9 static int nr_objs;
10 int obj_allocs;
11
12 -int track_object_refs = 1;
12 +int track_object_refs = 0;
13
14 static int hashtable_index(const unsigned char *sha1)
15 {
revision.c
+2 -2
@@ -68,9 +68,9 @@ void mark_tree_uninteresting(struct tree *tree)
68 while (entry) {
69 struct tree_entry_list *next = entry->next;
70 if (entry->directory)
71 - mark_tree_uninteresting(entry->item.tree);
71 + mark_tree_uninteresting(lookup_tree(entry->sha1));
72 else
73 - mark_blob_uninteresting(entry->item.blob);
73 + mark_blob_uninteresting(lookup_blob(entry->sha1));
74 free(entry);
75 entry = next;
76 }
tree.c
+14 -11
@@ -8,7 +8,7 @@
8
9 const char *tree_type = "tree";
10
11 -static int read_one_entry(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
11 +static int read_one_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
12 {
13 int len;
14 unsigned int size;
@@ -89,7 +89,7 @@ int read_tree_recursive(struct tree *tree,
89 current->mode, match))
90 continue;
91
92 - switch (fn(current->item.any->sha1, base, baselen,
92 + switch (fn(current->sha1, base, baselen,
93 current->name, current->mode, stage)) {
94 case 0:
95 continue;
@@ -107,7 +107,7 @@ int read_tree_recursive(struct tree *tree,
107 memcpy(newbase, base, baselen);
108 memcpy(newbase + baselen, current->name, pathlen);
109 newbase[baselen + pathlen] = '/';
110 - retval = read_tree_recursive(current->item.tree,
110 + retval = read_tree_recursive(lookup_tree(current->sha1),
111 newbase,
112 baselen + pathlen + 1,
113 stage, match, fn);
@@ -170,6 +170,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
170
171 entry = xmalloc(sizeof(struct tree_entry_list));
172 entry->name = path;
173 + entry->sha1 = sha1;
174 entry->mode = mode;
175 entry->directory = S_ISDIR(mode) != 0;
176 entry->executable = (mode & S_IXUSR) != 0;
@@ -178,12 +179,6 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
179 entry->next = NULL;
180
181 update_tree_entry(&desc);
181 -
182 - if (entry->directory) {
183 - entry->item.tree = lookup_tree(sha1);
184 - } else {
185 - entry->item.blob = lookup_blob(sha1);
186 - }
182 n_refs++;
183 *list_p = entry;
184 list_p = &entry->next;
@@ -193,8 +188,16 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
188 struct tree_entry_list *entry;
189 unsigned i = 0;
190 struct object_refs *refs = alloc_object_refs(n_refs);
196 - for (entry = item->entries; entry; entry = entry->next)
197 - refs->ref[i++] = entry->item.any;
191 + for (entry = item->entries; entry; entry = entry->next) {
192 + struct object *obj;
193 +
194 + if (entry->directory)
195 + obj = &lookup_tree(entry->sha1)->object;
196 + else
197 + obj = &lookup_blob(entry->sha1)->object;
198 + refs->ref[i++] = obj;
199 + }
200 +
201 set_object_refs(&item->object, refs);
202 }
203
tree.h
+2 -6
@@ -13,11 +13,7 @@ struct tree_entry_list {
13 unsigned zeropad : 1;
14 unsigned int mode;
15 const char *name;
16 - union {
17 - struct object *any;
18 - struct tree *tree;
19 - struct blob *blob;
20 - } item;
16 + const unsigned char *sha1;
17 };
18
19 struct tree {
@@ -37,7 +33,7 @@ int parse_tree(struct tree *tree);
33 struct tree *parse_tree_indirect(const unsigned char *sha1);
34
35 #define READ_TREE_RECURSIVE 1
40 -typedef int (*read_tree_fn_t)(unsigned char *, const char *, int, const char *, unsigned int, int);
36 +typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int);
37
38 extern int read_tree_recursive(struct tree *tree,
39 const char *base, int baselen,