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 <p...@peff.net>
---
I looked into just passing "blob_a" and "blob_b", instead of passing an
array and letting the called functions decide how many elements
should be in it. But I don't know if we would ever want to handle
arbitrary numbers of blobs (e.g., n-way combined diffs). It would be a
step backwards in that case, so I decided not to.

 builtin/diff.c | 38 +++++++++++++++-----------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/builtin/diff.c b/builtin/diff.c
index d184aafab..8b276ae57 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -20,12 +20,6 @@
 #define DIFF_NO_INDEX_EXPLICIT 1
 #define DIFF_NO_INDEX_IMPLICIT 2
 
-struct blobinfo {
-       struct object_id oid;
-       const char *name;
-       unsigned mode;
-};
-
 static const char builtin_diff_usage[] =
 "git diff [<options>] [<commit> [<commit>]] [--] [<path>...]";
 
@@ -65,7 +59,7 @@ static void stuff_change(struct diff_options *opt,
 
 static int builtin_diff_b_f(struct rev_info *revs,
                            int argc, const char **argv,
-                           struct blobinfo *blob)
+                           struct object_array_entry **blob)
 {
        /* Blob vs file in the working tree*/
        struct stat st;
@@ -84,12 +78,12 @@ static int builtin_diff_b_f(struct rev_info *revs,
 
        diff_set_mnemonic_prefix(&revs->diffopt, "o/", "w/");
 
-       if (blob[0].mode == S_IFINVALID)
-               blob[0].mode = canon_mode(st.st_mode);
+       if (blob[0]->mode == S_IFINVALID)
+               blob[0]->mode = canon_mode(st.st_mode);
 
        stuff_change(&revs->diffopt,
-                    blob[0].mode, canon_mode(st.st_mode),
-                    &blob[0].oid, &null_oid,
+                    blob[0]->mode, canon_mode(st.st_mode),
+                    &blob[0]->item->oid, &null_oid,
                     1, 0,
                     path, path);
        diffcore_std(&revs->diffopt);
@@ -99,24 +93,24 @@ static int builtin_diff_b_f(struct rev_info *revs,
 
 static int builtin_diff_blobs(struct rev_info *revs,
                              int argc, const char **argv,
-                             struct blobinfo *blob)
+                             struct object_array_entry **blob)
 {
        unsigned mode = canon_mode(S_IFREG | 0644);
 
        if (argc > 1)
                usage(builtin_diff_usage);
 
-       if (blob[0].mode == S_IFINVALID)
-               blob[0].mode = mode;
+       if (blob[0]->mode == S_IFINVALID)
+               blob[0]->mode = mode;
 
-       if (blob[1].mode == S_IFINVALID)
-               blob[1].mode = mode;
+       if (blob[1]->mode == S_IFINVALID)
+               blob[1]->mode = mode;
 
        stuff_change(&revs->diffopt,
-                    blob[0].mode, blob[1].mode,
-                    &blob[0].oid, &blob[1].oid,
+                    blob[0]->mode, blob[1]->mode,
+                    &blob[0]->item->oid, &blob[1]->item->oid,
                     1, 1,
-                    blob[0].name, blob[1].name);
+                    blob[0]->name, blob[1]->name);
        diffcore_std(&revs->diffopt);
        diff_flush(&revs->diffopt);
        return 0;
@@ -259,7 +253,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix)
        struct rev_info rev;
        struct object_array ent = OBJECT_ARRAY_INIT;
        int blobs = 0, paths = 0;
-       struct blobinfo blob[2];
+       struct object_array_entry *blob[2];
        int nongit = 0, no_index = 0;
        int result = 0;
 
@@ -408,9 +402,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix)
                } else if (obj->type == OBJ_BLOB) {
                        if (2 <= blobs)
                                die(_("more than two blobs given: '%s'"), name);
-                       hashcpy(blob[blobs].oid.hash, obj->oid.hash);
-                       blob[blobs].name = name;
-                       blob[blobs].mode = entry->mode;
+                       blob[blobs] = entry;
                        blobs++;
 
                } else {
-- 
2.13.0.219.g63f6bc368

Reply via email to