builtin/diff: convert to 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 Mar 26, 2017 at 16:01 UTC 9c4b0f66aab720a997228c071c671454196706d6
1 file changed +17 -17
builtin/diff.c
+17 -17
@@ -21,7 +21,7 @@
21 #define DIFF_NO_INDEX_IMPLICIT 2
22
23 struct blobinfo {
24 - unsigned char sha1[20];
24 + struct object_id oid;
25 const char *name;
26 unsigned mode;
27 };
@@ -31,22 +31,22 @@ static const char builtin_diff_usage[] =
31
32 static void stuff_change(struct diff_options *opt,
33 unsigned old_mode, unsigned new_mode,
34 - const unsigned char *old_sha1,
35 - const unsigned char *new_sha1,
36 - int old_sha1_valid,
37 - int new_sha1_valid,
34 + const struct object_id *old_oid,
35 + const struct object_id *new_oid,
36 + int old_oid_valid,
37 + int new_oid_valid,
38 const char *old_name,
39 const char *new_name)
40 {
41 struct diff_filespec *one, *two;
42
43 - if (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&
44 - !hashcmp(old_sha1, new_sha1) && (old_mode == new_mode))
43 + if (!is_null_oid(old_oid) && !is_null_oid(new_oid) &&
44 + !oidcmp(old_oid, new_oid) && (old_mode == new_mode))
45 return;
46
47 if (DIFF_OPT_TST(opt, REVERSE_DIFF)) {
48 SWAP(old_mode, new_mode);
49 - SWAP(old_sha1, new_sha1);
49 + SWAP(old_oid, new_oid);
50 SWAP(old_name, new_name);
51 }
52
@@ -57,8 +57,8 @@ static void stuff_change(struct diff_options *opt,
57
58 one = alloc_filespec(old_name);
59 two = alloc_filespec(new_name);
60 - fill_filespec(one, old_sha1, old_sha1_valid, old_mode);
61 - fill_filespec(two, new_sha1, new_sha1_valid, new_mode);
60 + fill_filespec(one, old_oid->hash, old_oid_valid, old_mode);
61 + fill_filespec(two, new_oid->hash, new_oid_valid, new_mode);
62
63 diff_queue(&diff_queued_diff, one, two);
64 }
@@ -89,7 +89,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
89
90 stuff_change(&revs->diffopt,
91 blob[0].mode, canon_mode(st.st_mode),
92 - blob[0].sha1, null_sha1,
92 + &blob[0].oid, &null_oid,
93 1, 0,
94 path, path);
95 diffcore_std(&revs->diffopt);
@@ -114,7 +114,7 @@ static int builtin_diff_blobs(struct rev_info *revs,
114
115 stuff_change(&revs->diffopt,
116 blob[0].mode, blob[1].mode,
117 - blob[0].sha1, blob[1].sha1,
117 + &blob[0].oid, &blob[1].oid,
118 1, 1,
119 blob[0].name, blob[1].name);
120 diffcore_std(&revs->diffopt);
@@ -160,7 +160,7 @@ static int builtin_diff_tree(struct rev_info *revs,
160 struct object_array_entry *ent0,
161 struct object_array_entry *ent1)
162 {
163 - const unsigned char *(sha1[2]);
163 + const struct object_id *(oid[2]);
164 int swap = 0;
165
166 if (argc > 1)
@@ -172,9 +172,9 @@ static int builtin_diff_tree(struct rev_info *revs,
172 */
173 if (ent1->item->flags & UNINTERESTING)
174 swap = 1;
175 - sha1[swap] = ent0->item->oid.hash;
176 - sha1[1 - swap] = ent1->item->oid.hash;
177 - diff_tree_sha1(sha1[0], sha1[1], "", &revs->diffopt);
175 + oid[swap] = &ent0->item->oid;
176 + oid[1 - swap] = &ent1->item->oid;
177 + diff_tree_sha1(oid[0]->hash, oid[1]->hash, "", &revs->diffopt);
178 log_tree_diff_flush(revs);
179 return 0;
180 }
@@ -408,7 +408,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
408 } else if (obj->type == OBJ_BLOB) {
409 if (2 <= blobs)
410 die(_("more than two blobs given: '%s'"), name);
411 - hashcpy(blob[blobs].sha1, obj->oid.hash);
411 + hashcpy(blob[blobs].oid.hash, obj->oid.hash);
412 blob[blobs].name = name;
413 blob[blobs].mode = entry->mode;
414 blobs++;