diff options
author | Jeff King <peff@peff.net> | 2017-05-19 14:59:15 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-24 03:59:27 +0200 |
commit | 158b06caee5f9ea2987f444b8e49bd2d678b187d (patch) | |
tree | c7038b47c4392461e760b97f0d4ef0d9a766f073 /builtin | |
parent | diff: use the word "path" instead of "name" for blobs (diff) | |
download | git-158b06caee5f9ea2987f444b8e49bd2d678b187d.tar.xz git-158b06caee5f9ea2987f444b8e49bd2d678b187d.zip |
diff: use pending "path" if it is available
There's a subtle distinction between "name" and "path" for a
blob that we resolve: the name is what the user told us on
the command line, and the path is what we traversed when
finding the blob within a tree (if we did so).
When we diff blobs directly, we use "name", but "path" is
more likely to be useful to the user (it will find the
correct .gitattributes, and give them a saner diff header).
We still have to fall back to using the name for some cases
(i.e., any blob reference that isn't of the form tree:path).
That's the best we can do in such a case.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/diff.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/builtin/diff.c b/builtin/diff.c index 4c0811d6fc..1a1149eed4 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -23,6 +23,11 @@ static const char builtin_diff_usage[] = "git diff [<options>] [<commit> [<commit>]] [--] [<path>...]"; +static const char *blob_path(struct object_array_entry *entry) +{ + return entry->path ? entry->path : entry->name; +} + static void stuff_change(struct diff_options *opt, unsigned old_mode, unsigned new_mode, const struct object_id *old_oid, @@ -110,7 +115,7 @@ static int builtin_diff_blobs(struct rev_info *revs, blob[0]->mode, blob[1]->mode, &blob[0]->item->oid, &blob[1]->item->oid, 1, 1, - blob[0]->name, blob[1]->name); + blob_path(blob[0]), blob_path(blob[1])); diffcore_std(&revs->diffopt); diff_flush(&revs->diffopt); return 0; |