git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] config: add back code comment
@ 2024-01-28 18:31 Kristoffer Haugsbakk
  2024-01-28 18:31 ` [PATCH 1/1] " Kristoffer Haugsbakk
  0 siblings, 1 reply; 6+ messages in thread
From: Kristoffer Haugsbakk @ 2024-01-28 18:31 UTC (permalink / raw)
  To: git; +Cc: Kristoffer Haugsbakk, ps

This is a follow-up to the kh/maintenance-use-xdg-when-it-should
[series] which was merged in 12ee4ed506 (Merge branch
'kh/maintenance-use-xdg-when-it-sho.., 2024-01-26).

I dropped a code comment while iterating on a refactor. It still makes
as much sense in this context as before the refactor (it’s a _refactor_
in the sense of “don’t change code behavior”).

The code comment was moved to `config.c` in patch v1 3/4.[1] But review
feedback said that this comment didn’t fit in this new place and that we
shouldn’t `die()` in `git_global_config`. So in v2 3/4[2] I removed the
comment in `git_global_config`. But I forgot to put the comment back to
its original place, where it still makes as much sense as before my
series.

[Here] is the diff when I squash this patch into c15129b699 (config:
factor out global config file retrieval, 2024-01-18).

Sorry about the churn.

Cc: ps@pks.im

🔗 series: https://lore.kernel.org/git/cover.1697660181.git.code@khaugsbakk.name/
🔗 1: https://lore.kernel.org/git/147c767443c35b3b4a5516bf40557f41bb201078.1697660181.git.code@khaugsbakk.name/
🔗 2: https://lore.kernel.org/git/32e5ec7d866ff8fd26554b325812c6e19cb65126.1705267839.git.code@khaugsbakk.name/
† Here:

    diff --git a/builtin/config.c b/builtin/config.c
    index 6fff265581..b55bfae7d6 100644
    --- a/builtin/config.c
    +++ b/builtin/config.c
    @@ -708,10 +708,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
            }

            if (use_global_config) {
    -		char *user_config, *xdg_config;
    -
    -		git_global_config_paths(&user_config, &xdg_config);
    -		if (!user_config)
    +		given_config_source.file = git_global_config();
    +		if (!given_config_source.file)
                            /*
                             * It is unknown if HOME/.gitconfig exists, so
                             * we do not know if we should write to XDG
    @@ -719,19 +717,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                             * is set and points at a sane location.
                             */
                            die(_("$HOME not set"));
    -
                    given_config_source.scope = CONFIG_SCOPE_GLOBAL;
    -
    -		if (access_or_warn(user_config, R_OK, 0) &&
    -		    xdg_config && !access_or_warn(xdg_config, R_OK, 0)) {
    -			given_config_source.file = xdg_config;
    -			free(user_config);
    -		} else {
    -			given_config_source.file = user_config;
    -			free(xdg_config);
    -		}
    -	}
    -	else if (use_system_config) {
    +	} else if (use_system_config) {
                    given_config_source.file = git_system_config();
                    given_config_source.scope = CONFIG_SCOPE_SYSTEM;
            } else if (use_local_config) {
    diff --git a/config.c b/config.c
    index ebc6a57e1c..3cfeb3d8bd 100644
    --- a/config.c
    +++ b/config.c
    @@ -1987,6 +1987,26 @@ char *git_system_config(void)
            return system_config;
     }

    +char *git_global_config(void)
    +{
    +	char *user_config, *xdg_config;
    +
    +	git_global_config_paths(&user_config, &xdg_config);
    +	if (!user_config) {
    +		free(xdg_config);
    +		return NULL;
    +	}
    +
    +	if (access_or_warn(user_config, R_OK, 0) && xdg_config &&
    +	    !access_or_warn(xdg_config, R_OK, 0)) {
    +		free(user_config);
    +		return xdg_config;
    +	} else {
    +		free(xdg_config);
    +		return user_config;
    +	}
    +}
    +
     void git_global_config_paths(char **user_out, char **xdg_out)
     {
            char *user_config = xstrdup_or_null(getenv("GIT_CONFIG_GLOBAL"));
    diff --git a/config.h b/config.h
    index e5e523553c..5dba984f77 100644
    --- a/config.h
    +++ b/config.h
    @@ -382,6 +382,7 @@ int config_error_nonbool(const char *);
     #endif

     char *git_system_config(void);
    +char *git_global_config(void);
     void git_global_config_paths(char **user, char **xdg);

     int git_config_parse_parameter(const char *, config_fn_t fn, void *data);


Kristoffer Haugsbakk (1):
  config: add back code comment

 builtin/config.c | 6 ++++++
 1 file changed, 6 insertions(+)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] config: add back code comment
  2024-01-28 18:31 [PATCH 0/1] config: add back code comment Kristoffer Haugsbakk
@ 2024-01-28 18:31 ` Kristoffer Haugsbakk
  2024-01-29 11:32   ` Patrick Steinhardt
  2024-01-29 17:57   ` [PATCH v2 0/1] " Kristoffer Haugsbakk
  0 siblings, 2 replies; 6+ messages in thread
From: Kristoffer Haugsbakk @ 2024-01-28 18:31 UTC (permalink / raw)
  To: git; +Cc: Kristoffer Haugsbakk

c15129b699 (config: factor out global config file retrieval, 2024-01-18)
was a refactor that moved some of the code in this function to
`config.c`. However, in the process I managed to drop this code comment
which explains `$HOME not set`.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
 builtin/config.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/builtin/config.c b/builtin/config.c
index 08fe36d499..b55bfae7d6 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -710,6 +710,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	if (use_global_config) {
 		given_config_source.file = git_global_config();
 		if (!given_config_source.file)
+			/*
+			 * It is unknown if HOME/.gitconfig exists, so
+			 * we do not know if we should write to XDG
+			 * location; error out even if XDG_CONFIG_HOME
+			 * is set and points at a sane location.
+			 */
 			die(_("$HOME not set"));
 		given_config_source.scope = CONFIG_SCOPE_GLOBAL;
 	} else if (use_system_config) {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] config: add back code comment
  2024-01-28 18:31 ` [PATCH 1/1] " Kristoffer Haugsbakk
@ 2024-01-29 11:32   ` Patrick Steinhardt
  2024-01-29 18:28     ` Junio C Hamano
  2024-01-29 17:57   ` [PATCH v2 0/1] " Kristoffer Haugsbakk
  1 sibling, 1 reply; 6+ messages in thread
From: Patrick Steinhardt @ 2024-01-29 11:32 UTC (permalink / raw)
  To: Kristoffer Haugsbakk; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1253 bytes --]

On Sun, Jan 28, 2024 at 07:31:40PM +0100, Kristoffer Haugsbakk wrote:
> c15129b699 (config: factor out global config file retrieval, 2024-01-18)
> was a refactor that moved some of the code in this function to
> `config.c`. However, in the process I managed to drop this code comment
> which explains `$HOME not set`.
> 
> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> ---
>  builtin/config.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/builtin/config.c b/builtin/config.c
> index 08fe36d499..b55bfae7d6 100644
> --- a/builtin/config.c
> +++ b/builtin/config.c
> @@ -710,6 +710,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)
>  	if (use_global_config) {
>  		given_config_source.file = git_global_config();
>  		if (!given_config_source.file)
> +			/*
> +			 * It is unknown if HOME/.gitconfig exists, so
> +			 * we do not know if we should write to XDG
> +			 * location; error out even if XDG_CONFIG_HOME
> +			 * is set and points at a sane location.
> +			 */
>  			die(_("$HOME not set"));
>  		given_config_source.scope = CONFIG_SCOPE_GLOBAL;
>  	} else if (use_system_config) {

Thanks for adding the comment back in! The patch looks good to me.

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 0/1] config: add back code comment
  2024-01-28 18:31 ` [PATCH 1/1] " Kristoffer Haugsbakk
  2024-01-29 11:32   ` Patrick Steinhardt
@ 2024-01-29 17:57   ` Kristoffer Haugsbakk
  2024-01-29 17:57     ` [PATCH v2 1/1] " Kristoffer Haugsbakk
  1 sibling, 1 reply; 6+ messages in thread
From: Kristoffer Haugsbakk @ 2024-01-29 17:57 UTC (permalink / raw)
  To: gitster; +Cc: Kristoffer Haugsbakk, git, ps

This is a follow-up to the kh/maintenance-use-xdg-when-it-should
[series] which was merged in 12ee4ed506 (Merge branch
'kh/maintenance-use-xdg-when-it-sho.., 2024-01-26).

I dropped a code comment while iterating on a refactor. It still makes
as much sense in this context as before the refactor (it’s a _refactor_
in the sense of “don’t change code behavior”).

The code comment was moved to `config.c` in patch v1 3/4.[1] But review
feedback said that this comment didn’t fit in this new place and that we
shouldn’t `die()` in `git_global_config`. So in v2 3/4[2] I removed the
comment in `git_global_config`. But I forgot to put the comment back to
its original place, where it still makes as much sense as before my
series.

See the cover letter on the first version for the diff when I squash
this patch into c15129b699 (config: factor out global config file
retrieval, 2024-01-18).

Sorry about the churn.

Cc: ps@pks.im

§ Changes in v2

Add an ack trailer.

This is the (tentative) final version. I read (interpreted)
`SubmittingPatches` as saying that the final version should be sent,
even though it’s just to add an additional trailer. I’m open for
feedback on the submission process of course.

I’ve added it after my signoff since it seems preferred to maintain the
chronology (although in this case either choice seems equally
clear). Also it seemed more common in the recent Git log.

🔗 series: https://lore.kernel.org/git/cover.1697660181.git.code@khaugsbakk.name/
🔗 1: https://lore.kernel.org/git/147c767443c35b3b4a5516bf40557f41bb201078.1697660181.git.code@khaugsbakk.name/
🔗 2: https://lore.kernel.org/git/32e5ec7d866ff8fd26554b325812c6e19cb65126.1705267839.git.code@khaugsbakk.name/

Kristoffer Haugsbakk (1):
  config: add back code comment

 builtin/config.c | 6 ++++++
 1 file changed, 6 insertions(+)

Range-diff against v1:
1:  48d66e94ec ! 1:  24f536d575 config: add back code comment
    @@ Commit message
         which explains `$HOME not set`.
     
         Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
    +    Acked-by: Patrick Steinhardt <ps@pks.im>
     
      ## builtin/config.c ##
     @@ builtin/config.c: int cmd_config(int argc, const char **argv, const char *prefix)
-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/1] config: add back code comment
  2024-01-29 17:57   ` [PATCH v2 0/1] " Kristoffer Haugsbakk
@ 2024-01-29 17:57     ` Kristoffer Haugsbakk
  0 siblings, 0 replies; 6+ messages in thread
From: Kristoffer Haugsbakk @ 2024-01-29 17:57 UTC (permalink / raw)
  To: gitster; +Cc: Kristoffer Haugsbakk, git, Patrick Steinhardt

c15129b699 (config: factor out global config file retrieval, 2024-01-18)
was a refactor that moved some of the code in this function to
`config.c`. However, in the process I managed to drop this code comment
which explains `$HOME not set`.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Acked-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/config.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/builtin/config.c b/builtin/config.c
index 08fe36d499..b55bfae7d6 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -710,6 +710,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	if (use_global_config) {
 		given_config_source.file = git_global_config();
 		if (!given_config_source.file)
+			/*
+			 * It is unknown if HOME/.gitconfig exists, so
+			 * we do not know if we should write to XDG
+			 * location; error out even if XDG_CONFIG_HOME
+			 * is set and points at a sane location.
+			 */
 			die(_("$HOME not set"));
 		given_config_source.scope = CONFIG_SCOPE_GLOBAL;
 	} else if (use_system_config) {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] config: add back code comment
  2024-01-29 11:32   ` Patrick Steinhardt
@ 2024-01-29 18:28     ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2024-01-29 18:28 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: Kristoffer Haugsbakk, git

Patrick Steinhardt <ps@pks.im> writes:

>>  		if (!given_config_source.file)
>> +			/*
>> +			 * It is unknown if HOME/.gitconfig exists, so
>> +			 * we do not know if we should write to XDG
>> +			 * location; error out even if XDG_CONFIG_HOME
>> +			 * is set and points at a sane location.
>> +			 */
>>  			die(_("$HOME not set"));
>>  		given_config_source.scope = CONFIG_SCOPE_GLOBAL;
>>  	} else if (use_system_config) {
>
> Thanks for adding the comment back in! The patch looks good to me.

Yeah, thanks, both.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-29 18:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-28 18:31 [PATCH 0/1] config: add back code comment Kristoffer Haugsbakk
2024-01-28 18:31 ` [PATCH 1/1] " Kristoffer Haugsbakk
2024-01-29 11:32   ` Patrick Steinhardt
2024-01-29 18:28     ` Junio C Hamano
2024-01-29 17:57   ` [PATCH v2 0/1] " Kristoffer Haugsbakk
2024-01-29 17:57     ` [PATCH v2 1/1] " Kristoffer Haugsbakk

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).