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

Re: [PATCH v3 6/8] send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS"

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 16, 2024, 08:36 UTC
Message-ID
<Z1_mgG7sqNtHWFnQ@pks.im>
In-Reply-To
<77f5e128fc1b66a9c8b0df3ce274a98921800685.1733830410.git.zhiyou.jx@alibaba-inc.com>
On Tue, Dec 10, 2024 at 07:36:26PM +0800, Jiang Xin wrote:
Show 13 quoted lines
> diff --git a/send-pack.c b/send-pack.c
> index 6677c44e8a..f1556dd53c 100644
> --- a/send-pack.c
> +++ b/send-pack.c
> @@ -630,7 +630,7 @@ int send_pack(struct send_pack_args *args,
>  				reject_atomic_push(remote_refs, args->send_mirror);
>  				error("atomic push failed for ref %s. status: %d",
>  				      ref->name, ref->status);
> -				ret = args->porcelain ? 0 : -1;
> +				ret = ERROR_SEND_PACK_BAD_REF_STATUS;
>  				goto out;
>  			}
>  			/* else fallthrough */

Okay, this change looks sensible -- instead of having different behaviour with `--porcelain` we now have the exact same behaviour with and without that flag set, which is good.

Show 8 quoted lines
> @@ -761,11 +761,6 @@ int send_pack(struct send_pack_args *args,
>  	if (ret < 0)
>  		goto out;
>  
> -	if (args->porcelain) {
> -		ret = 0;
> -		goto out;
> -	}
We don't reset the error code here anymore.
Show 12 quoted lines
>  	for (ref = remote_refs; ref; ref = ref->next) {
>  		switch (ref->status) {
>  		case REF_STATUS_NONE:
> @@ -773,7 +768,7 @@ int send_pack(struct send_pack_args *args,
>  		case REF_STATUS_OK:
>  			break;
>  		default:
> -			ret = -1;
> +			ret = ERROR_SEND_PACK_BAD_REF_STATUS;
>  			goto out;
>  		}
>  	}
And this is the equivalent change without `--atomic`.

Also, none of the existing code paths used to set `ret = 1`. We do call `ret = receive_status()` and bubble that up, but neither that nor any of its transitive calls set `ret = 1`, either. So this should be fine and we don't seem to have conflicting error codes.

Show 14 quoted lines
> diff --git a/send-pack.h b/send-pack.h
> index 7edb80596c..ee88f9fe9f 100644
> --- a/send-pack.h
> +++ b/send-pack.h
> @@ -12,6 +12,9 @@ struct ref;
>  #define SEND_PACK_PUSH_CERT_IF_ASKED 1
>  #define SEND_PACK_PUSH_CERT_ALWAYS 2
>  
> +/* Custom exit code from send_pack. */
> +#define ERROR_SEND_PACK_BAD_REF_STATUS 1
> +
>  struct send_pack_args {
>  	const char *url;
>  	unsigned verbose:1,

It might help to document `send_pack()` accordingly and point out the special return code.

Show 18 quoted lines
> diff --git a/transport.c b/transport.c
> index 47fda6a773..454d7f21a9 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -914,6 +914,13 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
>  	case protocol_v0:
>  		ret = send_pack(&args, data->fd, data->conn, remote_refs,
>  				&data->extra_have);
> +		/*
> +		 * Ignore the specific error code to maintain consistent behavior
> +		 * with the "push_refs()" function across different transports,
> +		 * such as "push_refs_with_push()" for HTTP protocol.
> +		 */
> +		if (ret == ERROR_SEND_PACK_BAD_REF_STATUS)
> +			ret = 0;
>  		break;
>  	case protocol_unknown_version:
>  		BUG("unknown protocol version");
And here we ignore the error code to retain compatibility.

Is there any case where this causes a user-visible change in behaviour already? If so, we can add a test for this?

Patrick
Previous: Jiang XinNext: Jiang Xin
Message 25 of 54 in “transport: don't ignore git-receive-pack(1) exit code on atomic push”
  1. 0/2 transport: don't ignore git-receive-pack(1) exit code on atomic pushPatrick Steinhardt, Nov 13, 2024
  2. 1/2 t5504: modernize test by moving heredocs into test bodiesPatrick Steinhardt, Nov 13, 2024
  3. 2/2 transport: don't ignore git-receive-pack(1) exit code on atomic pushPatrick Steinhardt, Nov 13, 2024
  4. Jiang XinNov 14, 2024
  5. 0/6 fix behaviors of git-push --porcelainJiang Xin, Nov 14, 2024
  6. 1/6 t5548: new test cases for push --porcelain and --dry-runJiang Xin, Nov 14, 2024
  7. Patrick SteinhardtNov 25, 2024
  8. Jiang XinDec 3, 2024
  9. 2/6 push: fix the behavior of the Done message for porcelainJiang Xin, Nov 14, 2024
  10. Patrick SteinhardtNov 25, 2024
  11. 3/6 t5504: modernize test by moving heredocs into test bodiesJiang Xin, Nov 14, 2024
  12. 4/6 t5543: atomic push reports exit code failureJiang Xin, Nov 14, 2024
  13. 5/6 push: only ignore finish_connect() for dry-run modeJiang Xin, Nov 14, 2024
  14. Patrick SteinhardtNov 25, 2024
  15. 6/6 push: not send push-options to server with --dry-runJiang Xin, Nov 14, 2024
  16. Patrick SteinhardtNov 25, 2024
  17. 0/8 fix behaviors of git-push --porcelainJiang Xin, Dec 10, 2024
  18. 1/8 t5504: modernize test by moving heredocs into test bodiesJiang Xin, Dec 10, 2024
  19. 2/8 t5548: refactor to reuse setup_upstream() functionJiang Xin, Dec 10, 2024
  20. 3/8 t5548: refactor test cases by resetting upstreamJiang Xin, Dec 10, 2024
  21. 4/8 t5548: add new porcelain test casesJiang Xin, Dec 10, 2024
  22. 5/8 t5548: add porcelain push test cases for dry-run modeJiang Xin, Dec 10, 2024
  23. Jiang XinDec 10, 2024
  24. 6/8 send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS"Jiang Xin, Dec 10, 2024
  25. Patrick SteinhardtDec 16, 2024
  26. 7/8 t5543: atomic push reports exit code failureJiang Xin, Dec 10, 2024
  27. 8/8 send-pack: gracefully close the connection for atomic pushJiang Xin, Dec 10, 2024
  28. Patrick SteinhardtDec 16, 2024
  29. Junio C HamanoNov 14, 2024
  30. Patrick SteinhardtNov 25, 2024
  31. 0/8 transport: don't ignore git-receive-pack(1) exit code on atomic pushPatrick Steinhardt, Jan 31, 2025
  32. 1/8 t5504: modernize test by moving heredocs into test bodiesPatrick Steinhardt, Jan 31, 2025
  33. Eric SunshineJan 31, 2025
  34. Junio C HamanoJan 31, 2025
  35. Patrick SteinhardtFeb 3, 2025
  36. 2/8 t5548: refactor to reuse setup_upstream() functionPatrick Steinhardt, Jan 31, 2025
  37. Eric SunshineJan 31, 2025
  38. 4/8 t5548: add new porcelain test casesPatrick Steinhardt, Jan 31, 2025
  39. Eric SunshineJan 31, 2025
  40. 5/8 t5548: add porcelain push test cases for dry-run modePatrick Steinhardt, Jan 31, 2025
  41. 3/8 t5548: refactor test cases by resetting upstreamPatrick Steinhardt, Jan 31, 2025
  42. 7/8 t5543: atomic push reports exit code failurePatrick Steinhardt, Jan 31, 2025
  43. 6/8 send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS"Patrick Steinhardt, Jan 31, 2025
  44. 8/8 send-pack: gracefully close the connection for atomic pushPatrick Steinhardt, Jan 31, 2025
  45. 0/8 transport: don't ignore git-receive-pack(1) exit code on atomic pushPatrick Steinhardt, Feb 3, 2025
  46. 1/8 t5504: modernize test by moving heredocs into test bodiesPatrick Steinhardt, Feb 3, 2025
  47. 2/8 t5548: refactor to reuse setup_upstream() functionPatrick Steinhardt, Feb 3, 2025
  48. 3/8 t5548: refactor test cases by resetting upstreamPatrick Steinhardt, Feb 3, 2025
  49. 4/8 t5548: add new porcelain test casesPatrick Steinhardt, Feb 3, 2025
  50. 5/8 t5548: add porcelain push test cases for dry-run modePatrick Steinhardt, Feb 3, 2025
  51. 6/8 send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS"Patrick Steinhardt, Feb 3, 2025
  52. 7/8 t5543: atomic push reports exit code failurePatrick Steinhardt, Feb 3, 2025
  53. 8/8 send-pack: gracefully close the connection for atomic pushPatrick Steinhardt, Feb 3, 2025
  54. Junio C HamanoFeb 3, 2025

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.