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>
48 files changed:
raw | patch | inline | side by side (parent: cff0302 )
- if (!strncmp(buffer, "delta ", 6 )) {
+ if (!prefixcmp(buffer, "delta " )) {
patch_method = BINARY_DELTA_DEFLATED;
origlen = strtoul(buffer + 6, NULL, 10);
}
patch_method = BINARY_DELTA_DEFLATED;
origlen = strtoul(buffer + 6, NULL, 10);
}
- else if (!strncmp(buffer, "literal ", 8 )) {
+ else if (!prefixcmp(buffer, "literal " )) {
patch_method = BINARY_LITERAL_DEFLATED;
origlen = strtoul(buffer + 8, NULL, 10);
}
patch_method = BINARY_LITERAL_DEFLATED;
origlen = strtoul(buffer + 8, NULL, 10);
}
read_stdin = 0;
continue;
}
read_stdin = 0;
continue;
}
- if (!strncmp(arg, "--exclude=", 10 )) {
+ if (!prefixcmp(arg, "--exclude=" )) {
struct excludes *x = xmalloc(sizeof(*x));
x->path = arg + 10;
x->next = excludes;
excludes = x;
continue;
}
struct excludes *x = xmalloc(sizeof(*x));
x->path = arg + 10;
x->next = excludes;
excludes = x;
continue;
}
- if (!strncmp(arg, "-p", 2 )) {
+ if (!prefixcmp(arg, "-p" )) {
p_value = atoi(arg + 2);
continue;
}
p_value = atoi(arg + 2);
continue;
}
line_termination = 0;
continue;
}
line_termination = 0;
continue;
}
- if (!strncmp(arg, "-C", 2 )) {
+ if (!prefixcmp(arg, "-C" )) {
p_context = strtoul(arg + 2, &end, 0);
if (*end != '\0')
die("unrecognized context count '%s'", arg + 2);
continue;
}
p_context = strtoul(arg + 2, &end, 0);
if (*end != '\0')
die("unrecognized context count '%s'", arg + 2);
continue;
}
- if (!strncmp(arg, "--whitespace=", 13 )) {
+ if (!prefixcmp(arg, "--whitespace=" )) {
whitespace_option = arg + 13;
parse_whitespace_option(arg + 13);
continue;
whitespace_option = arg + 13;
parse_whitespace_option(arg + 13);
continue;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
- if (!strncmp("--exec=", arg, 7 )) {
+ if (!(-prefixcmp(arg, "--exec=") )) {
if (exec_at)
die("multiple --exec specified");
exec = arg + 7;
if (exec_at)
die("multiple --exec specified");
exec = arg + 7;
if (buf[len-1] == '\n')
buf[--len] = 0;
if (strcmp(buf, "ACK")) {
if (buf[len-1] == '\n')
buf[--len] = 0;
if (strcmp(buf, "ACK")) {
- if (len > 5 && !strncmp(buf, "NACK ", 5 ))
+ if (len > 5 && !prefixcmp(buf, "NACK " ))
die("git-archive: NACK %s", buf + 5);
die("git-archive: protocol error");
}
die("git-archive: NACK %s", buf + 5);
die("git-archive: protocol error");
}
- if (!strncmp(arg, "--format=", 9 )) {
+ if (!prefixcmp(arg, "--format=" )) {
format = arg + 9;
continue;
}
format = arg + 9;
continue;
}
- if (!strncmp(arg, "--prefix=", 9 )) {
+ if (!prefixcmp(arg, "--prefix=" )) {
base = arg + 9;
continue;
}
base = arg + 9;
continue;
}
if (!strcmp(arg, "--"))
no_more_options = 1;
if (!no_more_options) {
if (!strcmp(arg, "--"))
no_more_options = 1;
if (!no_more_options) {
- if (!strncmp(arg, "--remote=", 9 )) {
+ if (!prefixcmp(arg, "--remote=" )) {
if (remote)
die("Multiple --remote specified");
remote = arg + 9;
if (remote)
die("Multiple --remote specified");
remote = arg + 9;
output_option |= OUTPUT_LONG_OBJECT_NAME;
else if (!strcmp("-S", arg) && ++i < argc)
revs_file = argv[i];
output_option |= OUTPUT_LONG_OBJECT_NAME;
else if (!strcmp("-S", arg) && ++i < argc)
revs_file = argv[i];
- else if (!strncmp("-M", arg, 2 )) {
+ else if (!(-prefixcmp(arg, "-M") )) {
opt |= PICKAXE_BLAME_MOVE;
blame_move_score = parse_score(arg+2);
}
opt |= PICKAXE_BLAME_MOVE;
blame_move_score = parse_score(arg+2);
}
- else if (!strncmp("-C", arg, 2 )) {
+ else if (!(-prefixcmp(arg, "-C") )) {
if (opt & PICKAXE_BLAME_COPY)
opt |= PICKAXE_BLAME_COPY_HARDER;
opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
blame_copy_score = parse_score(arg+2);
}
if (opt & PICKAXE_BLAME_COPY)
opt |= PICKAXE_BLAME_COPY_HARDER;
opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
blame_copy_score = parse_score(arg+2);
}
- else if (!strncmp("-L", arg, 2 )) {
+ else if (!(-prefixcmp(arg, "-L") )) {
if (!arg[2]) {
if (++i >= argc)
usage(blame_usage);
if (!arg[2]) {
if (++i >= argc)
usage(blame_usage);
branch_use_color = git_config_colorbool(var, value);
return 0;
}
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;
int slot = parse_branch_color_slot(var, 13);
color_parse(value, var, branch_colors[slot]);
return 0;
int len;
/* Detect kind */
int len;
/* Detect kind */
- if (!strncmp(refname, "refs/heads/", 11 )) {
+ if (!prefixcmp(refname, "refs/heads/" )) {
kind = REF_LOCAL_BRANCH;
refname += 11;
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;
kind = REF_REMOTE_BRANCH;
refname += 13;
- } else if (!strncmp(refname, "refs/tags/", 10 )) {
+ } else if (!prefixcmp(refname, "refs/tags/" )) {
kind = REF_TAG;
refname += 10;
}
kind = REF_TAG;
refname += 10;
}
- if (!strncmp(arg, "--abbrev=", 9 )) {
+ if (!prefixcmp(arg, "--abbrev=" )) {
abbrev = atoi(arg+9);
continue;
}
abbrev = atoi(arg+9);
continue;
}
- if (strncmp(head, "refs/heads/", 11 ))
+ if (prefixcmp(head, "refs/heads/" ))
die("HEAD not found below refs/heads!");
head += 11;
}
die("HEAD not found below refs/heads!");
head += 11;
}
to_tempfile = 1;
continue;
}
to_tempfile = 1;
continue;
}
- if (!strncmp(arg, "--prefix=", 9 )) {
+ if (!prefixcmp(arg, "--prefix=" )) {
state.base_dir = arg+9;
state.base_dir_len = strlen(state.base_dir);
continue;
}
state.base_dir = arg+9;
state.base_dir_len = strlen(state.base_dir);
continue;
}
- if (!strncmp(arg, "--stage=", 8 )) {
+ if (!prefixcmp(arg, "--stage=" )) {
if (!strcmp(arg + 8, "all")) {
to_tempfile = 1;
checkout_stage = CHECKOUT_ALL;
if (!strcmp(arg + 8, "all")) {
to_tempfile = 1;
checkout_stage = CHECKOUT_ALL;
* If --tags, then any tags are used.
* Otherwise only annotated tags are used.
*/
* If --tags, then any tags are used.
* Otherwise only annotated tags are used.
*/
- if (!strncmp(path, "refs/tags/", 10 )) {
+ if (!prefixcmp(path, "refs/tags/" )) {
if (object->type == OBJ_TAG)
prio = 2;
else
if (object->type == OBJ_TAG)
prio = 2;
else
all = 1;
else if (!strcmp(arg, "--tags"))
tags = 1;
all = 1;
else if (!strcmp(arg, "--tags"))
tags = 1;
- else if (!strncmp(arg, "--abbrev=", 9 )) {
+ else if (!prefixcmp(arg, "--abbrev=" )) {
abbrev = strtoul(arg + 9, NULL, 10);
if (abbrev != 0 && (abbrev < MINIMUM_ABBREV || 40 < abbrev))
abbrev = DEFAULT_ABBREV;
}
abbrev = strtoul(arg + 9, NULL, 10);
if (abbrev != 0 && (abbrev < MINIMUM_ABBREV || 40 < abbrev))
abbrev = DEFAULT_ABBREV;
}
- else if (!strncmp(arg, "--candidates=", 13 )) {
+ else if (!prefixcmp(arg, "--candidates=" )) {
max_candidates = strtoul(arg + 13, NULL, 10);
if (max_candidates < 1)
max_candidates = 1;
max_candidates = strtoul(arg + 13, NULL, 10);
if (max_candidates < 1)
max_candidates = 1;
if (len < 43 || line[40] != '\t')
return 1;
if (len < 43 || line[40] != '\t')
return 1;
- if (!strncmp(line + 41, "not-for-merge", 13 ))
+ if (!prefixcmp(line + 41, "not-for-merge" ))
return 0;
if (line[41] != '\t')
return 0;
if (line[41] != '\t')
if (pulling_head) {
origin = xstrdup(src);
src_data->head_status |= 1;
if (pulling_head) {
origin = xstrdup(src);
src_data->head_status |= 1;
- } else if (!strncmp(line, "branch ", 7 )) {
+ } else if (!prefixcmp(line, "branch " )) {
origin = xstrdup(line + 7);
append_to_list(&src_data->branch, origin, NULL);
src_data->head_status |= 2;
origin = xstrdup(line + 7);
append_to_list(&src_data->branch, origin, NULL);
src_data->head_status |= 2;
- } else if (!strncmp(line, "tag ", 4 )) {
+ } else if (!prefixcmp(line, "tag " )) {
origin = line;
append_to_list(&src_data->tag, xstrdup(origin + 4), NULL);
src_data->head_status |= 2;
origin = line;
append_to_list(&src_data->tag, xstrdup(origin + 4), NULL);
src_data->head_status |= 2;
- } else if (!strncmp(line, "remote branch ", 14 )) {
+ } else if (!prefixcmp(line, "remote branch " )) {
origin = xstrdup(line + 14);
append_to_list(&src_data->r_branch, origin, NULL);
src_data->head_status |= 2;
origin = xstrdup(line + 14);
append_to_list(&src_data->r_branch, origin, NULL);
src_data->head_status |= 2;
current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
if (!current_branch)
die("No current branch");
current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
if (!current_branch)
die("No current branch");
- if (!strncmp(current_branch, "refs/heads/", 11 ))
+ if (!prefixcmp(current_branch, "refs/heads/" ))
current_branch += 11;
while (fgets(line, sizeof(line), in)) {
current_branch += 11;
while (fgets(line, sizeof(line), in)) {
- if (!strncmp(arg, "--format=", 9 )) {
+ if (!prefixcmp(arg, "--format=" )) {
if (format)
die("more than one --format?");
format = arg + 9;
if (format)
die("more than one --format?");
format = arg + 9;
quote_style = QUOTE_TCL;
continue;
}
quote_style = QUOTE_TCL;
continue;
}
- if (!strncmp(arg, "--count=", 8 )) {
+ if (!prefixcmp(arg, "--count=" )) {
if (maxcount)
die("more than one --count?");
maxcount = atoi(arg + 8);
if (maxcount)
die("more than one --count?");
maxcount = atoi(arg + 8);
die("The number %s did not parse", arg);
continue;
}
die("The number %s did not parse", arg);
continue;
}
- if (!strncmp(arg, "--sort=", 7 )) {
+ if (!prefixcmp(arg, "--sort=" )) {
struct ref_sort *s = xcalloc(1, sizeof(*s));
int len;
struct ref_sort *s = xcalloc(1, sizeof(*s));
int len;
if (!head_points_at || !(flag & REF_ISSYMREF))
return error("HEAD is not a symbolic ref");
if (!head_points_at || !(flag & REF_ISSYMREF))
return error("HEAD is not a symbolic ref");
- if (strncmp(head_points_at, "refs/heads/", 11 ))
+ if (prefixcmp(head_points_at, "refs/heads/" ))
return error("HEAD points to something strange (%s)",
head_points_at);
if (is_null_sha1(sha1))
return error("HEAD points to something strange (%s)",
head_points_at);
if (is_null_sha1(sha1))
opt.word_regexp = 1;
continue;
}
opt.word_regexp = 1;
continue;
}
- if (!strncmp("-A", arg, 2 ) ||
- !strncmp("-B", arg, 2 ) ||
- !strncmp("-C", arg, 2 ) ||
+ if (!(-prefixcmp(arg, "-A") ) ||
+ !(-prefixcmp(arg, "-B") ) ||
+ !(-prefixcmp(arg, "-C") ) ||
(arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {
unsigned num;
const char *scan;
(arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {
unsigned num;
const char *scan;
for (i = 1; i < argc; i++, argv++) {
const char *arg = argv[1];
for (i = 1; i < argc; i++, argv++) {
const char *arg = argv[1];
- if (!strncmp(arg, "--template=", 11 ))
+ if (!prefixcmp(arg, "--template=" ))
template_dir = arg+11;
else if (!strcmp(arg, "--shared"))
shared_repository = PERM_GROUP;
template_dir = arg+11;
else if (!strcmp(arg, "--shared"))
shared_repository = PERM_GROUP;
- else if (!strncmp(arg, "--shared=", 9 ))
+ else if (!prefixcmp(arg, "--shared=" ))
shared_repository = git_config_perm("arg", arg+9);
else
usage(init_db_usage);
shared_repository = git_config_perm("arg", arg+9);
else
usage(init_db_usage);
rev->always_show_header = 0;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
rev->always_show_header = 0;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
- if (!strncmp(arg, "--encoding=", 11 )) {
+ if (!prefixcmp(arg, "--encoding=" )) {
arg += 11;
if (strcmp(arg, "none"))
git_log_output_encoding = strdup(arg);
arg += 11;
if (strcmp(arg, "none"))
git_log_output_encoding = strdup(arg);
sol += 2;
/* strip [PATCH] or [PATCH blabla] */
sol += 2;
/* strip [PATCH] or [PATCH blabla] */
- if (!keep_subject && !strncmp(sol, "[PATCH", 6 )) {
+ if (!keep_subject && !prefixcmp(sol, "[PATCH" )) {
char *eos = strchr(sol + 6, ']');
if (eos) {
while (isspace(*eos))
char *eos = strchr(sol + 6, ']');
if (eos) {
while (isspace(*eos))
else if (!strcmp(argv[i], "-n") ||
!strcmp(argv[i], "--numbered"))
numbered = 1;
else if (!strcmp(argv[i], "-n") ||
!strcmp(argv[i], "--numbered"))
numbered = 1;
- else if (!strncmp(argv[i], "--start-number=", 15 ))
+ else if (!prefixcmp(argv[i], "--start-number=" ))
start_number = strtol(argv[i] + 15, NULL, 10);
else if (!strcmp(argv[i], "--start-number")) {
i++;
start_number = strtol(argv[i] + 15, NULL, 10);
else if (!strcmp(argv[i], "--start-number")) {
i++;
}
else if (!strcmp(argv[i], "--attach"))
rev.mime_boundary = git_version_string;
}
else if (!strcmp(argv[i], "--attach"))
rev.mime_boundary = git_version_string;
- else if (!strncmp(argv[i], "--attach=", 9 ))
+ else if (!prefixcmp(argv[i], "--attach=" ))
rev.mime_boundary = argv[i] + 9;
else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
ignore_if_in_upstream = 1;
else if (!strcmp(argv[i], "--thread"))
thread = 1;
rev.mime_boundary = argv[i] + 9;
else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
ignore_if_in_upstream = 1;
else if (!strcmp(argv[i], "--thread"))
thread = 1;
- else if (!strncmp(argv[i], "--in-reply-to=", 14 ))
+ else if (!prefixcmp(argv[i], "--in-reply-to=" ))
in_reply_to = argv[i] + 14;
else if (!strcmp(argv[i], "--in-reply-to")) {
i++;
in_reply_to = argv[i] + 14;
else if (!strcmp(argv[i], "--in-reply-to")) {
i++;
die("Need a Message-Id for --in-reply-to");
in_reply_to = argv[i];
}
die("Need a Message-Id for --in-reply-to");
in_reply_to = argv[i];
}
- else if (!strncmp(argv[i], "--suffix=", 9 ))
+ else if (!prefixcmp(argv[i], "--suffix=" ))
fmt_patch_suffix = argv[i] + 9;
else
argv[j++] = argv[i];
fmt_patch_suffix = argv[i] + 9;
else
argv[j++] = argv[i];
add_exclude(argv[++i], "", 0, &dir.exclude_list[EXC_CMDL]);
continue;
}
add_exclude(argv[++i], "", 0, &dir.exclude_list[EXC_CMDL]);
continue;
}
- if (!strncmp(arg, "--exclude=", 10 )) {
+ if (!prefixcmp(arg, "--exclude=" )) {
exc_given = 1;
add_exclude(arg+10, "", 0, &dir.exclude_list[EXC_CMDL]);
continue;
exc_given = 1;
add_exclude(arg+10, "", 0, &dir.exclude_list[EXC_CMDL]);
continue;
add_excludes_from_file(&dir, argv[++i]);
continue;
}
add_excludes_from_file(&dir, argv[++i]);
continue;
}
- if (!strncmp(arg, "--exclude-from=", 15 )) {
+ if (!prefixcmp(arg, "--exclude-from=" )) {
exc_given = 1;
add_excludes_from_file(&dir, arg+15);
continue;
}
exc_given = 1;
add_excludes_from_file(&dir, arg+15);
continue;
}
- if (!strncmp(arg, "--exclude-per-directory=", 24 )) {
+ if (!prefixcmp(arg, "--exclude-per-directory=" )) {
exc_given = 1;
dir.exclude_per_dir = arg + 24;
continue;
exc_given = 1;
dir.exclude_per_dir = arg + 24;
continue;
error_unmatch = 1;
continue;
}
error_unmatch = 1;
continue;
}
- if (!strncmp(arg, "--abbrev=", 9 )) {
+ if (!prefixcmp(arg, "--abbrev=" )) {
abbrev = strtoul(arg+9, NULL, 10);
if (abbrev && abbrev < MINIMUM_ABBREV)
abbrev = MINIMUM_ABBREV;
abbrev = strtoul(arg+9, NULL, 10);
if (abbrev && abbrev < MINIMUM_ABBREV)
abbrev = MINIMUM_ABBREV;
metainfo_charset = def_charset;
else if (!strcmp(argv[1], "-n"))
metainfo_charset = NULL;
metainfo_charset = def_charset;
else if (!strcmp(argv[1], "-n"))
metainfo_charset = NULL;
- else if (!strncmp(argv[1], "--encoding=", 11 ))
+ else if (!prefixcmp(argv[1], "--encoding=" ))
metainfo_charset = argv[1] + 11;
else
usage(mailinfo_usage);
metainfo_charset = argv[1] + 11;
else
usage(mailinfo_usage);
struct name_ref_data *data = cb_data;
int deref = 0;
struct name_ref_data *data = cb_data;
int deref = 0;
- if (data->tags_only && strncmp(path, "refs/tags/", 10 ))
+ if (data->tags_only && prefixcmp(path, "refs/tags/" ))
return 0;
if (data->ref_filter && fnmatch(data->ref_filter, path, 0))
return 0;
if (data->ref_filter && fnmatch(data->ref_filter, path, 0))
if (o && o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o;
if (o && o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o;
- if (!strncmp(path, "refs/heads/", 11 ))
+ if (!prefixcmp(path, "refs/heads/" ))
- else if (!strncmp(path, "refs/", 5 ))
+ else if (!prefixcmp(path, "refs/" ))
path = path + 5;
name_rev(commit, xstrdup(path), 0, 0, deref);
path = path + 5;
name_rev(commit, xstrdup(path), 0, 0, deref);
} else if (!strcmp(*argv, "--tags")) {
data.tags_only = 1;
continue;
} else if (!strcmp(*argv, "--tags")) {
data.tags_only = 1;
continue;
- } else if (!strncmp(*argv, "--refs=", 7 )) {
+ } else if (!prefixcmp(*argv, "--refs=" )) {
data.ref_filter = *argv + 7;
continue;
} else if (!strcmp(*argv, "--all")) {
data.ref_filter = *argv + 7;
continue;
} else if (!strcmp(*argv, "--all")) {
incremental = 1;
continue;
}
incremental = 1;
continue;
}
- if (!strncmp("--window=", arg, 9 )) {
+ if (!(-prefixcmp(arg, "--window=") )) {
char *end;
window = strtoul(arg+9, &end, 0);
if (!arg[9] || *end)
usage(pack_usage);
continue;
}
char *end;
window = strtoul(arg+9, &end, 0);
if (!arg[9] || *end)
usage(pack_usage);
continue;
}
- if (!strncmp("--depth=", arg, 8 )) {
+ if (!(-prefixcmp(arg, "--depth=") )) {
char *end;
depth = strtoul(arg+8, &end, 0);
if (!arg[8] || *end)
char *end;
depth = strtoul(arg+8, &end, 0);
if (!arg[8] || *end)
continue;
}
if (!strcmp("--unpacked", arg) ||
continue;
}
if (!strcmp("--unpacked", arg) ||
- !strncmp("--unpacked=", arg, 11 ) ||
+ !(-prefixcmp(arg, "--unpacked=") ) ||
!strcmp("--reflog", arg) ||
!strcmp("--all", arg)) {
use_internal_rev_list = 1;
!strcmp("--reflog", arg) ||
!strcmp("--all", arg)) {
use_internal_rev_list = 1;
/* Do not pack the symbolic refs */
if ((flags & REF_ISSYMREF))
return 0;
/* Do not pack the symbolic refs */
if ((flags & REF_ISSYMREF))
return 0;
- is_tag_ref = !strncmp(path, "refs/tags/", 10 );
+ is_tag_ref = !prefixcmp(path, "refs/tags/" );
/* ALWAYS pack refs that were already packed or are tags */
if (!cb->all && !is_tag_ref && !(flags & REF_ISPACKED))
/* ALWAYS pack refs that were already packed or are tags */
if (!cb->all && !is_tag_ref && !(flags & REF_ISPACKED))
/* Ignore the "refs/" at the beginning of the refname */
ref += 5;
/* Ignore the "refs/" at the beginning of the refname */
ref += 5;
- if (!strncmp(ref, "tags/", 5 ))
+ if (!prefixcmp(ref, "tags/" ))
add_refspec(xstrdup(ref));
return 0;
}
add_refspec(xstrdup(ref));
return 0;
}
int is_refspec;
char *s, *p;
int is_refspec;
char *s, *p;
- if (!strncmp("URL:", buffer, 4 )) {
+ if (!(-prefixcmp(buffer, "URL:") )) {
is_refspec = 0;
s = buffer + 4;
is_refspec = 0;
s = buffer + 4;
- } else if (!strncmp("Push:", buffer, 5 )) {
+ } else if (!(-prefixcmp(buffer, "Push:") )) {
is_refspec = 1;
s = buffer + 5;
} else
is_refspec = 1;
s = buffer + 5;
} else
static int get_remote_config(const char* key, const char* value)
{
static int get_remote_config(const char* key, const char* value)
{
- if (!strncmp(key, "remote.", 7 ) &&
+ if (!prefixcmp(key, "remote." ) &&
!strncmp(key + 7, config_repo, config_repo_len)) {
if (!strcmp(key + 7 + config_repo_len, ".url")) {
if (config_current_uri < MAX_URI)
!strncmp(key + 7, config_repo, config_repo_len)) {
if (!strcmp(key + 7 + config_repo_len, ".url")) {
if (config_current_uri < MAX_URI)
const char **dest_refspec = refspec;
const char *dest = uri[i];
const char *sender = "git-send-pack";
const char **dest_refspec = refspec;
const char *dest = uri[i];
const char *sender = "git-send-pack";
- if (!strncmp(dest, "http://", 7 ) ||
- !strncmp(dest, "https://", 8 ))
+ if (!prefixcmp(dest, "http://" ) ||
+ !prefixcmp(dest, "https://" ))
sender = "git-http-push";
else if (thin)
argv[dest_argc++] = "--thin";
sender = "git-http-push";
else if (thin)
argv[dest_argc++] = "--thin";
- if (!strncmp(arg, "--repo=", 7 )) {
+ if (!prefixcmp(arg, "--repo=" )) {
repo = arg+7;
continue;
}
repo = arg+7;
continue;
}
- if (!strncmp(arg, "--receive-pack=", 15 )) {
+ if (!prefixcmp(arg, "--receive-pack=" )) {
receivepack = arg;
continue;
}
receivepack = arg;
continue;
}
- if (!strncmp(arg, "--exec=", 7 )) {
+ if (!prefixcmp(arg, "--exec=" )) {
receivepack = arg;
continue;
}
receivepack = arg;
continue;
}
* entries and put the entries from the tree under the
* given subdirectory.
*/
* entries and put the entries from the tree under the
* given subdirectory.
*/
- if (!strncmp(arg, "--prefix=", 9 )) {
+ if (!prefixcmp(arg, "--prefix=" )) {
if (stage || opts.merge || opts.prefix)
usage(read_tree_usage);
opts.prefix = arg + 9;
if (stage || opts.merge || opts.prefix)
usage(read_tree_usage);
opts.prefix = arg + 9;
- if (!strncmp(arg, "--exclude-per-directory=", 24 )) {
+ if (!prefixcmp(arg, "--exclude-per-directory=" )) {
struct dir_struct *dir;
if (opts.dir)
struct dir_struct *dir;
if (opts.dir)
const char *arg = argv[i];
if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
cb.dry_run = 1;
const char *arg = argv[i];
if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
cb.dry_run = 1;
- else if (!strncmp(arg, "--expire=", 9 ))
+ else if (!prefixcmp(arg, "--expire=" ))
cb.expire_total = approxidate(arg + 9);
cb.expire_total = approxidate(arg + 9);
- else if (!strncmp(arg, "--expire-unreachable=", 21 ))
+ else if (!prefixcmp(arg, "--expire-unreachable=" ))
cb.expire_unreachable = approxidate(arg + 21);
else if (!strcmp(arg, "--stale-fix"))
cb.stalefix = 1;
cb.expire_unreachable = approxidate(arg + 21);
else if (!strcmp(arg, "--stale-fix"))
cb.stalefix = 1;
SHA1_Init(&ctx);
while (fgets(buf, sizeof(buf), f)) {
SHA1_Init(&ctx);
while (fgets(buf, sizeof(buf), f)) {
- if (!strncmp("<<<<<<< ", buf, 8 ))
+ if (!(-prefixcmp(buf, "<<<<<<< ") ))
- else if (!strncmp("=======", buf, 7 ))
+ else if (!(-prefixcmp(buf, "=======") ))
- else if (!strncmp(">>>>>>> ", buf, 8 )) {
+ else if (!(-prefixcmp(buf, ">>>>>>> ") )) {
hunk_no++;
hunk = 0;
if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
hunk_no++;
hunk = 0;
if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
continue;
}
if (!strcmp(arg, "--short") ||
continue;
}
if (!strcmp(arg, "--short") ||
- !strncmp(arg, "--short=", 8 )) {
+ !prefixcmp(arg, "--short=" )) {
filter &= ~(DO_FLAGS|DO_NOREV);
verify = 1;
abbrev = DEFAULT_ABBREV;
filter &= ~(DO_FLAGS|DO_NOREV);
verify = 1;
abbrev = DEFAULT_ABBREV;
- if (!strncmp(arg, "--since=", 8 )) {
+ if (!prefixcmp(arg, "--since=" )) {
show_datestring("--max-age=", arg+8);
continue;
}
show_datestring("--max-age=", arg+8);
continue;
}
- if (!strncmp(arg, "--after=", 8 )) {
+ if (!prefixcmp(arg, "--after=" )) {
show_datestring("--max-age=", arg+8);
continue;
}
show_datestring("--max-age=", arg+8);
continue;
}
- if (!strncmp(arg, "--before=", 9 )) {
+ if (!prefixcmp(arg, "--before=" )) {
show_datestring("--min-age=", arg+9);
continue;
}
show_datestring("--min-age=", arg+9);
continue;
}
- if (!strncmp(arg, "--until=", 8 )) {
+ if (!prefixcmp(arg, "--until=" )) {
show_datestring("--min-age=", arg+8);
continue;
}
show_datestring("--min-age=", arg+8);
continue;
}
- if (!strncmp(oneline, "[PATCH", 6 )) {
+ if (!prefixcmp(oneline, "[PATCH" )) {
char *eob = strchr(oneline, ']');
if (eob) {
char *eob = strchr(oneline, ']');
if (eob) {
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
char *bob;
if ((buffer[0] == 'A' || buffer[0] == 'a') &&
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
char *bob;
if ((buffer[0] == 'A' || buffer[0] == 'a') &&
- !strncmp(buffer + 1, "uthor: ", 7 ) &&
+ !prefixcmp(buffer + 1, "uthor: " ) &&
(bob = strchr(buffer + 7, '<')) != NULL) {
char buffer2[1024], offset = 0;
(bob = strchr(buffer + 7, '<')) != NULL) {
char buffer2[1024], offset = 0;
- if (!strncmp(buffer, "author ", 7 )) {
+ if (!prefixcmp(buffer, "author " )) {
char *bracket = strchr(buffer, '<');
if (bracket == NULL || bracket > eol)
char *bracket = strchr(buffer, '<');
if (bracket == NULL || bracket > eol)
pretty, sizeof(pretty), 0, NULL, NULL, 0);
else
strcpy(pretty, "(unavailable)");
pretty, sizeof(pretty), 0, NULL, NULL, 0);
else
strcpy(pretty, "(unavailable)");
- if (!strncmp(pretty, "[PATCH] ", 8 ))
+ if (!prefixcmp(pretty, "[PATCH] " ))
cp = pretty + 8;
else
cp = pretty;
cp = pretty + 8;
else
cp = pretty;
static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
{
- if (strncmp(refname, "refs/tags/", 10 ))
+ if (prefixcmp(refname, "refs/tags/" ))
return 0;
return append_ref(refname + 5, sha1, 0);
}
return 0;
return append_ref(refname + 5, sha1, 0);
}
return 0;
if (fnmatch(match_ref_pattern, tail, 0))
return 0;
return 0;
if (fnmatch(match_ref_pattern, tail, 0))
return 0;
- if (!strncmp("refs/heads/", refname, 11 ))
+ if (!(-prefixcmp(refname, "refs/heads/") ))
return append_head_ref(refname, sha1, flag, cb_data);
return append_head_ref(refname, sha1, flag, cb_data);
- if (!strncmp("refs/tags/", refname, 10 ))
+ if (!(-prefixcmp(refname, "refs/tags/") ))
return append_tag_ref(refname, sha1, flag, cb_data);
return append_ref(refname, sha1, 0);
}
return append_tag_ref(refname, sha1, flag, cb_data);
return append_ref(refname, sha1, 0);
}
if ((!head[0]) ||
(head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
return 0;
if ((!head[0]) ||
(head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
return 0;
- if (!strncmp(head, "refs/heads/", 11 ))
+ if (!prefixcmp(head, "refs/heads/" ))
- if (!strncmp(name, "refs/heads/", 11 ))
+ if (!prefixcmp(name, "refs/heads/" ))
- else if (!strncmp(name, "heads/", 6 ))
+ else if (!prefixcmp(name, "heads/" ))
name += 6;
return !strcmp(head, name);
}
name += 6;
return !strcmp(head, name);
}
with_current_branch = 1;
else if (!strcmp(arg, "--sha1-name"))
sha1_name = 1;
with_current_branch = 1;
else if (!strcmp(arg, "--sha1-name"))
sha1_name = 1;
- else if (!strncmp(arg, "--more=", 7 ))
+ else if (!prefixcmp(arg, "--more=" ))
extra = atoi(arg + 7);
else if (!strcmp(arg, "--merge-base"))
merge_base = 1;
extra = atoi(arg + 7);
else if (!strcmp(arg, "--merge-base"))
merge_base = 1;
else if (!strcmp(arg, "--reflog") || !strcmp(arg, "-g")) {
reflog = DEFAULT_REFLOG;
}
else if (!strcmp(arg, "--reflog") || !strcmp(arg, "-g")) {
reflog = DEFAULT_REFLOG;
}
- else if (!strncmp(arg, "--reflog=", 9 ))
+ else if (!prefixcmp(arg, "--reflog=" ))
parse_reflog_param(arg + 9, &reflog, &reflog_base);
parse_reflog_param(arg + 9, &reflog, &reflog_base);
- else if (!strncmp(arg, "-g=", 3 ))
+ else if (!prefixcmp(arg, "-g=" ))
parse_reflog_param(arg + 3, &reflog, &reflog_base);
else
usage(show_branch_usage);
parse_reflog_param(arg + 3, &reflog, &reflog_base);
else
usage(show_branch_usage);
if (tags_only || heads_only) {
int match;
if (tags_only || heads_only) {
int match;
- match = heads_only && !strncmp(refname, "refs/heads/", 11 );
- match |= tags_only && !strncmp(refname, "refs/tags/", 10 );
+ match = heads_only && !prefixcmp(refname, "refs/heads/" );
+ match |= tags_only && !prefixcmp(refname, "refs/tags/" );
hash_only = 1;
continue;
}
hash_only = 1;
continue;
}
- if (!strncmp(arg, "--hash=", 7 ) ||
- (!strncmp(arg, "--abbrev", 8 ) &&
+ if (!prefixcmp(arg, "--hash=" ) ||
+ (!prefixcmp(arg, "--abbrev" ) &&
(arg[8] == '=' || arg[8] == '\0'))) {
if (arg[2] != 'h' && !arg[8])
/* --abbrev only */
(arg[8] == '=' || arg[8] == '\0'))) {
if (arg[2] != 'h' && !arg[8])
/* --abbrev only */
}
if (!strcmp(arg, "--exclude-existing"))
return exclude_existing(NULL);
}
if (!strcmp(arg, "--exclude-existing"))
return exclude_existing(NULL);
- if (!strncmp(arg, "--exclude-existing=", 19 ))
+ if (!prefixcmp(arg, "--exclude-existing=" ))
return exclude_existing(arg + 19);
usage(show_ref_usage);
}
return exclude_existing(arg + 19);
usage(show_ref_usage);
}
unsigned char sha1[20];
while (*pattern) {
unsigned char sha1[20];
while (*pattern) {
- if (!strncmp(*pattern, "refs/", 5 ) &&
+ if (!prefixcmp(*pattern, "refs/" ) &&
resolve_ref(*pattern, sha1, 1, NULL)) {
if (!quiet)
show_one(*pattern, sha1);
resolve_ref(*pattern, sha1, 1, NULL)) {
if (!quiet)
show_one(*pattern, sha1);
nargv[nargc++] = "git-archive";
nargv[nargc++] = "--format=tar";
nargv[nargc++] = "git-archive";
nargv[nargc++] = "--format=tar";
- if (2 <= argc && !strncmp("--remote=", argv[1], 9 )) {
+ if (2 <= argc && !(-prefixcmp(argv[1], "--remote=") )) {
nargv[nargc++] = argv[1];
argv++;
argc--;
nargv[nargc++] = argv[1];
argv++;
argc--;
- if (!strncmp(arg, "--pack_header=", 14 )) {
+ if (!prefixcmp(arg, "--pack_header=" )) {
struct pack_header *hdr;
char *c;
struct pack_header *hdr;
char *c;
const char *arg = argv[1];
if (!strcmp(arg, "--missing-ok"))
missing_ok = 1;
const char *arg = argv[1];
if (!strcmp(arg, "--missing-ok"))
missing_ok = 1;
- else if (!strncmp(arg, "--prefix=", 9 ))
+ else if (!prefixcmp(arg, "--prefix=" ))
prefix = arg + 9;
else
usage(write_tree_usage);
prefix = arg + 9;
else
usage(write_tree_usage);
line[--len] = 0;
if (!strcmp(line, "NAK"))
return 0;
line[--len] = 0;
if (!strcmp(line, "NAK"))
return 0;
- if (!strncmp(line, "ACK ", 4 )) {
+ if (!prefixcmp(line, "ACK " )) {
if (!get_sha1_hex(line+4, result_sha1)) {
if (strstr(line+45, "continue"))
return 2;
if (!get_sha1_hex(line+4, result_sha1)) {
if (strstr(line+45, "continue"))
return 2;
*/
if (namelen != patlen &&
patlen != namelen - 5 &&
*/
if (namelen != patlen &&
patlen != namelen - 5 &&
- strncmp(name, "refs/heads/", 11 ) &&
- strncmp(name, "refs/tags/", 10 )) {
+ prefixcmp(name, "refs/heads/" ) &&
+ prefixcmp(name, "refs/tags/" )) {
/* We want to catch the case where only weak
* matches are found and there are multiple
* matches, and where more than one strong
/* We want to catch the case where only weak
* matches are found and there are multiple
* matches, and where more than one strong
static int git_daemon_config(const char *var, const char *value)
{
static int git_daemon_config(const char *var, const char *value)
{
- if (!strncmp(var, "daemon.", 7 ) &&
+ if (!prefixcmp(var, "daemon." ) &&
!strcmp(var + 7, service_looking_at->config_name)) {
service_enabled = git_config_bool(var, value);
return 0;
!strcmp(var + 7, service_looking_at->config_name)) {
service_enabled = git_config_bool(var, value);
return 0;
for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
struct daemon_service *s = &(daemon_service[i]);
int namelen = strlen(s->name);
for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
struct daemon_service *s = &(daemon_service[i]);
int namelen = strlen(s->name);
- if (!strncmp("git-", line, 4 ) &&
+ if (!(-prefixcmp(line, "git-") ) &&
!strncmp(s->name, line + 4, namelen) &&
line[namelen + 4] == ' ') {
/*
!strncmp(s->name, line + 4, namelen) &&
line[namelen + 4] == ' ') {
/*
for (i = 1; i < argc; i++) {
char *arg = argv[i];
for (i = 1; i < argc; i++) {
char *arg = argv[i];
- if (!strncmp(arg, "--listen=", 9 )) {
+ if (!prefixcmp(arg, "--listen=" )) {
char *p = arg + 9;
char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);
while (*p)
char *p = arg + 9;
char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);
while (*p)
- if (!strncmp(arg, "--port=", 7 )) {
+ if (!prefixcmp(arg, "--port=" )) {
char *end;
unsigned long n;
n = strtoul(arg+7, &end, 0);
char *end;
unsigned long n;
n = strtoul(arg+7, &end, 0);
export_all_trees = 1;
continue;
}
export_all_trees = 1;
continue;
}
- if (!strncmp(arg, "--timeout=", 10 )) {
+ if (!prefixcmp(arg, "--timeout=" )) {
timeout = atoi(arg+10);
continue;
}
timeout = atoi(arg+10);
continue;
}
- if (!strncmp(arg, "--init-timeout=", 15 )) {
+ if (!prefixcmp(arg, "--init-timeout=" )) {
init_timeout = atoi(arg+15);
continue;
}
init_timeout = atoi(arg+15);
continue;
}
strict_paths = 1;
continue;
}
strict_paths = 1;
continue;
}
- if (!strncmp(arg, "--base-path=", 12 )) {
+ if (!prefixcmp(arg, "--base-path=" )) {
base_path = arg+12;
continue;
}
base_path = arg+12;
continue;
}
- if (!strncmp(arg, "--interpolated-path=", 20 )) {
+ if (!prefixcmp(arg, "--interpolated-path=" )) {
interpolated_path = arg+20;
continue;
}
interpolated_path = arg+20;
continue;
}
user_path = "";
continue;
}
user_path = "";
continue;
}
- if (!strncmp(arg, "--user-path=", 12 )) {
+ if (!prefixcmp(arg, "--user-path=" )) {
user_path = arg + 12;
continue;
}
user_path = arg + 12;
continue;
}
- if (!strncmp(arg, "--pid-file=", 11 )) {
+ if (!prefixcmp(arg, "--pid-file=" )) {
pid_file = arg + 11;
continue;
}
pid_file = arg + 11;
continue;
}
log_syslog = 1;
continue;
}
log_syslog = 1;
continue;
}
- if (!strncmp(arg, "--user=", 7 )) {
+ if (!prefixcmp(arg, "--user=" )) {
user_name = arg + 7;
continue;
}
user_name = arg + 7;
continue;
}
- if (!strncmp(arg, "--group=", 8 )) {
+ if (!prefixcmp(arg, "--group=" )) {
group_name = arg + 8;
continue;
}
group_name = arg + 8;
continue;
}
- if (!strncmp(arg, "--enable=", 9 )) {
+ if (!prefixcmp(arg, "--enable=" )) {
enable_service(arg + 9, 1);
continue;
}
enable_service(arg + 9, 1);
continue;
}
- if (!strncmp(arg, "--disable=", 10 )) {
+ if (!prefixcmp(arg, "--disable=" )) {
enable_service(arg + 10, 0);
continue;
}
enable_service(arg + 10, 0);
continue;
}
- if (!strncmp(arg, "--allow-override=", 17 )) {
+ if (!prefixcmp(arg, "--allow-override=" )) {
make_service_overridable(arg + 17, 1);
continue;
}
make_service_overridable(arg + 17, 1);
continue;
}
- if (!strncmp(arg, "--forbid-override=", 18 )) {
+ if (!prefixcmp(arg, "--forbid-override=" )) {
make_service_overridable(arg + 18, 0);
continue;
}
make_service_overridable(arg + 18, 0);
continue;
}
diff_detect_rename_default = DIFF_DETECT_RENAME;
return 0;
}
diff_detect_rename_default = DIFF_DETECT_RENAME;
return 0;
}
- if (!strncmp(var, "diff.color.", 11 ) || !strncmp(var, "color.diff.", 11)) {
+ if (!prefixcmp(var, "diff.color." ) || !strncmp(var, "color.diff.", 11)) {
int slot = parse_diff_color_slot(var, 11);
color_parse(value, var, diff_colors[slot]);
return 0;
int slot = parse_diff_color_slot(var, 11);
color_parse(value, var, diff_colors[slot]);
return 0;
xecfg.flags = XDL_EMIT_FUNCNAMES;
if (!diffopts)
;
xecfg.flags = XDL_EMIT_FUNCNAMES;
if (!diffopts)
;
- else if (!strncmp(diffopts, "--unified=", 10 ))
+ else if (!prefixcmp(diffopts, "--unified=" ))
xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
- else if (!strncmp(diffopts, "-u", 2 ))
+ else if (!prefixcmp(diffopts, "-u" ))
xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
ecb.outf = xdiff_outf;
ecb.priv = &ecbdata;
xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
ecb.outf = xdiff_outf;
ecb.priv = &ecbdata;
else if (!strcmp(arg, "--shortstat")) {
options->output_format |= DIFF_FORMAT_SHORTSTAT;
}
else if (!strcmp(arg, "--shortstat")) {
options->output_format |= DIFF_FORMAT_SHORTSTAT;
}
- else if (!strncmp(arg, "--stat", 6 )) {
+ else if (!prefixcmp(arg, "--stat" )) {
char *end;
int width = options->stat_width;
int name_width = options->stat_name_width;
char *end;
int width = options->stat_width;
int name_width = options->stat_name_width;
switch (*arg) {
case '-':
switch (*arg) {
case '-':
- if (!strncmp(arg, "-width=", 7 ))
+ if (!prefixcmp(arg, "-width=" ))
width = strtoul(arg + 7, &end, 10);
width = strtoul(arg + 7, &end, 10);
- else if (!strncmp(arg, "-name-width=", 12 ))
+ else if (!prefixcmp(arg, "-name-width=" ))
name_width = strtoul(arg + 12, &end, 10);
break;
case '=':
name_width = strtoul(arg + 12, &end, 10);
break;
case '=':
}
else if (!strcmp(arg, "-z"))
options->line_termination = 0;
}
else if (!strcmp(arg, "-z"))
options->line_termination = 0;
- else if (!strncmp(arg, "-l", 2 ))
+ else if (!prefixcmp(arg, "-l" ))
options->rename_limit = strtoul(arg+2, NULL, 10);
else if (!strcmp(arg, "--full-index"))
options->full_index = 1;
options->rename_limit = strtoul(arg+2, NULL, 10);
else if (!strcmp(arg, "--full-index"))
options->full_index = 1;
options->output_format |= DIFF_FORMAT_NAME_STATUS;
else if (!strcmp(arg, "-R"))
options->reverse_diff = 1;
options->output_format |= DIFF_FORMAT_NAME_STATUS;
else if (!strcmp(arg, "-R"))
options->reverse_diff = 1;
- else if (!strncmp(arg, "-S", 2 ))
+ else if (!prefixcmp(arg, "-S" ))
options->pickaxe = arg + 2;
else if (!strcmp(arg, "-s")) {
options->output_format |= DIFF_FORMAT_NO_OUTPUT;
}
options->pickaxe = arg + 2;
else if (!strcmp(arg, "-s")) {
options->output_format |= DIFF_FORMAT_NO_OUTPUT;
}
- else if (!strncmp(arg, "-O", 2 ))
+ else if (!prefixcmp(arg, "-O" ))
options->orderfile = arg + 2;
options->orderfile = arg + 2;
- else if (!strncmp(arg, "--diff-filter=", 14 ))
+ else if (!prefixcmp(arg, "--diff-filter=" ))
options->filter = arg + 14;
else if (!strcmp(arg, "--pickaxe-all"))
options->pickaxe_opts = DIFF_PICKAXE_ALL;
else if (!strcmp(arg, "--pickaxe-regex"))
options->pickaxe_opts = DIFF_PICKAXE_REGEX;
options->filter = arg + 14;
else if (!strcmp(arg, "--pickaxe-all"))
options->pickaxe_opts = DIFF_PICKAXE_ALL;
else if (!strcmp(arg, "--pickaxe-regex"))
options->pickaxe_opts = DIFF_PICKAXE_REGEX;
- else if (!strncmp(arg, "-B", 2 )) {
+ else if (!prefixcmp(arg, "-B" )) {
if ((options->break_opt =
diff_scoreopt_parse(arg)) == -1)
return -1;
}
if ((options->break_opt =
diff_scoreopt_parse(arg)) == -1)
return -1;
}
- else if (!strncmp(arg, "-M", 2 )) {
+ else if (!prefixcmp(arg, "-M" )) {
if ((options->rename_score =
diff_scoreopt_parse(arg)) == -1)
return -1;
options->detect_rename = DIFF_DETECT_RENAME;
}
if ((options->rename_score =
diff_scoreopt_parse(arg)) == -1)
return -1;
options->detect_rename = DIFF_DETECT_RENAME;
}
- else if (!strncmp(arg, "-C", 2 )) {
+ else if (!prefixcmp(arg, "-C" )) {
if ((options->rename_score =
diff_scoreopt_parse(arg)) == -1)
return -1;
if ((options->rename_score =
diff_scoreopt_parse(arg)) == -1)
return -1;
options->find_copies_harder = 1;
else if (!strcmp(arg, "--abbrev"))
options->abbrev = DEFAULT_ABBREV;
options->find_copies_harder = 1;
else if (!strcmp(arg, "--abbrev"))
options->abbrev = DEFAULT_ABBREV;
- else if (!strncmp(arg, "--abbrev=", 9 )) {
+ else if (!prefixcmp(arg, "--abbrev=" )) {
options->abbrev = strtoul(arg + 9, NULL, 10);
if (options->abbrev < MINIMUM_ABBREV)
options->abbrev = MINIMUM_ABBREV;
options->abbrev = strtoul(arg + 9, NULL, 10);
if (options->abbrev < MINIMUM_ABBREV)
options->abbrev = MINIMUM_ABBREV;
int new_len;
/* Ignore line numbers when computing the SHA1 of the patch */
int new_len;
/* Ignore line numbers when computing the SHA1 of the patch */
- if (!strncmp(line, "@@ -", 4 ))
+ if (!prefixcmp(line, "@@ -" ))
return;
new_len = remove_space(line, len);
return;
new_len = remove_space(line, len);
len = strlen(git_command);
/* Trivial cleanup */
len = strlen(git_command);
/* Trivial cleanup */
- while (!strncmp(exec_dir, "./", 2 )) {
+ while (!prefixcmp(exec_dir, "./" )) {
exec_dir += 2;
while (*exec_dir == '/')
exec_dir++;
exec_dir += 2;
while (*exec_dir == '/')
exec_dir++;
static void cmd_mark(void)
{
static void cmd_mark(void)
{
- if (!strncmp("mark :", command_buf.buf, 6 )) {
+ if (!(-prefixcmp(command_buf.buf, "mark :") )) {
next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
read_next_command();
}
next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
read_next_command();
}
size_t length;
char *buffer;
size_t length;
char *buffer;
- if (strncmp("data ", command_buf.buf, 5 ))
+ if ((-prefixcmp(command_buf.buf, "data ") ))
die("Expected 'data n' command, found: %s", command_buf.buf);
die("Expected 'data n' command, found: %s", command_buf.buf);
- if (!strncmp("<<", command_buf.buf + 5, 2 )) {
+ if (!(-prefixcmp(command_buf.buf + 5, "<<") )) {
char *term = xstrdup(command_buf.buf + 5 + 2);
size_t sz = 8192, term_len = command_buf.len - 5 - 2;
length = 0;
char *term = xstrdup(command_buf.buf + 5 + 2);
size_t sz = 8192, term_len = command_buf.len - 5 - 2;
length = 0;
oe = find_mark(strtoumax(p + 1, &x, 10));
hashcpy(sha1, oe->sha1);
p = x;
oe = find_mark(strtoumax(p + 1, &x, 10));
hashcpy(sha1, oe->sha1);
p = x;
- } else if (!strncmp("inline", p, 6 )) {
+ } else if (!(-prefixcmp(p, "inline") )) {
inline_data = 1;
p += 6;
} else {
inline_data = 1;
p += 6;
} else {
const char *from;
struct branch *s;
const char *from;
struct branch *s;
- if (strncmp("from ", command_buf.buf, 5 ))
+ if ((-prefixcmp(command_buf.buf, "from ") ))
return;
if (b->branch_tree.tree) {
return;
if (b->branch_tree.tree) {
struct branch *s;
*count = 0;
struct branch *s;
*count = 0;
- while (!strncmp("merge ", command_buf.buf, 6 )) {
+ while (!(-prefixcmp(command_buf.buf, "merge ") )) {
from = strchr(command_buf.buf, ' ') + 1;
n = xmalloc(sizeof(*n));
s = lookup_branch(from);
from = strchr(command_buf.buf, ' ') + 1;
n = xmalloc(sizeof(*n));
s = lookup_branch(from);
read_next_command();
cmd_mark();
read_next_command();
cmd_mark();
- if (!strncmp("author ", command_buf.buf, 7 )) {
+ if (!(-prefixcmp(command_buf.buf, "author ") )) {
author = parse_ident(command_buf.buf + 7);
read_next_command();
}
author = parse_ident(command_buf.buf + 7);
read_next_command();
}
- if (!strncmp("committer ", command_buf.buf, 10 )) {
+ if (!(-prefixcmp(command_buf.buf, "committer ") )) {
committer = parse_ident(command_buf.buf + 10);
read_next_command();
}
committer = parse_ident(command_buf.buf + 10);
read_next_command();
}
for (;;) {
if (1 == command_buf.len)
break;
for (;;) {
if (1 == command_buf.len)
break;
- else if (!strncmp("M ", command_buf.buf, 2 ))
+ else if (!(-prefixcmp(command_buf.buf, "M ") ))
- else if (!strncmp("D ", command_buf.buf, 2 ))
+ else if (!(-prefixcmp(command_buf.buf, "D ") ))
file_change_d(b);
else if (!strcmp("deleteall", command_buf.buf))
file_change_deleteall(b);
file_change_d(b);
else if (!strcmp("deleteall", command_buf.buf))
file_change_deleteall(b);
read_next_command();
/* from ... */
read_next_command();
/* from ... */
- if (strncmp("from ", command_buf.buf, 5 ))
+ if ((-prefixcmp(command_buf.buf, "from ") ))
die("Expected from command, got %s", command_buf.buf);
from = strchr(command_buf.buf, ' ') + 1;
s = lookup_branch(from);
die("Expected from command, got %s", command_buf.buf);
from = strchr(command_buf.buf, ' ') + 1;
s = lookup_branch(from);
read_next_command();
/* tagger ... */
read_next_command();
/* tagger ... */
- if (strncmp("tagger ", command_buf.buf, 7 ))
+ if ((-prefixcmp(command_buf.buf, "tagger ") ))
die("Expected tagger command, got %s", command_buf.buf);
tagger = parse_ident(command_buf.buf + 7);
die("Expected tagger command, got %s", command_buf.buf);
tagger = parse_ident(command_buf.buf + 7);
if (*a != '-' || !strcmp(a, "--"))
break;
if (*a != '-' || !strcmp(a, "--"))
break;
- else if (!strncmp(a, "--date-format=", 14 )) {
+ else if (!prefixcmp(a, "--date-format=" )) {
const char *fmt = a + 14;
if (!strcmp(fmt, "raw"))
whenspec = WHENSPEC_RAW;
const char *fmt = a + 14;
if (!strcmp(fmt, "raw"))
whenspec = WHENSPEC_RAW;
else
die("unknown --date-format argument %s", fmt);
}
else
die("unknown --date-format argument %s", fmt);
}
- else if (!strncmp(a, "--max-pack-size=", 16 ))
+ else if (!prefixcmp(a, "--max-pack-size=" ))
max_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024;
max_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024;
- else if (!strncmp(a, "--depth=", 8 ))
+ else if (!prefixcmp(a, "--depth=" ))
max_depth = strtoul(a + 8, NULL, 0);
max_depth = strtoul(a + 8, NULL, 0);
- else if (!strncmp(a, "--active-branches=", 18 ))
+ else if (!prefixcmp(a, "--active-branches=" ))
max_active_branches = strtoul(a + 18, NULL, 0);
max_active_branches = strtoul(a + 18, NULL, 0);
- else if (!strncmp(a, "--export-marks=", 15 ))
+ else if (!prefixcmp(a, "--export-marks=" ))
- else if (!strncmp(a, "--export-pack-edges=", 20 )) {
+ else if (!prefixcmp(a, "--export-pack-edges=" )) {
if (pack_edges)
fclose(pack_edges);
pack_edges = fopen(a + 20, "a");
if (pack_edges)
fclose(pack_edges);
pack_edges = fopen(a + 20, "a");
break;
else if (!strcmp("blob", command_buf.buf))
cmd_new_blob();
break;
else if (!strcmp("blob", command_buf.buf))
cmd_new_blob();
- else if (!strncmp("commit ", command_buf.buf, 7 ))
+ else if (!(-prefixcmp(command_buf.buf, "commit ") ))
- else if (!strncmp("tag ", command_buf.buf, 4 ))
+ else if (!(-prefixcmp(command_buf.buf, "tag ") ))
- else if (!strncmp("reset ", command_buf.buf, 6 ))
+ else if (!(-prefixcmp(command_buf.buf, "reset ") ))
cmd_reset_branch();
else if (!strcmp("checkpoint", command_buf.buf))
cmd_checkpoint();
cmd_reset_branch();
else if (!strcmp("checkpoint", command_buf.buf))
cmd_checkpoint();
int len;
while ((len = packet_read_line(fd[0], line, sizeof(line)))) {
int len;
while ((len = packet_read_line(fd[0], line, sizeof(line)))) {
- if (!strncmp("shallow ", line, 8 )) {
+ if (!(-prefixcmp(line, "shallow ") )) {
if (get_sha1_hex(line + 8, sha1))
die("invalid shallow line: %s", line);
register_shallow(sha1);
continue;
}
if (get_sha1_hex(line + 8, sha1))
die("invalid shallow line: %s", line);
register_shallow(sha1);
continue;
}
- if (!strncmp("unshallow ", line, 10 )) {
+ if (!(-prefixcmp(line, "unshallow ") )) {
if (get_sha1_hex(line + 10, sha1))
die("invalid unshallow line: %s", line);
if (!lookup_object(sha1))
if (get_sha1_hex(line + 10, sha1))
die("invalid unshallow line: %s", line);
if (!lookup_object(sha1))
check_ref_format(ref->name + 5))
; /* trash */
else if (fetch_all &&
check_ref_format(ref->name + 5))
; /* trash */
else if (fetch_all &&
- (!depth || strncmp(ref->name, "refs/tags/", 10 ) )) {
+ (!depth || prefixcmp(ref->name, "refs/tags/" ) )) {
*newtail = ref;
ref->next = NULL;
newtail = &ref->next;
*newtail = ref;
ref->next = NULL;
newtail = &ref->next;
char *arg = argv[i];
if (*arg == '-') {
char *arg = argv[i];
if (*arg == '-') {
- if (!strncmp("--upload-pack=", arg, 14 )) {
+ if (!(-prefixcmp(arg, "--upload-pack=") )) {
uploadpack = arg + 14;
continue;
}
uploadpack = arg + 14;
continue;
}
- if (!strncmp("--exec=", arg, 7 )) {
+ if (!(-prefixcmp(arg, "--exec=") )) {
uploadpack = arg + 7;
continue;
}
uploadpack = arg + 7;
continue;
}
- if (!strncmp("--depth=", arg, 8 )) {
+ if (!(-prefixcmp(arg, "--depth=") )) {
depth = strtol(arg + 8, NULL, 0);
if (stat(git_path("shallow"), &st))
st.st_mtime = 0;
depth = strtol(arg + 8, NULL, 0);
if (stat(git_path("shallow"), &st))
st.st_mtime = 0;
/*
* Check remaining flags.
*/
/*
* Check remaining flags.
*/
- if (!strncmp(cmd, "--exec-path", 11 )) {
+ if (!prefixcmp(cmd, "--exec-path" )) {
cmd += 11;
if (*cmd == '=')
git_set_exec_path(cmd + 1);
cmd += 11;
if (*cmd == '=')
git_set_exec_path(cmd + 1);
setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);
(*argv)++;
(*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];
setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
} else if (!strcmp(cmd, "--bare")) {
static char git_dir[PATH_MAX+1];
static int git_alias_config(const char *var, const char *value)
{
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;
alias_string = xstrdup(value);
}
return 0;
* So we just directly call the internal command handler, and
* die if that one cannot handle it.
*/
* 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);
cmd += 4;
argv[0] = cmd;
handle_internal_command(argc, argv, envp);
argc--;
handle_options(&argv, &argc);
if (argc > 0) {
argc--;
handle_options(&argv, &argc);
if (argc > 0) {
- if (!strncmp(argv[0], "--", 2 ))
+ if (!prefixcmp(argv[0], "--" ))
argv[0] += 2;
} else {
/* Default command: "help" */
argv[0] += 2;
} else {
/* Default command: "help" */
struct stat st;
int entlen;
struct stat st;
int entlen;
- if (strncmp(de->d_name, "git-", 4 ))
+ if (prefixcmp(de->d_name, "git-" ))
continue;
strcpy(path+dirlen, de->d_name);
if (stat(path, &st) || /* stat, not lstat */
continue;
strcpy(path+dirlen, de->d_name);
if (stat(path, &st) || /* stat, not lstat */
- if (!strncmp(git_cmd, "git", 3 ))
+ if (!prefixcmp(git_cmd, "git" ))
page = git_cmd;
else {
int page_len = strlen(git_cmd) + 4;
page = git_cmd;
else {
int page_len = strlen(git_cmd) + 4;
case 'P':
i++;
if (i + 52 <= buffer.posn &&
case 'P':
i++;
if (i + 52 <= buffer.posn &&
- !strncmp(data + i, " pack-", 6 ) &&
+ !prefixcmp(data + i, " pack-" ) &&
!strncmp(data + i + 46, ".pack\n", 6)) {
get_sha1_hex(data + i + 6, sha1);
setup_index(repo, sha1);
!strncmp(data + i + 46, ".pack\n", 6)) {
get_sha1_hex(data + i + 6, sha1);
setup_index(repo, sha1);
case 'P':
i++;
if (i + 52 < buffer.posn &&
case 'P':
i++;
if (i + 52 < buffer.posn &&
- !strncmp(data + i, " pack-", 6 ) &&
+ !prefixcmp(data + i, " pack-" ) &&
!strncmp(data + i + 46, ".pack\n", 6)) {
get_sha1_hex(data + i + 6, sha1);
setup_index(sha1);
!strncmp(data + i + 46, ".pack\n", 6)) {
get_sha1_hex(data + i + 6, sha1);
setup_index(sha1);
lock->owner = xmalloc(strlen(ctx->cdata) + 1);
strcpy(lock->owner, ctx->cdata);
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TIMEOUT)) {
lock->owner = xmalloc(strlen(ctx->cdata) + 1);
strcpy(lock->owner, ctx->cdata);
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TIMEOUT)) {
- if (!strncmp(ctx->cdata, "Second-", 7 ))
+ if (!prefixcmp(ctx->cdata, "Second-" ))
lock->timeout =
strtol(ctx->cdata + 7, NULL, 10);
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
lock->timeout =
strtol(ctx->cdata + 7, NULL, 10);
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
- if (!strncmp(ctx->cdata, "opaquelocktoken:", 16 )) {
+ if (!prefixcmp(ctx->cdata, "opaquelocktoken:" )) {
lock->token = xmalloc(strlen(ctx->cdata) - 15);
strcpy(lock->token, ctx->cdata + 16);
}
lock->token = xmalloc(strlen(ctx->cdata) - 15);
strcpy(lock->token, ctx->cdata + 16);
}
return;
/* If it's a symref, set the refname; otherwise try for a sha1 */
return;
/* If it's a symref, set the refname; otherwise try for a sha1 */
- if (!strncmp((char *)buffer.buffer, "ref: ", 5 )) {
+ if (!prefixcmp((char *)buffer.buffer, "ref: " )) {
*symref = xmalloc(buffer.posn - 5);
strlcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5);
} else {
*symref = xmalloc(buffer.posn - 5);
strlcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5);
} else {
fix_thin_pack = 1;
} else if (!strcmp(arg, "--keep")) {
keep_msg = "";
fix_thin_pack = 1;
} else if (!strcmp(arg, "--keep")) {
keep_msg = "";
- } else if (!strncmp(arg, "--keep=", 7 )) {
+ } else if (!prefixcmp(arg, "--keep=" )) {
- } else if (!strncmp(arg, "--pack_header=", 14 )) {
+ } else if (!prefixcmp(arg, "--pack_header=" )) {
struct pack_header *hdr;
char *c;
struct pack_header *hdr;
char *c;
char *arg = argv[i];
if (*arg == '-') {
char *arg = argv[i];
if (*arg == '-') {
- if (!strncmp("--upload-pack=", arg, 14 )) {
+ if (!(-prefixcmp(arg, "--upload-pack=") )) {
uploadpack = arg + 14;
continue;
}
uploadpack = arg + 14;
continue;
}
- if (!strncmp("--exec=", arg, 7 )) {
+ if (!(-prefixcmp(arg, "--exec=") )) {
uploadpack = arg + 7;
continue;
}
uploadpack = arg + 7;
continue;
}
struct ref_lock *lock;
cmd->error_string = NULL;
struct ref_lock *lock;
cmd->error_string = NULL;
- if (!strncmp(name, "refs/", 5 ) && check_ref_format(name + 5)) {
+ if (!prefixcmp(name, "refs/" ) && check_ref_format(name + 5)) {
cmd->error_string = "funny refname";
return error("refusing to create funny ref '%s' locally",
name);
cmd->error_string = "funny refname";
return error("refusing to create funny ref '%s' locally",
name);
}
if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
!is_null_sha1(old_sha1) &&
}
if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
!is_null_sha1(old_sha1) &&
- !strncmp(name, "refs/heads/", 11 )) {
+ !prefixcmp(name, "refs/heads/" )) {
struct commit *old_commit, *new_commit;
struct commit_list *bases, *ent;
struct commit *old_commit, *new_commit;
struct commit_list *bases, *ent;
- if (!strncmp(oldref, "refs/heads/", 11 ) &&
- !strncmp(newref, "refs/heads/", 11 )) {
+ if (!prefixcmp(oldref, "refs/heads/" ) &&
+ !prefixcmp(newref, "refs/heads/" )) {
char oldsection[1024], newsection[1024];
snprintf(oldsection, 1024, "branch.%s", oldref + 11);
char oldsection[1024], newsection[1024];
snprintf(oldsection, 1024, "branch.%s", oldref + 11);
log_file = git_path("logs/%s", ref_name);
if (log_all_ref_updates &&
log_file = git_path("logs/%s", ref_name);
if (log_all_ref_updates &&
- (!strncmp(ref_name, "refs/heads/", 11 ) ||
- !strncmp(ref_name, "refs/remotes/", 13 ) ||
+ (!prefixcmp(ref_name, "refs/heads/" ) ||
+ !prefixcmp(ref_name, "refs/remotes/" ) ||
!strcmp(ref_name, "HEAD"))) {
if (safe_create_leading_directories(log_file) < 0)
return error("unable to create directory for %s",
!strcmp(ref_name, "HEAD"))) {
if (safe_create_leading_directories(log_file) < 0)
return error("unable to create directory for %s",
const char *arg = argv[i];
if (*arg == '-') {
int opts;
const char *arg = argv[i];
if (*arg == '-') {
int opts;
- if (!strncmp(arg, "--max-count=", 12 )) {
+ if (!prefixcmp(arg, "--max-count=" )) {
revs->max_count = atoi(arg + 12);
continue;
}
revs->max_count = atoi(arg + 12);
continue;
}
- if (!strncmp(arg, "--skip=", 7 )) {
+ if (!prefixcmp(arg, "--skip=" )) {
revs->skip_count = atoi(arg + 7);
continue;
}
revs->skip_count = atoi(arg + 7);
continue;
}
revs->max_count = atoi(arg + 2);
continue;
}
revs->max_count = atoi(arg + 2);
continue;
}
- if (!strncmp(arg, "--max-age=", 10 )) {
+ if (!prefixcmp(arg, "--max-age=" )) {
revs->max_age = atoi(arg + 10);
continue;
}
revs->max_age = atoi(arg + 10);
continue;
}
- if (!strncmp(arg, "--since=", 8 )) {
+ if (!prefixcmp(arg, "--since=" )) {
revs->max_age = approxidate(arg + 8);
continue;
}
revs->max_age = approxidate(arg + 8);
continue;
}
- if (!strncmp(arg, "--after=", 8 )) {
+ if (!prefixcmp(arg, "--after=" )) {
revs->max_age = approxidate(arg + 8);
continue;
}
revs->max_age = approxidate(arg + 8);
continue;
}
- if (!strncmp(arg, "--min-age=", 10 )) {
+ if (!prefixcmp(arg, "--min-age=" )) {
revs->min_age = atoi(arg + 10);
continue;
}
revs->min_age = atoi(arg + 10);
continue;
}
- if (!strncmp(arg, "--before=", 9 )) {
+ if (!prefixcmp(arg, "--before=" )) {
revs->min_age = approxidate(arg + 9);
continue;
}
revs->min_age = approxidate(arg + 9);
continue;
}
- if (!strncmp(arg, "--until=", 8 )) {
+ if (!prefixcmp(arg, "--until=" )) {
revs->min_age = approxidate(arg + 8);
continue;
}
revs->min_age = approxidate(arg + 8);
continue;
}
revs->num_ignore_packed = 0;
continue;
}
revs->num_ignore_packed = 0;
continue;
}
- if (!strncmp(arg, "--unpacked=", 11 )) {
+ if (!prefixcmp(arg, "--unpacked=" )) {
revs->unpacked = 1;
add_ignore_packed(revs, arg+11);
continue;
revs->unpacked = 1;
add_ignore_packed(revs, arg+11);
continue;
revs->verbose_header = 1;
continue;
}
revs->verbose_header = 1;
continue;
}
- if (!strncmp(arg, "--pretty", 8 )) {
+ if (!prefixcmp(arg, "--pretty" )) {
revs->verbose_header = 1;
revs->commit_format = get_commit_format(arg+8);
continue;
revs->verbose_header = 1;
revs->commit_format = get_commit_format(arg+8);
continue;
revs->abbrev = DEFAULT_ABBREV;
continue;
}
revs->abbrev = DEFAULT_ABBREV;
continue;
}
- if (!strncmp(arg, "--abbrev=", 9 )) {
+ if (!prefixcmp(arg, "--abbrev=" )) {
revs->abbrev = strtoul(arg + 9, NULL, 10);
if (revs->abbrev < MINIMUM_ABBREV)
revs->abbrev = MINIMUM_ABBREV;
revs->abbrev = strtoul(arg + 9, NULL, 10);
if (revs->abbrev < MINIMUM_ABBREV)
revs->abbrev = MINIMUM_ABBREV;
/*
* Grepping the commit log
*/
/*
* Grepping the commit log
*/
- if (!strncmp(arg, "--author=", 9 )) {
+ if (!prefixcmp(arg, "--author=" )) {
add_header_grep(revs, "author", arg+9);
continue;
}
add_header_grep(revs, "author", arg+9);
continue;
}
- if (!strncmp(arg, "--committer=", 12 )) {
+ if (!prefixcmp(arg, "--committer=" )) {
add_header_grep(revs, "committer", arg+12);
continue;
}
add_header_grep(revs, "committer", arg+12);
continue;
}
- if (!strncmp(arg, "--grep=", 7 )) {
+ if (!prefixcmp(arg, "--grep=" )) {
add_message_grep(revs, arg+7);
continue;
}
add_message_grep(revs, arg+7);
continue;
}
all_match = 1;
continue;
}
all_match = 1;
continue;
}
- if (!strncmp(arg, "--encoding=", 11 )) {
+ if (!prefixcmp(arg, "--encoding=" )) {
arg += 11;
if (strcmp(arg, "none"))
git_log_output_encoding = strdup(arg);
arg += 11;
if (strcmp(arg, "none"))
git_log_output_encoding = strdup(arg);
char *arg = *argv;
if (*arg == '-') {
char *arg = *argv;
if (*arg == '-') {
- if (!strncmp(arg, "--receive-pack=", 15 )) {
+ if (!prefixcmp(arg, "--receive-pack=" )) {
receivepack = arg + 15;
continue;
}
receivepack = arg + 15;
continue;
}
- if (!strncmp(arg, "--exec=", 7 )) {
+ if (!prefixcmp(arg, "--exec=" )) {
receivepack = arg + 7;
continue;
}
receivepack = arg + 7;
continue;
}
offset++;
cwd[len++] = '/';
cwd[len] = 0;
offset++;
cwd[len++] = '/';
cwd[len] = 0;
- inside_git_dir = !strncmp(cwd + offset, ".git/", 5 );
+ inside_git_dir = !prefixcmp(cwd + offset, ".git/" );
if (!arg || !(arg = sq_dequote(arg)))
die("bad argument");
if (!arg || !(arg = sq_dequote(arg)))
die("bad argument");
- if (strncmp(me, "git-", 4 ))
+ if (prefixcmp(me, "git-" ))
die("bad command");
my_argv[0] = me + 4;
die("bad command");
my_argv[0] = me + 4;
continue;
}
len = strip(line, len);
continue;
}
len = strip(line, len);
- if (!strncmp(line, "have ", 5 )) {
+ if (!prefixcmp(line, "have " )) {
switch (got_sha1(line+5, sha1)) {
case -1: /* they have what we do not */
if (multi_ack && ok_to_give_up())
switch (got_sha1(line+5, sha1)) {
case -1: /* they have what we do not */
if (multi_ack && ok_to_give_up())
- if (!strncmp("shallow ", line, 8 )) {
+ if (!(-prefixcmp(line, "shallow ") )) {
unsigned char sha1[20];
struct object *object;
use_thin_pack = 0;
unsigned char sha1[20];
struct object *object;
use_thin_pack = 0;
add_object_array(object, NULL, &shallows);
continue;
}
add_object_array(object, NULL, &shallows);
continue;
}
- if (!strncmp("deepen ", line, 7 )) {
+ if (!(-prefixcmp(line, "deepen ") )) {
char *end;
use_thin_pack = 0;
depth = strtol(line + 7, &end, 0);
char *end;
use_thin_pack = 0;
depth = strtol(line + 7, &end, 0);
die("Invalid deepen: %s", line);
continue;
}
die("Invalid deepen: %s", line);
continue;
}
- if (strncmp("want ", line, 5 ) ||
+ if ((-prefixcmp(line, "want ") ) ||
get_sha1_hex(line+5, sha1_buf))
die("git-upload-pack: protocol error, "
"expected to get sha, not '%s'", line);
get_sha1_hex(line+5, sha1_buf))
die("git-upload-pack: protocol error, "
"expected to get sha, not '%s'", line);
- if (!strncmp(arg, "--timeout=", 10 )) {
+ if (!prefixcmp(arg, "--timeout=" )) {
timeout = atoi(arg+10);
continue;
}
timeout = atoi(arg+10);
continue;
}
if (s->branch) {
const char *on_what = "On branch ";
const char *branch_name = s->branch;
if (s->branch) {
const char *on_what = "On branch ";
const char *branch_name = s->branch;
- if (!strncmp(branch_name, "refs/heads/", 11 ))
+ if (!prefixcmp(branch_name, "refs/heads/" ))
branch_name += 11;
else if (!strcmp(branch_name, "HEAD")) {
branch_name = "";
branch_name += 11;
else if (!strcmp(branch_name, "HEAD")) {
branch_name = "";
wt_status_use_color = git_config_colorbool(k, v);
return 0;
}
wt_status_use_color = git_config_colorbool(k, v);
return 0;
}
- if (!strncmp(k, "status.color.", 13 ) || !strncmp(k, "color.status.", 13)) {
+ if (!prefixcmp(k, "status.color." ) || !strncmp(k, "color.status.", 13)) {
int slot = parse_status_slot(k, 13);
color_parse(v, k, wt_status_colors[slot]);
}
int slot = parse_status_slot(k, 13);
color_parse(v, k, wt_status_colors[slot]);
}