From: Tanay Abhra <tanayabh@gmail.com>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>
Subject: Re: [PATCH v9r2 1/2] add `config_set` API for caching config-like files
Date: Thu, 17 Jul 2014 16:36:43 +0530 [thread overview]
Message-ID: <53C7AE43.5080402@gmail.com> (raw)
In-Reply-To: <vpqvbqwpalt.fsf@anie.imag.fr>
On 7/17/2014 3:31 PM, Matthieu Moy wrote:
> Tanay Abhra <tanayabh@gmail.com> writes:
>
>> I have a question about renaming git_config() to git_config_raw().
>> I was working on a patch and I am getting stuck here.
>> It fails in t1001, t1020 & t4018. The reason for the last test failure
>> is unknown right now. For the first two, it boils down to this,
>>
>> git init --bare bare-ancestor-aliased.git &&
>> cd bare-ancestor-aliased.git &&
>> echo "[alias] aliasedinit = init" >>config &&
>> mkdir plain-nested &&
>> cd plain-nested &&
>> git aliasedinit
>
> Git tries to read .git/config relative to the current directory, and
> tries to resolve aliases from it. The problem is: if one tries to do
> this from a subdirectory inside the repo, .git/config is not the right
> path, and the alias lookup fails.
>
> I'll investigate more later.
>
Hmn, this does the trick,
-- 8< --
diff --git a/cache.h b/cache.h
index c67639d..66b52f1 100644
--- a/cache.h
+++ b/cache.h
@@ -1272,6 +1272,7 @@ extern int git_config_from_buf(config_fn_t fn, const char *name,
const char *buf, size_t len, void *data);
extern void git_config_push_parameter(const char *text);
extern int git_config_from_parameters(config_fn_t fn, void *data);
+extern int git_config_raw(config_fn_t fn, void *);
extern int git_config(config_fn_t fn, void *);
extern int git_config_with_options(config_fn_t fn, void *,
struct git_config_source *config_source,
diff --git a/config.c b/config.c
index d14f761..9e3f99a 100644
--- a/config.c
+++ b/config.c
@@ -1222,11 +1222,36 @@ int git_config_with_options(config_fn_t fn, void *data,
return ret;
}
-int git_config(config_fn_t fn, void *data)
+extern int git_config_raw(config_fn_t fn, void *data)
{
return git_config_with_options(fn, data, NULL, 1);
}
+int git_configset_iter(struct config_set *cs, config_fn_t fn, void *data)
+{
+ int i;
+ struct string_list *strptr;
+ struct config_set_element *entry;
+ struct hashmap_iter iter;
+ hashmap_iter_init(&cs->config_hash, &iter);
+ while ((entry = hashmap_iter_next(&iter))) {
+ strptr = &entry->value_list;
+ for (i = 0; i < strptr->nr; i++) {
+ if (fn(entry->key, strptr->items[i].string, data) < 0)
+ die("bad config file");
+ }
+ }
+ return 0;
+}
+
+static void git_config_check_init(void);
+
+int git_config(config_fn_t fn, void *data)
+{
+ git_config_check_init();
+ return git_configset_iter(&the_config_set, fn, data);
+}
+
static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)
{
struct config_set_element k;
@@ -1409,7 +1434,7 @@ static void git_config_check_init(void)
if (the_config_set.hash_initialized)
return;
git_configset_init(&the_config_set);
- git_config(config_hash_callback, &the_config_set);
+ git_config_raw(config_hash_callback, &the_config_set);
}
void git_config_clear(void)
diff --git a/pager.c b/pager.c
index 8b5cbc5..b4237e6 100644
--- a/pager.c
+++ b/pager.c
@@ -177,7 +177,7 @@ int check_pager_config(const char *cmd)
c.cmd = cmd;
c.want = -1;
c.value = NULL;
- git_config(pager_command_config, &c);
+ git_config_raw(pager_command_config, &c);
if (c.value)
pager_program = c.value;
return c.want;
-- 8< --
The offending part is in git.c, line number 540:
static void execv_dashed_external(const char **argv)
{
struct strbuf cmd = STRBUF_INIT;
const char *tmp;
int status;
if (use_pager == -1)
use_pager = check_pager_config(argv[0]);
----------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^
commit_pager_choice();
which cause git_config() to be called before handle_alias
can call it in git.c line no 587,
static int run_argv(int *argcp, const char ***argv)
{
int done_alias = 0;
while (1) {
/* See if it's a builtin */
handle_builtin(*argcp, *argv);
/* .. then try the external ones */
execv_dashed_external(*argv);
/* calls git_config() first, skips the .git/config file*/
/* It could be an alias -- this works around the insanity
* of overriding "git log" with "git show" by having
* alias.log = show
*/
if (done_alias)
break;
save_env();
if (!handle_alias(argcp, argv))
/* does setup_git_directory_gently() before calling git_config() */
break;
done_alias = 1;
}
return done_alias;
}
I am searching for a more elegant solution to this problem.
Thanks,
Tanay Abhra.
next prev parent reply other threads:[~2014-07-17 11:06 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-15 14:29 [PATCH v9 0/3] git config cache & special querying api utilizing the cache Tanay Abhra
2014-07-15 14:29 ` [PATCH v9 1/2] add `config_set` API for caching config-like files Tanay Abhra
2014-07-15 15:46 ` Junio C Hamano
2014-07-15 16:22 ` Tanay Abhra
2014-07-16 11:41 ` [PATCH v9r1 " Tanay Abhra
2014-07-15 14:29 ` [PATCH v9 2/2] test-config: add tests for the config_set API Tanay Abhra
2014-07-15 15:57 ` Junio C Hamano
2014-07-15 17:07 ` Tanay Abhra
2014-07-15 18:26 ` Junio C Hamano
2014-07-16 11:44 ` [PATCH v9r1 " Tanay Abhra
2014-07-16 11:49 ` Matthieu Moy
2014-07-16 12:22 ` [PATCH v9r2 1/2] add `config_set` API for caching config-like files Tanay Abhra
2014-07-16 16:06 ` Matthieu Moy
2014-07-16 16:09 ` [PATCH 1/3] fixup for patch 2: minor style fix Matthieu Moy
2014-07-16 16:09 ` [PATCH 2/3] fixup for patch 2: actually check the return value Matthieu Moy
2014-07-16 16:55 ` Tanay Abhra
2014-07-16 17:10 ` Matthieu Moy
2014-07-16 16:09 ` [PATCH 3/3] fixup for patch 1: typo Matthieu Moy
2014-07-16 16:44 ` [PATCH v9r2 1/2] add `config_set` API for caching config-like files Tanay Abhra
2014-07-16 17:06 ` Matthieu Moy
[not found] ` <53C6C2BD.3030703@gmail.com>
2014-07-17 10:01 ` Matthieu Moy
2014-07-17 11:06 ` Tanay Abhra [this message]
2014-07-17 11:34 ` Matthieu Moy
2014-07-17 11:13 ` Matthieu Moy
2014-07-17 17:12 ` Junio C Hamano
2014-07-16 12:22 ` [PATCH v9r2 2/2] test-config: add tests for the config_set API Tanay Abhra
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=53C7AE43.5080402@gmail.com \
--to=tanayabh@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=artagnon@gmail.com \
--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.
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).