summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-02-20 09:53:29 (GMT)
committerJunio C Hamano <junkio@cox.net>2007-02-21 06:03:15 (GMT)
commitcc44c7655fe2dd0cfb46e841156634fe622df397 (patch)
tree6829fa96174f857c90e8baf966a2a8c7b924514a /git.c
parentcff0302c14522ba7b34265ee39f23e6321a4777d (diff)
downloadgit-cc44c7655fe2dd0cfb46e841156634fe622df397.zip
git-cc44c7655fe2dd0cfb46e841156634fe622df397.tar.gz
git-cc44c7655fe2dd0cfb46e841156634fe622df397.tar.bz2
Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when the parameters match specific patterns, so that they can be verified easily. Leftover from this will be fixed in a separate step, including idiotic conversions like if (!strncmp("foo", arg, 3)) => if (!(-prefixcmp(arg, "foo"))) This was done by using this script in px.perl #!/usr/bin/perl -i.bak -p if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) { s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|; } if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) { s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|; } and running: $ git grep -l strncmp -- '*.c' | xargs perl px.perl Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git.c')
-rw-r--r--git.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/git.c b/git.c
index 4dd1967..1fad852 100644
--- a/git.c
+++ b/git.c
@@ -48,7 +48,7 @@ static int handle_options(const char*** argv, int* argc)
/*
* Check remaining flags.
*/
- if (!strncmp(cmd, "--exec-path", 11)) {
+ if (!prefixcmp(cmd, "--exec-path")) {
cmd += 11;
if (*cmd == '=')
git_set_exec_path(cmd + 1);
@@ -66,7 +66,7 @@ static int handle_options(const char*** argv, int* argc)
setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);
(*argv)++;
(*argc)--;
- } else if (!strncmp(cmd, "--git-dir=", 10)) {
+ } else if (!prefixcmp(cmd, "--git-dir=")) {
setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
} else if (!strcmp(cmd, "--bare")) {
static char git_dir[PATH_MAX+1];
@@ -88,7 +88,7 @@ static char *alias_string;
static int git_alias_config(const char *var, const char *value)
{
- if (!strncmp(var, "alias.", 6) && !strcmp(var + 6, alias_command)) {
+ if (!prefixcmp(var, "alias.") && !strcmp(var + 6, alias_command)) {
alias_string = xstrdup(value);
}
return 0;
@@ -348,7 +348,7 @@ int main(int argc, const char **argv, char **envp)
* So we just directly call the internal command handler, and
* die if that one cannot handle it.
*/
- if (!strncmp(cmd, "git-", 4)) {
+ if (!prefixcmp(cmd, "git-")) {
cmd += 4;
argv[0] = cmd;
handle_internal_command(argc, argv, envp);
@@ -360,7 +360,7 @@ int main(int argc, const char **argv, char **envp)
argc--;
handle_options(&argv, &argc);
if (argc > 0) {
- if (!strncmp(argv[0], "--", 2))
+ if (!prefixcmp(argv[0], "--"))
argv[0] += 2;
} else {
/* Default command: "help" */