diff: pass whole pending entry in blobinfo

When diffing blobs directly, git-diff picks the blobs out of the rev_info's pending array and copies the relevant bits to a custom "struct blobinfo". But the pending array entry already has all of this information (and more, which we'll use in future patches). Let's just pass the original entry instead. In practice, these two blobs are probably adjacent in the revs->pending array, and we could just pass the whole array. But the current code is careful to pick each blob out separately and put it into another array, so we'll continue to do so and make our own array-of-pointers. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 19, 2017 at 08:57 UTC 42f5ba5bb6648c16a3c90a0110fbdb430e590a1b
1 file changed +15 -23
builtin/diff.c
+15 -23
@@ -20,12 +20,6 @@
20 #define DIFF_NO_INDEX_EXPLICIT 1
21 #define DIFF_NO_INDEX_IMPLICIT 2
22
23 -struct blobinfo {
24 - struct object_id oid;
25 - const char *name;
26 - unsigned mode;
27 -};
28 -
23 static const char builtin_diff_usage[] =
24 "git diff [<options>] [<commit> [<commit>]] [--] [<path>...]";
25
@@ -65,7 +59,7 @@ static void stuff_change(struct diff_options *opt,
59
60 static int builtin_diff_b_f(struct rev_info *revs,
61 int argc, const char **argv,
68 - struct blobinfo *blob)
62 + struct object_array_entry **blob)
63 {
64 /* Blob vs file in the working tree*/
65 struct stat st;
@@ -84,12 +78,12 @@ static int builtin_diff_b_f(struct rev_info *revs,
78
79 diff_set_mnemonic_prefix(&revs->diffopt, "o/", "w/");
80
87 - if (blob[0].mode == S_IFINVALID)
88 - blob[0].mode = canon_mode(st.st_mode);
81 + if (blob[0]->mode == S_IFINVALID)
82 + blob[0]->mode = canon_mode(st.st_mode);
83
84 stuff_change(&revs->diffopt,
91 - blob[0].mode, canon_mode(st.st_mode),
92 - &blob[0].oid, &null_oid,
85 + blob[0]->mode, canon_mode(st.st_mode),
86 + &blob[0]->item->oid, &null_oid,
87 1, 0,
88 path, path);
89 diffcore_std(&revs->diffopt);
@@ -99,24 +93,24 @@ static int builtin_diff_b_f(struct rev_info *revs,
93
94 static int builtin_diff_blobs(struct rev_info *revs,
95 int argc, const char **argv,
102 - struct blobinfo *blob)
96 + struct object_array_entry **blob)
97 {
98 unsigned mode = canon_mode(S_IFREG | 0644);
99
100 if (argc > 1)
101 usage(builtin_diff_usage);
102
109 - if (blob[0].mode == S_IFINVALID)
110 - blob[0].mode = mode;
103 + if (blob[0]->mode == S_IFINVALID)
104 + blob[0]->mode = mode;
105
112 - if (blob[1].mode == S_IFINVALID)
113 - blob[1].mode = mode;
106 + if (blob[1]->mode == S_IFINVALID)
107 + blob[1]->mode = mode;
108
109 stuff_change(&revs->diffopt,
116 - blob[0].mode, blob[1].mode,
117 - &blob[0].oid, &blob[1].oid,
110 + blob[0]->mode, blob[1]->mode,
111 + &blob[0]->item->oid, &blob[1]->item->oid,
112 1, 1,
119 - blob[0].name, blob[1].name);
113 + blob[0]->name, blob[1]->name);
114 diffcore_std(&revs->diffopt);
115 diff_flush(&revs->diffopt);
116 return 0;
@@ -259,7 +253,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
253 struct rev_info rev;
254 struct object_array ent = OBJECT_ARRAY_INIT;
255 int blobs = 0, paths = 0;
262 - struct blobinfo blob[2];
256 + struct object_array_entry *blob[2];
257 int nongit = 0, no_index = 0;
258 int result = 0;
259
@@ -408,9 +402,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
402 } else if (obj->type == OBJ_BLOB) {
403 if (2 <= blobs)
404 die(_("more than two blobs given: '%s'"), name);
411 - hashcpy(blob[blobs].oid.hash, obj->oid.hash);
412 - blob[blobs].name = name;
413 - blob[blobs].mode = entry->mode;
405 + blob[blobs] = entry;
406 blobs++;
407
408 } else {