Skip to content

Commit e0a9280

Browse files
bk2204gitster
authored andcommitted
Convert struct cache_tree to use struct object_id
Convert the sha1 member of struct cache_tree to struct object_id by changing the definition and applying the following semantic patch, plus the standard object_id transforms: @@ struct cache_tree E1; @@ - E1.sha1 + E1.oid.hash @@ struct cache_tree *E1; @@ - E1->sha1 + E1->oid.hash Fix up one reference to active_cache_tree which was not automatically caught by Coccinelle. These changes are prerequisites for converting parse_object. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb4e352 commit e0a9280

File tree

8 files changed

+27
-24
lines changed

8 files changed

+27
-24
lines changed

builtin/commit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17581758
append_merge_tag_headers(parents, &tail);
17591759
}
17601760

1761-
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,
1761+
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash,
17621762
parents, oid.hash, author_ident.buf, sign_commit, extra)) {
17631763
rollback_index_files();
17641764
die(_("failed to write commit object"));

builtin/fsck.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,10 @@ static int fsck_cache_tree(struct cache_tree *it)
599599
fprintf(stderr, "Checking cache tree\n");
600600

601601
if (0 <= it->entry_count) {
602-
struct object *obj = parse_object(it->sha1);
602+
struct object *obj = parse_object(it->oid.hash);
603603
if (!obj) {
604604
error("%s: invalid sha1 pointer in cache-tree",
605-
sha1_to_hex(it->sha1));
605+
oid_to_hex(&it->oid));
606606
errors_found |= ERROR_REFS;
607607
return 1;
608608
}

cache-tree.c

+16-15
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
225225
int i;
226226
if (!it)
227227
return 0;
228-
if (it->entry_count < 0 || !has_sha1_file(it->sha1))
228+
if (it->entry_count < 0 || !has_sha1_file(it->oid.hash))
229229
return 0;
230230
for (i = 0; i < it->subtree_nr; i++) {
231231
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it,
253253

254254
*skip_count = 0;
255255

256-
if (0 <= it->entry_count && has_sha1_file(it->sha1))
256+
if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
257257
return it->entry_count;
258258

259259
/*
@@ -340,7 +340,7 @@ static int update_one(struct cache_tree *it,
340340
die("cache-tree.c: '%.*s' in '%s' not found",
341341
entlen, path + baselen, path);
342342
i += sub->count;
343-
sha1 = sub->cache_tree->sha1;
343+
sha1 = sub->cache_tree->oid.hash;
344344
mode = S_IFDIR;
345345
contains_ita = sub->cache_tree->entry_count < 0;
346346
if (contains_ita) {
@@ -402,12 +402,13 @@ static int update_one(struct cache_tree *it,
402402
unsigned char sha1[20];
403403
hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1);
404404
if (has_sha1_file(sha1))
405-
hashcpy(it->sha1, sha1);
405+
hashcpy(it->oid.hash, sha1);
406406
else
407407
to_invalidate = 1;
408408
} else if (dryrun)
409-
hash_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1);
410-
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1)) {
409+
hash_sha1_file(buffer.buf, buffer.len, tree_type,
410+
it->oid.hash);
411+
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) {
411412
strbuf_release(&buffer);
412413
return -1;
413414
}
@@ -417,7 +418,7 @@ static int update_one(struct cache_tree *it,
417418
#if DEBUG
418419
fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n",
419420
it->entry_count, it->subtree_nr,
420-
sha1_to_hex(it->sha1));
421+
oid_to_hex(&it->oid));
421422
#endif
422423
return i;
423424
}
@@ -457,14 +458,14 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it,
457458
if (0 <= it->entry_count)
458459
fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n",
459460
pathlen, path, it->entry_count, it->subtree_nr,
460-
sha1_to_hex(it->sha1));
461+
oid_to_hex(&it->oid));
461462
else
462463
fprintf(stderr, "cache-tree <%.*s> (%d subtree) invalid\n",
463464
pathlen, path, it->subtree_nr);
464465
#endif
465466

466467
if (0 <= it->entry_count) {
467-
strbuf_add(buffer, it->sha1, 20);
468+
strbuf_add(buffer, it->oid.hash, 20);
468469
}
469470
for (i = 0; i < it->subtree_nr; i++) {
470471
struct cache_tree_sub *down = it->down[i];
@@ -521,7 +522,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
521522
if (0 <= it->entry_count) {
522523
if (size < 20)
523524
goto free_return;
524-
hashcpy(it->sha1, (const unsigned char*)buf);
525+
hashcpy(it->oid.hash, (const unsigned char*)buf);
525526
buf += 20;
526527
size -= 20;
527528
}
@@ -530,7 +531,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
530531
if (0 <= it->entry_count)
531532
fprintf(stderr, "cache-tree <%s> (%d ent, %d subtree) %s\n",
532533
*buffer, it->entry_count, subtree_nr,
533-
sha1_to_hex(it->sha1));
534+
oid_to_hex(&it->oid));
534535
else
535536
fprintf(stderr, "cache-tree <%s> (%d subtrees) invalid\n",
536537
*buffer, subtree_nr);
@@ -641,10 +642,10 @@ int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, co
641642
subtree = cache_tree_find(index_state->cache_tree, prefix);
642643
if (!subtree)
643644
return WRITE_TREE_PREFIX_ERROR;
644-
hashcpy(sha1, subtree->sha1);
645+
hashcpy(sha1, subtree->oid.hash);
645646
}
646647
else
647-
hashcpy(sha1, index_state->cache_tree->sha1);
648+
hashcpy(sha1, index_state->cache_tree->oid.hash);
648649

649650
if (0 <= newfd)
650651
rollback_lock_file(lock_file);
@@ -663,7 +664,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
663664
struct name_entry entry;
664665
int cnt;
665666

666-
hashcpy(it->sha1, tree->object.oid.hash);
667+
oidcpy(&it->oid, &tree->object.oid);
667668
init_tree_desc(&desc, tree->buffer, tree->size);
668669
cnt = 0;
669670
while (tree_entry(&desc, &entry)) {
@@ -718,7 +719,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
718719

719720
it = find_cache_tree_from_traversal(root, info);
720721
it = cache_tree_find(it, ent->path);
721-
if (it && it->entry_count > 0 && !hashcmp(ent->oid->hash, it->sha1))
722+
if (it && it->entry_count > 0 && !oidcmp(ent->oid, &it->oid))
722723
return it->entry_count;
723724
return 0;
724725
}

cache-tree.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CACHE_TREE_H
22
#define CACHE_TREE_H
33

4+
#include "cache.h"
45
#include "tree.h"
56
#include "tree-walk.h"
67

@@ -15,7 +16,7 @@ struct cache_tree_sub {
1516

1617
struct cache_tree {
1718
int entry_count; /* negative means "invalid" */
18-
unsigned char sha1[20];
19+
struct object_id oid;
1920
int subtree_nr;
2021
int subtree_alloc;
2122
struct cache_tree_sub **down;

merge-recursive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
304304
return NULL;
305305
}
306306

307-
result = lookup_tree(active_cache_tree->sha1);
307+
result = lookup_tree(active_cache_tree->oid.hash);
308308

309309
return result;
310310
}

revision.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
12491249
int i;
12501250

12511251
if (it->entry_count >= 0) {
1252-
struct tree *tree = lookup_tree(it->sha1);
1252+
struct tree *tree = lookup_tree(it->oid.hash);
12531253
add_pending_object_with_path(revs, &tree->object, "",
12541254
040000, path->buf);
12551255
}

sequencer.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ static int is_index_unchanged(void)
508508
if (cache_tree_update(&the_index, 0))
509509
return error(_("unable to update cache tree\n"));
510510

511-
return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.oid.hash);
511+
return !oidcmp(&active_cache_tree->oid,
512+
&head_commit->tree->object.oid);
512513
}
513514

514515
static int write_author_script(const char *message)

t/helper/test-dump-cache-tree.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
1010
"invalid", x, pfx, it->subtree_nr);
1111
else
1212
printf("%s %s%s (%d entries, %d subtrees)\n",
13-
sha1_to_hex(it->sha1), x, pfx,
13+
oid_to_hex(&it->oid), x, pfx,
1414
it->entry_count, it->subtree_nr);
1515
}
1616

@@ -32,7 +32,7 @@ static int dump_cache_tree(struct cache_tree *it,
3232
}
3333
else {
3434
dump_one(it, pfx, "");
35-
if (hashcmp(it->sha1, ref->sha1) ||
35+
if (oidcmp(&it->oid, &ref->oid) ||
3636
ref->entry_count != it->entry_count ||
3737
ref->subtree_nr != it->subtree_nr) {
3838
/* claims to be valid but is lying */

0 commit comments

Comments
 (0)