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

Re: [PATCH] stash: show error message when lockfile is present

From
Taylor Blau <me@ttaylorr.com>
Date
Nov 8, 2021, 04:15 UTC
Message-ID
<YYike53eJEjSX3er@nand.local>
In-Reply-To
<YYiXw41upJfPS7l0@nand.local>
I forgot to mention in my earlier email, but in this hunk:
Show 13 quoted lines
> diff --git a/builtin/stash.c b/builtin/stash.c
> index a0ccc8654d..977fcc4e40 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -501,7 +501,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
>         const struct object_id *bases[1];
>
>         read_cache_preload(NULL);
> -       if (refresh_and_write_cache(REFRESH_QUIET, 0, 0))
> +       if (refresh_and_write_cache(REFRESH_QUIET, 0, LOCK_REPORT_ON_ERROR, 0))
>                 return -1;
>
>         if (write_cache_as_tree(&c_tree, 0, NULL))

Not the fault of your patch, but this hunk is unlike the others in that it only checks the return value of refresh_and_write_cache() is non-zero, not non-negative.

Looking through refresh_and_write_cache(), we can return a non-zero value in any one of three cases:

  - We could not acquire the index.lock file with
    repo_hold_locked_index(), or
  - We failed to write the index (indicated by write_locked_index()
    failing), or
  - refresh_index() returned a non-*zero* value, which happens when it
    sets its `has_errors` variable to 1.

So because even non-zero positive return values from this function indicate an error, this is OK. In other words, the current implementation of refresh_and_write_cache() (and the functions that it calls) make it so that it doesn't matter if you check whether the return value is negative, or non-zero.

But at least for consistency with the other callers (not to mention saving future readers in this area the same thought process I just wrote down here) it may be worth changing this to:

    if (refresh_and_write_cache(...) < 0)
      return -1;

Thanks, Taylor

Previous: Taylor BlauNext: Junio C Hamano
Message 3 of 8 in “stash: show error message when lockfile is present”
  1. stash: show error message when lockfile is presentBirk Tjelmeland, Nov 7, 2021
  2. Taylor BlauNov 8, 2021
  3. Taylor BlauNov 8, 2021
  4. Junio C HamanoNov 8, 2021
  5. Taylor BlauNov 8, 2021
  6. Ævar Arnfjörð BjarmasonNov 8, 2021
  7. Junio C HamanoNov 8, 2021
  8. Birk TjelmelandNov 8, 2021

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.