From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH 5/5] transport-helper: fix sync issue on crashes
Date: Sat, 19 Apr 2014 00:00:43 -0700 [thread overview]
Message-ID: <1397890843-27035-6-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1397890843-27035-1-git-send-email-gitster@pobox.com>
From: Felipe Contreras <felipe.contreras@gmail.com>
When a remote helper crashes while pushing we should revert back to the
state before the push, however, it's possible that `git fast-export`
already finished its job, and therefore has exported the marks already.
This creates a synchronization problem because from that moment on
`git fast-{import,export}` will have marks that the remote helper is not
aware of and all further commands fail (if those marks are referenced).
The fix is to tell `git fast-export` to export to a temporary file, and
only after the remote helper has finishes successfully, move to the
final destination.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
t/t5801-remote-helpers.sh | 20 +++++++++++++++++++-
transport-helper.c | 13 +++++++++++--
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh
index 25fd2e7..aa3e223 100755
--- a/t/t5801-remote-helpers.sh
+++ b/t/t5801-remote-helpers.sh
@@ -220,6 +220,20 @@ test_expect_success 'push update refs failure' '
)
'
+clean_mark () {
+ cut -f 2 -d ' ' "$1" |
+ git cat-file --batch-check |
+ grep commit |
+ sort >$(basename "$1")
+}
+
+cmp_marks () {
+ test_when_finished "rm -rf git.marks testgit.marks" &&
+ clean_mark ".git/testgit/$1/git.marks" &&
+ clean_mark ".git/testgit/$1/testgit.marks" &&
+ test_cmp git.marks testgit.marks
+}
+
test_expect_success 'proper failure checks for fetching' '
(GIT_REMOTE_TESTGIT_FAILURE=1 &&
export GIT_REMOTE_TESTGIT_FAILURE &&
@@ -232,7 +246,11 @@ test_expect_success 'proper failure checks for fetching' '
test_expect_success 'proper failure checks for pushing' '
(cd local &&
- test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all
+ git checkout -b crash master &&
+ echo crash >>file &&
+ git commit -a -m crash &&
+ test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
+ cmp_marks origin
)
'
diff --git a/transport-helper.c b/transport-helper.c
index c890db6..b468e4f 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -435,7 +435,7 @@ static int get_exporter(struct transport *transport,
fastexport->argv[argc++] = data->signed_tags ?
"--signed-tags=verbatim" : "--signed-tags=warn-strip";
if (data->export_marks) {
- strbuf_addf(&tmp, "--export-marks=%s", data->export_marks);
+ strbuf_addf(&tmp, "--export-marks=%s.tmp", data->export_marks);
fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
}
if (data->import_marks) {
@@ -911,7 +911,16 @@ static int push_refs_with_export(struct transport *transport,
if (finish_command(&exporter))
die("Error while running fast-export");
- return push_update_refs_status(data, remote_refs, flags);
+ if (push_update_refs_status(data, remote_refs, flags))
+ return 1;
+
+ if (data->export_marks) {
+ strbuf_addf(&buf, "%s.tmp", data->export_marks);
+ rename(buf.buf, data->export_marks);
+ strbuf_release(&buf);
+ }
+
+ return 0;
}
static int push_refs(struct transport *transport,
--
1.9.2-459-g68773ac
next prev parent reply other threads:[~2014-04-19 6:59 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-12 20:33 [PATCH 0/5] transport-helper: serious crash fix Felipe Contreras
2014-04-12 20:33 ` [PATCH 1/5] transport-helper: remove barely used xchgline() Felipe Contreras
2014-04-12 20:33 ` [PATCH 2/5] remote-helpers: make recvline return an error Felipe Contreras
2014-04-12 20:33 ` [PATCH 3/5] transport-helper: propagate recvline() error pushing Felipe Contreras
2014-04-12 20:33 ` [PATCH 4/5] transport-helper: trivial cleanup Felipe Contreras
2014-04-14 21:14 ` Junio C Hamano
2014-04-12 20:33 ` [PATCH 5/5] transport-helper: fix sync issue on crashes Felipe Contreras
2014-04-14 21:25 ` Junio C Hamano
2014-04-15 21:28 ` [PATCH 0/5] transport-helper: serious crash fix Junio C Hamano
2014-04-19 7:00 ` [PATCH 0/5] fc/transport-helper-sync-error-fix rebased Junio C Hamano
2014-04-19 7:00 ` [PATCH 1/5] transport-helper: remove barely used xchgline() Junio C Hamano
2014-04-19 7:00 ` [PATCH 2/5] remote-helpers: make recvline return an error Junio C Hamano
2014-04-19 7:00 ` [PATCH 3/5] transport-helper: propagate recvline() error pushing Junio C Hamano
2014-04-19 7:00 ` [PATCH 4/5] transport-helper: trivial cleanup Junio C Hamano
2014-04-19 7:00 ` Junio C Hamano [this message]
2014-04-20 18:36 ` [PATCH 0/5] fc/transport-helper-sync-error-fix rebased Felipe Contreras
2014-04-20 21:10 ` Junio C Hamano
2014-04-20 21:12 ` Felipe Contreras
2014-04-20 21:52 ` Junio C Hamano
2014-04-20 21:54 ` Felipe Contreras
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=1397890843-27035-6-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
/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).