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

Re: [PATCH v3] worktree: add 'list' command

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 11, 2015, 15:46 UTC
Message-ID
<xmqq37zpu8tv.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CANoM8SWeqxD2vWLQmEfxxxn8Dz4yPfjGOoOH=Azn1A3So+wz2Q@mail.gmail.com>
Mike Rappazzo <rappazzo@gmail.com> writes:
Show 5 quoted lines
>>> +     int is_bare = is_bare_repository();
>>
>> Please do not introduce decl-after-stmt.
>
> Since I reused this value below, I thought it would be acceptable.

Use of a new variable is fine. "Do not declare one in a block after you already wrote statement" is what "decl-after-stmt not allowed" means. In your patch:

+static int list(int ac, const char **av, const char *prefix) +{ + int main_only = 0; + struct option options[] = { + OPT_BOOL(0, "main-only", &main_only, N_("only list the main worktree")), + OPT_END() + }; + + ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + if (ac) + usage_with_options(worktree_usage, options); + + struct strbuf main_path = STRBUF_INIT; + const char* common_dir = get_git_common_dir(); + int is_bare = is_bare_repository();

Three variables, main_path, common_dir and is_bare are declared here after statements such as a call to parse_options(). Don't.

+static int list(int ac, const char **av, const char *prefix) +{ + int main_only = 0; + struct strbuf main_path = STRBUF_INIT; + const char *common_dir; + int is_bare; + struct option options[] = { + OPT_BOOL(0, "main-only", &main_only, N_("only list the main worktree")), + OPT_END() + }; + + ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + if (ac) + usage_with_options(worktree_usage, options); + + common_dir = get_git_common_dir(); + int is_bare = is_bare_repository();

Previous: Mike RappazzoNext: David Turner
Message 5 of 8 in “worktree: add 'list' command”
  1. worktree: add 'list' commandMichael Rappazzo, Aug 10, 2015
  2. worktree: add 'list' commandMichael Rappazzo, Aug 10, 2015
  3. Junio C HamanoAug 10, 2015
  4. Mike RappazzoAug 11, 2015
  5. Junio C HamanoAug 11, 2015
  6. David TurnerAug 11, 2015
  7. Mike RappazzoAug 11, 2015
  8. Junio C HamanoAug 11, 2015

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.