diff options
author | Patrick Steinhardt <ps@pks.im> | 2022-11-17 06:46:43 +0100 |
---|---|---|
committer | Taylor Blau <me@ttaylorr.com> | 2022-11-17 22:22:51 +0100 |
commit | 9b67eb6fbeb9666640f34cccf401cfea22f7bd22 (patch) | |
tree | 0e621cf74bf789927c02e3ec70c95fc1ff8af217 /refs.c | |
parent | refs: fix memory leak when parsing hideRefs config (diff) | |
download | git-9b67eb6fbeb9666640f34cccf401cfea22f7bd22.tar.xz git-9b67eb6fbeb9666640f34cccf401cfea22f7bd22.zip |
refs: get rid of global list of hidden refs
We're about to add a new argument to git-rev-list(1) that allows it to
add all references that are visible when taking `transfer.hideRefs` et
al into account. This will require us to potentially parse multiple sets
of hidden refs, which is not easily possible right now as there is only
a single, global instance of the list of parsed hidden refs.
Refactor `parse_hide_refs_config()` and `ref_is_hidden()` so that both
take the list of hidden references as input and adjust callers to keep a
local list, instead. This allows us to easily use multiple hidden-ref
lists. Furthermore, it allows us to properly free this list before we
exit.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 14 |
1 files changed, 4 insertions, 10 deletions
@@ -1414,9 +1414,8 @@ char *shorten_unambiguous_ref(const char *refname, int strict) refname, strict); } -static struct string_list *hide_refs; - -int parse_hide_refs_config(const char *var, const char *value, const char *section) +int parse_hide_refs_config(const char *var, const char *value, const char *section, + struct string_list *hide_refs) { const char *key; if (!strcmp("transfer.hiderefs", var) || @@ -1431,21 +1430,16 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti len = strlen(ref); while (len && ref[len - 1] == '/') ref[--len] = '\0'; - if (!hide_refs) { - CALLOC_ARRAY(hide_refs, 1); - hide_refs->strdup_strings = 1; - } string_list_append_nodup(hide_refs, ref); } return 0; } -int ref_is_hidden(const char *refname, const char *refname_full) +int ref_is_hidden(const char *refname, const char *refname_full, + const struct string_list *hide_refs) { int i; - if (!hide_refs) - return 0; for (i = hide_refs->nr - 1; i >= 0; i--) { const char *match = hide_refs->items[i].string; const char *subject; |