xC: don't autosave when nothing changed

This commit is contained in:
Přemysl Eric Janouch 2022-08-29 08:20:51 +02:00
parent ecebeace0e
commit bea8d13227
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 13 additions and 10 deletions

23
xC.c
View File

@ -11361,7 +11361,7 @@ handle_command_set_modify
return result; return result;
} }
static void static bool
handle_command_set_assign_item (struct app_context *ctx, handle_command_set_assign_item (struct app_context *ctx,
char *key, struct config_item *new_, bool add, bool remove) char *key, struct config_item *new_, bool add, bool remove)
{ {
@ -11384,14 +11384,14 @@ handle_command_set_assign_item (struct app_context *ctx,
log_global_error (ctx, log_global_error (ctx,
"Failed to set option \"#s\": #s", key, e->message); "Failed to set option \"#s\": #s", key, e->message);
error_free (e); error_free (e);
return false;
} }
else
{ struct strv tmp = strv_make ();
struct strv tmp = strv_make (); dump_matching_options (ctx->config.root, key, &tmp);
dump_matching_options (ctx->config.root, key, &tmp); log_global_status (ctx, "Option changed: #s", tmp.vector[0]);
log_global_status (ctx, "Option changed: #s", tmp.vector[0]); strv_free (&tmp);
strv_free (&tmp); return true;
}
} }
static bool static bool
@ -11427,15 +11427,18 @@ handle_command_set_assign
config_item_destroy (new_); config_item_destroy (new_);
return true; return true;
} }
bool changed = false;
for (size_t i = 0; i < all->len; i++) for (size_t i = 0; i < all->len; i++)
{ {
char *key = cstr_cut_until (all->vector[i], " "); char *key = cstr_cut_until (all->vector[i], " ");
handle_command_set_assign_item (ctx, key, new_, add, remove); if (handle_command_set_assign_item (ctx, key, new_, add, remove))
changed = true;
free (key); free (key);
} }
config_item_destroy (new_); config_item_destroy (new_);
if (get_config_boolean (ctx->config.root, "general.autosave")) if (changed && get_config_boolean (ctx->config.root, "general.autosave"))
save_configuration (ctx); save_configuration (ctx);
return true; return true;
} }