tree-walk: convert tree_entry_extract() to use struct object_id
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
ce6663a9da77c0adc0743e801946dc1a49f4a186
5 files changed
+17
-17
fsck.c
+3
-3
@@ -450,11 +450,11 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
450
while (desc.size) {
451
unsigned mode;
452
const char *name;
453
- const unsigned char *sha1;
453
+ const struct object_id *oid;
454
455
- sha1 = tree_entry_extract(&desc, &name, &mode);
455
+ oid = tree_entry_extract(&desc, &name, &mode);
456
457
- has_null_sha1 |= is_null_sha1(sha1);
457
+ has_null_sha1 |= is_null_oid(oid);
458
has_full_path |= !!strchr(name, '/');
459
has_empty_name |= !*name;
460
has_dot |= !strcmp(name, ".");
match-trees.c
+6
-6
@@ -131,14 +131,14 @@ static void match_trees(const unsigned char *hash1,
131
132
while (one.size) {
133
const char *path;
134
- const unsigned char *elem;
134
+ const struct object_id *elem;
135
unsigned mode;
136
int score;
137
138
elem = tree_entry_extract(&one, &path, &mode);
139
if (!S_ISDIR(mode))
140
goto next;
141
- score = score_trees(elem, hash2);
141
+ score = score_trees(elem->hash, hash2);
142
if (*best_score < score) {
143
free(*best_match);
144
*best_match = xstrfmt("%s%s", base, path);
@@ -146,7 +146,7 @@ static void match_trees(const unsigned char *hash1,
146
}
147
if (recurse_limit) {
148
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,
150
newbase, recurse_limit - 1);
151
free(newbase);
152
}
@@ -191,15 +191,15 @@ static int splice_tree(const unsigned char *hash1,
191
while (desc.size) {
192
const char *name;
193
unsigned mode;
194
- const unsigned char *sha1;
194
+ const struct object_id *oid;
195
196
- sha1 = tree_entry_extract(&desc, &name, &mode);
196
+ oid = tree_entry_extract(&desc, &name, &mode);
197
if (strlen(name) == toplen &&
198
!memcmp(name, prefix, toplen)) {
199
if (!S_ISDIR(mode))
200
die("entry %s in tree %s is not a tree",
201
name, sha1_to_hex(hash1));
202
- rewrite_here = (unsigned char *) sha1;
202
+ rewrite_here = (unsigned char *) oid->hash;
203
break;
204
}
205
update_tree_entry(&desc);
tree-diff.c
+1
-1
@@ -183,7 +183,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
183
184
if (t) {
185
/* path present in resulting tree */
186
- sha1 = tree_entry_extract(t, &path, &mode);
186
+ sha1 = tree_entry_extract(t, &path, &mode)->hash;
187
pathlen = tree_entry_len(&t->entry);
188
isdir = S_ISDIR(mode);
189
} else {
tree-walk.c
+5
-5
@@ -433,10 +433,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
433
int namelen = strlen(name);
434
while (t->size) {
435
const char *entry;
436
- const unsigned char *sha1;
436
+ const struct object_id *oid;
437
int entrylen, cmp;
438
439
- sha1 = tree_entry_extract(t, &entry, mode);
439
+ oid = tree_entry_extract(t, &entry, mode);
440
entrylen = tree_entry_len(&t->entry);
441
update_tree_entry(t);
442
if (entrylen > namelen)
@@ -447,7 +447,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
447
if (cmp < 0)
448
break;
449
if (entrylen == namelen) {
450
- hashcpy(result, sha1);
450
+ hashcpy(result, oid->hash);
451
return 0;
452
}
453
if (name[entrylen] != '/')
@@ -455,10 +455,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
455
if (!S_ISDIR(*mode))
456
break;
457
if (++entrylen == namelen) {
458
- hashcpy(result, sha1);
458
+ hashcpy(result, oid->hash);
459
return 0;
460
}
461
- return get_tree_entry(sha1, name + entrylen, result, mode);
461
+ return get_tree_entry(oid->hash, name + entrylen, result, mode);
462
}
463
return -1;
464
}
tree-walk.h
+2
-2
@@ -13,11 +13,11 @@ struct tree_desc {
13
unsigned int size;
14
};
15
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)
17
{
18
*pathp = desc->entry.path;
19
*modep = desc->entry.mode;
20
- return desc->entry.oid->hash;
20
+ return desc->entry.oid;
21
}
22
23
static inline int tree_entry_len(const struct name_entry *ne)