From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Joshua Hudson <jhudson@cedaron.com>, Elijah Newren <newren@gmail.com>
Subject: [PATCH] ll-merge: killing the external merge driver aborts the merge
Date: Thu, 22 Jun 2023 17:33:01 -0700 [thread overview]
Message-ID: <xmqq4jmzc91e.fsf_-_@gitster.g> (raw)
In-Reply-To: <xmqqttuze2fh.fsf@gitster.g> (Junio C. Hamano's message of "Thu, 22 Jun 2023 12:12:50 -0700")
When an external merge driver dies with a signal, we should not
expect that the result left on the filesystem is in any useful
state. However, because the current code uses the return value from
run_command() and declares any positive value as a sign that the
driver successfully left conflicts in the result, and because the
return value from run_command() for a subprocess that died upon a
signal is positive, we end up treating whatever garbage left on the
filesystem as the result the merge driver wanted to leave us.
run_command() returns larger than 128 (WTERMSIG(status) + 128, to be
exact) when it notices that the subprocess died with a signal, so
detect such a case and return LL_MERGE_ERROR from ll_ext_merge().
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* This time with an updated title, a minimal documentation, and an
additional test.
Documentation/gitattributes.txt | 5 ++++-
ll-merge.c | 9 ++++++++-
t/t6406-merge-attr.sh | 23 +++++++++++++++++++++++
3 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 02a3ec83e4..6deb89a296 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -1132,7 +1132,10 @@ size (see below).
The merge driver is expected to leave the result of the merge in
the file named with `%A` by overwriting it, and exit with zero
status if it managed to merge them cleanly, or non-zero if there
-were conflicts.
+were conflicts. When the driver crashes (e.g. killed by SEGV),
+it is expected to exit with non-zero status that are higher than
+128, and in such a case, the merge results in a failure (which is
+different from producing a conflict).
The `merge.*.recursive` variable specifies what other merge
driver to use when the merge driver is called for an internal
diff --git a/ll-merge.c b/ll-merge.c
index 07ec16e8e5..ba45aa2f79 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -243,7 +243,14 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn,
unlink_or_warn(temp[i]);
strbuf_release(&cmd);
strbuf_release(&path_sq);
- ret = (status > 0) ? LL_MERGE_CONFLICT : status;
+
+ if (!status)
+ ret = LL_MERGE_OK;
+ else if (status <= 128)
+ ret = LL_MERGE_CONFLICT;
+ else
+ /* died due to a signal: WTERMSIG(status) + 128 */
+ ret = LL_MERGE_ERROR;
return ret;
}
diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh
index 5e4e4dd6d9..b50aedbc00 100755
--- a/t/t6406-merge-attr.sh
+++ b/t/t6406-merge-attr.sh
@@ -56,6 +56,12 @@ test_expect_success setup '
) >"$ours+"
cat "$ours+" >"$ours"
rm -f "$ours+"
+
+ if test -f ./please-abort
+ then
+ echo >>./please-abort killing myself
+ kill -9 $$
+ fi
exit "$exit"
EOF
chmod +x ./custom-merge
@@ -162,6 +168,23 @@ test_expect_success 'custom merge backend' '
rm -f $o $a $b
'
+test_expect_success 'custom merge driver that is killed with a signal' '
+ test_when_finished "rm -f output please-abort" &&
+
+ git reset --hard anchor &&
+ git config --replace-all \
+ merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
+ git config --replace-all \
+ merge.custom.name "custom merge driver for testing" &&
+
+ >./please-abort &&
+ echo "* merge=custom" >.gitattributes &&
+ test_must_fail git merge main &&
+ git ls-files -u >output &&
+ git diff --name-only HEAD >>output &&
+ test_must_be_empty output
+'
+
test_expect_success 'up-to-date merge without common ancestor' '
git init repo1 &&
git init repo2 &&
--
2.41.0-159-g0bfa463d37
next prev parent reply other threads:[~2023-06-23 0:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 16:50 Design issue in git merge driver interface Joshua Hudson
2023-06-22 19:12 ` Junio C Hamano
2023-06-23 0:33 ` Junio C Hamano [this message]
2023-06-23 6:25 ` [PATCH] ll-merge: killing the external merge driver aborts the merge Elijah Newren
2023-06-23 16:26 ` Junio C Hamano
2023-06-23 23:31 ` Junio C Hamano
2023-06-25 13:40 ` Joshua Hudson
2023-06-27 12:02 ` Johannes Schindelin
2023-06-27 13:43 ` Joshua Hudson
2023-06-27 19:08 ` Junio C Hamano
2023-06-27 19:10 ` Joshua Hudson
2023-06-27 20:04 ` Junio C Hamano
2023-06-27 21:14 ` Joshua Hudson
2023-06-27 21:26 ` Junio C Hamano
2023-06-27 21:32 ` Joshua Hudson
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=xmqq4jmzc91e.fsf_-_@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jhudson@cedaron.com \
--cc=newren@gmail.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).