Junio C Hamano [off-list ref] writes:
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]