diff options
| author | Jeff King <peff@peff.net> | 2026-02-15 04:00:52 -0500 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-02-17 09:45:28 -0800 |
| commit | 5ec4c22e49839c2eeb319070cde14ddbea3d1adb (patch) | |
| tree | 75b50ba62800509d33a925a7ba27c0df00bc2206 /contrib/persistent-https | |
| parent | 67ad42147a7acc2af6074753ebd03d904476118f (diff) | |
| download | git-5ec4c22e49839c2eeb319070cde14ddbea3d1adb.tar.gz git-5ec4c22e49839c2eeb319070cde14ddbea3d1adb.zip | |
ref-filter: factor out refname component counting
The "lstrip" and "rstrip" options to the %(refname) placeholder both
accept a negative length, which asks us to keep that many path
components (rather than stripping that many).
The code to count components and convert the negative value to a
positive was copied from lstrip to rstrip in 1a34728e6b (ref-filter: add
an 'rstrip=<N>' option to atoms which deal with refnames, 2017-01-10).
Let's factor it out into a separate function. This reduces duplication
and also makes the lstrip/rstrip functions much easier to follow, since
the bulk of their code is now the actual stripping.
Note that the computed "remaining" value is currently stored as a
"long", so in theory that's what our function should return. But this is
purely historical. When the variable was added in 0571979bd6 (tag: do
not show ambiguous tag names as "tags/foo", 2016-01-25), we parsed the
value from strtol(), and thus used a long. But these days we take "len"
as an int, and also use an int to count up components. So let's just
consistently use int here. This value could only overflow in a
pathological case (e.g., 4GB worth of "a/a/...") and even then will not
result in out-of-bounds memory access (we keep stripping until we run
out of string to parse).
The minimal Myers diff here is a little hard to read; with --patience
the code movement is shown much more clearly.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/persistent-https')
0 files changed, 0 insertions, 0 deletions
