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

Re: [PATCH 1/2] bisect--helper: `is_expected_rev` shell function in C

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 9, 2016, 21:33 UTC
Message-ID
<CAPig+cRC_y9MBSsrLEs0OxL4=FMfU-=ACwhESUiECrWrDNvaCw@mail.gmail.com>
In-Reply-To
<20160608152415.7770-1-pranit.bauva@gmail.com>
On Wed, Jun 8, 2016 at 11:24 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
> Reimplement `is_expected_rev` shell function in C. This will further be
> called from `check_expected_revs` function. This is a quite small
> function thus subcommand facility is redundant.

This patch should be squashed into patch 2/2, as it is otherwise pointless without that patch, and merely adds dead code.

Show 10 quoted lines
> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
> ---
> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> @@ -160,6 +160,20 @@ int bisect_reset(const char *commit)
> +static int is_expected_rev(const char *expected_hex)
> +{
> +       struct strbuf actual_hex = STRBUF_INIT;
> +
> +       if (!file_exists(git_path_bisect_expected_rev()))
> +               return 0;

Invoking file_exists() seems unnecessarily redundant when you can discern effectively the same by checking the return value of strbuf_read_file() below. I'd drop the file_exists() check altogether.

> +       if (!strbuf_read_file(&actual_hex, git_path_bisect_expected_rev(), 0))
> +               return 0;

What exactly is this trying to do? Considering that strbuf_read_file() returns -1 upon error, otherwise the number of bytes read, if I'm reading this correctly, is_expected_rev() returns false if strbuf_read_file() encounters an error (which is fine) but also when it successfully reads the file and its content length is non-zero (which is very odd).

> +       strbuf_trim(&actual_hex);
> +       return !strcmp(actual_hex.buf, expected_hex);

Thus, it only ever gets to this point if the file exists but is empty, which is very unlikely to match 'expected_hex'. I could understand it if you checked the result of strbuf_read_file() with <0 or even <=0, but the current code doesn't make sense to me.

Am I misunderstanding?
> +}
Previous: Pranit BauvaNext: Eric Sunshine
Message 5 of 9 in “bisect--helper: `is_expected_rev` shell function in C”
  1. 1/2 bisect--helper: `is_expected_rev` shell function in CPranit Bauva, Jun 8, 2016
  2. 2/2 bisect--helper: `check_expected_revs` shell function in CPranit Bauva, Jun 8, 2016
  3. Eric SunshineJun 9, 2016
  4. Pranit BauvaJun 10, 2016
  5. Eric SunshineJun 9, 2016
  6. Eric SunshineJun 9, 2016
  7. Pranit BauvaJun 10, 2016
  8. Eric SunshineJun 10, 2016
  9. Pranit BauvaJun 11, 2016

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.