]> git.ipfire.org Git - thirdparty/git.git/commit
attr: don't recompute default attribute source
authorPatrick Steinhardt <ps@pks.im>
Tue, 7 May 2024 04:53:01 +0000 (06:53 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 May 2024 05:50:48 +0000 (22:50 -0700)
commitbbb82f8dc88aee588a35615fdb10862f3b41e16c
treed87fb01e6c9e0fcbb7352a37ef2233250b2cb1cf
parentb7afb462258ab02d94e437652cd230a7827d3329
attr: don't recompute default attribute source

The `default_attr_source()` function lazily computes the attr source
supposedly once, only. This is done via a static variable `attr_source`
that contains the resolved object ID of the attr source's tree. If the
variable is the null object ID then we try to look up the attr source,
otherwise we skip over it.

This approach is flawed though: the variable will never be set to
anything else but the null object ID in case there is no attr source.
Consequently, we re-compute the information on every call. And in the
worst case, when we silently ignore bad trees, this will cause us to try
and look up the treeish every single time.

Improve this by introducing a separate variable `has_attr_source` to
track whether we already computed the attr source and, if so, whether we
have an attr source or not.

This also allows us to convert the `ignore_bad_attr_tree` to not be
static anymore as the code will only be executed once anyway.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
attr.c