From: "Michael S. Tsirkin" <mst@redhat.com>
To: git@vger.kernel.org
Cc: sunshine@sunshineco.com, jrnieder@gmail.com, peff@peff.net,
gitster@pobox.com
Subject: [PATCH v5 6/9] patch-id-test: test stable and unstable behaviour
Date: Thu, 24 Apr 2014 12:31:07 +0300 [thread overview]
Message-ID: <1398331809-11309-6-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1398331809-11309-1-git-send-email-mst@redhat.com>
Verify that patch ID supports an algorithm
that is stable against diff split and reordering.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
t/t4204-patch-id.sh | 128 +++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 117 insertions(+), 11 deletions(-)
diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh
index d2c930d..cd13e8e 100755
--- a/t/t4204-patch-id.sh
+++ b/t/t4204-patch-id.sh
@@ -5,27 +5,51 @@ test_description='git patch-id'
. ./test-lib.sh
test_expect_success 'setup' '
- test_commit initial foo a &&
- test_commit first foo b &&
- git checkout -b same HEAD^ &&
- test_commit same-msg foo b &&
- git checkout -b notsame HEAD^ &&
- test_commit notsame-msg foo c
+ as="a a a a a a a a" && # eight a
+ test_write_lines $as >foo &&
+ test_write_lines $as >bar &&
+ git add foo bar &&
+ git commit -a -m initial &&
+ test_write_lines $as b >foo &&
+ test_write_lines $as b >bar &&
+ git commit -a -m first &&
+ git checkout -b same master &&
+ git commit --amend -m same-msg &&
+ git checkout -b notsame master &&
+ echo c >foo &&
+ echo c >bar &&
+ git commit --amend -a -m notsame-msg &&
+ git checkout -b split master &&
+ test_write_lines d $as b >foo &&
+ test_write_lines d $as b >bar &&
+ git commit -a -m split &&
+ git checkout -b merged master &&
+ git checkout split -- foo bar &&
+ git commit --amend -a -m merged &&
+ test_write_lines bar foo >bar-then-foo &&
+ test_write_lines foo bar >foo-then-bar
'
test_expect_success 'patch-id output is well-formed' '
- git log -p -1 | git patch-id > output &&
+ git log -p -1 | git patch-id >output &&
grep "^[a-f0-9]\{40\} $(git rev-parse HEAD)$" output
'
+#calculate patch id. Make sure output is not empty.
calc_patch_id () {
- git patch-id |
- sed "s# .*##" > patch-id_"$1"
+ name="$1"
+ shift
+ git patch-id "$@" |
+ sed "s/ .*//" >patch-id_"$name" &&
+ test_line_count -gt 0 patch-id_"$name"
+}
+
+get_top_diff () {
+ git log -p -1 "$@" -O bar-then-foo --
}
get_patch_id () {
- git log -p -1 "$1" | git patch-id |
- sed "s# .*##" > patch-id_"$1"
+ get_top_diff "$1" | calc_patch_id "$@"
}
test_expect_success 'patch-id detects equality' '
@@ -56,6 +80,88 @@ test_expect_success 'whitespace is irrelevant in footer' '
test_cmp patch-id_master patch-id_same
'
+cmp_patch_id () {
+ if
+ test "$1" = "relevant"
+ then
+ ! test_cmp patch-id_"$2" patch-id_"$3"
+ else
+ test_cmp patch-id_"$2" patch-id_"$3"
+ fi
+}
+
+test_patch_id_file_order () {
+ relevant="$1"
+ shift
+ name="order-${1}-$relevant"
+ shift
+ get_top_diff "master" | calc_patch_id "$name" "$@" &&
+ git checkout same &&
+ git format-patch -1 --stdout -O foo-then-bar |
+ calc_patch_id "ordered-$name" "$@" &&
+ cmp_patch_id $relevant "$name" "ordered-$name"
+
+}
+
+test_patch_id_split () {
+ relevant="$1"
+ shift
+ name="split-${1}-$relevant"
+ shift
+ get_top_diff merged | calc_patch_id "$name" "$@" &&
+ (git log -p -1 -O foo-then-bar split~1; git diff split~1..split) |
+ calc_patch_id "split-$name" "$@" &&
+ cmp_patch_id "$relevant" "$name" "split-$name"
+}
+
+# combined test for options
+test_patch_id () {
+ test_patch_id_file_order "$@" &&
+ test_patch_id_split "$@"
+}
+
+# small tests with detailed diagnostic for basic options.
+test_expect_success 'file order is irrelevant with --stable' '
+ test_patch_id_file_order irrelevant --stable --stable
+'
+
+test_expect_success 'file order is relevant with --unstable' '
+ test_patch_id_file_order relevant --unstable --unstable
+'
+
+test_expect_success 'splitting patch is irrelevant with --stable' '
+ test_patch_id_split irrelevant --stable --stable
+'
+
+test_expect_success 'splitting patch affects id with --unstable' '
+ test_patch_id_split relevant --unstable --unstable
+'
+
+#Now test various option combinations.
+test_expect_success 'default is unstable' '
+ test_patch_id relevant default
+'
+
+test_expect_success 'patchid.stable = true is stable' '
+ test_config patchid.stable true &&
+ test_patch_id irrelevant patchid.stable=true
+'
+
+test_expect_success 'patchid.stable = false is unstable' '
+ test_config patchid.stable false &&
+ test_patch_id relevant patchid.stable=false
+'
+
+test_expect_success '--unstable overrides patchid.stable = true' '
+ test_config patchid.stable true &&
+ test_patch_id relevant patchid.stable=true--unstable --unstable
+'
+
+test_expect_success '--stable overrides patchid.stable = false' '
+ test_config patchid.stable false &&
+ test_patch_id irrelevant patchid.stable=false--stable --stable
+'
+
test_expect_success 'patch-id supports git-format-patch MIME output' '
get_patch_id master &&
git checkout same &&
--
MST
next prev parent reply other threads:[~2014-04-24 9:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-24 9:30 [PATCH v5 1/9] diff: add a config option to control orderfile Michael S. Tsirkin
2014-04-24 9:30 ` [PATCH v5 2/9] test: add test_write_lines helper Michael S. Tsirkin
2014-04-24 17:08 ` Jonathan Nieder
2014-04-24 18:31 ` Junio C Hamano
2014-04-24 9:30 ` [PATCH v5 3/9] tests: new test for orderfile options Michael S. Tsirkin
2014-04-24 17:11 ` Jonathan Nieder
2014-04-24 18:45 ` Junio C Hamano
2014-04-24 21:39 ` Michael S. Tsirkin
2014-04-24 9:31 ` [PATCH v5 4/9] patch-id: make it stable against hunk reordering Michael S. Tsirkin
2014-04-24 17:30 ` Jonathan Nieder
2014-04-24 19:12 ` Junio C Hamano
2014-04-24 21:32 ` Michael S. Tsirkin
2014-04-24 9:31 ` [PATCH v5 5/9] patch-id: document new behaviour Michael S. Tsirkin
2014-04-24 17:33 ` Jonathan Nieder
2014-04-24 21:26 ` Michael S. Tsirkin
2014-04-24 22:12 ` Junio C Hamano
2014-04-27 18:26 ` Michael S. Tsirkin
2014-04-24 9:31 ` Michael S. Tsirkin [this message]
2014-04-24 9:31 ` [PATCH v5 7/9] patch-id: change default to stable Michael S. Tsirkin
2014-04-24 9:31 ` [PATCH v5 8/9] t4204-patch-id.sh: default is now stable Michael S. Tsirkin
2014-04-24 9:31 ` [PATCH v5 9/9] Documentation/git-patch-id.txt: default is stable Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1398331809-11309-6-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).