]> git.ipfire.org Git - thirdparty/git.git/commit
for-each-ref: add 'is-base' token
authorDerrick Stolee <stolee@gmail.com>
Wed, 14 Aug 2024 10:31:29 +0000 (10:31 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:10:06 +0000 (10:10 -0700)
commit9c1732ca113d565e431b303911fcf66bfa1f8f56
tree0ede812846f1316e15ecdcf3eedb970cc14ed33b
parent69020d034b75a7cd198c7351219d07ee6926fe59
for-each-ref: add 'is-base' token

The previous change introduced the get_branch_base_for_tip() method in
commit-reach.c. The motivation of that change was about using a heuristic to
deteremine the base branch for a source commit from a list of candidate
commit tips. This change makes that algorithm visible to users via a new
atom in the 'git for-each-ref' format. This change is very similar to the
chang in 49abcd21da6 (for-each-ref: add ahead-behind format atom,
2023-03-20).

Introduce the 'is-base:<source>' atom, which will indicate that the
algorithm should be computed and the result of the algorithm is reported
using an indicator of the form '(<source>)'. For example, using
'%(is-base:HEAD)' would result in one line having the token '(HEAD)'.

Use the sorted order of refs included in the ref filter to break ties in the
algorithm's heuristic. In the previous change, the motivating examples
include using an L0 trunk, long-lived L1 branches, and temporary release
branches. A caller could communicate the ordered preference among these
categories using the input refpecs and avoiding a different sort mechanism.
This sorting behavior is tested in the test scripts.

It is important to include this atom as a special case to
can_do_iterative_format() to match the expectations created in bd98f9774e1
(ref-filter.c: filter & format refs in the same callback, 2023-11-14). The
ahead-behind atom was one of the special cases, and this similarly requires
using an algorithm across all input refs before starting the format of any
single ref.

In the test script, the format tokens use colons or lack whitespace to avoid
Git complaining about trailing whitespace errors.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-for-each-ref.txt
ref-filter.c
ref-filter.h
t/t6300-for-each-ref.sh
t/t6600-test-reach.sh