Re: [PATCH v7 3/3] bisect--helper: `write_terms` shell function in C
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- May 23, 2016, 16:01 UTC
- Message-ID
- <CAPig+cSOOv9sGGCTD7=5As9Opu3=e9ofkTpFhCzXC9cJPK21Tg@mail.gmail.com>
- In-Reply-To
- <1464014928-31548-4-git-send-email-pranit.bauva@gmail.com>
On Mon, May 23, 2016 at 10:48 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
Show 23 quoted lines
> Reimplement the `write_terms` shell function in C and add a `write-terms`
> subcommand to `git bisect--helper` to call it from git-bisect.sh . Also
> remove the subcommand `--check-term-format` as it can now be called from
> inside the function write_terms() C implementation.
> [...]
> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
> ---
> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> @@ -56,18 +58,38 @@ static int check_term_format(const char *term, const char *orig_term)
> +static int write_terms(const char *bad, const char *good)
> +{
> + FILE *fp;
> + int res;
> +
> + if (!strcmp(bad, good))
> + return error(_("please use two different terms"));
> +
> + if (check_term_format(bad, "bad") || check_term_format(good, "good"))
> + return -1;
> +
> + fp = fopen(git_path_bisect_write_terms(), "w");
> + if (!fp)
> + return error(_("could not open the file to write terms"));By adding two pieces of information, you could make this error message much more helpful for anyone trying to debug the failure. Specifically:
(1) the pathname for which open() failed (2) the actual system-level error
For (2), you could use strerror(errno) or, better yet, error_errno() which recently graduated to 'master'.
> + res = fprintf(fp, "%s\n%s\n", bad, good); > + fclose(fp); > + return (res < 0) ? -1 : 0; > +}