From: nguyenhu@minatec.inpg.fr
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Lucien KONG <Lucien.Kong@ensimag.imag.fr>,
Valentin DUPERRAY <Valentin.Duperray@ensimag.imag.fr>,
Thomas NGUY <Thomas.Nguy@ensimag.imag.fr>,
Franck JONAS <Franck.Jonas@ensimag.imag.fr>,
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: Re: [PATCHv3] Read from XDG configuration file, not write
Date: Sat, 02 Jun 2012 00:07:13 +0200 [thread overview]
Message-ID: <20120602000713.Horde.oEKVanwdC4BPyT0RI-CkWSA@webmail.minatec.grenoble-inp.fr> (raw)
Junio C Hamano <gitster@pobox.com> wrote:
> 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.
next reply other threads:[~2012-06-01 22:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-01 22:07 nguyenhu [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-05-30 21:19 [PATCHv2] Possibility to read both from ~/.gitconfig and from $XDG_CONFIG_HOME/git/config Huynh Khoi Nguyen NGUYEN
2012-05-31 14:40 ` [PATCHv3] Read from XDG configuration file, not write Huynh Khoi Nguyen NGUYEN
2012-05-31 20:13 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120602000713.Horde.oEKVanwdC4BPyT0RI-CkWSA@webmail.minatec.grenoble-inp.fr \
--to=nguyenhu@minatec.inpg.fr \
--cc=Franck.Jonas@ensimag.imag.fr \
--cc=Lucien.Kong@ensimag.imag.fr \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=Thomas.Nguy@ensimag.imag.fr \
--cc=Valentin.Duperray@ensimag.imag.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).