git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv3] Read from XDG configuration file, not write

From
Nnguyenhu@minatec.inpg.fr <nguyenhu@minatec.inpg.fr>
Date
Jun 1, 2012, 22:07 UTC
Message-ID
<20120602000713.Horde.oEKVanwdC4BPyT0RI-CkWSA@webmail.minatec.grenoble-inp.fr>
Junio C Hamano <gitster@pobox.com> wrote:
Show 49 quoted lines
> Hrm, xdg_git_path() returns allocated memory, and each call site
> leaks its return value, no?
>
> I didn't mean a micro-helper function like xdg_git_path() when I
> suggested refactoring.  I meant a helper that figures out all the
> necessary bits in one go.  For example, can't the above call site
> look more like this?
>
>       static int get_value(const char *key_, const char *regex_)
>       {
>               int ret = -1;
>               char *global = NULL, *xdg = NULL, *repo_config = NULL;
>               const char *system_wide = NULL, *local;
>               struct config_include_data inc = CONFIG_INCLUDE_INIT;
>               config_fn_t fn;
>               void *data;
>
>               local = given_config_file;
>               if (!local) {
>                       local = repo_config = git_pathdup("config");
>                       if (git_config_system())
>                               system_wide = git_etc_gitconfig();
>                       home_config_paths(&global, &xdg);
>               }
>               ...
>
> And then the config.c::home_config_paths() may look like:
>
>       void home_config_paths(char **global, char **xdg)
>       {
>               char *xdg_home = getenv("XDG_CONFIG_HOME");
>               char *home = getenv("HOME");
>               char *to_free = NULL;
>
>               if (!home) {
>                       *global = NULL;
>               } else {
>                       if (!xdg_home) {
>                               to_free = strdup(mkpath("%s/.config", home));
>                               xdg_home = to_free;
>                       }
>                       *global = xstrdup(mkpath("%s/.gitconfig", home));
>               }
>
>               if (!xdg_home)
>                       *xdg = NULL;
>               else
>                       *xdg = xstrdup(mkpath("%s/git/config", xdg_home));
>               free(to_free);

We adapted this code to allow reuse and introduce default values to core.excludesfile and core.attributesfile in the XDG directory too, in our V4 version.

Message 1 of 1 in “Re: [PATCHv3] Read from XDG configuration file, not write”
  1. nguyenhu@minatec.inpg.frJun 1, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.