]> git.ipfire.org Git - thirdparty/git.git/commit
ls-refs: drop config caching
authorJeff King <peff@peff.net>
Fri, 24 Feb 2023 06:37:22 +0000 (01:37 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Feb 2023 17:13:28 +0000 (09:13 -0800)
commitc4716086d8653ff2761b5f8b0452c97c24e117ed
tree47d1145ce3ee874ac9c7965b5eddb24ed830d33a
parentfe6258c348ad79a3c11e309995d88cdf08cde984
ls-refs: drop config caching

The code for the v2 ls-refs command has an ensure_config_read() function
that tries to read the lsrefs.unborn config only once and caches it in
some static global variables.

There's no real need for this caching. In any given process we'd only
need the value twice (once to decide whether to advertise, and once if
somebody runs the command). And since the config code already has its
own cache, each access is only incurring a hash lookup and string
comparison anyway.

Since the values we set are going to be specific to the_repository, the
globals we set are a mild anti-pattern. In practice it's not a bug (yet)
since the server-side v2 code only handles a single repository anyway.
But it doesn't hurt to take a small step in the right direction and
model a good approach.

Note that we currently set two booleans: advertise_unborn and
allow_unborn. But we can get away with a single value, since "advertise"
naturally implies "allow". That lets us just convert this to a function
with a return value.

Note that we still always read from the_repository; we'll deal with that
in a follow-on patch.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ls-refs.c