refs: stop modifying global log_all_ref_updates
variable
In refs-related code we modify the global `log_all_ref_updates` variable, which is done because `should_autocreate_reflog()` does not accept passing an `enum log_refs_config` but instead accesses the global variable. Adapt its interface such that the value is provided by the caller, which allows us to compute the proper value locally without having to modify global state. This change requires us to move the enum to "repo-settings.h", or otherwise we get compilation errors due to include cycles. We're about to fully move this setting into the repo-settings subsystem anyway, so this is fine. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
118fd1a26d
commit
9a20b889e8
@ -19,6 +19,7 @@
|
||||
#include "../reftable/reftable-record.h"
|
||||
#include "../reftable/reftable-error.h"
|
||||
#include "../reftable/reftable-iterator.h"
|
||||
#include "../repo-settings.h"
|
||||
#include "../setup.h"
|
||||
#include "../strmap.h"
|
||||
#include "parse.h"
|
||||
@ -158,20 +159,21 @@ static struct reftable_stack *stack_for(struct reftable_ref_store *store,
|
||||
|
||||
static int should_write_log(struct ref_store *refs, const char *refname)
|
||||
{
|
||||
if (log_all_ref_updates == LOG_REFS_UNSET)
|
||||
log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
|
||||
enum log_refs_config log_refs_cfg = log_all_ref_updates;
|
||||
if (log_refs_cfg == LOG_REFS_UNSET)
|
||||
log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
|
||||
|
||||
switch (log_all_ref_updates) {
|
||||
switch (log_refs_cfg) {
|
||||
case LOG_REFS_NONE:
|
||||
return refs_reflog_exists(refs, refname);
|
||||
case LOG_REFS_ALWAYS:
|
||||
return 1;
|
||||
case LOG_REFS_NORMAL:
|
||||
if (should_autocreate_reflog(refname))
|
||||
if (should_autocreate_reflog(log_refs_cfg, refname))
|
||||
return 1;
|
||||
return refs_reflog_exists(refs, refname);
|
||||
default:
|
||||
BUG("unhandled core.logAllRefUpdates value %d", log_all_ref_updates);
|
||||
BUG("unhandled core.logAllRefUpdates value %d", log_refs_cfg);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user