Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-06-18 22:16:56 +0400
committerJunio C Hamano <gitster@pobox.com>2010-06-18 22:16:56 +0400
commit18fd805583130862632e40e98aecc7edcd16d878 (patch)
treea72e49115b5c03f9291545f44af78394e9765198
parentecdb3ec9846d06750a0d4b79884a763aa91daa40 (diff)
parent3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf (diff)
Merge branch 'jh/diff-index-line-abbrev'
* jh/diff-index-line-abbrev: diff.c: Ensure "index $from..$to" line contains unambiguous SHA1s Conflicts: diff.c
-rw-r--r--diff.c6
-rwxr-xr-xt/t4044-diff-index-unique-abbrev.sh35
2 files changed, 38 insertions, 3 deletions
diff --git a/diff.c b/diff.c
index c82b605a94..b53b6ec8e2 100644
--- a/diff.c
+++ b/diff.c
@@ -2430,9 +2430,9 @@ static void fill_metainfo(struct strbuf *msg,
(!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
abbrev = 40;
}
- strbuf_addf(msg, "%sindex %.*s..%.*s", set,
- abbrev, sha1_to_hex(one->sha1),
- abbrev, sha1_to_hex(two->sha1));
+ strbuf_addf(msg, "%sindex %s..", set,
+ 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_addf(msg, "%s\n", reset);
diff --git a/t/t4044-diff-index-unique-abbrev.sh b/t/t4044-diff-index-unique-abbrev.sh
new file mode 100755
index 0000000000..d5ce72be63
--- /dev/null
+++ b/t/t4044-diff-index-unique-abbrev.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+test_description='test unique sha1 abbreviation on "index from..to" line'
+. ./test-lib.sh
+
+cat >expect_initial <<EOF
+100644 blob 51d2738463ea4ca66f8691c91e33ce64b7d41bb1 foo
+EOF
+
+cat >expect_update <<EOF
+100644 blob 51d2738efb4ad8a1e40bed839ab8e116f0a15e47 foo
+EOF
+
+test_expect_success 'setup' '
+ echo 4827 > foo &&
+ git add foo &&
+ git commit -m "initial" &&
+ git cat-file -p HEAD: > actual &&
+ test_cmp expect_initial actual &&
+ echo 11742 > foo &&
+ git commit -a -m "update" &&
+ git cat-file -p HEAD: > actual &&
+ test_cmp expect_update actual
+'
+
+cat >expect <<EOF
+index 51d27384..51d2738e 100644
+EOF
+
+test_expect_success 'diff does not produce ambiguous index line' '
+ git diff HEAD^..HEAD | grep index > actual &&
+ test_cmp expect actual
+'
+
+test_done