Skip to content

Commit 42f5ba5

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 18f1ad7 commit 42f5ba5

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

builtin/diff.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#define DIFF_NO_INDEX_EXPLICIT 1
2121
#define DIFF_NO_INDEX_IMPLICIT 2
2222

23-
struct blobinfo {
24-
struct object_id oid;
25-
const char *name;
26-
unsigned mode;
27-
};
28-
2923
static const char builtin_diff_usage[] =
3024
"git diff [<options>] [<commit> [<commit>]] [--] [<path>...]";
3125

@@ -65,7 +59,7 @@ static void stuff_change(struct diff_options *opt,
6559

6660
static int builtin_diff_b_f(struct rev_info *revs,
6761
int argc, const char **argv,
68-
struct blobinfo *blob)
62+
struct object_array_entry **blob)
6963
{
7064
/* Blob vs file in the working tree*/
7165
struct stat st;
@@ -84,12 +78,12 @@ static int builtin_diff_b_f(struct rev_info *revs,
8478

8579
diff_set_mnemonic_prefix(&revs->diffopt, "o/", "w/");
8680

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);
8983

9084
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,
9387
1, 0,
9488
path, path);
9589
diffcore_std(&revs->diffopt);
@@ -99,24 +93,24 @@ static int builtin_diff_b_f(struct rev_info *revs,
9993

10094
static int builtin_diff_blobs(struct rev_info *revs,
10195
int argc, const char **argv,
102-
struct blobinfo *blob)
96+
struct object_array_entry **blob)
10397
{
10498
unsigned mode = canon_mode(S_IFREG | 0644);
10599

106100
if (argc > 1)
107101
usage(builtin_diff_usage);
108102

109-
if (blob[0].mode == S_IFINVALID)
110-
blob[0].mode = mode;
103+
if (blob[0]->mode == S_IFINVALID)
104+
blob[0]->mode = mode;
111105

112-
if (blob[1].mode == S_IFINVALID)
113-
blob[1].mode = mode;
106+
if (blob[1]->mode == S_IFINVALID)
107+
blob[1]->mode = mode;
114108

115109
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,
118112
1, 1,
119-
blob[0].name, blob[1].name);
113+
blob[0]->name, blob[1]->name);
120114
diffcore_std(&revs->diffopt);
121115
diff_flush(&revs->diffopt);
122116
return 0;
@@ -259,7 +253,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
259253
struct rev_info rev;
260254
struct object_array ent = OBJECT_ARRAY_INIT;
261255
int blobs = 0, paths = 0;
262-
struct blobinfo blob[2];
256+
struct object_array_entry *blob[2];
263257
int nongit = 0, no_index = 0;
264258
int result = 0;
265259

@@ -408,9 +402,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
408402
} else if (obj->type == OBJ_BLOB) {
409403
if (2 <= blobs)
410404
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;
414406
blobs++;
415407

416408
} else {

0 commit comments

Comments
 (0)