Skip to content

Commit 7d924c9

Browse files
bk2204gitster
authored andcommitted
struct name_entry: use struct object_id instead of unsigned char sha1[20]
Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 82db3d4 commit 7d924c9

17 files changed

+48
-48
lines changed

builtin/grep.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
438438
strbuf_add(base, entry.path, te_len);
439439

440440
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,
442442
check_attr ? base->buf + tn_len : NULL);
443443
}
444444
else if (S_ISDIR(entry.mode)) {
@@ -447,10 +447,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
447447
void *data;
448448
unsigned long size;
449449

450-
data = lock_and_read_sha1_file(entry.sha1, &type, &size);
450+
data = lock_and_read_sha1_file(entry.oid->hash, &type, &size);
451451
if (!data)
452452
die(_("unable to read tree (%s)"),
453-
sha1_to_hex(entry.sha1));
453+
oid_to_hex(entry.oid));
454454

455455
strbuf_addch(base, '/');
456456
init_tree_desc(&sub, data, size);

builtin/merge-tree.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ static void show_result(void)
150150
/* An empty entry never compares same, not even to another empty entry */
151151
static int same_entry(struct name_entry *a, struct name_entry *b)
152152
{
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) &&
156156
a->mode == b->mode;
157157
}
158158

159159
static int both_empty(struct name_entry *a, struct name_entry *b)
160160
{
161-
return !(a->sha1 || b->sha1);
161+
return !(a->oid || b->oid);
162162
}
163163

164164
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
188188
return;
189189

190190
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);
193193

194194
final->link = orig;
195195

@@ -213,7 +213,7 @@ static void unresolved_directory(const struct traverse_info *info,
213213

214214
newbase = traverse_path(info, p);
215215

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)
217217
buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
218218
buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
219219
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
239239
path = entry->path;
240240
else
241241
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);
243243
link->link = entry;
244244
return link;
245245
}
@@ -314,7 +314,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s
314314
}
315315

316316
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)) {
318318
/* We did not touch, they modified -- take theirs */
319319
resolve(info, entry+1, entry+2);
320320
return mask;

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ static void add_pbase_object(struct tree_desc *tree,
11861186
if (cmp < 0)
11871187
return;
11881188
if (name[cmplen] != '/') {
1189-
add_object_entry(entry.sha1,
1189+
add_object_entry(entry.oid->hash,
11901190
object_type(entry.mode),
11911191
fullname, 1);
11921192
return;
@@ -1197,7 +1197,7 @@ static void add_pbase_object(struct tree_desc *tree,
11971197
const char *down = name+cmplen+1;
11981198
int downlen = name_cmp_len(down);
11991199

1200-
tree = pbase_tree_get(entry.sha1);
1200+
tree = pbase_tree_get(entry.oid->hash);
12011201
if (!tree)
12021202
return;
12031203
init_tree_desc(&sub, tree->tree_data, tree->tree_size);

builtin/reflog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static int tree_is_complete(const unsigned char *sha1)
8484
init_tree_desc(&desc, tree->buffer, tree->size);
8585
complete = 1;
8686
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))) {
8989
tree->object.flags |= INCOMPLETE;
9090
complete = 0;
9191
}

cache-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
663663
cnt++;
664664
else {
665665
struct cache_tree_sub *sub;
666-
struct tree *subtree = lookup_tree(entry.sha1);
666+
struct tree *subtree = lookup_tree(entry.oid->hash);
667667
if (!subtree->object.parsed)
668668
parse_tree(subtree);
669669
sub = cache_tree_sub(it, entry.path);
@@ -710,7 +710,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
710710

711711
it = find_cache_tree_from_traversal(root, info);
712712
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))
714714
return it->entry_count;
715715
return 0;
716716
}

fsck.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
312312
if (S_ISGITLINK(entry.mode))
313313
continue;
314314
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);
316316
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);
318318
else {
319319
result = error("in tree %s: entry %s has bad mode %.6o",
320320
oid_to_hex(&tree->object.oid), entry.path, entry.mode);

http-push.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,10 +1312,10 @@ static struct object_list **process_tree(struct tree *tree,
13121312
while (tree_entry(&desc, &entry))
13131313
switch (object_type(entry.mode)) {
13141314
case OBJ_TREE:
1315-
p = process_tree(lookup_tree(entry.sha1), p);
1315+
p = process_tree(lookup_tree(entry.oid->hash), p);
13161316
break;
13171317
case OBJ_BLOB:
1318-
p = process_blob(lookup_blob(entry.sha1), p);
1318+
p = process_blob(lookup_blob(entry.oid->hash), p);
13191319
break;
13201320
default:
13211321
/* Subproject commit - not in this repository */

list-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ static void process_tree(struct rev_info *revs,
110110

111111
if (S_ISDIR(entry.mode))
112112
process_tree(revs,
113-
lookup_tree(entry.sha1),
113+
lookup_tree(entry.oid->hash),
114114
show, base, entry.path,
115115
cb_data);
116116
else if (S_ISGITLINK(entry.mode))
117-
process_gitlink(revs, entry.sha1,
117+
process_gitlink(revs, entry.oid->hash,
118118
show, base, entry.path,
119119
cb_data);
120120
else
121121
process_blob(revs,
122-
lookup_blob(entry.sha1),
122+
lookup_blob(entry.oid->hash),
123123
show, base, entry.path,
124124
cb_data);
125125
}

match-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
104104
else if (cmp > 0)
105105
/* path2 does not appear in one */
106106
score += score_missing(e2.mode, e2.path);
107-
else if (hashcmp(e1.sha1, e2.sha1))
107+
else if (oidcmp(e1.oid, e2.oid))
108108
/* they are different */
109109
score += score_differs(e1.mode, e2.mode, e1.path);
110110
else

notes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
446446
l = (struct leaf_node *)
447447
xcalloc(1, sizeof(struct leaf_node));
448448
hashcpy(l->key_sha1, object_sha1);
449-
hashcpy(l->val_sha1, entry.sha1);
449+
hashcpy(l->val_sha1, entry.oid->hash);
450450
if (len < 20) {
451451
if (!S_ISDIR(entry.mode) || path_len != 2)
452452
goto handle_non_note; /* not subtree */
@@ -493,7 +493,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
493493
}
494494
strbuf_addstr(&non_note_path, entry.path);
495495
add_non_note(t, strbuf_detach(&non_note_path, NULL),
496-
entry.mode, entry.sha1);
496+
entry.mode, entry.oid->hash);
497497
}
498498
}
499499
free(buf);

0 commit comments

Comments
 (0)