]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/for-each-ref: factor out core logic into a helper
authorMeet Soni <meetsoni3017@gmail.com>
Tue, 5 Aug 2025 09:27:55 +0000 (14:57 +0530)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Aug 2025 16:11:54 +0000 (09:11 -0700)
commit6eeb1c070a8746734d74064905a8edeae08bd2a8
treeae54d37877c2c2da7b01912c8208bf2a43ede209
parent69c207dc45c0e95bff2bdcaf1c7aca41e9679fb8
builtin/for-each-ref: factor out core logic into a helper

The implementation of `git for-each-ref` is monolithic within
`cmd_for_each_ref()`, making it impossible to share its logic with other
commands. To enable code reuse for the upcoming `git refs list`
subcommand, refactor the core logic into a shared helper function.

Introduce a new `for-each-ref.h` header to define the public interface
for this shared logic. It contains the declaration for a new helper
function, `for_each_ref_core()`, and a macro for the common usage
options.

Move the option parsing, filtering, and formatting logic from
`cmd_for_each_ref()` into a new helper function named
`for_each_ref_core()`. This helper is made generic by accepting the
command's usage string as a parameter.

The original `cmd_for_each_ref()` is simplified to a thin wrapper that
is only responsible for defining its specific usage array and calling
the shared helper.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/for-each-ref.c
for-each-ref.h [new file with mode: 0644]