]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/receive-pack: fix exclude patterns when announcing refs
authorPatrick Steinhardt <ps@pks.im>
Mon, 16 Sep 2024 08:50:05 +0000 (10:50 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Sep 2024 20:57:18 +0000 (13:57 -0700)
commitd8faf50c36e94bdf47f57e2f1e7ea1b767e0ea00
treea1a4b0b582d7216a7c0aaf1dba16318e36f4c08d
parent155dc8447d3590ea856bb17919bfc85172b52e09
builtin/receive-pack: fix exclude patterns when announcing refs

In `write_head_info()` we announce references to the remote client. We
need to honor "transfer.hideRefs" here so that we do not announce any
references that the client shouldn't be able to learn about. This is
done via two separate mechanisms:

  - We hand over exclude patterns to the reference backend. We can only
    honor "plain" exclude patterns here that do not have prefixes with
    special meaning such as "^" or "!". Filtering down the references is
    handled by `hidden_refs_to_excludes()`.

  - In `show_ref_cb()` we perform a second check against hidden refs.
    For one this is done such that we can handle those special prefixes.
    And second, handling exclude patterns in ref backends is optional,
    so we also have to handle "normal" patterns.

The special-meaning "^" prefix alters whether a hidden ref applies to
the namespace-stripped reference name or the full name. So while we
would usually call `refs_for_each_namespaced_ref()` to only get those
references in the current namespace, we can't because we'd get the
already-rewritten reference names. Instead, we are forced to use
`refs_for_each_fullref_in()` and then manually strip away the namespace
prefix such that we have access to both names.

But this also means that we do not get namespace handling for exclude
patterns, which `refs_for_each_namespaced_ref()` brings for free. This
results in a bug because we potentially end up hiding away references
based on their namespaced name and not on the stripped name as we really
should be doing.

Fix this by manually rewriting the exclude patterns to their namespaced
variants.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/receive-pack.c
t/t5509-fetch-push-namespaces.sh