Skip to content

Commit ce6663a

Browse files
bk2204gitster
authored andcommitted
tree-walk: convert tree_entry_extract() to use struct object_id
Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d924c9 commit ce6663a

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

fsck.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,11 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
450450
while (desc.size) {
451451
unsigned mode;
452452
const char *name;
453-
const unsigned char *sha1;
453+
const struct object_id *oid;
454454

455-
sha1 = tree_entry_extract(&desc, &name, &mode);
455+
oid = tree_entry_extract(&desc, &name, &mode);
456456

457-
has_null_sha1 |= is_null_sha1(sha1);
457+
has_null_sha1 |= is_null_oid(oid);
458458
has_full_path |= !!strchr(name, '/');
459459
has_empty_name |= !*name;
460460
has_dot |= !strcmp(name, ".");

match-trees.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,22 @@ static void match_trees(const unsigned char *hash1,
131131

132132
while (one.size) {
133133
const char *path;
134-
const unsigned char *elem;
134+
const struct object_id *elem;
135135
unsigned mode;
136136
int score;
137137

138138
elem = tree_entry_extract(&one, &path, &mode);
139139
if (!S_ISDIR(mode))
140140
goto next;
141-
score = score_trees(elem, hash2);
141+
score = score_trees(elem->hash, hash2);
142142
if (*best_score < score) {
143143
free(*best_match);
144144
*best_match = xstrfmt("%s%s", base, path);
145145
*best_score = score;
146146
}
147147
if (recurse_limit) {
148148
char *newbase = xstrfmt("%s%s/", base, path);
149-
match_trees(elem, hash2, best_score, best_match,
149+
match_trees(elem->hash, hash2, best_score, best_match,
150150
newbase, recurse_limit - 1);
151151
free(newbase);
152152
}
@@ -191,15 +191,15 @@ static int splice_tree(const unsigned char *hash1,
191191
while (desc.size) {
192192
const char *name;
193193
unsigned mode;
194-
const unsigned char *sha1;
194+
const struct object_id *oid;
195195

196-
sha1 = tree_entry_extract(&desc, &name, &mode);
196+
oid = tree_entry_extract(&desc, &name, &mode);
197197
if (strlen(name) == toplen &&
198198
!memcmp(name, prefix, toplen)) {
199199
if (!S_ISDIR(mode))
200200
die("entry %s in tree %s is not a tree",
201201
name, sha1_to_hex(hash1));
202-
rewrite_here = (unsigned char *) sha1;
202+
rewrite_here = (unsigned char *) oid->hash;
203203
break;
204204
}
205205
update_tree_entry(&desc);

tree-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
183183

184184
if (t) {
185185
/* path present in resulting tree */
186-
sha1 = tree_entry_extract(t, &path, &mode);
186+
sha1 = tree_entry_extract(t, &path, &mode)->hash;
187187
pathlen = tree_entry_len(&t->entry);
188188
isdir = S_ISDIR(mode);
189189
} else {

tree-walk.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
433433
int namelen = strlen(name);
434434
while (t->size) {
435435
const char *entry;
436-
const unsigned char *sha1;
436+
const struct object_id *oid;
437437
int entrylen, cmp;
438438

439-
sha1 = tree_entry_extract(t, &entry, mode);
439+
oid = tree_entry_extract(t, &entry, mode);
440440
entrylen = tree_entry_len(&t->entry);
441441
update_tree_entry(t);
442442
if (entrylen > namelen)
@@ -447,18 +447,18 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
447447
if (cmp < 0)
448448
break;
449449
if (entrylen == namelen) {
450-
hashcpy(result, sha1);
450+
hashcpy(result, oid->hash);
451451
return 0;
452452
}
453453
if (name[entrylen] != '/')
454454
continue;
455455
if (!S_ISDIR(*mode))
456456
break;
457457
if (++entrylen == namelen) {
458-
hashcpy(result, sha1);
458+
hashcpy(result, oid->hash);
459459
return 0;
460460
}
461-
return get_tree_entry(sha1, name + entrylen, result, mode);
461+
return get_tree_entry(oid->hash, name + entrylen, result, mode);
462462
}
463463
return -1;
464464
}

tree-walk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ struct tree_desc {
1313
unsigned int size;
1414
};
1515

16-
static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
16+
static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
1717
{
1818
*pathp = desc->entry.path;
1919
*modep = desc->entry.mode;
20-
return desc->entry.oid->hash;
20+
return desc->entry.oid;
2121
}
2222

2323
static inline int tree_entry_len(const struct name_entry *ne)

0 commit comments

Comments
 (0)