summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2010-05-30 13:37:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-06-01 00:44:01 (GMT)
commit3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf (patch)
tree126ef36605cca11b458eeee5c9e4150a4effe553 /diff.c
parent81fa024cd8e336ba257f13fe7724b95baacfa3ad (diff)
downloadgit-3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf.zip
git-3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf.tar.gz
git-3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf.tar.bz2
diff.c: Ensure "index $from..$to" line contains unambiguous SHA1s
In the metainfo section of git diffs there's an "index" line providing abbreviated (unless --full-index is used) blob SHA1s from the pre-/post-images used to generate the diff. These provide hints that can be used to reconstruct a 3-way merge when applying the patch (see the --3way option to 'git am' for more details). In order for this to work, however, the blob SHA1s must not be abbreviated into ambiguity. This patch eliminates the possible ambiguity by using find_unique_abbrev() to produce the abbreviated SHA1s (instead of blind abbreviation by way of "%.*s"). A testcase verifying the fix is also included. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/diff.c b/diff.c
index 494f560..1aefa66 100644
--- a/diff.c
+++ b/diff.c
@@ -2419,9 +2419,9 @@ static void fill_metainfo(struct strbuf *msg,
(!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
abbrev = 40;
}
- strbuf_addf(msg, "index %.*s..%.*s",
- abbrev, sha1_to_hex(one->sha1),
- abbrev, sha1_to_hex(two->sha1));
+ strbuf_addf(msg, "index %s..",
+ find_unique_abbrev(one->sha1, abbrev));
+ strbuf_addstr(msg, find_unique_abbrev(two->sha1, abbrev));
if (one->mode == two->mode)
strbuf_addf(msg, " %06o", one->mode);
strbuf_addch(msg, '\n');