summaryrefslogtreecommitdiff
path: root/builtin-branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-02-20 01:53:29 -0800
committerJunio C Hamano <junkio@cox.net>2007-02-20 22:03:15 -0800
commitcc44c7655fe2dd0cfb46e841156634fe622df397 (patch)
tree6829fa96174f857c90e8baf966a2a8c7b924514a /builtin-branch.c
parentcff0302c14522ba7b34265ee39f23e6321a4777d (diff)
downloadgit-cc44c7655fe2dd0cfb46e841156634fe622df397.tar.gz
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 'builtin-branch.c')
-rw-r--r--builtin-branch.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/builtin-branch.c b/builtin-branch.c
index d0e7209368..d0179b00a2 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -59,7 +59,7 @@ int git_branch_config(const char *var, const char *value)
branch_use_color = git_config_colorbool(var, value);
return 0;
}
- if (!strncmp(var, "color.branch.", 13)) {
+ if (!prefixcmp(var, "color.branch.")) {
int slot = parse_branch_color_slot(var, 13);
color_parse(value, var, branch_colors[slot]);
return 0;
@@ -178,13 +178,13 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
int len;
/* Detect kind */
- if (!strncmp(refname, "refs/heads/", 11)) {
+ if (!prefixcmp(refname, "refs/heads/")) {
kind = REF_LOCAL_BRANCH;
refname += 11;
- } else if (!strncmp(refname, "refs/remotes/", 13)) {
+ } else if (!prefixcmp(refname, "refs/remotes/")) {
kind = REF_REMOTE_BRANCH;
refname += 13;
- } else if (!strncmp(refname, "refs/tags/", 10)) {
+ } else if (!prefixcmp(refname, "refs/tags/")) {
kind = REF_TAG;
refname += 10;
}
@@ -446,7 +446,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
reflog = 1;
continue;
}
- if (!strncmp(arg, "--abbrev=", 9)) {
+ if (!prefixcmp(arg, "--abbrev=")) {
abbrev = atoi(arg+9);
continue;
}
@@ -476,7 +476,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
detached = 1;
}
else {
- if (strncmp(head, "refs/heads/", 11))
+ if (prefixcmp(head, "refs/heads/"))
die("HEAD not found below refs/heads!");
head += 11;
}