struct name_entry: use struct object_id instead of unsigned char sha1[20]

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Apr 17, 2016 at 23:10 UTC 7d924c9139e33e7599d7aed0446e634c427a5f15
17 files changed +48 -48
builtin/grep.c
+3 -3
@@ -438,7 +438,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
438 strbuf_add(base, entry.path, te_len);
439
440 if (S_ISREG(entry.mode)) {
441 - hit |= grep_sha1(opt, entry.sha1, base->buf, tn_len,
441 + hit |= grep_sha1(opt, entry.oid->hash, base->buf, tn_len,
442 check_attr ? base->buf + tn_len : NULL);
443 }
444 else if (S_ISDIR(entry.mode)) {
@@ -447,10 +447,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
447 void *data;
448 unsigned long size;
449
450 - data = lock_and_read_sha1_file(entry.sha1, &type, &size);
450 + data = lock_and_read_sha1_file(entry.oid->hash, &type, &size);
451 if (!data)
452 die(_("unable to read tree (%s)"),
453 - sha1_to_hex(entry.sha1));
453 + oid_to_hex(entry.oid));
454
455 strbuf_addch(base, '/');
456 init_tree_desc(&sub, data, size);
builtin/merge-tree.c
+9 -9
@@ -150,15 +150,15 @@ static void show_result(void)
150 /* An empty entry never compares same, not even to another empty entry */
151 static int same_entry(struct name_entry *a, struct name_entry *b)
152 {
153 - return a->sha1 &&
154 - b->sha1 &&
155 - !hashcmp(a->sha1, b->sha1) &&
153 + return a->oid &&
154 + b->oid &&
155 + !oidcmp(a->oid, b->oid) &&
156 a->mode == b->mode;
157 }
158
159 static int both_empty(struct name_entry *a, struct name_entry *b)
160 {
161 - return !(a->sha1 || b->sha1);
161 + return !(a->oid || b->oid);
162 }
163
164 static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
@@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
188 return;
189
190 path = traverse_path(info, result);
191 - orig = create_entry(2, ours->mode, ours->sha1, path);
192 - final = create_entry(0, result->mode, result->sha1, path);
191 + orig = create_entry(2, ours->mode, ours->oid->hash, path);
192 + final = create_entry(0, result->mode, result->oid->hash, path);
193
194 final->link = orig;
195
@@ -213,7 +213,7 @@ static void unresolved_directory(const struct traverse_info *info,
213
214 newbase = traverse_path(info, p);
215
216 -#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->sha1 : NULL)
216 +#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid->hash : NULL)
217 buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
218 buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
219 buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));
@@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info
239 path = entry->path;
240 else
241 path = traverse_path(info, n);
242 - link = create_entry(stage, n->mode, n->sha1, path);
242 + link = create_entry(stage, n->mode, n->oid->hash, path);
243 link->link = entry;
244 return link;
245 }
@@ -314,7 +314,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s
314 }
315
316 if (same_entry(entry+0, entry+1)) {
317 - if (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {
317 + if (entry[2].oid && !S_ISDIR(entry[2].mode)) {
318 /* We did not touch, they modified -- take theirs */
319 resolve(info, entry+1, entry+2);
320 return mask;
builtin/pack-objects.c
+2 -2
@@ -1186,7 +1186,7 @@ static void add_pbase_object(struct tree_desc *tree,
1186 if (cmp < 0)
1187 return;
1188 if (name[cmplen] != '/') {
1189 - add_object_entry(entry.sha1,
1189 + add_object_entry(entry.oid->hash,
1190 object_type(entry.mode),
1191 fullname, 1);
1192 return;
@@ -1197,7 +1197,7 @@ static void add_pbase_object(struct tree_desc *tree,
1197 const char *down = name+cmplen+1;
1198 int downlen = name_cmp_len(down);
1199
1200 - tree = pbase_tree_get(entry.sha1);
1200 + tree = pbase_tree_get(entry.oid->hash);
1201 if (!tree)
1202 return;
1203 init_tree_desc(&sub, tree->tree_data, tree->tree_size);
builtin/reflog.c
+2 -2
@@ -84,8 +84,8 @@ static int tree_is_complete(const unsigned char *sha1)
84 init_tree_desc(&desc, tree->buffer, tree->size);
85 complete = 1;
86 while (tree_entry(&desc, &entry)) {
87 - if (!has_sha1_file(entry.sha1) ||
88 - (S_ISDIR(entry.mode) && !tree_is_complete(entry.sha1))) {
87 + if (!has_sha1_file(entry.oid->hash) ||
88 + (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid->hash))) {
89 tree->object.flags |= INCOMPLETE;
90 complete = 0;
91 }
cache-tree.c
+2 -2
@@ -663,7 +663,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
663 cnt++;
664 else {
665 struct cache_tree_sub *sub;
666 - struct tree *subtree = lookup_tree(entry.sha1);
666 + struct tree *subtree = lookup_tree(entry.oid->hash);
667 if (!subtree->object.parsed)
668 parse_tree(subtree);
669 sub = cache_tree_sub(it, entry.path);
@@ -710,7 +710,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
710
711 it = find_cache_tree_from_traversal(root, info);
712 it = cache_tree_find(it, ent->path);
713 - if (it && it->entry_count > 0 && !hashcmp(ent->sha1, it->sha1))
713 + if (it && it->entry_count > 0 && !hashcmp(ent->oid->hash, it->sha1))
714 return it->entry_count;
715 return 0;
716 }
fsck.c
+2 -2
@@ -312,9 +312,9 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
312 if (S_ISGITLINK(entry.mode))
313 continue;
314 if (S_ISDIR(entry.mode))
315 - result = options->walk(&lookup_tree(entry.sha1)->object, OBJ_TREE, data, options);
315 + result = options->walk(&lookup_tree(entry.oid->hash)->object, OBJ_TREE, data, options);
316 else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode))
317 - result = options->walk(&lookup_blob(entry.sha1)->object, OBJ_BLOB, data, options);
317 + result = options->walk(&lookup_blob(entry.oid->hash)->object, OBJ_BLOB, data, options);
318 else {
319 result = error("in tree %s: entry %s has bad mode %.6o",
320 oid_to_hex(&tree->object.oid), entry.path, entry.mode);
http-push.c
+2 -2
@@ -1312,10 +1312,10 @@ static struct object_list **process_tree(struct tree *tree,
1312 while (tree_entry(&desc, &entry))
1313 switch (object_type(entry.mode)) {
1314 case OBJ_TREE:
1315 - p = process_tree(lookup_tree(entry.sha1), p);
1315 + p = process_tree(lookup_tree(entry.oid->hash), p);
1316 break;
1317 case OBJ_BLOB:
1318 - p = process_blob(lookup_blob(entry.sha1), p);
1318 + p = process_blob(lookup_blob(entry.oid->hash), p);
1319 break;
1320 default:
1321 /* Subproject commit - not in this repository */
list-objects.c
+3 -3
@@ -110,16 +110,16 @@ static void process_tree(struct rev_info *revs,
110
111 if (S_ISDIR(entry.mode))
112 process_tree(revs,
113 - lookup_tree(entry.sha1),
113 + lookup_tree(entry.oid->hash),
114 show, base, entry.path,
115 cb_data);
116 else if (S_ISGITLINK(entry.mode))
117 - process_gitlink(revs, entry.sha1,
117 + process_gitlink(revs, entry.oid->hash,
118 show, base, entry.path,
119 cb_data);
120 else
121 process_blob(revs,
122 - lookup_blob(entry.sha1),
122 + lookup_blob(entry.oid->hash),
123 show, base, entry.path,
124 cb_data);
125 }
match-trees.c
+1 -1
@@ -104,7 +104,7 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
104 else if (cmp > 0)
105 /* path2 does not appear in one */
106 score += score_missing(e2.mode, e2.path);
107 - else if (hashcmp(e1.sha1, e2.sha1))
107 + else if (oidcmp(e1.oid, e2.oid))
108 /* they are different */
109 score += score_differs(e1.mode, e2.mode, e1.path);
110 else
notes.c
+2 -2
@@ -446,7 +446,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
446 l = (struct leaf_node *)
447 xcalloc(1, sizeof(struct leaf_node));
448 hashcpy(l->key_sha1, object_sha1);
449 - hashcpy(l->val_sha1, entry.sha1);
449 + hashcpy(l->val_sha1, entry.oid->hash);
450 if (len < 20) {
451 if (!S_ISDIR(entry.mode) || path_len != 2)
452 goto handle_non_note; /* not subtree */
@@ -493,7 +493,7 @@ handle_non_note:
493 }
494 strbuf_addstr(&non_note_path, entry.path);
495 add_non_note(t, strbuf_detach(&non_note_path, NULL),
496 - entry.mode, entry.sha1);
496 + entry.mode, entry.oid->hash);
497 }
498 }
499 free(buf);
revision.c
+2 -2
@@ -59,10 +59,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
59 while (tree_entry(&desc, &entry)) {
60 switch (object_type(entry.mode)) {
61 case OBJ_TREE:
62 - mark_tree_uninteresting(lookup_tree(entry.sha1));
62 + mark_tree_uninteresting(lookup_tree(entry.oid->hash));
63 break;
64 case OBJ_BLOB:
65 - mark_blob_uninteresting(lookup_blob(entry.sha1));
65 + mark_blob_uninteresting(lookup_blob(entry.oid->hash));
66 break;
67 default:
68 /* Subproject commit - not in this repository */
tree-diff.c
+3 -3
@@ -229,7 +229,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
229 DIFF_STATUS_ADDED;
230
231 if (tpi_valid) {
232 - sha1_i = tp[i].entry.sha1;
232 + sha1_i = tp[i].entry.oid->hash;
233 mode_i = tp[i].entry.mode;
234 }
235 else {
@@ -270,7 +270,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
270 /* same rule as in emitthis */
271 int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
272
273 - parents_sha1[i] = tpi_valid ? tp[i].entry.sha1
273 + parents_sha1[i] = tpi_valid ? tp[i].entry.oid->hash
274 : NULL;
275 }
276
@@ -482,7 +482,7 @@ static struct combine_diff_path *ll_diff_tree_paths(
482 continue;
483
484 /* diff(t,pi) != ø */
485 - if (hashcmp(t.entry.sha1, tp[i].entry.sha1) ||
485 + if (oidcmp(t.entry.oid, tp[i].entry.oid) ||
486 (t.entry.mode != tp[i].entry.mode))
487 continue;
488
tree-walk.c
+3 -3
@@ -38,7 +38,7 @@ static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned
38 /* Initialize the descriptor entry */
39 desc->entry.path = path;
40 desc->entry.mode = canon_mode(mode);
41 - desc->entry.sha1 = (const unsigned char *)(path + len);
41 + desc->entry.oid = (const struct object_id *)(path + len);
42 }
43
44 void init_tree_desc(struct tree_desc *desc, const void *buffer, unsigned long size)
@@ -76,7 +76,7 @@ static void entry_extract(struct tree_desc *t, struct name_entry *a)
76 void update_tree_entry(struct tree_desc *desc)
77 {
78 const void *buf = desc->buffer;
79 - const unsigned char *end = desc->entry.sha1 + 20;
79 + const unsigned char *end = desc->entry.oid->hash + 20;
80 unsigned long size = desc->size;
81 unsigned long len = end - (const unsigned char *)buf;
82
@@ -110,7 +110,7 @@ void setup_traverse_info(struct traverse_info *info, const char *base)
110 pathlen--;
111 info->pathlen = pathlen ? pathlen + 1 : 0;
112 info->name.path = base;
113 - info->name.sha1 = (void *)(base + pathlen + 1);
113 + info->name.oid = (void *)(base + pathlen + 1);
114 if (pathlen)
115 info->prev = &dummy;
116 }
tree-walk.h
+3 -3
@@ -2,7 +2,7 @@
2 #define TREE_WALK_H
3
4 struct name_entry {
5 - const unsigned char *sha1;
5 + const struct object_id *oid;
6 const char *path;
7 unsigned int mode;
8 };
@@ -17,12 +17,12 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co
17 {
18 *pathp = desc->entry.path;
19 *modep = desc->entry.mode;
20 - return desc->entry.sha1;
20 + return desc->entry.oid->hash;
21 }
22
23 static inline int tree_entry_len(const struct name_entry *ne)
24 {
25 - return (const char *)ne->sha1 - ne->path - 1;
25 + return (const char *)ne->oid - ne->path - 1;
26 }
27
28 void update_tree_entry(struct tree_desc *);
tree.c
+5 -5
@@ -76,7 +76,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
76 continue;
77 }
78
79 - switch (fn(entry.sha1, base,
79 + switch (fn(entry.oid->hash, base,
80 entry.path, entry.mode, stage, context)) {
81 case 0:
82 continue;
@@ -87,19 +87,19 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
87 }
88
89 if (S_ISDIR(entry.mode))
90 - hashcpy(sha1, entry.sha1);
90 + hashcpy(sha1, entry.oid->hash);
91 else if (S_ISGITLINK(entry.mode)) {
92 struct commit *commit;
93
94 - commit = lookup_commit(entry.sha1);
94 + commit = lookup_commit(entry.oid->hash);
95 if (!commit)
96 die("Commit %s in submodule path %s%s not found",
97 - sha1_to_hex(entry.sha1),
97 + oid_to_hex(entry.oid),
98 base->buf, entry.path);
99
100 if (parse_commit(commit))
101 die("Invalid commit %s in submodule path %s%s",
102 - sha1_to_hex(entry.sha1),
102 + oid_to_hex(entry.oid),
103 base->buf, entry.path);
104
105 hashcpy(sha1, commit->tree->object.oid.hash);
unpack-trees.c
+2 -2
@@ -475,7 +475,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
475 for (i = 0; i < n; i++, dirmask >>= 1) {
476 const unsigned char *sha1 = NULL;
477 if (dirmask & 1)
478 - sha1 = names[i].sha1;
478 + sha1 = names[i].oid->hash;
479 buf[i] = fill_tree_descriptor(t+i, sha1);
480 }
481
@@ -591,7 +591,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con
591 ce->ce_mode = create_ce_mode(n->mode);
592 ce->ce_flags = create_ce_flags(stage);
593 ce->ce_namelen = len;
594 - hashcpy(ce->sha1, n->sha1);
594 + hashcpy(ce->sha1, n->oid->hash);
595 make_traverse_path(ce->name, info, n);
596
597 return ce;
walker.c
+2 -2
@@ -43,12 +43,12 @@ static int process_tree(struct walker *walker, struct tree *tree)
43 if (S_ISGITLINK(entry.mode))
44 continue;
45 if (S_ISDIR(entry.mode)) {
46 - struct tree *tree = lookup_tree(entry.sha1);
46 + struct tree *tree = lookup_tree(entry.oid->hash);
47 if (tree)
48 obj = &tree->object;
49 }
50 else {
51 - struct blob *blob = lookup_blob(entry.sha1);
51 + struct blob *blob = lookup_blob(entry.oid->hash);
52 if (blob)
53 obj = &blob->object;
54 }