Thread (47 messages) flat view 47 messages, 4 authors, 8d ago

Re: [PATCH v2 1/8] checkout: pass cb_option explicitly to branch name parsers

From: Karthik Nayak <hidden>
Date: 2026-09-01 11:31:23

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]

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help