From: Tejun Heo <tj@kernel.org>
To: git@vger.kernel.org, Junio C Hamano <jch2355@gmail.com>,
Jeff King <peff@peff.net>
Cc: kernel-team@fb.com, Tejun Heo <htejun@fb.com>
Subject: [PATCH 5/5] notes: Implement xref-cherry-picks hooks and tests
Date: Tue, 11 Dec 2018 15:49:09 -0800 [thread overview]
Message-ID: <20181211234909.2855638-6-tj@kernel.org> (raw)
In-Reply-To: <20181211234909.2855638-1-tj@kernel.org>
From: Tejun Heo <htejun@fb.com>
Add post-cherry-pick.sample and post-fetch.sample which, when enabled,
will keep refs/notes/xref-cherry-picks up-to-date as new cherry-picks
are created and fetched. Also, add tests to verify xref-cherry-picks.
Signed-off-by: Tejun Heo <htejun@fb.com>
---
Documentation/git-reverse-trailer-xrefs.txt | 9 ++
t/t3321-notes-xref-cherry-picks.sh | 124 ++++++++++++++++++++
templates/hooks--post-cherry-pick.sample | 8 ++
templates/hooks--post-fetch.sample | 30 +++++
4 files changed, 171 insertions(+)
create mode 100644 t/t3321-notes-xref-cherry-picks.sh
create mode 100644 templates/hooks--post-cherry-pick.sample
create mode 100644 templates/hooks--post-fetch.sample
diff --git a/Documentation/git-reverse-trailer-xrefs.txt b/Documentation/git-reverse-trailer-xrefs.txt
index 20d260486..651ecdce1 100644
--- a/Documentation/git-reverse-trailer-xrefs.txt
+++ b/Documentation/git-reverse-trailer-xrefs.txt
@@ -131,6 +131,15 @@ ddd1bf2 commit A
------------
+Keeping xref-cherry-picks up-to-date
+------------------------------------
+
+Reverse-maps can be kept-up incrementally with hooks. For example, to
+keep xref-cherry-picks up-to-date, `git-reverse-trailer-xrefs` should
+be invoked on new cherry-picks and fetched commits. See
+`hooks/post-cherry-pick.sample` and `hooks/post-fetch.sample`.
+
+
GIT
---
Part of the linkgit:git[1] suite
diff --git a/t/t3321-notes-xref-cherry-picks.sh b/t/t3321-notes-xref-cherry-picks.sh
new file mode 100644
index 000000000..96b6731c9
--- /dev/null
+++ b/t/t3321-notes-xref-cherry-picks.sh
@@ -0,0 +1,124 @@
+#!/bin/sh
+
+test_description='Verify xref-cherry-picks handling
+
+Assume the following git repository.
+
+ D*---E** release-B
+ /
+ C* E* release-D
+ / /
+ A---B---C---D---E master
+
+which contains the following cherry-picks.
+
+ C -> C*
+ D -> D*
+ E -> E* -> E**
+
+1. Build the above repository using `git-cherry-pick -x` with the
+ sample post-cherry-pick hook enabled. Verify that the
+ xref-cherry-picks notes are populated correctly.
+
+2. Clear the notes and rebuild them by directly running
+ git-reverse-xref-trailers and verify the output.
+
+3. Run it again and check the output still agrees to verify duplicate
+ handling.
+
+4. Build a cloned repository using per-branch fetches with the sample
+ post-fetch hook enabled. Verify that the xref-cherry-picks notes
+ are populatec correctly.
+'
+
+TEST_NO_CREATE_REPO=1
+
+. ./test-lib.sh
+
+GIT_AUTHOR_EMAIL=bogus_email_address
+export GIT_AUTHOR_EMAIL
+
+test_expect_success \
+ 'Build repo with cherry-picks and verify xref-cherry-picks' \
+ 'test_create_repo main &&
+ cd main &&
+ mkdir -p .git/hooks &&
+ mv .git/hooks-disabled/post-cherry-pick.sample .git/hooks/post-cherry-pick &&
+
+ test_tick &&
+ echo A >> testfile &&
+ git update-index --add testfile &&
+ git commit -am "A" &&
+ echo B >> testfile &&
+ git commit -am "B" &&
+ echo C >> testfile &&
+ git commit -am "C" &&
+ echo D >> testfile &&
+ git commit -am "D" &&
+ echo E >> testfile &&
+ git commit -am "E" &&
+
+ test_tick &&
+ git checkout -b release-D master^ &&
+ git cherry-pick -x master &&
+
+ test_tick &&
+ git checkout -b release-B master^^^ &&
+ git cherry-pick -x release-D^^ &&
+ git cherry-pick -x release-D^ &&
+ git cherry-pick -x release-D &&
+
+ cat > expect <<-EOF &&
+master E
+Notes (xref-cherry-picks):
+ Cherry-picked-to: release-D
+ Cherry-picked-to: release-B
+
+master~1 D
+Notes (xref-cherry-picks):
+ Cherry-picked-to: release-B~1
+
+master~2 C
+Notes (xref-cherry-picks):
+ Cherry-picked-to: release-B~2
+
+master~3 B
+master~4 A
+EOF
+
+ git log --pretty=oneline --notes=xref-cherry-picks master | git name-rev --name-only --stdin > actual &&
+ test_cmp expect actual
+'
+
+test_expect_success \
+ 'Clear, rebuild and verify xref-cherry-picks' \
+ 'git reverse-trailer-xrefs --xref-cherry-picks --all --clear &&
+ git reverse-trailer-xrefs --xref-cherry-picks --all &&
+ git log --pretty=oneline --notes=xref-cherry-picks master | git name-rev --name-only --stdin > actual &&
+ test_cmp expect actual
+'
+
+test_expect_success \
+ 'Build it again to verify duplicate handling' \
+ 'git reverse-trailer-xrefs --xref-cherry-picks --all &&
+ git log --pretty=oneline --notes=xref-cherry-picks master | git name-rev --name-only --stdin > actual &&
+ test_cmp expect actual
+'
+
+test_expect_success \
+ 'Build a clone through per-branch fetches and verify xref-cherry-picks' \
+ 'cd .. &&
+ test_create_repo clone &&
+ cd clone &&
+ mkdir -p .git/hooks &&
+ mv .git/hooks-disabled/post-fetch.sample .git/hooks/post-fetch &&
+
+ git fetch -fu ../main master:master &&
+ git fetch -fu ../main release-D:release-D &&
+ git fetch -fu ../main release-B:release-B &&
+
+ git log --pretty=oneline --notes=xref-cherry-picks master | git name-rev --name-only --stdin > actual &&
+ test_cmp ../main/expect actual
+'
+
+test_done
diff --git a/templates/hooks--post-cherry-pick.sample b/templates/hooks--post-cherry-pick.sample
new file mode 100644
index 000000000..3af8b5d23
--- /dev/null
+++ b/templates/hooks--post-cherry-pick.sample
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# An example hook script to reverse map new cherry-picks. See
+# git-reverse-trailer-xrefs(1) for details.
+#
+# To enable this hook, rename this file to "post-cherry-pick".
+
+git reverse-trailer-xrefs --xref-cherry-picks $1..$2
diff --git a/templates/hooks--post-fetch.sample b/templates/hooks--post-fetch.sample
new file mode 100644
index 000000000..6b98a5c10
--- /dev/null
+++ b/templates/hooks--post-fetch.sample
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# An example hook script to reverse map cherry-picks in newly fetched
+# commits. See git-reverse-trailer-xrefs(1) for details.
+#
+# To enable this hook, rename this file to "post-fetch".
+
+z40=0000000000000000000000000000000000000000
+
+while read ref old_sha remote new_sha
+do
+ case $ref in
+ refs/heads/*)
+ ;;
+ *)
+ continue
+ esac
+
+ if [ $new_sha == $z40 ]
+ then
+ continue
+ fi
+
+ if [ $old_sha != $z40 ]
+ then
+ git reverse-trailer-xrefs --xref-cherry-picks $old_sha..$new_sha
+ else
+ git reverse-trailer-xrefs --xref-cherry-picks $new_sha
+ fi
+done
--
2.17.1
next prev parent reply other threads:[~2018-12-11 23:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-11 23:49 [PATCHSET] git-reverse-trailer-xrefs: Reverse map cherry-picks and other cross-references Tejun Heo
2018-12-11 23:49 ` [PATCH 1/5] trailer: Implement a helper to reverse-map trailer xrefs Tejun Heo
2018-12-11 23:49 ` [PATCH 2/5] notes: Implement special handlings for refs/notes/xref- Tejun Heo
2018-12-11 23:49 ` [PATCH 3/5] notes: Implement git-reverse-trailer-xrefs Tejun Heo
2018-12-11 23:49 ` [PATCH 4/5] githooks: Add post-cherry-pick and post-fetch hooks Tejun Heo
2018-12-11 23:49 ` Tejun Heo [this message]
2018-12-12 7:26 ` [PATCHSET] git-reverse-trailer-xrefs: Reverse map cherry-picks and other cross-references Junio C Hamano
2018-12-12 14:54 ` Tejun Heo
2018-12-13 3:01 ` Junio C Hamano
2018-12-13 3:09 ` Junio C Hamano
2018-12-13 3:46 ` Tejun Heo
2018-12-18 14:40 ` Stefan Xenos
2018-12-18 16:48 ` Stefan Xenos
2018-12-18 16:51 ` Tejun Heo
2018-12-13 3:40 ` Tejun Heo
2018-12-13 5:47 ` Junio C Hamano
2018-12-13 16:15 ` Tejun Heo
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=20181211234909.2855638-6-tj@kernel.org \
--to=tj@kernel.org \
--cc=git@vger.kernel.org \
--cc=htejun@fb.com \
--cc=jch2355@gmail.com \
--cc=kernel-team@fb.com \
--cc=peff@peff.net \
/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).