git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Matthew Hughes <matthewhughes934@gmail.com>
Cc: git@vger.kernel.org, Derrick Stolee <stolee@gmail.com>
Subject: Re: [QUESTION] how to find options set by scalar?
Date: Tue, 16 Sep 2025 09:45:44 +0200	[thread overview]
Message-ID: <aMkVqNbdgxqBJ9K4@pks.im> (raw)
In-Reply-To: <vppjutjcdglp44qvsk4qozphycyg663yrq5775zztim2oe7ty5@uttjrshb52bd>

On Tue, Sep 16, 2025 at 07:21:21AM +0100, Matthew Hughes wrote:
> Hi,
> 
> I'm wondering about making the config options set by `scalar register` a bit
> more discoverable.
> 
> Background: I was recently working in a large repo that recommended I run
> `scalar register` to help make git run a bit more smoothly, and I did (and
> didn't think much of it and forgot about it). It was a couple of weeks later I
> was again working in this repo and wanted to update my config, but was a bit
> confused when I saw a bunch of things set that I didn't remember setting, e.g.
> 'status.aheadBehind false'. It took me remembering that I had run `scalar
> register` and some poking around the code to discover where these options had
> come from.
> 
> I'm not sure if this is something best addressed by documentation, or maybe by
> `scalar register` adding comments to the config lines it changes?

I think documentation wouldn't help much -- the config entries we set
may change over time, so at the point in time where the user reads the
documentation it may already list entries that we either don't set at
all anymore or that we started setting now. So these config entries that
scalar(1) did set and the config entries that its man page claims to set
will diverge over time.

But doing this via comments may be viable indeed. A start for such a
change could be the following patch, which causes us to write a comment
"# set by scalar" after every config that we set in the repository:

diff --git a/scalar.c b/scalar.c
index 4a373c133d..c69ec57374 100644
--- a/scalar.c
+++ b/scalar.c
@@ -8,6 +8,7 @@
 #include "abspath.h"
 #include "gettext.h"
 #include "parse-options.h"
+#include "path.h"
 #include "config.h"
 #include "run-command.h"
 #include "simple-ipc.h"
@@ -102,8 +103,11 @@ static int set_scalar_config(const struct scalar_config *config, int reconfigure
 
 	if ((reconfigure && config->overwrite_on_reconfigure) ||
 	    repo_config_get_string(the_repository, config->key, &value)) {
+		char *file = repo_git_path(the_repository, "config");
 		trace2_data_string("scalar", the_repository, config->key, "created");
-		res = repo_config_set_gently(the_repository, config->key, config->value);
+		res = repo_config_set_multivar_in_file_gently(the_repository, file, config->key,
+							      config->value, NULL, " # set by scalar", 0);
+		free(file);
 	} else {
 		trace2_data_string("scalar", the_repository, config->key, "exists");
 		res = 0;

With that change in place, a (subset of) ".git/config" file would look
like this:

    [extensions]
        refstorage = reftable
    [core]
        repositoryformatversion = 1
        filemode = true
        bare = false
        logallrefupdates = true
        FSCache = true # set by scalar
        multiPackIndex = true # set by scalar
        preloadIndex = true # set by scalar
        untrackedCache = true # set by scalar
        autoCRLF = false # set by scalar
        safeCRLF = false # set by scalar
    [am]
        keepCR = true # set by scalar

Which I think is quite helpful overall. This cannot grow stale over time
and it's immediately obvious which entries have been set up by scalar in
case the user wants to drop them again.

Cc'ing Stolee, the primary author of scalar(1).

Patrick

  reply	other threads:[~2025-09-16  7:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-16  6:21 [QUESTION] how to find options set by scalar? Matthew Hughes
2025-09-16  7:45 ` Patrick Steinhardt [this message]
2025-09-18 19:32   ` Matthew Hughes
2025-09-18 20:29     ` Junio C Hamano
2025-09-19 15:38       ` Derrick Stolee
2025-09-22  6:20         ` Patrick Steinhardt
2025-09-22 13:36           ` Derrick Stolee
2025-10-19 17:43             ` Matthew Hughes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aMkVqNbdgxqBJ9K4@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=matthewhughes934@gmail.com \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).