git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 5/5] transport-helper: fix sync issue on crashes

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 14, 2014, 21:25 UTC
Message-ID
<xmqq38hfmwml.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1397334812-12215-6-git-send-email-felipe.contreras@gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 14 quoted lines
> 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>
> ---

This seems to be based on a somewhat older codebase; I tried to be careful while adjusting the patch to the current codebase, but please give it an eyeball to see if I didn't make any silly mistake when I push today's integration result out in a few hours.

Thanks.
Show 70 quoted lines
>  t/t5801-remote-helpers.sh | 17 ++++++++++++++++-
>  transport-helper.c        | 13 +++++++++++--
>  2 files changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh
> index 613f69a..cf7fd43 100755
> --- a/t/t5801-remote-helpers.sh
> +++ b/t/t5801-remote-helpers.sh
> @@ -207,6 +207,17 @@ 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 &&
> @@ -221,7 +232,11 @@ test_expect_success 'proper failure checks for pushing' '
>  	(GIT_REMOTE_TESTGIT_FAILURE=1 &&
>  	export GIT_REMOTE_TESTGIT_FAILURE &&
>  	cd local &&
> -	test_must_fail git push --all
> +	git checkout -b crash master &&
> +	echo crash >> file &&
> +	git commit -a -m crash &&
> +	test_must_fail git push --all &&
> +	cmp_marks origin
>  	)
>  '
>  
> diff --git a/transport-helper.c b/transport-helper.c
> index 2747f98..090c863 100644
> --- a/transport-helper.c
> +++ b/transport-helper.c
> @@ -434,7 +434,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) {
> @@ -901,7 +901,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);
> +	if (push_update_refs_status(data, remote_refs))
> +		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,
Previous: Felipe ContrerasNext: Junio C Hamano
Message 8 of 20 in “transport-helper: serious crash fix”
  1. 0/5 transport-helper: serious crash fixFelipe Contreras, Apr 12, 2014
  2. 1/5 transport-helper: remove barely used xchgline()Felipe Contreras, Apr 12, 2014
  3. 2/5 remote-helpers: make recvline return an errorFelipe Contreras, Apr 12, 2014
  4. 3/5 transport-helper: propagate recvline() error pushingFelipe Contreras, Apr 12, 2014
  5. 4/5 transport-helper: trivial cleanupFelipe Contreras, Apr 12, 2014
  6. Junio C HamanoApr 14, 2014
  7. 5/5 transport-helper: fix sync issue on crashesFelipe Contreras, Apr 12, 2014
  8. Junio C HamanoApr 14, 2014
  9. Junio C HamanoApr 15, 2014
  10. 0/5 fc/transport-helper-sync-error-fix rebasedJunio C Hamano, Apr 19, 2014
  11. 1/5 transport-helper: remove barely used xchgline()Junio C Hamano, Apr 19, 2014
  12. 2/5 remote-helpers: make recvline return an errorJunio C Hamano, Apr 19, 2014
  13. 3/5 transport-helper: propagate recvline() error pushingJunio C Hamano, Apr 19, 2014
  14. 4/5 transport-helper: trivial cleanupJunio C Hamano, Apr 19, 2014
  15. 5/5 transport-helper: fix sync issue on crashesJunio C Hamano, Apr 19, 2014
  16. Felipe ContrerasApr 20, 2014
  17. Junio C HamanoApr 20, 2014
  18. Felipe ContrerasApr 20, 2014
  19. Junio C HamanoApr 20, 2014
  20. Felipe ContrerasApr 20, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.