From: Tanay Abhra <tanayabh@gmail.com>
To: git@vger.kernel.org
Cc: Tanay Abhra <tanayabh@gmail.com>,
Ramkumar Ramachandra <artagnon@gmail.com>,
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: [PATCH/RFC] alias.c: Replace git_config with git_config_get_string
Date: Mon, 16 Jun 2014 02:15:54 -0700 [thread overview]
Message-ID: <1402910154-417-1-git-send-email-tanayabh@gmail.com> (raw)
Original implementation uses a callback based approach which has some
deficiencies like a convoluted control flow and redundant variables.
Use git_config_get_string instead of git_config to take advantage of
the config hash-table.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
**DOUBT**
This patch builds on top of patch series[1]. The first patch in the
replace `git_config` series is [2], which passed all the tests.
But this patch falters at this test in t1300-repo-config.sh,
git config alias.checkconfig "-c foo.check=bar config foo.check" &&
echo bar >expect &&
git checkconfig >actual &&
test_cmp expect actual
I hand tested this case and the outputs match. But I don't know why the tests
are failing.
In t1300-repo-config this test also fails,
# git config alias.split-cmdline-fix 'echo "' &&
# test_must_fail git split-cmdline-fix &&
# echo foo > foo &&
# git add foo &&
# git commit -m 'initial commit' &&
# git config branch.master.mergeoptions 'echo "' &&
# test_must_fail git merge master
Can anybody help me with this one?
Thanks.
[1] http://thread.gmane.org/gmane.comp.version-control.git/251704
[2] http://thread.gmane.org/gmane.comp.version-control.git/251707
Cheers,
Tanay Abhra.
alias.c | 27 ++++++++++-----------------
1 file changed, 10 insertions(+), 17 deletions(-)
diff --git a/alias.c b/alias.c
index 5efc3d6..fffad73 100644
--- a/alias.c
+++ b/alias.c
@@ -1,24 +1,17 @@
#include "cache.h"
-static const char *alias_key;
-static char *alias_val;
-
-static int alias_lookup_cb(const char *k, const char *v, void *cb)
-{
- if (starts_with(k, "alias.") && !strcmp(k + 6, alias_key)) {
- if (!v)
- return config_error_nonbool(k);
- alias_val = xstrdup(v);
- return 0;
- }
- return 0;
-}
-
char *alias_lookup(const char *alias)
{
- alias_key = alias;
- alias_val = NULL;
- git_config(alias_lookup_cb, NULL);
+ char *alias_key, *alias_val;
+ const char *v;
+ alias_key = xmalloc(7+strlen(alias));
+ strcpy(alias_key, "alias.");
+ strcat(alias_key, alias);
+ v = git_config_get_string(alias_key);
+ if (!v)
+ config_error_nonbool(alias_key);
+ alias_val = xstrdup(v);
+ free(alias_key);
return alias_val;
}
--
1.9.0.GIT
next reply other threads:[~2014-06-16 9:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-16 9:15 Tanay Abhra [this message]
2014-06-17 5:43 ` [PATCH/RFC] alias.c: Replace git_config with git_config_get_string Jeff King
2014-06-17 18:51 ` Tanay Abhra
2014-06-17 21:14 ` Jeff King
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=1402910154-417-1-git-send-email-tanayabh@gmail.com \
--to=tanayabh@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
/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).