Re: [PATCH v2 1/8] checkout: pass cb_option explicitly to branch name parsers
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Sep 1, 2026, 11:31 UTC
- Message-ID
- <CAOLa=ZS7seJs9bt4DiSzD=hDXNTnB9qO261Er39PG2sDbj9=MA@mail.gmail.com>
- In-Reply-To
- <20260830204835.1040408-2-gitster@pobox.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 10 quoted lines
> The file-scope static variable 'cb_option' is used to record whether > a new branch is being created via '-b' (in 'git checkout') or '-c' > (in 'git switch'), primarily for error reporting and advice messages > in parse_remote_branch(). > > Global mutable state makes the code harder to reason about and refactor. > > Pass 'cb_option' explicitly as a parameter to parse_remote_branch() > and parse_branchname_arg(), removing the file-scope static variable. >
I was wondering why we couldn't simply get rid of 'cb_option' entirely? The only usecase for it is for printing user facing messages in `checkout_main()`, where we already have access to `enum checkout_command`. Wouldn't it be better to simply only keep the enum and drop this?
[snip]