git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brandon Williams <bmwill@google.com>
To: Stefan Beller <sbeller@google.com>
Cc: gitster@pobox.com, git@vger.kernel.org,
	sandals@crustytoothpaste.net, David.Turner@twosigma.com
Subject: Re: [PATCHv4 3/5] run-command: add {run,start,finish}_command_or_die
Date: Mon, 19 Dec 2016 15:32:56 -0800	[thread overview]
Message-ID: <20161219233256.GB41080@google.com> (raw)
In-Reply-To: <20161219232828.5075-4-sbeller@google.com>

On 12/19, Stefan Beller wrote:
> In a later patch we want to report the exact command that we run in the
> error message. Add a convenient way to the run command API that runs the
> given command or reports the exact command as failure.
> 
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  run-command.c | 28 ++++++++++++++++++++++++++++
>  run-command.h |  4 ++++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/run-command.c b/run-command.c
> index ca905a9e80..a0587db334 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -279,6 +279,17 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
>  	return code;
>  }
>  
> +static void report_and_die(struct child_process *cmd, const char *action)
> +{
> +	int i;
> +	struct strbuf err = STRBUF_INIT;
> +	if (cmd->git_cmd)
> +		strbuf_addstr(&err, "git ");
> +	for (i = 0; cmd->argv[i]; )

Missing the increment of i here.

> +		strbuf_addf(&err, "'%s'", cmd->argv[i]);
> +	die(_("could not %s %s"), action, err.buf);
> +}
> +
>  int start_command(struct child_process *cmd)
>  {
>  	int need_in, need_out, need_err;
> @@ -546,6 +557,12 @@ int start_command(struct child_process *cmd)
>  	return 0;
>  }
>  
> +void start_command_or_die(struct child_process *cmd)
> +{
> +	if (start_command(cmd))
> +		report_and_die(cmd, "start");
> +}
> +
>  int finish_command(struct child_process *cmd)
>  {
>  	int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
> @@ -558,6 +575,11 @@ int finish_command_in_signal(struct child_process *cmd)
>  	return wait_or_whine(cmd->pid, cmd->argv[0], 1);
>  }
>  
> +void finish_command_or_die(struct child_process *cmd)
> +{
> +	if (finish_command(cmd))
> +		report_and_die(cmd, "finish");
> +}
>  
>  int run_command(struct child_process *cmd)
>  {
> @@ -592,6 +614,12 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
>  	return run_command(&cmd);
>  }
>  
> +void run_command_or_die(struct child_process *cmd)
> +{
> +	if (finish_command(cmd))
> +		report_and_die(cmd, "run");
> +}
> +
>  #ifndef NO_PTHREADS
>  static pthread_t main_thread;
>  static int main_thread_set;
> diff --git a/run-command.h b/run-command.h
> index dd1c78c28d..e4585885c5 100644
> --- a/run-command.h
> +++ b/run-command.h
> @@ -56,6 +56,10 @@ int finish_command(struct child_process *);
>  int finish_command_in_signal(struct child_process *);
>  int run_command(struct child_process *);
>  
> +void start_command_or_die(struct child_process *);
> +void finish_command_or_die(struct child_process *);
> +void run_command_or_die(struct child_process *);
> +
>  /*
>   * Returns the path to the hook file, or NULL if the hook is missing
>   * or disabled. Note that this points to static storage that will be
> -- 
> 2.11.0.rc2.53.gb7b3fba.dirty
> 

-- 
Brandon Williams

  reply	other threads:[~2016-12-19 23:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19 23:28 [PATCHv4 0/5] git-rm absorbs submodule git directory before deletion Stefan Beller
2016-12-19 23:28 ` [PATCHv4 1/5] submodule.h: add extern keyword to functions Stefan Beller
2016-12-19 23:28 ` [PATCHv4 2/5] submodule: modernize ok_to_remove_submodule to use argv_array Stefan Beller
2016-12-19 23:28 ` [PATCHv4 3/5] run-command: add {run,start,finish}_command_or_die Stefan Beller
2016-12-19 23:32   ` Brandon Williams [this message]
2016-12-19 23:35     ` Stefan Beller
2016-12-20 18:33   ` Johannes Sixt
2016-12-20 18:54     ` Johannes Sixt
2016-12-20 19:23     ` Stefan Beller
2016-12-20 20:12       ` Johannes Sixt
2016-12-20 20:49         ` Stefan Beller
2016-12-20 21:47           ` Johannes Sixt
2016-12-20 22:07             ` Stefan Beller
2016-12-19 23:28 ` [PATCHv4 4/5] submodule: add flags to ok_to_remove_submodule Stefan Beller
2016-12-19 23:28 ` [PATCHv4 5/5] rm: absorb a submodules git dir before deletion Stefan Beller
2016-12-19 23:35 ` [PATCHv4 0/5] git-rm absorbs submodule git directory " David Turner

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=20161219233256.GB41080@google.com \
    --to=bmwill@google.com \
    --cc=David.Turner@twosigma.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=sbeller@google.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).