threads / patch / 39053

patch, 7 partsattr.c: replace home_config_paths() with xdg_config_home()

Subject: [PATCH 2/7] attr.c: replace home_config_paths() with xdg_config_home()

## tl;dr

26 messages between Apr 12, 2015 and May 6, 2015. Diffs are folded; open one to read it.

replies: 25people: 6as markdown or json

Paul Tan· Apr 12, 2015, 07:46 UTC · lore

[PATCH 1/7] path.c: implement xdg_config_home()

The XDG base dir spec[1] specifies that configuration files be stored in a subdirectory in $XDG_CONFIG_HOME. To construct such a configuration file path, home_config_paths() can be used. However, home_config_paths() combines distinct functionality:

1. Retrieve the home git config file path ~/.gitconfig
2. Construct the XDG config path of the file specified by `file`.

This function was introduced in commit 21cf3227 ("read (but not write) from $XDG_CONFIG_HOME/git/config file"). While the intention of the function was to allow the home directory configuration file path and the xdg directory configuration file path to be retrieved with one function call, the hard-coding of the path ~/.gitconfig prevents it from being used for other configuration files. Furthermore, retrieving a file path relative to the user's home directory can be done with expand_user_path(). Hence, it can be seen that home_config_paths() introduces unnecessary complexity, especially if a user just wants to retrieve the xdg config file path.

As such, implement a simpler function xdg_config_home() for constructing the XDG base dir spec configuration file path. This function, together with expand_user_path(), can replace all uses of home_config_paths().

[1] http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 cache.h |  7 +++++++
 path.c  | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)
Show changes to 2 files +23 −0

cache.h, path.c

diff --git a/cache.h b/cache.h
index 3d3244b..7f9bab0 100644
--- a/cache.h
+++ b/cache.h
@@ -836,6 +836,13 @@ char *strip_path_suffix(const char *path, const char *suffix);
 int daemon_avoid_alias(const char *path);
 extern int is_ntfs_dotgit(const char *name);
 
+/**
+ * Returns the newly allocated string "$XDG_CONFIG_HOME/git/%s".  If
+ * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
+ * "$HOME/.config/git/%s". Returns NULL if an error occurred.
+ */
+extern char *xdg_config_home(const char *fn);
+
 /* object replacement */
 #define LOOKUP_REPLACE_OBJECT 1
 extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
diff --git a/path.c b/path.c
index e608993..4c32d16 100644
--- a/path.c
+++ b/path.c
@@ -856,3 +856,19 @@ int is_ntfs_dotgit(const char *name)
 			len = -1;
 		}
 }
+
+char *xdg_config_home(const char *fn)
+{
+	const char *config_home = getenv("XDG_CONFIG_HOME");
+
+	if (!fn)
+		fn = "";
+	if (!config_home || !config_home[0]) {
+		const char *home = getenv("HOME");
+
+		if (!home)
+			return NULL;
+		return mkpathdup("%s/.config/git/%s", home, fn);
+	} else
+		return mkpathdup("%s/git/%s", config_home, fn);
+}
-- 
2.1.4
Paul Tan· Apr 12, 2015, 07:46 UTC · re: Paul Tan · lore

Since only the xdg attributes file path is required, simplify the code by using xdg_config_home() instead of home_config_paths().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 attr.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Show changes to attr.c +2 −5
diff --git a/attr.c b/attr.c
index 1f9eebd..868dce3 100644
--- a/attr.c
+++ b/attr.c
@@ -488,7 +488,6 @@ static int git_attr_system(void)
 static void bootstrap_attr_stack(void)
 {
 	struct attr_stack *elem;
-	char *xdg_attributes_file;
 
 	if (attr_stack)
 		return;
@@ -507,10 +506,8 @@ static void bootstrap_attr_stack(void)
 		}
 	}
 
-	if (!git_attributes_file) {
-		home_config_paths(NULL, &xdg_attributes_file, "attributes");
-		git_attributes_file = xdg_attributes_file;
-	}
+	if (!git_attributes_file)
+		git_attributes_file = xdg_config_home("attributes");
 	if (git_attributes_file) {
 		elem = read_attr_from_file(git_attributes_file, 1);
 		if (elem) {
-- 
2.1.4
Paul Tan· Apr 12, 2015, 07:46 UTC · re: Paul Tan · lore

[PATCH 3/7] dir.c: replace home_config_paths() with xdg_config_home()

Since only the xdg excludes file path is required, simplify the code by replacing use of home_config_paths() with xdg_config_home().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 dir.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Show changes to dir.c +2 −5
diff --git a/dir.c b/dir.c
index 0943a81..335dc7e 100644
--- a/dir.c
+++ b/dir.c
@@ -1665,14 +1665,11 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 void setup_standard_excludes(struct dir_struct *dir)
 {
 	const char *path;
-	char *xdg_path;
 
 	dir->exclude_per_dir = ".gitignore";
 	path = git_path("info/exclude");
-	if (!excludes_file) {
-		home_config_paths(NULL, &xdg_path, "ignore");
-		excludes_file = xdg_path;
-	}
+	if (!excludes_file)
+		excludes_file = xdg_config_home("ignore");
 	if (!access_or_warn(path, R_OK, 0))
 		add_excludes_from_file(dir, path);
 	if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
-- 
2.1.4
Paul Tan· Apr 12, 2015, 07:46 UTC · re: Paul Tan · lore

[PATCH 4/7] credential-store.c: replace home_config_paths() with xdg_config_home()

Since only the xdg credentials file path is required, and home_config_paths() is unable to construct the path ~/.git-credentials, simplify the code by replacing home_config_paths() with xdg_config_home().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 credential-store.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to credential-store.c +1 −1
diff --git a/credential-store.c b/credential-store.c
index 8b22251..f692509 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -170,7 +170,7 @@ int main(int argc, char **argv)
 	} else {
 		if ((file = expand_user_path("~/.git-credentials")))
 			string_list_append_nodup(&fns, file);
-		home_config_paths(NULL, &file, "credentials");
+		file = xdg_config_home("credentials");
 		if (file)
 			string_list_append_nodup(&fns, file);
 	}
-- 
2.1.4
Paul Tan· Apr 12, 2015, 07:46 UTC · re: Paul Tan · lore

[PATCH 5/7] git-commit: replace use of home_config_paths()

Since home_config_paths() combines two distinct functionality already implemented by expand_user_path() and xdg_config_home(), and hides the home config file path ~/.gitconfig. Make the code more explicit by replacing the use of home_config_paths() with expand_user_path() and xdg_config_home().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 builtin/commit.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Show changes to builtin/commit.c +3 −5
diff --git a/builtin/commit.c b/builtin/commit.c
index da79ac4..c2ebea4 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1398,12 +1398,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
 static const char *implicit_ident_advice(void)
 {
-	char *user_config = NULL;
-	char *xdg_config = NULL;
-	int config_exists;
+	char *user_config = expand_user_path("~/.gitconfig");
+	char *xdg_config = xdg_config_home("config");
+	int config_exists = file_exists(user_config) || file_exists(xdg_config);
 
-	home_config_paths(&user_config, &xdg_config, "config");
-	config_exists = file_exists(user_config) || file_exists(xdg_config);
 	free(user_config);
 	free(xdg_config);
 
-- 
2.1.4
Paul Tan· Apr 12, 2015, 07:46 UTC · re: Paul Tan · lore

[PATCH 6/7] git-config: replace use of home_config_paths()

Since home_config_paths() combines distinct functionality already implemented by expand_user_path() and xdg_config_home(), and hides the home config file path ~/.gitconfig. Make the code more explicit by replacing the use of home_config_paths() with expand_user_path() and xdg_config_home().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 builtin/config.c | 6 ++----
 config.c         | 6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)
Show changes to 2 files +4 −8

builtin/config.c, config.c

diff --git a/builtin/config.c b/builtin/config.c
index d32c532..5e61f4a 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -488,10 +488,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	}
 
 	if (use_global_config) {
-		char *user_config = NULL;
-		char *xdg_config = NULL;
-
-		home_config_paths(&user_config, &xdg_config, "config");
+		char *user_config = expand_user_path("~/.gitconfig");
+		char *xdg_config = xdg_config_home("config");
 
 		if (!user_config)
 			/*
diff --git a/config.c b/config.c
index 66c0a51..3a619da 100644
--- a/config.c
+++ b/config.c
@@ -1185,10 +1185,8 @@ int git_config_system(void)
 int git_config_early(config_fn_t fn, void *data, const char *repo_config)
 {
 	int ret = 0, found = 0;
-	char *xdg_config = NULL;
-	char *user_config = NULL;
-
-	home_config_paths(&user_config, &xdg_config, "config");
+	char *xdg_config = xdg_config_home("config");
+	char *user_config = expand_user_path("~/.gitconfig");
 
 	if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
 		ret += git_config_from_file(fn, git_etc_gitconfig(),
-- 
2.1.4
Paul Tan· Apr 12, 2015, 07:46 UTC · re: Paul Tan · lore

[PATCH 7/7] path.c: remove home_config_paths()

home_config_paths() combines distinct functionality already implemented by expand_user_path() and xdg_config_home(), and it also hard-codes the path ~/.gitconfig, which makes it unsuitable to use for other home config file paths. Since its use will just add unnecessary complexity to the code, remove it.

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 cache.h |  1 -
 path.c  | 28 ----------------------------
 2 files changed, 29 deletions(-)
Show changes to 2 files +0 −29

cache.h, path.c

diff --git a/cache.h b/cache.h
index 7f9bab0..19d75ef 100644
--- a/cache.h
+++ b/cache.h
@@ -816,7 +816,6 @@ enum scld_error safe_create_leading_directories(char *path);
 enum scld_error safe_create_leading_directories_const(const char *path);
 
 int mkdir_in_gitdir(const char *path);
-extern void home_config_paths(char **global, char **xdg, char *file);
 extern char *expand_user_path(const char *path);
 const char *enter_repo(const char *path, int strict);
 static inline int is_absolute_path(const char *path)
diff --git a/path.c b/path.c
index 4c32d16..84ec589 100644
--- a/path.c
+++ b/path.c
@@ -130,34 +130,6 @@ char *git_path(const char *fmt, ...)
 	return ret;
 }
 
-void home_config_paths(char **global, char **xdg, char *file)
-{
-	char *xdg_home = getenv("XDG_CONFIG_HOME");
-	char *home = getenv("HOME");
-	char *to_free = NULL;
-
-	if (!home) {
-		if (global)
-			*global = NULL;
-	} else {
-		if (!xdg_home) {
-			to_free = mkpathdup("%s/.config", home);
-			xdg_home = to_free;
-		}
-		if (global)
-			*global = mkpathdup("%s/.gitconfig", home);
-	}
-
-	if (xdg) {
-		if (!xdg_home)
-			*xdg = NULL;
-		else
-			*xdg = mkpathdup("%s/git/%s", xdg_home, file);
-	}
-
-	free(to_free);
-}
-
 char *git_path_submodule(const char *path, const char *fmt, ...)
 {
 	char *pathname = get_pathname();
-- 
2.1.4
Johannes Schindelin· Apr 13, 2015, 15:50 UTC · re: Paul Tan · lore

Re: [PATCH 1/7] path.c: implement xdg_config_home()

Hi Paul,
maybe it would be a good idea to add a `0/7` mail that describes the overall goal of this patch series, much like a Pull Request? I found it very useful -- even for myself -- to set a description via `git branch --edit-description` and to let `git format-patch` use that via the `--cover-letter` option.
below just two minor nits because the rest of the patches looks fine to me:
On 2015-04-12 09:46, Paul Tan wrote:
Show 15 quoted lines
> diff --git a/cache.h b/cache.h
> index 3d3244b..7f9bab0 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -836,6 +836,13 @@ char *strip_path_suffix(const char *path, const
> char *suffix);
>  int daemon_avoid_alias(const char *path);
>  extern int is_ntfs_dotgit(const char *name);
>  
> +/**
> + * Returns the newly allocated string "$XDG_CONFIG_HOME/git/%s".  If
> + * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
> + * "$HOME/.config/git/%s". Returns NULL if an error occurred.
> + */
> +extern char *xdg_config_home(const char *fn);
Should this not be inserted close to home_config_paths()? Also, the name "fn" sounds more like "function" than like "filename" to me, especially keeping the name `config_fn_t` in mind. Maybe call the parameter "filename" to avoid confusion?

Thanks, Dscho

Paul Tan· Apr 14, 2015, 17:28 UTC · re: Johannes Schindelin · lore

[PATCH v2 1/7] path.c: implement xdg_config_home()

Hi,
On Mon, Apr 13, 2015 at 05:50:49PM +0200, Johannes Schindelin wrote:
Show 5 quoted lines
> maybe it would be a good idea to add a `0/7` mail that describes the
> overall goal of this patch series, much like a Pull Request? I found
> it very useful -- even for myself -- to set a description via `git
> branch --edit-description` and to let `git format-patch` use that via
> the `--cover-letter` option.

In this case I felt that the first patch's commit message was descriptive enough and a cover message would simply repeat it.

Show 20 quoted lines
> below just two minor nits because the rest of the patches looks fine to me:
> 
> On 2015-04-12 09:46, Paul Tan wrote:
> > diff --git a/cache.h b/cache.h
> > index 3d3244b..7f9bab0 100644
> > --- a/cache.h
> > +++ b/cache.h
> > @@ -836,6 +836,13 @@ char *strip_path_suffix(const char *path, const
> > char *suffix);
> >  int daemon_avoid_alias(const char *path);
> >  extern int is_ntfs_dotgit(const char *name);
> >  
> > +/**
> > + * Returns the newly allocated string "$XDG_CONFIG_HOME/git/%s".  If
> > + * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
> > + * "$HOME/.config/git/%s". Returns NULL if an error occurred.
> > + */
> > +extern char *xdg_config_home(const char *fn);
> 
> Should this not be inserted close to home_config_paths()?

A personal style thing, but I wanted to add the function's docstring to cache.h (where I personally think it belongs), but I didn't want to break up the huge block of path function declarations. Hence, it was added at the end.

> Also, the name "fn" sounds more like "function" than like "filename"
> to me, especially keeping the name `config_fn_t` in mind. Maybe call
> the parameter "filename" to avoid confusion?

That's true, especially since there is still lots of horizontal space for this name.

Below is the fixed patch. I also decided to return NULL if `filename` is NULL because such an input usually indicated an uncaught error. The docstring has also been modified to be a little clearer.

Thanks all for the reviews.

---- >8 ---- The XDG base dir spec[1] specifies that configuration files be stored in a subdirectory in $XDG_CONFIG_HOME. To construct such a configuration file path, home_config_paths() can be used. However, home_config_paths() combines distinct functionality:

1. Retrieve the home git config file path ~/.gitconfig
2. Construct the XDG config path of the file specified by `file`.

This function was introduced in commit 21cf3227 ("read (but not write) from $XDG_CONFIG_HOME/git/config file"). While the intention of the function was to allow the home directory configuration file path and the xdg directory configuration file path to be retrieved with one function call, the hard-coding of the path ~/.gitconfig prevents it from being used for other configuration files. Furthermore, retrieving a file path relative to the user's home directory can be done with expand_user_path(). Hence, it can be seen that home_config_paths() introduces unnecessary complexity, especially if a user just wants to retrieve the xdg config file path.

As such, implement a simpler function xdg_config_home() for constructing the XDG base dir spec configuration file path. This function, together with expand_user_path(), can replace all uses of home_config_paths().

[1] http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 cache.h |  8 ++++++++
 path.c  | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)
Show changes to 2 files +24 −0

cache.h, path.c

diff --git a/cache.h b/cache.h
index 3d3244b..2db10b8 100644
--- a/cache.h
+++ b/cache.h
@@ -836,6 +836,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
 int daemon_avoid_alias(const char *path);
 extern int is_ntfs_dotgit(const char *name);
 
+/**
+ * Returns the newly allocated string "$XDG_CONFIG_HOME/git/{filename}".  If
+ * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
+ * "$HOME/.config/git/{filename}". Returns NULL if filename is NULL or an error
+ * occurred.
+ */
+extern char *xdg_config_home(const char *filename);
+
 /* object replacement */
 #define LOOKUP_REPLACE_OBJECT 1
 extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
diff --git a/path.c b/path.c
index e608993..8ee7191 100644
--- a/path.c
+++ b/path.c
@@ -856,3 +856,19 @@ int is_ntfs_dotgit(const char *name)
 			len = -1;
 		}
 }
+
+char *xdg_config_home(const char *filename)
+{
+	const char *config_home = getenv("XDG_CONFIG_HOME");
+
+	if (!filename)
+		return NULL;
+	if (!config_home || !config_home[0]) {
+		const char *home = getenv("HOME");
+
+		if (!home)
+			return NULL;
+		return mkpathdup("%s/.config/git/%s", home, filename);
+	} else
+		return mkpathdup("%s/git/%s", config_home, filename);
+}
-- 
2.1.4
Eric Sunshine· Apr 16, 2015, 21:41 UTC · re: Paul Tan · lore

Re: [PATCH v2 1/7] path.c: implement xdg_config_home()

On Tue, Apr 14, 2015 at 1:28 PM, Paul Tan <pyokagan@gmail.com> wrote:
> Below is the fixed patch. I also decided to return NULL if `filename` is
> NULL because such an input usually indicated an uncaught error.

Unfortunately, this blurs the line between programmer error (passing NULL for filename) and a user/configuration error (XDG_CONFIG_HOME and HOME being undefined). If there is indeed no valid interpretation for filename==NULL, then it may be better to die() or assert() here to flag the programmer error as early as possible, rather than returning NULL.

More below.
Show 43 quoted lines
> ---- >8 ----
> The XDG base dir spec[1] specifies that configuration files be stored in
> a subdirectory in $XDG_CONFIG_HOME. To construct such a configuration
> file path, home_config_paths() can be used. However, home_config_paths()
> combines distinct functionality:
>
> 1. Retrieve the home git config file path ~/.gitconfig
>
> 2. Construct the XDG config path of the file specified by `file`.
>
> This function was introduced in commit 21cf3227 ("read (but not write)
> from $XDG_CONFIG_HOME/git/config file").  While the intention of the
> function was to allow the home directory configuration file path and the
> xdg directory configuration file path to be retrieved with one function
> call, the hard-coding of the path ~/.gitconfig prevents it from being
> used for other configuration files. Furthermore, retrieving a file path
> relative to the user's home directory can be done with
> expand_user_path(). Hence, it can be seen that home_config_paths()
> introduces unnecessary complexity, especially if a user just wants to
> retrieve the xdg config file path.
>
> As such, implement a simpler function xdg_config_home() for constructing
> the XDG base dir spec configuration file path. This function, together
> with expand_user_path(), can replace all uses of home_config_paths().
>
> [1] http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
>
> Signed-off-by: Paul Tan <pyokagan@gmail.com>
> ---
> diff --git a/cache.h b/cache.h
> index 3d3244b..2db10b8 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -836,6 +836,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
>  int daemon_avoid_alias(const char *path);
>  extern int is_ntfs_dotgit(const char *name);
>
> +/**
> + * Returns the newly allocated string "$XDG_CONFIG_HOME/git/{filename}".  If
> + * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
> + * "$HOME/.config/git/{filename}". Returns NULL if filename is NULL or an error
> + * occurred.
> + */

This is better than the original which said "$XDG_CONFIG_HOME/git/%s", but is still potentially confusing. When I read the earlier iteration, I was left with the impression that it was returning that literal string, with '$' and '%s' embedded, and that the caller would have to process it further to have '$' and '%s' expanded. Perhaps rephrasing it something like this will help?

    Return a newly allocated string with value xdg+"/git/"+filename
    where xdg is the interpolated value of $XDG_CONFIG_HOME if
    defined and non-empty, otherwise "$HOME/.config". Return NULL
    upon error.

Also, for consistency with other API documentation, say "Return" rather than "Returns".

More below.
Show 20 quoted lines
> +extern char *xdg_config_home(const char *filename);
> +
>  /* object replacement */
>  #define LOOKUP_REPLACE_OBJECT 1
>  extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
> diff --git a/path.c b/path.c
> index e608993..8ee7191 100644
> --- a/path.c
> +++ b/path.c
> @@ -856,3 +856,19 @@ int is_ntfs_dotgit(const char *name)
>                         len = -1;
>                 }
>  }
> +
> +char *xdg_config_home(const char *filename)
> +{
> +       const char *config_home = getenv("XDG_CONFIG_HOME");
> +
> +       if (!filename)
> +               return NULL;
See above regarding conflation of programmer error and user/configuration error.
> +       if (!config_home || !config_home[0]) {
On this project, *config_home is usually favored over config_home[0].
Show 7 quoted lines
> +               const char *home = getenv("HOME");
> +
> +               if (!home)
> +                       return NULL;
> +               return mkpathdup("%s/.config/git/%s", home, filename);
> +       } else
> +               return mkpathdup("%s/git/%s", config_home, filename);

This logic is more difficult to follow than it ought to be due to the use of 'config_home' so distant from the 'if' which checked it, and due to the nested 'if'. It could be expressed more straight-forwardly as:

    if (config_home && *config_home)
        return mkpathdup("%s/git/%s", config_home, filename);
    home = getenv("HOME");
    if (home)
        return mkpathdup("%s/.config/git/%s", home, filename);
    return NULL;
> +}
> --
> 2.1.4
Paul Tan· Apr 18, 2015, 07:51 UTC · re: Eric Sunshine · lore

Re: [PATCH v2 1/7] path.c: implement xdg_config_home()

Hi,
On Fri, Apr 17, 2015 at 5:41 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 41 quoted lines
> On Tue, Apr 14, 2015 at 1:28 PM, Paul Tan <pyokagan@gmail.com> wrote:
>> Below is the fixed patch. I also decided to return NULL if `filename` is
>> NULL because such an input usually indicated an uncaught error.
>
> Unfortunately, this blurs the line between programmer error (passing
> NULL for filename) and a user/configuration error (XDG_CONFIG_HOME and
> HOME being undefined). If there is indeed no valid interpretation for
> filename==NULL, then it may be better to die() or assert() here to
> flag the programmer error as early as possible, rather than returning
> NULL.
>
> More below.
>
>> ---
>> diff --git a/cache.h b/cache.h
>> index 3d3244b..2db10b8 100644
>> --- a/cache.h
>> +++ b/cache.h
>> @@ -836,6 +836,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
>>  int daemon_avoid_alias(const char *path);
>>  extern int is_ntfs_dotgit(const char *name);
>>
>> +/**
>> + * Returns the newly allocated string "$XDG_CONFIG_HOME/git/{filename}".  If
>> + * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
>> + * "$HOME/.config/git/{filename}". Returns NULL if filename is NULL or an error
>> + * occurred.
>> + */
>
> This is better than the original which said "$XDG_CONFIG_HOME/git/%s",
> but is still potentially confusing. When I read the earlier iteration,
> I was left with the impression that it was returning that literal
> string, with '$' and '%s' embedded, and that the caller would have to
> process it further to have '$' and '%s' expanded. Perhaps rephrasing
> it something like this will help?
>
>     Return a newly allocated string with value xdg+"/git/"+filename
>     where xdg is the interpolated value of $XDG_CONFIG_HOME if
>     defined and non-empty, otherwise "$HOME/.config". Return NULL
>     upon error.
>

Personally I think interpolated strings are easier to read than concatenated strings. $VARIABLE (all upper case) in shell scripting is understood to be an environment variable, and $variable (all lower case) to be a local variable.

Thinking about it again, I should not be using python-style format strings either ;-). So I would write it as "$XDG_CONFIG_HOME/git/$filename".

But anyway, I don't have strong opinions on documentation, so I will leave this to majority opinion. I will change it if you strongly disagree :-).

> Also, for consistency with other API documentation, say "Return"
> rather than "Returns".
Okay, will fix.
Show 52 quoted lines
>
> More below.
>
>> +extern char *xdg_config_home(const char *filename);
>> +
>>  /* object replacement */
>>  #define LOOKUP_REPLACE_OBJECT 1
>>  extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
>> diff --git a/path.c b/path.c
>> index e608993..8ee7191 100644
>> --- a/path.c
>> +++ b/path.c
>> @@ -856,3 +856,19 @@ int is_ntfs_dotgit(const char *name)
>>                         len = -1;
>>                 }
>>  }
>> +
>> +char *xdg_config_home(const char *filename)
>> +{
>> +       const char *config_home = getenv("XDG_CONFIG_HOME");
>> +
>> +       if (!filename)
>> +               return NULL;
>
> See above regarding conflation of programmer error and user/configuration error.
>
>> +       if (!config_home || !config_home[0]) {
>
> On this project, *config_home is usually favored over config_home[0].
>
>> +               const char *home = getenv("HOME");
>> +
>> +               if (!home)
>> +                       return NULL;
>> +               return mkpathdup("%s/.config/git/%s", home, filename);
>> +       } else
>> +               return mkpathdup("%s/git/%s", config_home, filename);
>
> This logic is more difficult to follow than it ought to be due to the
> use of 'config_home' so distant from the 'if' which checked it, and
> due to the nested 'if'. It could be expressed more straight-forwardly
> as:
>
>     if (config_home && *config_home)
>         return mkpathdup("%s/git/%s", config_home, filename);
>
>     home = getenv("HOME");
>     if (home)
>         return mkpathdup("%s/.config/git/%s", home, filename);
>
>     return NULL;
>

Ah, flipping the conditionals definitely makes it look nicer. I guess I will need your sign off to use your code? Thanks!

Regards, Paul

Eric Sunshine· Apr 20, 2015, 00:39 UTC · re: Paul Tan · lore

Re: [PATCH v2 1/7] path.c: implement xdg_config_home()

On Sat, Apr 18, 2015 at 3:51 AM, Paul Tan <pyokagan@gmail.com> wrote:
Show 29 quoted lines
> On Fri, Apr 17, 2015 at 5:41 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>> On Tue, Apr 14, 2015 at 1:28 PM, Paul Tan <pyokagan@gmail.com> wrote:
>>> + * Returns the newly allocated string "$XDG_CONFIG_HOME/git/{filename}".  If
>>> + * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
>>> + * "$HOME/.config/git/{filename}". Returns NULL if filename is NULL or an error
>>> + * occurred.
>> This is better than the original which said "$XDG_CONFIG_HOME/git/%s",
>> but is still potentially confusing. When I read the earlier iteration,
>> I was left with the impression that it was returning that literal
>> string, with '$' and '%s' embedded, and that the caller would have to
>> process it further to have '$' and '%s' expanded. Perhaps rephrasing
>> it something like this will help?
>>
>>     Return a newly allocated string with value xdg+"/git/"+filename
>>     where xdg is the interpolated value of $XDG_CONFIG_HOME if
>>     defined and non-empty, otherwise "$HOME/.config". Return NULL
>>     upon error.
>
> Personally I think interpolated strings are easier to read than
> concatenated strings. $VARIABLE (all upper case) in shell scripting is
> understood to be an environment variable, and $variable (all lower
> case) to be a local variable.
> Thinking about it again, I should not be using python-style format
> strings either ;-). So I would write it as
> "$XDG_CONFIG_HOME/git/$filename".
>
> But anyway, I don't have strong opinions on documentation, so I will
> leave this to majority opinion. I will change it if you strongly
> disagree :-).

Other than being enuinely confused by the original, and having to check the actual implementation for clarification, I don't feel strongly about it either. Perhaps mentioning "evaluation" like this might help?

    Return a newly allocated string with the evaluation of
    "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is
    non-empty, otherwise "$HOME/.config/git/$filename". Return
    NULL upon error.
More below.
Show 25 quoted lines
>>> +       if (!config_home || !config_home[0]) {
>>> +               const char *home = getenv("HOME");
>>> +
>>> +               if (!home)
>>> +                       return NULL;
>>> +               return mkpathdup("%s/.config/git/%s", home, filename);
>>> +       } else
>>> +               return mkpathdup("%s/git/%s", config_home, filename);
>>
>> This logic is more difficult to follow than it ought to be due to the
>> use of 'config_home' so distant from the 'if' which checked it, and
>> due to the nested 'if'. It could be expressed more straight-forwardly
>> as:
>>
>>     if (config_home && *config_home)
>>         return mkpathdup("%s/git/%s", config_home, filename);
>>
>>     home = getenv("HOME");
>>     if (home)
>>         return mkpathdup("%s/.config/git/%s", home, filename);
>>
>>     return NULL;
>
> Ah, flipping the conditionals definitely makes it look nicer. I guess
> I will need your sign off to use your code? Thanks!

My sign-off is probably overkill. I merely re-arranged some lines of code which you wrote. A simple Helped-by: is sufficient if you want to mention my name.

Paul Tan· Apr 21, 2015, 04:06 UTC · re: Eric Sunshine · lore

[PATCH v3 1/7] path.c: implement xdg_config_home()

Hi,
On Sun, Apr 19, 2015 at 08:39:44PM -0400, Eric Sunshine wrote:
Show 10 quoted lines
> Other than being enuinely confused by the original, and having to
> check the actual implementation for clarification, I don't feel
> strongly about it either. Perhaps mentioning "evaluation" like this
> might help?
> 
>     Return a newly allocated string with the evaluation of
>     "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is
>     non-empty, otherwise "$HOME/.config/git/$filename". Return
>     NULL upon error.
> 
This is perfect, thanks.

Re-rolled patch below now uses assert() to check if filename is non-NULL, and re-arranges the control flow.

--- >8 ---

The XDG base dir spec[1] specifies that configuration files be stored in a subdirectory in $XDG_CONFIG_HOME. To construct such a configuration file path, home_config_paths() can be used. However, home_config_paths() combines distinct functionality:

1. Retrieve the home git config file path ~/.gitconfig
2. Construct the XDG config path of the file specified by `file`.

This function was introduced in commit 21cf3227 ("read (but not write) from $XDG_CONFIG_HOME/git/config file"). While the intention of the function was to allow the home directory configuration file path and the xdg directory configuration file path to be retrieved with one function call, the hard-coding of the path ~/.gitconfig prevents it from being used for other configuration files. Furthermore, retrieving a file path relative to the user's home directory can be done with expand_user_path(). Hence, it can be seen that home_config_paths() introduces unnecessary complexity, especially if a user just wants to retrieve the xdg config file path.

As such, implement a simpler function xdg_config_home() for constructing the XDG base dir spec configuration file path. This function, together with expand_user_path(), can replace all uses of home_config_paths().

[1] http://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 cache.h |  7 +++++++
 path.c  | 15 +++++++++++++++
 2 files changed, 22 insertions(+)
Show changes to 2 files +22 −0

cache.h, path.c

diff --git a/cache.h b/cache.h
index 3d3244b..3512d32 100644
--- a/cache.h
+++ b/cache.h
@@ -836,6 +836,13 @@ char *strip_path_suffix(const char *path, const char *suffix);
 int daemon_avoid_alias(const char *path);
 extern int is_ntfs_dotgit(const char *name);
 
+/**
+ * Return a newly allocated string with the evaluation of
+ * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
+ * "$HOME/.config/git/$filename". Return NULL upon error.
+ */
+extern char *xdg_config_home(const char *filename);
+
 /* object replacement */
 #define LOOKUP_REPLACE_OBJECT 1
 extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
diff --git a/path.c b/path.c
index 595da81..c28b8f5 100644
--- a/path.c
+++ b/path.c
@@ -851,3 +851,18 @@ int is_ntfs_dotgit(const char *name)
 			len = -1;
 		}
 }
+
+char *xdg_config_home(const char *filename)
+{
+	const char *home, *config_home;
+
+	assert(filename);
+	config_home = getenv("XDG_CONFIG_HOME");
+	if (config_home && *config_home)
+		return mkpathdup("%s/git/%s", config_home, filename);
+
+	home = getenv("HOME");
+	if (home)
+		return mkpathdup("%s/.config/git/%s", home, filename);
+	return NULL;
+}
-- 
2.1.4
Paul Tan· May 6, 2015, 08:00 UTC · re: Paul Tan · lore

[PATCH v3 2/7] attr.c: replace home_config_paths() with xdg_config_home()

Since only the xdg attributes file path is required, simplify the code by using xdg_config_home() instead of home_config_paths().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
Re-sending the patch series. There are no changes.
 attr.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Show changes to attr.c +2 −5
diff --git a/attr.c b/attr.c
index 1f9eebd..868dce3 100644
--- a/attr.c
+++ b/attr.c
@@ -488,7 +488,6 @@ static int git_attr_system(void)
 static void bootstrap_attr_stack(void)
 {
 	struct attr_stack *elem;
-	char *xdg_attributes_file;
 
 	if (attr_stack)
 		return;
@@ -507,10 +506,8 @@ static void bootstrap_attr_stack(void)
 		}
 	}
 
-	if (!git_attributes_file) {
-		home_config_paths(NULL, &xdg_attributes_file, "attributes");
-		git_attributes_file = xdg_attributes_file;
-	}
+	if (!git_attributes_file)
+		git_attributes_file = xdg_config_home("attributes");
 	if (git_attributes_file) {
 		elem = read_attr_from_file(git_attributes_file, 1);
 		if (elem) {
-- 
2.1.4
Paul Tan· May 6, 2015, 08:01 UTC · re: Paul Tan · lore

[PATCH v3 3/7] dir.c: replace home_config_paths() with xdg_config_home()

Since only the xdg excludes file path is required, simplify the code by replacing use of home_config_paths() with xdg_config_home().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
Re-sending the patch series. There are no changes.
 dir.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Show changes to dir.c +2 −5
diff --git a/dir.c b/dir.c
index 0943a81..335dc7e 100644
--- a/dir.c
+++ b/dir.c
@@ -1665,14 +1665,11 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 void setup_standard_excludes(struct dir_struct *dir)
 {
 	const char *path;
-	char *xdg_path;
 
 	dir->exclude_per_dir = ".gitignore";
 	path = git_path("info/exclude");
-	if (!excludes_file) {
-		home_config_paths(NULL, &xdg_path, "ignore");
-		excludes_file = xdg_path;
-	}
+	if (!excludes_file)
+		excludes_file = xdg_config_home("ignore");
 	if (!access_or_warn(path, R_OK, 0))
 		add_excludes_from_file(dir, path);
 	if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
-- 
2.1.4
Paul Tan· May 6, 2015, 08:01 UTC · re: Paul Tan · lore

[PATCH v3 4/7] credential-store.c: replace home_config_paths() with xdg_config_home()

Since only the xdg credentials file path is required, and home_config_paths() is unable to construct the path ~/.git-credentials, simplify the code by replacing home_config_paths() with xdg_config_home().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
Re-sending the patch series. There are no changes.
 credential-store.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to credential-store.c +1 −1
diff --git a/credential-store.c b/credential-store.c
index 8b22251..f692509 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -170,7 +170,7 @@ int main(int argc, char **argv)
 	} else {
 		if ((file = expand_user_path("~/.git-credentials")))
 			string_list_append_nodup(&fns, file);
-		home_config_paths(NULL, &file, "credentials");
+		file = xdg_config_home("credentials");
 		if (file)
 			string_list_append_nodup(&fns, file);
 	}
-- 
2.1.4
Paul Tan· May 6, 2015, 08:01 UTC · re: Paul Tan · lore

[PATCH v3 5/7] git-commit: replace use of home_config_paths()

Since home_config_paths() combines two distinct functionality already implemented by expand_user_path() and xdg_config_home(), and hides the home config file path ~/.gitconfig. Make the code more explicit by replacing the use of home_config_paths() with expand_user_path() and xdg_config_home().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
Re-sending the patch series. There are no changes.
 builtin/commit.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Show changes to builtin/commit.c +3 −5
diff --git a/builtin/commit.c b/builtin/commit.c
index da79ac4..c2ebea4 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1398,12 +1398,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
 static const char *implicit_ident_advice(void)
 {
-	char *user_config = NULL;
-	char *xdg_config = NULL;
-	int config_exists;
+	char *user_config = expand_user_path("~/.gitconfig");
+	char *xdg_config = xdg_config_home("config");
+	int config_exists = file_exists(user_config) || file_exists(xdg_config);
 
-	home_config_paths(&user_config, &xdg_config, "config");
-	config_exists = file_exists(user_config) || file_exists(xdg_config);
 	free(user_config);
 	free(xdg_config);
 
-- 
2.1.4
Paul Tan· May 6, 2015, 08:01 UTC · re: Paul Tan · lore

[PATCH v3 6/7] git-config: replace use of home_config_paths()

Since home_config_paths() combines distinct functionality already implemented by expand_user_path() and xdg_config_home(), and hides the home config file path ~/.gitconfig. Make the code more explicit by replacing the use of home_config_paths() with expand_user_path() and xdg_config_home().

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
Re-sending the patch series. There are no changes.
 builtin/config.c | 6 ++----
 config.c         | 6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)
Show changes to 2 files +4 −8

builtin/config.c, config.c

diff --git a/builtin/config.c b/builtin/config.c
index d32c532..5e61f4a 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -488,10 +488,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	}
 
 	if (use_global_config) {
-		char *user_config = NULL;
-		char *xdg_config = NULL;
-
-		home_config_paths(&user_config, &xdg_config, "config");
+		char *user_config = expand_user_path("~/.gitconfig");
+		char *xdg_config = xdg_config_home("config");
 
 		if (!user_config)
 			/*
diff --git a/config.c b/config.c
index 66c0a51..3a619da 100644
--- a/config.c
+++ b/config.c
@@ -1185,10 +1185,8 @@ int git_config_system(void)
 int git_config_early(config_fn_t fn, void *data, const char *repo_config)
 {
 	int ret = 0, found = 0;
-	char *xdg_config = NULL;
-	char *user_config = NULL;
-
-	home_config_paths(&user_config, &xdg_config, "config");
+	char *xdg_config = xdg_config_home("config");
+	char *user_config = expand_user_path("~/.gitconfig");
 
 	if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
 		ret += git_config_from_file(fn, git_etc_gitconfig(),
-- 
2.1.4
Paul Tan· May 6, 2015, 08:01 UTC · re: Paul Tan · lore

[PATCH v3 7/7] path.c: remove home_config_paths()

home_config_paths() combines distinct functionality already implemented by expand_user_path() and xdg_config_home(), and it also hard-codes the path ~/.gitconfig, which makes it unsuitable to use for other home config file paths. Since its use will just add unnecessary complexity to the code, remove it.

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
Re-sending the patch series. There are no changes.
 cache.h |  1 -
 path.c  | 28 ----------------------------
 2 files changed, 29 deletions(-)
Show changes to 2 files +0 −29

cache.h, path.c

diff --git a/cache.h b/cache.h
index 3512d32..f6970bb 100644
--- a/cache.h
+++ b/cache.h
@@ -816,7 +816,6 @@ enum scld_error safe_create_leading_directories(char *path);
 enum scld_error safe_create_leading_directories_const(const char *path);
 
 int mkdir_in_gitdir(const char *path);
-extern void home_config_paths(char **global, char **xdg, char *file);
 extern char *expand_user_path(const char *path);
 const char *enter_repo(const char *path, int strict);
 static inline int is_absolute_path(const char *path)
diff --git a/path.c b/path.c
index c28b8f5..6b537cc 100644
--- a/path.c
+++ b/path.c
@@ -130,34 +130,6 @@ char *git_path(const char *fmt, ...)
 	return ret;
 }
 
-void home_config_paths(char **global, char **xdg, char *file)
-{
-	char *xdg_home = getenv("XDG_CONFIG_HOME");
-	char *home = getenv("HOME");
-	char *to_free = NULL;
-
-	if (!home) {
-		if (global)
-			*global = NULL;
-	} else {
-		if (!xdg_home) {
-			to_free = mkpathdup("%s/.config", home);
-			xdg_home = to_free;
-		}
-		if (global)
-			*global = mkpathdup("%s/.gitconfig", home);
-	}
-
-	if (xdg) {
-		if (!xdg_home)
-			*xdg = NULL;
-		else
-			*xdg = mkpathdup("%s/git/%s", xdg_home, file);
-	}
-
-	free(to_free);
-}
-
 char *git_path_submodule(const char *path, const char *fmt, ...)
 {
 	char *pathname = get_pathname();
-- 
2.1.4
Paul Tan· Apr 18, 2015, 08:48 UTC · re: Eric Sunshine · lore

Re: [PATCH v2 1/7] path.c: implement xdg_config_home()

Hi,
On Fri, Apr 17, 2015 at 5:41 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 10 quoted lines
> On Tue, Apr 14, 2015 at 1:28 PM, Paul Tan <pyokagan@gmail.com> wrote:
>> Below is the fixed patch. I also decided to return NULL if `filename` is
>> NULL because such an input usually indicated an uncaught error.
>
> Unfortunately, this blurs the line between programmer error (passing
> NULL for filename) and a user/configuration error (XDG_CONFIG_HOME and
> HOME being undefined). If there is indeed no valid interpretation for
> filename==NULL, then it may be better to die() or assert() here to
> flag the programmer error as early as possible, rather than returning
> NULL.
I'm inclined to agree, but off the top of my head an API user may wish to do:
    xdg_config_home(function_which_returns_NULL_on_error())

And wish for the error to propagate, but that may be considered sloppy programming and so it's better to treat a NULL input as a bug.

Will fix this by calling assert(). Thanks.

Regards, Paul

Junio C Hamano· Apr 14, 2015, 20:39 UTC · re: Johannes Schindelin · lore

Re: [PATCH 1/7] path.c: implement xdg_config_home()

Johannes Schindelin <johannes.schindelin@gmx.de> writes:
Show 20 quoted lines
>> diff --git a/cache.h b/cache.h
>> index 3d3244b..7f9bab0 100644
>> --- a/cache.h
>> +++ b/cache.h
>> @@ -836,6 +836,13 @@ char *strip_path_suffix(const char *path, const
>> char *suffix);
>>  int daemon_avoid_alias(const char *path);
>>  extern int is_ntfs_dotgit(const char *name);
>>  
>> +/**
>> + * Returns the newly allocated string "$XDG_CONFIG_HOME/git/%s".  If
>> + * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
>> + * "$HOME/.config/git/%s". Returns NULL if an error occurred.
>> + */
>> +extern char *xdg_config_home(const char *fn);
>
> Should this not be inserted close to home_config_paths()? Also, the
> name "fn" sounds more like "function" than like "filename" to me,
> especially keeping the name `config_fn_t` in mind. Maybe call the
> parameter "filename" to avoid confusion?

It is OK to omit the name in the extern declaration here. We have to have a sensible variable name in the definition in path.c, of course ;-), and "filename" sounds like a very sensible suggestion.

Stefan Beller· Apr 14, 2015, 22:28 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/7] path.c: implement xdg_config_home()

On Tue, Apr 14, 2015 at 1:39 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 27 quoted lines
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
>>> diff --git a/cache.h b/cache.h
>>> index 3d3244b..7f9bab0 100644
>>> --- a/cache.h
>>> +++ b/cache.h
>>> @@ -836,6 +836,13 @@ char *strip_path_suffix(const char *path, const
>>> char *suffix);
>>>  int daemon_avoid_alias(const char *path);
>>>  extern int is_ntfs_dotgit(const char *name);
>>>
>>> +/**
>>> + * Returns the newly allocated string "$XDG_CONFIG_HOME/git/%s".  If
>>> + * $XDG_CONFIG_HOME is unset or empty, returns the newly allocated string
>>> + * "$HOME/.config/git/%s". Returns NULL if an error occurred.
>>> + */
>>> +extern char *xdg_config_home(const char *fn);
>>
>> Should this not be inserted close to home_config_paths()? Also, the
>> name "fn" sounds more like "function" than like "filename" to me,
>> especially keeping the name `config_fn_t` in mind. Maybe call the
>> parameter "filename" to avoid confusion?
>
> It is OK to omit the name in the extern declaration here.  We have
> to have a sensible variable name in the definition in path.c, of
> course ;-), and "filename" sounds like a very sensible suggestion.
>

It is OK, but I think this is bad practice. Have a look at strbuf.h, there you'll find:

    extern int strbuf_getwholeline_fd(struct strbuf *, int, int);

It's not clear what the 2 ints are, probably a fd and a max size? Even if guessed correctly, you'd still need another guess for the order.

Junio C Hamano· Apr 14, 2015, 22:30 UTC · re: Stefan Beller · lore

Re: [PATCH 1/7] path.c: implement xdg_config_home()

Stefan Beller <sbeller@google.com> writes:
Show 5 quoted lines
> On Tue, Apr 14, 2015 at 1:39 PM, Junio C Hamano <gitster@pobox.com> wrote:
>
>> It is OK to omit the name in the extern declaration here.
>
> It is OK, but I think this is bad practice.

Take a special note on the word "here", meaning "in this particular case." It is perfectly fine when the meaning of the parameter is clear from its type.

I was assuming that our developers have common sense to disambiguate ambiguous cases, of course ;-)

Stefan Beller· Apr 14, 2015, 22:34 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/7] path.c: implement xdg_config_home()

I need to learn to read the whole sentence. :( Apologies.

On Tue, Apr 14, 2015 at 3:30 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> On Tue, Apr 14, 2015 at 1:39 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>
>>> It is OK to omit the name in the extern declaration here.
>>
>> It is OK, but I think this is bad practice.
>
> Take a special note on the word "here", meaning "in this particular
> case."  It is perfectly fine when the meaning of the parameter is
> clear from its type.
>
> I was assuming that our developers have common sense to disambiguate
> ambiguous cases, of course ;-)
Matthieu Moy· Apr 13, 2015, 21:43 UTC · re: Paul Tan · lore

Re: [PATCH 1/7] path.c: implement xdg_config_home()

Paul Tan <pyokagan@gmail.com> writes:
> As such, implement a simpler function xdg_config_home() for constructing
> the XDG base dir spec configuration file path. This function, together
> with expand_user_path(), can replace all uses of home_config_paths().
Indeed. The code looks much better after your patch series than before.

I agree with Dscho's remark that "fn" sounds like "function" more than "filename". Perhaps just "name" would be better.

Anyway, the series is
Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr>
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Stefan Beller· Apr 14, 2015, 00:18 UTC · re: Matthieu Moy · lore

Re: [PATCH 1/7] path.c: implement xdg_config_home()

On Mon, Apr 13, 2015 at 2:43 PM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

Show 10 quoted lines
> Paul Tan <pyokagan@gmail.com> writes:
>
>> As such, implement a simpler function xdg_config_home() for constructing
>> the XDG base dir spec configuration file path. This function, together
>> with expand_user_path(), can replace all uses of home_config_paths().
>
> Indeed. The code looks much better after your patch series than before.
>
> I agree with Dscho's remark that "fn" sounds like "function" more than
> "filename". Perhaps just "name" would be better.
I'd go with fname but that's just bikeshedding now.
>
> Anyway, the series is
>
> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr>
and
Reviewed-by: Stefan Beller <sbeller@google.com>
Show 8 quoted lines
>
> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

← back to recent threads