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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 1, 2017 at 02:28 UTC
e0a92804044a4025fc8abbfa1d92fd16f6f2e1f4
8 files changed
+27
-24
builtin/commit.c
+1
-1
@@ -1758,7 +1758,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1758
append_merge_tag_headers(parents, &tail);
1759
}
1760
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,
1762
parents, oid.hash, author_ident.buf, sign_commit, extra)) {
1763
rollback_index_files();
1764
die(_("failed to write commit object"));
builtin/fsck.c
+2
-2
@@ -599,10 +599,10 @@ static int fsck_cache_tree(struct cache_tree *it)
599
fprintf(stderr, "Checking cache tree\n");
600
601
if (0 <= it->entry_count) {
602
- struct object *obj = parse_object(it->sha1);
602
+ struct object *obj = parse_object(it->oid.hash);
603
if (!obj) {
604
error("%s: invalid sha1 pointer in cache-tree",
605
- sha1_to_hex(it->sha1));
605
+ oid_to_hex(&it->oid));
606
errors_found |= ERROR_REFS;
607
return 1;
608
}
cache-tree.c
+16
-15
@@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
225
int i;
226
if (!it)
227
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))
229
return 0;
230
for (i = 0; i < it->subtree_nr; i++) {
231
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it,
253
254
*skip_count = 0;
255
256
- if (0 <= it->entry_count && has_sha1_file(it->sha1))
256
+ if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
257
return it->entry_count;
258
259
/*
@@ -340,7 +340,7 @@ static int update_one(struct cache_tree *it,
340
die("cache-tree.c: '%.*s' in '%s' not found",
341
entlen, path + baselen, path);
342
i += sub->count;
343
- sha1 = sub->cache_tree->sha1;
343
+ sha1 = sub->cache_tree->oid.hash;
344
mode = S_IFDIR;
345
contains_ita = sub->cache_tree->entry_count < 0;
346
if (contains_ita) {
@@ -402,12 +402,13 @@ static int update_one(struct cache_tree *it,
402
unsigned char sha1[20];
403
hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1);
404
if (has_sha1_file(sha1))
405
- hashcpy(it->sha1, sha1);
405
+ hashcpy(it->oid.hash, sha1);
406
else
407
to_invalidate = 1;
408
} 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)) {
412
strbuf_release(&buffer);
413
return -1;
414
}
@@ -417,7 +418,7 @@ static int update_one(struct cache_tree *it,
418
#if DEBUG
419
fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n",
420
it->entry_count, it->subtree_nr,
420
- sha1_to_hex(it->sha1));
421
+ oid_to_hex(&it->oid));
422
#endif
423
return i;
424
}
@@ -457,14 +458,14 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it,
458
if (0 <= it->entry_count)
459
fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n",
460
pathlen, path, it->entry_count, it->subtree_nr,
460
- sha1_to_hex(it->sha1));
461
+ oid_to_hex(&it->oid));
462
else
463
fprintf(stderr, "cache-tree <%.*s> (%d subtree) invalid\n",
464
pathlen, path, it->subtree_nr);
465
#endif
466
467
if (0 <= it->entry_count) {
467
- strbuf_add(buffer, it->sha1, 20);
468
+ strbuf_add(buffer, it->oid.hash, 20);
469
}
470
for (i = 0; i < it->subtree_nr; i++) {
471
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)
522
if (0 <= it->entry_count) {
523
if (size < 20)
524
goto free_return;
524
- hashcpy(it->sha1, (const unsigned char*)buf);
525
+ hashcpy(it->oid.hash, (const unsigned char*)buf);
526
buf += 20;
527
size -= 20;
528
}
@@ -530,7 +531,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
531
if (0 <= it->entry_count)
532
fprintf(stderr, "cache-tree <%s> (%d ent, %d subtree) %s\n",
533
*buffer, it->entry_count, subtree_nr,
533
- sha1_to_hex(it->sha1));
534
+ oid_to_hex(&it->oid));
535
else
536
fprintf(stderr, "cache-tree <%s> (%d subtrees) invalid\n",
537
*buffer, subtree_nr);
@@ -641,10 +642,10 @@ int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, co
642
subtree = cache_tree_find(index_state->cache_tree, prefix);
643
if (!subtree)
644
return WRITE_TREE_PREFIX_ERROR;
644
- hashcpy(sha1, subtree->sha1);
645
+ hashcpy(sha1, subtree->oid.hash);
646
}
647
else
647
- hashcpy(sha1, index_state->cache_tree->sha1);
648
+ hashcpy(sha1, index_state->cache_tree->oid.hash);
649
650
if (0 <= newfd)
651
rollback_lock_file(lock_file);
@@ -663,7 +664,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
664
struct name_entry entry;
665
int cnt;
666
666
- hashcpy(it->sha1, tree->object.oid.hash);
667
+ oidcpy(&it->oid, &tree->object.oid);
668
init_tree_desc(&desc, tree->buffer, tree->size);
669
cnt = 0;
670
while (tree_entry(&desc, &entry)) {
@@ -718,7 +719,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
719
720
it = find_cache_tree_from_traversal(root, info);
721
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))
723
return it->entry_count;
724
return 0;
725
}
cache-tree.h
+2
-1
@@ -1,6 +1,7 @@
1
#ifndef CACHE_TREE_H
2
#define CACHE_TREE_H
3
4
+#include "cache.h"
5
#include "tree.h"
6
#include "tree-walk.h"
7
@@ -15,7 +16,7 @@ struct cache_tree_sub {
16
17
struct cache_tree {
18
int entry_count; /* negative means "invalid" */
18
- unsigned char sha1[20];
19
+ struct object_id oid;
20
int subtree_nr;
21
int subtree_alloc;
22
struct cache_tree_sub **down;
merge-recursive.c
+1
-1
@@ -304,7 +304,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
304
return NULL;
305
}
306
307
- result = lookup_tree(active_cache_tree->sha1);
307
+ result = lookup_tree(active_cache_tree->oid.hash);
308
309
return result;
310
}
revision.c
+1
-1
@@ -1249,7 +1249,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1249
int i;
1250
1251
if (it->entry_count >= 0) {
1252
- struct tree *tree = lookup_tree(it->sha1);
1252
+ struct tree *tree = lookup_tree(it->oid.hash);
1253
add_pending_object_with_path(revs, &tree->object, "",
1254
040000, path->buf);
1255
}
sequencer.c
+2
-1
@@ -508,7 +508,8 @@ static int is_index_unchanged(void)
508
if (cache_tree_update(&the_index, 0))
509
return error(_("unable to update cache tree\n"));
510
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);
513
}
514
515
static int write_author_script(const char *message)
t/helper/test-dump-cache-tree.c
+2
-2
@@ -10,7 +10,7 @@ static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
10
"invalid", x, pfx, it->subtree_nr);
11
else
12
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,
14
it->entry_count, it->subtree_nr);
15
}
16
@@ -32,7 +32,7 @@ static int dump_cache_tree(struct cache_tree *it,
32
}
33
else {
34
dump_one(it, pfx, "");
35
- if (hashcmp(it->sha1, ref->sha1) ||
35
+ if (oidcmp(&it->oid, &ref->oid) ||
36
ref->entry_count != it->entry_count ||
37
ref->subtree_nr != it->subtree_nr) {
38
/* claims to be valid but is lying */