@matheusbsbs / matheus-bagliano / commits / cc44c7655f
Fork 0

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>

Junio C Hamano committed Feb 20, 2007 at 01:53 UTC cc44c7655fe2dd0cfb46e841156634fe622df397
48 files changed +211 -211
builtin-apply.c
+6 -6
@@ -1129,11 +1129,11 @@ static struct fragment *parse_binary_hunk(char **buf_p,
1129
1130 *status_p = 0;
1131
1132 - if (!strncmp(buffer, "delta ", 6)) {
1132 + if (!prefixcmp(buffer, "delta ")) {
1133 patch_method = BINARY_DELTA_DEFLATED;
1134 origlen = strtoul(buffer + 6, NULL, 10);
1135 }
1136 - else if (!strncmp(buffer, "literal ", 8)) {
1136 + else if (!prefixcmp(buffer, "literal ")) {
1137 patch_method = BINARY_LITERAL_DEFLATED;
1138 origlen = strtoul(buffer + 8, NULL, 10);
1139 }
@@ -2608,14 +2608,14 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
2608 read_stdin = 0;
2609 continue;
2610 }
2611 - if (!strncmp(arg, "--exclude=", 10)) {
2611 + if (!prefixcmp(arg, "--exclude=")) {
2612 struct excludes *x = xmalloc(sizeof(*x));
2613 x->path = arg + 10;
2614 x->next = excludes;
2615 excludes = x;
2616 continue;
2617 }
2618 - if (!strncmp(arg, "-p", 2)) {
2618 + if (!prefixcmp(arg, "-p")) {
2619 p_value = atoi(arg + 2);
2620 continue;
2621 }
@@ -2669,13 +2669,13 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
2669 line_termination = 0;
2670 continue;
2671 }
2672 - if (!strncmp(arg, "-C", 2)) {
2672 + if (!prefixcmp(arg, "-C")) {
2673 p_context = strtoul(arg + 2, &end, 0);
2674 if (*end != '\0')
2675 die("unrecognized context count '%s'", arg + 2);
2676 continue;
2677 }
2678 - if (!strncmp(arg, "--whitespace=", 13)) {
2678 + if (!prefixcmp(arg, "--whitespace=")) {
2679 whitespace_option = arg + 13;
2680 parse_whitespace_option(arg + 13);
2681 continue;
builtin-archive.c
+5 -5
@@ -35,7 +35,7 @@ static int run_remote_archiver(const char *remote, int argc,
35
36 for (i = 1; i < argc; i++) {
37 const char *arg = argv[i];
38 - if (!strncmp("--exec=", arg, 7)) {
38 + if (!(-prefixcmp(arg, "--exec="))) {
39 if (exec_at)
40 die("multiple --exec specified");
41 exec = arg + 7;
@@ -62,7 +62,7 @@ static int run_remote_archiver(const char *remote, int argc,
62 if (buf[len-1] == '\n')
63 buf[--len] = 0;
64 if (strcmp(buf, "ACK")) {
65 - if (len > 5 && !strncmp(buf, "NACK ", 5))
65 + if (len > 5 && !prefixcmp(buf, "NACK "))
66 die("git-archive: NACK %s", buf + 5);
67 die("git-archive: protocol error");
68 }
@@ -166,11 +166,11 @@ int parse_archive_args(int argc, const char **argv, struct archiver *ar)
166 verbose = 1;
167 continue;
168 }
169 - if (!strncmp(arg, "--format=", 9)) {
169 + if (!prefixcmp(arg, "--format=")) {
170 format = arg + 9;
171 continue;
172 }
173 - if (!strncmp(arg, "--prefix=", 9)) {
173 + if (!prefixcmp(arg, "--prefix=")) {
174 base = arg + 9;
175 continue;
176 }
@@ -218,7 +218,7 @@ static const char *extract_remote_arg(int *ac, const char **av)
218 if (!strcmp(arg, "--"))
219 no_more_options = 1;
220 if (!no_more_options) {
221 - if (!strncmp(arg, "--remote=", 9)) {
221 + if (!prefixcmp(arg, "--remote=")) {
222 if (remote)
223 die("Multiple --remote specified");
224 remote = arg + 9;
builtin-blame.c
+3 -3
@@ -2097,17 +2097,17 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2097 output_option |= OUTPUT_LONG_OBJECT_NAME;
2098 else if (!strcmp("-S", arg) && ++i < argc)
2099 revs_file = argv[i];
2100 - else if (!strncmp("-M", arg, 2)) {
2100 + else if (!(-prefixcmp(arg, "-M"))) {
2101 opt |= PICKAXE_BLAME_MOVE;
2102 blame_move_score = parse_score(arg+2);
2103 }
2104 - else if (!strncmp("-C", arg, 2)) {
2104 + else if (!(-prefixcmp(arg, "-C"))) {
2105 if (opt & PICKAXE_BLAME_COPY)
2106 opt |= PICKAXE_BLAME_COPY_HARDER;
2107 opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
2108 blame_copy_score = parse_score(arg+2);
2109 }
2110 - else if (!strncmp("-L", arg, 2)) {
2110 + else if (!(-prefixcmp(arg, "-L"))) {
2111 if (!arg[2]) {
2112 if (++i >= argc)
2113 usage(blame_usage);
builtin-branch.c
+6 -6
@@ -59,7 +59,7 @@ int git_branch_config(const char *var, const char *value)
59 branch_use_color = git_config_colorbool(var, value);
60 return 0;
61 }
62 - if (!strncmp(var, "color.branch.", 13)) {
62 + if (!prefixcmp(var, "color.branch.")) {
63 int slot = parse_branch_color_slot(var, 13);
64 color_parse(value, var, branch_colors[slot]);
65 return 0;
@@ -178,13 +178,13 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
178 int len;
179
180 /* Detect kind */
181 - if (!strncmp(refname, "refs/heads/", 11)) {
181 + if (!prefixcmp(refname, "refs/heads/")) {
182 kind = REF_LOCAL_BRANCH;
183 refname += 11;
184 - } else if (!strncmp(refname, "refs/remotes/", 13)) {
184 + } else if (!prefixcmp(refname, "refs/remotes/")) {
185 kind = REF_REMOTE_BRANCH;
186 refname += 13;
187 - } else if (!strncmp(refname, "refs/tags/", 10)) {
187 + } else if (!prefixcmp(refname, "refs/tags/")) {
188 kind = REF_TAG;
189 refname += 10;
190 }
@@ -446,7 +446,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
446 reflog = 1;
447 continue;
448 }
449 - if (!strncmp(arg, "--abbrev=", 9)) {
449 + if (!prefixcmp(arg, "--abbrev=")) {
450 abbrev = atoi(arg+9);
451 continue;
452 }
@@ -476,7 +476,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
476 detached = 1;
477 }
478 else {
479 - if (strncmp(head, "refs/heads/", 11))
479 + if (prefixcmp(head, "refs/heads/"))
480 die("HEAD not found below refs/heads!");
481 head += 11;
482 }
builtin-checkout-index.c
+2 -2
@@ -223,12 +223,12 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
223 to_tempfile = 1;
224 continue;
225 }
226 - if (!strncmp(arg, "--prefix=", 9)) {
226 + if (!prefixcmp(arg, "--prefix=")) {
227 state.base_dir = arg+9;
228 state.base_dir_len = strlen(state.base_dir);
229 continue;
230 }
231 - if (!strncmp(arg, "--stage=", 8)) {
231 + if (!prefixcmp(arg, "--stage=")) {
232 if (!strcmp(arg + 8, "all")) {
233 to_tempfile = 1;
234 checkout_stage = CHECKOUT_ALL;
builtin-describe.c
+3 -3
@@ -52,7 +52,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
52 * If --tags, then any tags are used.
53 * Otherwise only annotated tags are used.
54 */
55 - if (!strncmp(path, "refs/tags/", 10)) {
55 + if (!prefixcmp(path, "refs/tags/")) {
56 if (object->type == OBJ_TAG)
57 prio = 2;
58 else
@@ -254,12 +254,12 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
254 all = 1;
255 else if (!strcmp(arg, "--tags"))
256 tags = 1;
257 - else if (!strncmp(arg, "--abbrev=", 9)) {
257 + else if (!prefixcmp(arg, "--abbrev=")) {
258 abbrev = strtoul(arg + 9, NULL, 10);
259 if (abbrev != 0 && (abbrev < MINIMUM_ABBREV || 40 < abbrev))
260 abbrev = DEFAULT_ABBREV;
261 }
262 - else if (!strncmp(arg, "--candidates=", 13)) {
262 + else if (!prefixcmp(arg, "--candidates=")) {
263 max_candidates = strtoul(arg + 13, NULL, 10);
264 if (max_candidates < 1)
265 max_candidates = 1;
builtin-fmt-merge-msg.c
+5 -5
@@ -81,7 +81,7 @@ static int handle_line(char *line)
81 if (len < 43 || line[40] != '\t')
82 return 1;
83
84 - if (!strncmp(line + 41, "not-for-merge", 13))
84 + if (!prefixcmp(line + 41, "not-for-merge"))
85 return 0;
86
87 if (line[41] != '\t')
@@ -119,15 +119,15 @@ static int handle_line(char *line)
119 if (pulling_head) {
120 origin = xstrdup(src);
121 src_data->head_status |= 1;
122 - } else if (!strncmp(line, "branch ", 7)) {
122 + } else if (!prefixcmp(line, "branch ")) {
123 origin = xstrdup(line + 7);
124 append_to_list(&src_data->branch, origin, NULL);
125 src_data->head_status |= 2;
126 - } else if (!strncmp(line, "tag ", 4)) {
126 + } else if (!prefixcmp(line, "tag ")) {
127 origin = line;
128 append_to_list(&src_data->tag, xstrdup(origin + 4), NULL);
129 src_data->head_status |= 2;
130 - } else if (!strncmp(line, "remote branch ", 14)) {
130 + } else if (!prefixcmp(line, "remote branch ")) {
131 origin = xstrdup(line + 14);
132 append_to_list(&src_data->r_branch, origin, NULL);
133 src_data->head_status |= 2;
@@ -280,7 +280,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
280 current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
281 if (!current_branch)
282 die("No current branch");
283 - if (!strncmp(current_branch, "refs/heads/", 11))
283 + if (!prefixcmp(current_branch, "refs/heads/"))
284 current_branch += 11;
285
286 while (fgets(line, sizeof(line), in)) {
builtin-for-each-ref.c
+3 -3
@@ -814,7 +814,7 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix)
814 i++;
815 break;
816 }
817 - if (!strncmp(arg, "--format=", 9)) {
817 + if (!prefixcmp(arg, "--format=")) {
818 if (format)
819 die("more than one --format?");
820 format = arg + 9;
@@ -844,7 +844,7 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix)
844 quote_style = QUOTE_TCL;
845 continue;
846 }
847 - if (!strncmp(arg, "--count=", 8)) {
847 + if (!prefixcmp(arg, "--count=")) {
848 if (maxcount)
849 die("more than one --count?");
850 maxcount = atoi(arg + 8);
@@ -852,7 +852,7 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix)
852 die("The number %s did not parse", arg);
853 continue;
854 }
855 - if (!strncmp(arg, "--sort=", 7)) {
855 + if (!prefixcmp(arg, "--sort=")) {
856 struct ref_sort *s = xcalloc(1, sizeof(*s));
857 int len;
858
builtin-fsck.c
+1 -1
@@ -546,7 +546,7 @@ static int fsck_head_link(void)
546
547 if (!head_points_at || !(flag & REF_ISSYMREF))
548 return error("HEAD is not a symbolic ref");
549 - if (strncmp(head_points_at, "refs/heads/", 11))
549 + if (prefixcmp(head_points_at, "refs/heads/"))
550 return error("HEAD points to something strange (%s)",
551 head_points_at);
552 if (is_null_sha1(sha1))
builtin-grep.c
+3 -3
@@ -527,9 +527,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
527 opt.word_regexp = 1;
528 continue;
529 }
530 - if (!strncmp("-A", arg, 2) ||
531 - !strncmp("-B", arg, 2) ||
532 - !strncmp("-C", arg, 2) ||
530 + if (!(-prefixcmp(arg, "-A")) ||
531 + !(-prefixcmp(arg, "-B")) ||
532 + !(-prefixcmp(arg, "-C")) ||
533 (arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {
534 unsigned num;
535 const char *scan;
builtin-init-db.c
+2 -2
@@ -283,11 +283,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
283
284 for (i = 1; i < argc; i++, argv++) {
285 const char *arg = argv[1];
286 - if (!strncmp(arg, "--template=", 11))
286 + if (!prefixcmp(arg, "--template="))
287 template_dir = arg+11;
288 else if (!strcmp(arg, "--shared"))
289 shared_repository = PERM_GROUP;
290 - else if (!strncmp(arg, "--shared=", 9))
290 + else if (!prefixcmp(arg, "--shared="))
291 shared_repository = git_config_perm("arg", arg+9);
292 else
293 usage(init_db_usage);
builtin-log.c
+6 -6
@@ -32,7 +32,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
32 rev->always_show_header = 0;
33 for (i = 1; i < argc; i++) {
34 const char *arg = argv[i];
35 - if (!strncmp(arg, "--encoding=", 11)) {
35 + if (!prefixcmp(arg, "--encoding=")) {
36 arg += 11;
37 if (strcmp(arg, "none"))
38 git_log_output_encoding = strdup(arg);
@@ -287,7 +287,7 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
287
288 sol += 2;
289 /* strip [PATCH] or [PATCH blabla] */
290 - if (!keep_subject && !strncmp(sol, "[PATCH", 6)) {
290 + if (!keep_subject && !prefixcmp(sol, "[PATCH")) {
291 char *eos = strchr(sol + 6, ']');
292 if (eos) {
293 while (isspace(*eos))
@@ -435,7 +435,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
435 else if (!strcmp(argv[i], "-n") ||
436 !strcmp(argv[i], "--numbered"))
437 numbered = 1;
438 - else if (!strncmp(argv[i], "--start-number=", 15))
438 + else if (!prefixcmp(argv[i], "--start-number="))
439 start_number = strtol(argv[i] + 15, NULL, 10);
440 else if (!strcmp(argv[i], "--start-number")) {
441 i++;
@@ -471,13 +471,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
471 }
472 else if (!strcmp(argv[i], "--attach"))
473 rev.mime_boundary = git_version_string;
474 - else if (!strncmp(argv[i], "--attach=", 9))
474 + else if (!prefixcmp(argv[i], "--attach="))
475 rev.mime_boundary = argv[i] + 9;
476 else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
477 ignore_if_in_upstream = 1;
478 else if (!strcmp(argv[i], "--thread"))
479 thread = 1;
480 - else if (!strncmp(argv[i], "--in-reply-to=", 14))
480 + else if (!prefixcmp(argv[i], "--in-reply-to="))
481 in_reply_to = argv[i] + 14;
482 else if (!strcmp(argv[i], "--in-reply-to")) {
483 i++;
@@ -485,7 +485,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
485 die("Need a Message-Id for --in-reply-to");
486 in_reply_to = argv[i];
487 }
488 - else if (!strncmp(argv[i], "--suffix=", 9))
488 + else if (!prefixcmp(argv[i], "--suffix="))
489 fmt_patch_suffix = argv[i] + 9;
490 else
491 argv[j++] = argv[i];
builtin-ls-files.c
+4 -4
@@ -406,7 +406,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
406 add_exclude(argv[++i], "", 0, &dir.exclude_list[EXC_CMDL]);
407 continue;
408 }
409 - if (!strncmp(arg, "--exclude=", 10)) {
409 + if (!prefixcmp(arg, "--exclude=")) {
410 exc_given = 1;
411 add_exclude(arg+10, "", 0, &dir.exclude_list[EXC_CMDL]);
412 continue;
@@ -416,12 +416,12 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
416 add_excludes_from_file(&dir, argv[++i]);
417 continue;
418 }
419 - if (!strncmp(arg, "--exclude-from=", 15)) {
419 + if (!prefixcmp(arg, "--exclude-from=")) {
420 exc_given = 1;
421 add_excludes_from_file(&dir, arg+15);
422 continue;
423 }
424 - if (!strncmp(arg, "--exclude-per-directory=", 24)) {
424 + if (!prefixcmp(arg, "--exclude-per-directory=")) {
425 exc_given = 1;
426 dir.exclude_per_dir = arg + 24;
427 continue;
@@ -434,7 +434,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
434 error_unmatch = 1;
435 continue;
436 }
437 - if (!strncmp(arg, "--abbrev=", 9)) {
437 + if (!prefixcmp(arg, "--abbrev=")) {
438 abbrev = strtoul(arg+9, NULL, 10);
439 if (abbrev && abbrev < MINIMUM_ABBREV)
440 abbrev = MINIMUM_ABBREV;
builtin-mailinfo.c
+1 -1
@@ -811,7 +811,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
811 metainfo_charset = def_charset;
812 else if (!strcmp(argv[1], "-n"))
813 metainfo_charset = NULL;
814 - else if (!strncmp(argv[1], "--encoding=", 11))
814 + else if (!prefixcmp(argv[1], "--encoding="))
815 metainfo_charset = argv[1] + 11;
816 else
817 usage(mailinfo_usage);
builtin-name-rev.c
+4 -4
@@ -85,7 +85,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
85 struct name_ref_data *data = cb_data;
86 int deref = 0;
87
88 - if (data->tags_only && strncmp(path, "refs/tags/", 10))
88 + if (data->tags_only && prefixcmp(path, "refs/tags/"))
89 return 0;
90
91 if (data->ref_filter && fnmatch(data->ref_filter, path, 0))
@@ -101,9 +101,9 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
101 if (o && o->type == OBJ_COMMIT) {
102 struct commit *commit = (struct commit *)o;
103
104 - if (!strncmp(path, "refs/heads/", 11))
104 + if (!prefixcmp(path, "refs/heads/"))
105 path = path + 11;
106 - else if (!strncmp(path, "refs/", 5))
106 + else if (!prefixcmp(path, "refs/"))
107 path = path + 5;
108
109 name_rev(commit, xstrdup(path), 0, 0, deref);
@@ -156,7 +156,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
156 } else if (!strcmp(*argv, "--tags")) {
157 data.tags_only = 1;
158 continue;
159 - } else if (!strncmp(*argv, "--refs=", 7)) {
159 + } else if (!prefixcmp(*argv, "--refs=")) {
160 data.ref_filter = *argv + 7;
161 continue;
162 } else if (!strcmp(*argv, "--all")) {
builtin-pack-objects.c
+3 -3
@@ -1579,14 +1579,14 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1579 incremental = 1;
1580 continue;
1581 }
1582 - if (!strncmp("--window=", arg, 9)) {
1582 + if (!(-prefixcmp(arg, "--window="))) {
1583 char *end;
1584 window = strtoul(arg+9, &end, 0);
1585 if (!arg[9] || *end)
1586 usage(pack_usage);
1587 continue;
1588 }
1589 - if (!strncmp("--depth=", arg, 8)) {
1589 + if (!(-prefixcmp(arg, "--depth="))) {
1590 char *end;
1591 depth = strtoul(arg+8, &end, 0);
1592 if (!arg[8] || *end)
@@ -1622,7 +1622,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1622 continue;
1623 }
1624 if (!strcmp("--unpacked", arg) ||
1625 - !strncmp("--unpacked=", arg, 11) ||
1625 + !(-prefixcmp(arg, "--unpacked=")) ||
1626 !strcmp("--reflog", arg) ||
1627 !strcmp("--all", arg)) {
1628 use_internal_rev_list = 1;
builtin-pack-refs.c
+1 -1
@@ -36,7 +36,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,
36 /* Do not pack the symbolic refs */
37 if ((flags & REF_ISSYMREF))
38 return 0;
39 - is_tag_ref = !strncmp(path, "refs/tags/", 10);
39 + is_tag_ref = !prefixcmp(path, "refs/tags/");
40
41 /* ALWAYS pack refs that were already packed or are tags */
42 if (!cb->all && !is_tag_ref && !(flags & REF_ISPACKED))
builtin-push.c
+9 -9
@@ -32,7 +32,7 @@ static int expand_one_ref(const char *ref, const unsigned char *sha1, int flag,
32 /* Ignore the "refs/" at the beginning of the refname */
33 ref += 5;
34
35 - if (!strncmp(ref, "tags/", 5))
35 + if (!prefixcmp(ref, "tags/"))
36 add_refspec(xstrdup(ref));
37 return 0;
38 }
@@ -149,10 +149,10 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
149 int is_refspec;
150 char *s, *p;
151
152 - if (!strncmp("URL:", buffer, 4)) {
152 + if (!(-prefixcmp(buffer, "URL:"))) {
153 is_refspec = 0;
154 s = buffer + 4;
155 - } else if (!strncmp("Push:", buffer, 5)) {
155 + } else if (!(-prefixcmp(buffer, "Push:"))) {
156 is_refspec = 1;
157 s = buffer + 5;
158 } else
@@ -195,7 +195,7 @@ static int config_get_receivepack;
195
196 static int get_remote_config(const char* key, const char* value)
197 {
198 - if (!strncmp(key, "remote.", 7) &&
198 + if (!prefixcmp(key, "remote.") &&
199 !strncmp(key + 7, config_repo, config_repo_len)) {
200 if (!strcmp(key + 7 + config_repo_len, ".url")) {
201 if (config_current_uri < MAX_URI)
@@ -324,8 +324,8 @@ static int do_push(const char *repo)
324 const char **dest_refspec = refspec;
325 const char *dest = uri[i];
326 const char *sender = "git-send-pack";
327 - if (!strncmp(dest, "http://", 7) ||
328 - !strncmp(dest, "https://", 8))
327 + if (!prefixcmp(dest, "http://") ||
328 + !prefixcmp(dest, "https://"))
329 sender = "git-http-push";
330 else if (thin)
331 argv[dest_argc++] = "--thin";
@@ -373,7 +373,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
373 verbose=1;
374 continue;
375 }
376 - if (!strncmp(arg, "--repo=", 7)) {
376 + if (!prefixcmp(arg, "--repo=")) {
377 repo = arg+7;
378 continue;
379 }
@@ -397,11 +397,11 @@ int cmd_push(int argc, const char **argv, const char *prefix)
397 thin = 0;
398 continue;
399 }
400 - if (!strncmp(arg, "--receive-pack=", 15)) {
400 + if (!prefixcmp(arg, "--receive-pack=")) {
401 receivepack = arg;
402 continue;
403 }
404 - if (!strncmp(arg, "--exec=", 7)) {
404 + if (!prefixcmp(arg, "--exec=")) {
405 receivepack = arg;
406 continue;
407 }
builtin-read-tree.c
+2 -2
@@ -133,7 +133,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
133 * entries and put the entries from the tree under the
134 * given subdirectory.
135 */
136 - if (!strncmp(arg, "--prefix=", 9)) {
136 + if (!prefixcmp(arg, "--prefix=")) {
137 if (stage || opts.merge || opts.prefix)
138 usage(read_tree_usage);
139 opts.prefix = arg + 9;
@@ -179,7 +179,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
179 continue;
180 }
181
182 - if (!strncmp(arg, "--exclude-per-directory=", 24)) {
182 + if (!prefixcmp(arg, "--exclude-per-directory=")) {
183 struct dir_struct *dir;
184
185 if (opts.dir)
builtin-reflog.c
+2 -2
@@ -321,9 +321,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
321 const char *arg = argv[i];
322 if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
323 cb.dry_run = 1;
324 - else if (!strncmp(arg, "--expire=", 9))
324 + else if (!prefixcmp(arg, "--expire="))
325 cb.expire_total = approxidate(arg + 9);
326 - else if (!strncmp(arg, "--expire-unreachable=", 21))
326 + else if (!prefixcmp(arg, "--expire-unreachable="))
327 cb.expire_unreachable = approxidate(arg + 21);
328 else if (!strcmp(arg, "--stale-fix"))
329 cb.stalefix = 1;
builtin-rerere.c
+3 -3
@@ -105,11 +105,11 @@ static int handle_file(const char *path,
105 SHA1_Init(&ctx);
106
107 while (fgets(buf, sizeof(buf), f)) {
108 - if (!strncmp("<<<<<<< ", buf, 8))
108 + if (!(-prefixcmp(buf, "<<<<<<< ")))
109 hunk = 1;
110 - else if (!strncmp("=======", buf, 7))
110 + else if (!(-prefixcmp(buf, "=======")))
111 hunk = 2;
112 - else if (!strncmp(">>>>>>> ", buf, 8)) {
112 + else if (!(-prefixcmp(buf, ">>>>>>> "))) {
113 hunk_no++;
114 hunk = 0;
115 if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
builtin-rev-parse.c
+5 -5
@@ -274,7 +274,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
274 continue;
275 }
276 if (!strcmp(arg, "--short") ||
277 - !strncmp(arg, "--short=", 8)) {
277 + !prefixcmp(arg, "--short=")) {
278 filter &= ~(DO_FLAGS|DO_NOREV);
279 verify = 1;
280 abbrev = DEFAULT_ABBREV;
@@ -352,19 +352,19 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
352 : "false");
353 continue;
354 }
355 - if (!strncmp(arg, "--since=", 8)) {
355 + if (!prefixcmp(arg, "--since=")) {
356 show_datestring("--max-age=", arg+8);
357 continue;
358 }
359 - if (!strncmp(arg, "--after=", 8)) {
359 + if (!prefixcmp(arg, "--after=")) {
360 show_datestring("--max-age=", arg+8);
361 continue;
362 }
363 - if (!strncmp(arg, "--before=", 9)) {
363 + if (!prefixcmp(arg, "--before=")) {
364 show_datestring("--min-age=", arg+9);
365 continue;
366 }
367 - if (!strncmp(arg, "--until=", 8)) {
367 + if (!prefixcmp(arg, "--until=")) {
368 show_datestring("--min-age=", arg+8);
369 continue;
370 }
builtin-shortlog.c
+3 -3
@@ -124,7 +124,7 @@ static void insert_author_oneline(struct path_list *list,
124 else
125 free(buffer);
126
127 - if (!strncmp(oneline, "[PATCH", 6)) {
127 + if (!prefixcmp(oneline, "[PATCH")) {
128 char *eob = strchr(oneline, ']');
129
130 if (eob) {
@@ -179,7 +179,7 @@ static void read_from_stdin(struct path_list *list)
179 while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
180 char *bob;
181 if ((buffer[0] == 'A' || buffer[0] == 'a') &&
182 - !strncmp(buffer + 1, "uthor: ", 7) &&
182 + !prefixcmp(buffer + 1, "uthor: ") &&
183 (bob = strchr(buffer + 7, '<')) != NULL) {
184 char buffer2[1024], offset = 0;
185
@@ -230,7 +230,7 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list)
230 else
231 eol++;
232
233 - if (!strncmp(buffer, "author ", 7)) {
233 + if (!prefixcmp(buffer, "author ")) {
234 char *bracket = strchr(buffer, '<');
235
236 if (bracket == NULL || bracket > eol)
builtin-show-branch.c
+10 -10
@@ -266,7 +266,7 @@ static void show_one_commit(struct commit *commit, int no_name)
266 pretty, sizeof(pretty), 0, NULL, NULL, 0);
267 else
268 strcpy(pretty, "(unavailable)");
269 - if (!strncmp(pretty, "[PATCH] ", 8))
269 + if (!prefixcmp(pretty, "[PATCH] "))
270 cp = pretty + 8;
271 else
272 cp = pretty;
@@ -404,7 +404,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int
404
405 static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
406 {
407 - if (strncmp(refname, "refs/tags/", 10))
407 + if (prefixcmp(refname, "refs/tags/"))
408 return 0;
409 return append_ref(refname + 5, sha1, 0);
410 }
@@ -435,9 +435,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i
435 return 0;
436 if (fnmatch(match_ref_pattern, tail, 0))
437 return 0;
438 - if (!strncmp("refs/heads/", refname, 11))
438 + if (!(-prefixcmp(refname, "refs/heads/")))
439 return append_head_ref(refname, sha1, flag, cb_data);
440 - if (!strncmp("refs/tags/", refname, 10))
440 + if (!(-prefixcmp(refname, "refs/tags/")))
441 return append_tag_ref(refname, sha1, flag, cb_data);
442 return append_ref(refname, sha1, 0);
443 }
@@ -462,11 +462,11 @@ static int rev_is_head(char *head, int headlen, char *name,
462 if ((!head[0]) ||
463 (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
464 return 0;
465 - if (!strncmp(head, "refs/heads/", 11))
465 + if (!prefixcmp(head, "refs/heads/"))
466 head += 11;
467 - if (!strncmp(name, "refs/heads/", 11))
467 + if (!prefixcmp(name, "refs/heads/"))
468 name += 11;
469 - else if (!strncmp(name, "heads/", 6))
469 + else if (!prefixcmp(name, "heads/"))
470 name += 6;
471 return !strcmp(head, name);
472 }
@@ -635,7 +635,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
635 with_current_branch = 1;
636 else if (!strcmp(arg, "--sha1-name"))
637 sha1_name = 1;
638 - else if (!strncmp(arg, "--more=", 7))
638 + else if (!prefixcmp(arg, "--more="))
639 extra = atoi(arg + 7);
640 else if (!strcmp(arg, "--merge-base"))
641 merge_base = 1;
@@ -652,9 +652,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
652 else if (!strcmp(arg, "--reflog") || !strcmp(arg, "-g")) {
653 reflog = DEFAULT_REFLOG;
654 }
655 - else if (!strncmp(arg, "--reflog=", 9))
655 + else if (!prefixcmp(arg, "--reflog="))
656 parse_reflog_param(arg + 9, &reflog, &reflog_base);
657 - else if (!strncmp(arg, "-g=", 3))
657 + else if (!prefixcmp(arg, "-g="))
658 parse_reflog_param(arg + 3, &reflog, &reflog_base);
659 else
660 usage(show_branch_usage);
builtin-show-ref.c
+6 -6
@@ -28,8 +28,8 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo
28 if (tags_only || heads_only) {
29 int match;
30
31 - match = heads_only && !strncmp(refname, "refs/heads/", 11);
32 - match |= tags_only && !strncmp(refname, "refs/tags/", 10);
31 + match = heads_only && !prefixcmp(refname, "refs/heads/");
32 + match |= tags_only && !prefixcmp(refname, "refs/tags/");
33 if (!match)
34 return 0;
35 }
@@ -178,8 +178,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
178 hash_only = 1;
179 continue;
180 }
181 - if (!strncmp(arg, "--hash=", 7) ||
182 - (!strncmp(arg, "--abbrev", 8) &&
181 + if (!prefixcmp(arg, "--hash=") ||
182 + (!prefixcmp(arg, "--abbrev") &&
183 (arg[8] == '=' || arg[8] == '\0'))) {
184 if (arg[2] != 'h' && !arg[8])
185 /* --abbrev only */
@@ -215,7 +215,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
215 }
216 if (!strcmp(arg, "--exclude-existing"))
217 return exclude_existing(NULL);
218 - if (!strncmp(arg, "--exclude-existing=", 19))
218 + if (!prefixcmp(arg, "--exclude-existing="))
219 return exclude_existing(arg + 19);
220 usage(show_ref_usage);
221 }
@@ -224,7 +224,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
224 unsigned char sha1[20];
225
226 while (*pattern) {
227 - if (!strncmp(*pattern, "refs/", 5) &&
227 + if (!prefixcmp(*pattern, "refs/") &&
228 resolve_ref(*pattern, sha1, 1, NULL)) {
229 if (!quiet)
230 show_one(*pattern, sha1);
builtin-tar-tree.c
+1 -1
@@ -31,7 +31,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
31 nargv[nargc++] = "git-archive";
32 nargv[nargc++] = "--format=tar";
33
34 - if (2 <= argc && !strncmp("--remote=", argv[1], 9)) {
34 + if (2 <= argc && !(-prefixcmp(argv[1], "--remote="))) {
35 nargv[nargc++] = argv[1];
36 argv++;
37 argc--;
builtin-unpack-objects.c
+1 -1
@@ -369,7 +369,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
369 recover = 1;
370 continue;
371 }
372 - if (!strncmp(arg, "--pack_header=", 14)) {
372 + if (!prefixcmp(arg, "--pack_header=")) {
373 struct pack_header *hdr;
374 char *c;
375
builtin-write-tree.c
+1 -1
@@ -70,7 +70,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
70 const char *arg = argv[1];
71 if (!strcmp(arg, "--missing-ok"))
72 missing_ok = 1;
73 - else if (!strncmp(arg, "--prefix=", 9))
73 + else if (!prefixcmp(arg, "--prefix="))
74 prefix = arg + 9;
75 else
76 usage(write_tree_usage);
connect.c
+3 -3
@@ -96,7 +96,7 @@ int get_ack(int fd, unsigned char *result_sha1)
96 line[--len] = 0;
97 if (!strcmp(line, "NAK"))
98 return 0;
99 - if (!strncmp(line, "ACK ", 4)) {
99 + if (!prefixcmp(line, "ACK ")) {
100 if (!get_sha1_hex(line+4, result_sha1)) {
101 if (strstr(line+45, "continue"))
102 return 2;
@@ -196,8 +196,8 @@ static int count_refspec_match(const char *pattern,
196 */
197 if (namelen != patlen &&
198 patlen != namelen - 5 &&
199 - strncmp(name, "refs/heads/", 11) &&
200 - strncmp(name, "refs/tags/", 10)) {
199 + prefixcmp(name, "refs/heads/") &&
200 + prefixcmp(name, "refs/tags/")) {
201 /* We want to catch the case where only weak
202 * matches are found and there are multiple
203 * matches, and where more than one strong
daemon.c
+16 -16
@@ -286,7 +286,7 @@ static int service_enabled;
286
287 static int git_daemon_config(const char *var, const char *value)
288 {
289 - if (!strncmp(var, "daemon.", 7) &&
289 + if (!prefixcmp(var, "daemon.") &&
290 !strcmp(var + 7, service_looking_at->config_name)) {
291 service_enabled = git_config_bool(var, value);
292 return 0;
@@ -562,7 +562,7 @@ static int execute(struct sockaddr *addr)
562 for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
563 struct daemon_service *s = &(daemon_service[i]);
564 int namelen = strlen(s->name);
565 - if (!strncmp("git-", line, 4) &&
565 + if (!(-prefixcmp(line, "git-")) &&
566 !strncmp(s->name, line + 4, namelen) &&
567 line[namelen + 4] == ' ') {
568 /*
@@ -1011,7 +1011,7 @@ int main(int argc, char **argv)
1011 for (i = 1; i < argc; i++) {
1012 char *arg = argv[i];
1013
1014 - if (!strncmp(arg, "--listen=", 9)) {
1014 + if (!prefixcmp(arg, "--listen=")) {
1015 char *p = arg + 9;
1016 char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);
1017 while (*p)
@@ -1019,7 +1019,7 @@ int main(int argc, char **argv)
1019 *ph = 0;
1020 continue;
1021 }
1022 - if (!strncmp(arg, "--port=", 7)) {
1022 + if (!prefixcmp(arg, "--port=")) {
1023 char *end;
1024 unsigned long n;
1025 n = strtoul(arg+7, &end, 0);
@@ -1045,11 +1045,11 @@ int main(int argc, char **argv)
1045 export_all_trees = 1;
1046 continue;
1047 }
1048 - if (!strncmp(arg, "--timeout=", 10)) {
1048 + if (!prefixcmp(arg, "--timeout=")) {
1049 timeout = atoi(arg+10);
1050 continue;
1051 }
1052 - if (!strncmp(arg, "--init-timeout=", 15)) {
1052 + if (!prefixcmp(arg, "--init-timeout=")) {
1053 init_timeout = atoi(arg+15);
1054 continue;
1055 }
@@ -1057,11 +1057,11 @@ int main(int argc, char **argv)
1057 strict_paths = 1;
1058 continue;
1059 }
1060 - if (!strncmp(arg, "--base-path=", 12)) {
1060 + if (!prefixcmp(arg, "--base-path=")) {
1061 base_path = arg+12;
1062 continue;
1063 }
1064 - if (!strncmp(arg, "--interpolated-path=", 20)) {
1064 + if (!prefixcmp(arg, "--interpolated-path=")) {
1065 interpolated_path = arg+20;
1066 continue;
1067 }
@@ -1073,11 +1073,11 @@ int main(int argc, char **argv)
1073 user_path = "";
1074 continue;
1075 }
1076 - if (!strncmp(arg, "--user-path=", 12)) {
1076 + if (!prefixcmp(arg, "--user-path=")) {
1077 user_path = arg + 12;
1078 continue;
1079 }
1080 - if (!strncmp(arg, "--pid-file=", 11)) {
1080 + if (!prefixcmp(arg, "--pid-file=")) {
1081 pid_file = arg + 11;
1082 continue;
1083 }
@@ -1086,27 +1086,27 @@ int main(int argc, char **argv)
1086 log_syslog = 1;
1087 continue;
1088 }
1089 - if (!strncmp(arg, "--user=", 7)) {
1089 + if (!prefixcmp(arg, "--user=")) {
1090 user_name = arg + 7;
1091 continue;
1092 }
1093 - if (!strncmp(arg, "--group=", 8)) {
1093 + if (!prefixcmp(arg, "--group=")) {
1094 group_name = arg + 8;
1095 continue;
1096 }
1097 - if (!strncmp(arg, "--enable=", 9)) {
1097 + if (!prefixcmp(arg, "--enable=")) {
1098 enable_service(arg + 9, 1);
1099 continue;
1100 }
1101 - if (!strncmp(arg, "--disable=", 10)) {
1101 + if (!prefixcmp(arg, "--disable=")) {
1102 enable_service(arg + 10, 0);
1103 continue;
1104 }
1105 - if (!strncmp(arg, "--allow-override=", 17)) {
1105 + if (!prefixcmp(arg, "--allow-override=")) {
1106 make_service_overridable(arg + 17, 1);
1107 continue;
1108 }
1109 - if (!strncmp(arg, "--forbid-override=", 18)) {
1109 + if (!prefixcmp(arg, "--forbid-override=")) {
1110 make_service_overridable(arg + 18, 0);
1111 continue;
1112 }
diff.c
+15 -15
@@ -77,7 +77,7 @@ int git_diff_ui_config(const char *var, const char *value)
77 diff_detect_rename_default = DIFF_DETECT_RENAME;
78 return 0;
79 }
80 - if (!strncmp(var, "diff.color.", 11) || !strncmp(var, "color.diff.", 11)) {
80 + if (!prefixcmp(var, "diff.color.") || !strncmp(var, "color.diff.", 11)) {
81 int slot = parse_diff_color_slot(var, 11);
82 color_parse(value, var, diff_colors[slot]);
83 return 0;
@@ -1119,9 +1119,9 @@ static void builtin_diff(const char *name_a,
1119 xecfg.flags = XDL_EMIT_FUNCNAMES;
1120 if (!diffopts)
1121 ;
1122 - else if (!strncmp(diffopts, "--unified=", 10))
1122 + else if (!prefixcmp(diffopts, "--unified="))
1123 xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
1124 - else if (!strncmp(diffopts, "-u", 2))
1124 + else if (!prefixcmp(diffopts, "-u"))
1125 xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
1126 ecb.outf = xdiff_outf;
1127 ecb.priv = &ecbdata;
@@ -1957,7 +1957,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1957 else if (!strcmp(arg, "--shortstat")) {
1958 options->output_format |= DIFF_FORMAT_SHORTSTAT;
1959 }
1960 - else if (!strncmp(arg, "--stat", 6)) {
1960 + else if (!prefixcmp(arg, "--stat")) {
1961 char *end;
1962 int width = options->stat_width;
1963 int name_width = options->stat_name_width;
@@ -1966,9 +1966,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1966
1967 switch (*arg) {
1968 case '-':
1969 - if (!strncmp(arg, "-width=", 7))
1969 + if (!prefixcmp(arg, "-width="))
1970 width = strtoul(arg + 7, &end, 10);
1971 - else if (!strncmp(arg, "-name-width=", 12))
1971 + else if (!prefixcmp(arg, "-name-width="))
1972 name_width = strtoul(arg + 12, &end, 10);
1973 break;
1974 case '=':
@@ -1993,7 +1993,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1993 }
1994 else if (!strcmp(arg, "-z"))
1995 options->line_termination = 0;
1996 - else if (!strncmp(arg, "-l", 2))
1996 + else if (!prefixcmp(arg, "-l"))
1997 options->rename_limit = strtoul(arg+2, NULL, 10);
1998 else if (!strcmp(arg, "--full-index"))
1999 options->full_index = 1;
@@ -2010,31 +2010,31 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
2010 options->output_format |= DIFF_FORMAT_NAME_STATUS;
2011 else if (!strcmp(arg, "-R"))
2012 options->reverse_diff = 1;
2013 - else if (!strncmp(arg, "-S", 2))
2013 + else if (!prefixcmp(arg, "-S"))
2014 options->pickaxe = arg + 2;
2015 else if (!strcmp(arg, "-s")) {
2016 options->output_format |= DIFF_FORMAT_NO_OUTPUT;
2017 }
2018 - else if (!strncmp(arg, "-O", 2))
2018 + else if (!prefixcmp(arg, "-O"))
2019 options->orderfile = arg + 2;
2020 - else if (!strncmp(arg, "--diff-filter=", 14))
2020 + else if (!prefixcmp(arg, "--diff-filter="))
2021 options->filter = arg + 14;
2022 else if (!strcmp(arg, "--pickaxe-all"))
2023 options->pickaxe_opts = DIFF_PICKAXE_ALL;
2024 else if (!strcmp(arg, "--pickaxe-regex"))
2025 options->pickaxe_opts = DIFF_PICKAXE_REGEX;
2026 - else if (!strncmp(arg, "-B", 2)) {
2026 + else if (!prefixcmp(arg, "-B")) {
2027 if ((options->break_opt =
2028 diff_scoreopt_parse(arg)) == -1)
2029 return -1;
2030 }
2031 - else if (!strncmp(arg, "-M", 2)) {
2031 + else if (!prefixcmp(arg, "-M")) {
2032 if ((options->rename_score =
2033 diff_scoreopt_parse(arg)) == -1)
2034 return -1;
2035 options->detect_rename = DIFF_DETECT_RENAME;
2036 }
2037 - else if (!strncmp(arg, "-C", 2)) {
2037 + else if (!prefixcmp(arg, "-C")) {
2038 if ((options->rename_score =
2039 diff_scoreopt_parse(arg)) == -1)
2040 return -1;
@@ -2044,7 +2044,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
2044 options->find_copies_harder = 1;
2045 else if (!strcmp(arg, "--abbrev"))
2046 options->abbrev = DEFAULT_ABBREV;
2047 - else if (!strncmp(arg, "--abbrev=", 9)) {
2047 + else if (!prefixcmp(arg, "--abbrev=")) {
2048 options->abbrev = strtoul(arg + 9, NULL, 10);
2049 if (options->abbrev < MINIMUM_ABBREV)
2050 options->abbrev = MINIMUM_ABBREV;
@@ -2553,7 +2553,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
2553 int new_len;
2554
2555 /* Ignore line numbers when computing the SHA1 of the patch */
2556 - if (!strncmp(line, "@@ -", 4))
2556 + if (!prefixcmp(line, "@@ -"))
2557 return;
2558
2559 new_len = remove_space(line, len);
exec_cmd.c
+1 -1
@@ -56,7 +56,7 @@ int execv_git_cmd(const char **argv)
56 len = strlen(git_command);
57
58 /* Trivial cleanup */
59 - while (!strncmp(exec_dir, "./", 2)) {
59 + while (!prefixcmp(exec_dir, "./")) {
60 exec_dir += 2;
61 while (*exec_dir == '/')
62 exec_dir++;
fast-import.c
+21 -21
@@ -1392,7 +1392,7 @@ static void read_next_command(void)
1392
1393 static void cmd_mark(void)
1394 {
1395 - if (!strncmp("mark :", command_buf.buf, 6)) {
1395 + if (!(-prefixcmp(command_buf.buf, "mark :"))) {
1396 next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
1397 read_next_command();
1398 }
@@ -1405,10 +1405,10 @@ static void *cmd_data (size_t *size)
1405 size_t length;
1406 char *buffer;
1407
1408 - if (strncmp("data ", command_buf.buf, 5))
1408 + if ((-prefixcmp(command_buf.buf, "data ")))
1409 die("Expected 'data n' command, found: %s", command_buf.buf);
1410
1411 - if (!strncmp("<<", command_buf.buf + 5, 2)) {
1411 + if (!(-prefixcmp(command_buf.buf + 5, "<<"))) {
1412 char *term = xstrdup(command_buf.buf + 5 + 2);
1413 size_t sz = 8192, term_len = command_buf.len - 5 - 2;
1414 length = 0;
@@ -1595,7 +1595,7 @@ static void file_change_m(struct branch *b)
1595 oe = find_mark(strtoumax(p + 1, &x, 10));
1596 hashcpy(sha1, oe->sha1);
1597 p = x;
1598 - } else if (!strncmp("inline", p, 6)) {
1598 + } else if (!(-prefixcmp(p, "inline"))) {
1599 inline_data = 1;
1600 p += 6;
1601 } else {
@@ -1668,7 +1668,7 @@ static void cmd_from(struct branch *b)
1668 const char *from;
1669 struct branch *s;
1670
1671 - if (strncmp("from ", command_buf.buf, 5))
1671 + if ((-prefixcmp(command_buf.buf, "from ")))
1672 return;
1673
1674 if (b->branch_tree.tree) {
@@ -1734,7 +1734,7 @@ static struct hash_list *cmd_merge(unsigned int *count)
1734 struct branch *s;
1735
1736 *count = 0;
1737 - while (!strncmp("merge ", command_buf.buf, 6)) {
1737 + while (!(-prefixcmp(command_buf.buf, "merge "))) {
1738 from = strchr(command_buf.buf, ' ') + 1;
1739 n = xmalloc(sizeof(*n));
1740 s = lookup_branch(from);
@@ -1780,11 +1780,11 @@ static void cmd_new_commit(void)
1780
1781 read_next_command();
1782 cmd_mark();
1783 - if (!strncmp("author ", command_buf.buf, 7)) {
1783 + if (!(-prefixcmp(command_buf.buf, "author "))) {
1784 author = parse_ident(command_buf.buf + 7);
1785 read_next_command();
1786 }
1787 - if (!strncmp("committer ", command_buf.buf, 10)) {
1787 + if (!(-prefixcmp(command_buf.buf, "committer "))) {
1788 committer = parse_ident(command_buf.buf + 10);
1789 read_next_command();
1790 }
@@ -1805,9 +1805,9 @@ static void cmd_new_commit(void)
1805 for (;;) {
1806 if (1 == command_buf.len)
1807 break;
1808 - else if (!strncmp("M ", command_buf.buf, 2))
1808 + else if (!(-prefixcmp(command_buf.buf, "M ")))
1809 file_change_m(b);
1810 - else if (!strncmp("D ", command_buf.buf, 2))
1810 + else if (!(-prefixcmp(command_buf.buf, "D ")))
1811 file_change_d(b);
1812 else if (!strcmp("deleteall", command_buf.buf))
1813 file_change_deleteall(b);
@@ -1877,7 +1877,7 @@ static void cmd_new_tag(void)
1877 read_next_command();
1878
1879 /* from ... */
1880 - if (strncmp("from ", command_buf.buf, 5))
1880 + if ((-prefixcmp(command_buf.buf, "from ")))
1881 die("Expected from command, got %s", command_buf.buf);
1882 from = strchr(command_buf.buf, ' ') + 1;
1883 s = lookup_branch(from);
@@ -1904,7 +1904,7 @@ static void cmd_new_tag(void)
1904 read_next_command();
1905
1906 /* tagger ... */
1907 - if (strncmp("tagger ", command_buf.buf, 7))
1907 + if ((-prefixcmp(command_buf.buf, "tagger ")))
1908 die("Expected tagger command, got %s", command_buf.buf);
1909 tagger = parse_ident(command_buf.buf + 7);
1910
@@ -1981,7 +1981,7 @@ int main(int argc, const char **argv)
1981
1982 if (*a != '-' || !strcmp(a, "--"))
1983 break;
1984 - else if (!strncmp(a, "--date-format=", 14)) {
1984 + else if (!prefixcmp(a, "--date-format=")) {
1985 const char *fmt = a + 14;
1986 if (!strcmp(fmt, "raw"))
1987 whenspec = WHENSPEC_RAW;
@@ -1992,15 +1992,15 @@ int main(int argc, const char **argv)
1992 else
1993 die("unknown --date-format argument %s", fmt);
1994 }
1995 - else if (!strncmp(a, "--max-pack-size=", 16))
1995 + else if (!prefixcmp(a, "--max-pack-size="))
1996 max_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024;
1997 - else if (!strncmp(a, "--depth=", 8))
1997 + else if (!prefixcmp(a, "--depth="))
1998 max_depth = strtoul(a + 8, NULL, 0);
1999 - else if (!strncmp(a, "--active-branches=", 18))
1999 + else if (!prefixcmp(a, "--active-branches="))
2000 max_active_branches = strtoul(a + 18, NULL, 0);
2001 - else if (!strncmp(a, "--export-marks=", 15))
2001 + else if (!prefixcmp(a, "--export-marks="))
2002 mark_file = a + 15;
2003 - else if (!strncmp(a, "--export-pack-edges=", 20)) {
2003 + else if (!prefixcmp(a, "--export-pack-edges=")) {
2004 if (pack_edges)
2005 fclose(pack_edges);
2006 pack_edges = fopen(a + 20, "a");
@@ -2033,11 +2033,11 @@ int main(int argc, const char **argv)
2033 break;
2034 else if (!strcmp("blob", command_buf.buf))
2035 cmd_new_blob();
2036 - else if (!strncmp("commit ", command_buf.buf, 7))
2036 + else if (!(-prefixcmp(command_buf.buf, "commit ")))
2037 cmd_new_commit();
2038 - else if (!strncmp("tag ", command_buf.buf, 4))
2038 + else if (!(-prefixcmp(command_buf.buf, "tag ")))
2039 cmd_new_tag();
2040 - else if (!strncmp("reset ", command_buf.buf, 6))
2040 + else if (!(-prefixcmp(command_buf.buf, "reset ")))
2041 cmd_reset_branch();
2042 else if (!strcmp("checkpoint", command_buf.buf))
2043 cmd_checkpoint();
fetch-pack.c
+6 -6
@@ -198,13 +198,13 @@ static int find_common(int fd[2], unsigned char *result_sha1,
198 int len;
199
200 while ((len = packet_read_line(fd[0], line, sizeof(line)))) {
201 - if (!strncmp("shallow ", line, 8)) {
201 + if (!(-prefixcmp(line, "shallow "))) {
202 if (get_sha1_hex(line + 8, sha1))
203 die("invalid shallow line: %s", line);
204 register_shallow(sha1);
205 continue;
206 }
207 - if (!strncmp("unshallow ", line, 10)) {
207 + if (!(-prefixcmp(line, "unshallow "))) {
208 if (get_sha1_hex(line + 10, sha1))
209 die("invalid unshallow line: %s", line);
210 if (!lookup_object(sha1))
@@ -346,7 +346,7 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)
346 check_ref_format(ref->name + 5))
347 ; /* trash */
348 else if (fetch_all &&
349 - (!depth || strncmp(ref->name, "refs/tags/", 10) )) {
349 + (!depth || prefixcmp(ref->name, "refs/tags/") )) {
350 *newtail = ref;
351 ref->next = NULL;
352 newtail = &ref->next;
@@ -683,11 +683,11 @@ int main(int argc, char **argv)
683 char *arg = argv[i];
684
685 if (*arg == '-') {
686 - if (!strncmp("--upload-pack=", arg, 14)) {
686 + if (!(-prefixcmp(arg, "--upload-pack="))) {
687 uploadpack = arg + 14;
688 continue;
689 }
690 - if (!strncmp("--exec=", arg, 7)) {
690 + if (!(-prefixcmp(arg, "--exec="))) {
691 uploadpack = arg + 7;
692 continue;
693 }
@@ -712,7 +712,7 @@ int main(int argc, char **argv)
712 verbose = 1;
713 continue;
714 }
715 - if (!strncmp("--depth=", arg, 8)) {
715 + if (!(-prefixcmp(arg, "--depth="))) {
716 depth = strtol(arg + 8, NULL, 0);
717 if (stat(git_path("shallow"), &st))
718 st.st_mtime = 0;
git.c
+5 -5
@@ -48,7 +48,7 @@ static int handle_options(const char*** argv, int* argc)
48 /*
49 * Check remaining flags.
50 */
51 - if (!strncmp(cmd, "--exec-path", 11)) {
51 + if (!prefixcmp(cmd, "--exec-path")) {
52 cmd += 11;
53 if (*cmd == '=')
54 git_set_exec_path(cmd + 1);
@@ -66,7 +66,7 @@ static int handle_options(const char*** argv, int* argc)
66 setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);
67 (*argv)++;
68 (*argc)--;
69 - } else if (!strncmp(cmd, "--git-dir=", 10)) {
69 + } else if (!prefixcmp(cmd, "--git-dir=")) {
70 setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
71 } else if (!strcmp(cmd, "--bare")) {
72 static char git_dir[PATH_MAX+1];
@@ -88,7 +88,7 @@ static char *alias_string;
88
89 static int git_alias_config(const char *var, const char *value)
90 {
91 - if (!strncmp(var, "alias.", 6) && !strcmp(var + 6, alias_command)) {
91 + if (!prefixcmp(var, "alias.") && !strcmp(var + 6, alias_command)) {
92 alias_string = xstrdup(value);
93 }
94 return 0;
@@ -348,7 +348,7 @@ int main(int argc, const char **argv, char **envp)
348 * So we just directly call the internal command handler, and
349 * die if that one cannot handle it.
350 */
351 - if (!strncmp(cmd, "git-", 4)) {
351 + if (!prefixcmp(cmd, "git-")) {
352 cmd += 4;
353 argv[0] = cmd;
354 handle_internal_command(argc, argv, envp);
@@ -360,7 +360,7 @@ int main(int argc, const char **argv, char **envp)
360 argc--;
361 handle_options(&argv, &argc);
362 if (argc > 0) {
363 - if (!strncmp(argv[0], "--", 2))
363 + if (!prefixcmp(argv[0], "--"))
364 argv[0] += 2;
365 } else {
366 /* Default command: "help" */
help.c
+2 -2
@@ -130,7 +130,7 @@ static void list_commands(const char *exec_path, const char *pattern)
130 struct stat st;
131 int entlen;
132
133 - if (strncmp(de->d_name, "git-", 4))
133 + if (prefixcmp(de->d_name, "git-"))
134 continue;
135 strcpy(path+dirlen, de->d_name);
136 if (stat(path, &st) || /* stat, not lstat */
@@ -179,7 +179,7 @@ static void show_man_page(const char *git_cmd)
179 {
180 const char *page;
181
182 - if (!strncmp(git_cmd, "git", 3))
182 + if (!prefixcmp(git_cmd, "git"))
183 page = git_cmd;
184 else {
185 int page_len = strlen(git_cmd) + 4;
http-fetch.c
+1 -1
@@ -717,7 +717,7 @@ static int fetch_indices(struct alt_base *repo)
717 case 'P':
718 i++;
719 if (i + 52 <= buffer.posn &&
720 - !strncmp(data + i, " pack-", 6) &&
720 + !prefixcmp(data + i, " pack-") &&
721 !strncmp(data + i + 46, ".pack\n", 6)) {
722 get_sha1_hex(data + i + 6, sha1);
723 setup_index(repo, sha1);
http-push.c
+4 -4
@@ -1060,7 +1060,7 @@ static int fetch_indices(void)
1060 case 'P':
1061 i++;
1062 if (i + 52 < buffer.posn &&
1063 - !strncmp(data + i, " pack-", 6) &&
1063 + !prefixcmp(data + i, " pack-") &&
1064 !strncmp(data + i + 46, ".pack\n", 6)) {
1065 get_sha1_hex(data + i + 6, sha1);
1066 setup_index(sha1);
@@ -1206,11 +1206,11 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
1206 lock->owner = xmalloc(strlen(ctx->cdata) + 1);
1207 strcpy(lock->owner, ctx->cdata);
1208 } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TIMEOUT)) {
1209 - if (!strncmp(ctx->cdata, "Second-", 7))
1209 + if (!prefixcmp(ctx->cdata, "Second-"))
1210 lock->timeout =
1211 strtol(ctx->cdata + 7, NULL, 10);
1212 } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
1213 - if (!strncmp(ctx->cdata, "opaquelocktoken:", 16)) {
1213 + if (!prefixcmp(ctx->cdata, "opaquelocktoken:")) {
1214 lock->token = xmalloc(strlen(ctx->cdata) - 15);
1215 strcpy(lock->token, ctx->cdata + 16);
1216 }
@@ -2168,7 +2168,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
2168 return;
2169
2170 /* If it's a symref, set the refname; otherwise try for a sha1 */
2171 - if (!strncmp((char *)buffer.buffer, "ref: ", 5)) {
2171 + if (!prefixcmp((char *)buffer.buffer, "ref: ")) {
2172 *symref = xmalloc(buffer.posn - 5);
2173 strlcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5);
2174 } else {
index-pack.c
+2 -2
@@ -849,9 +849,9 @@ int main(int argc, char **argv)
849 fix_thin_pack = 1;
850 } else if (!strcmp(arg, "--keep")) {
851 keep_msg = "";
852 - } else if (!strncmp(arg, "--keep=", 7)) {
852 + } else if (!prefixcmp(arg, "--keep=")) {
853 keep_msg = arg + 7;
854 - } else if (!strncmp(arg, "--pack_header=", 14)) {
854 + } else if (!prefixcmp(arg, "--pack_header=")) {
855 struct pack_header *hdr;
856 char *c;
857
peek-remote.c
+2 -2
@@ -35,11 +35,11 @@ int main(int argc, char **argv)
35 char *arg = argv[i];
36
37 if (*arg == '-') {
38 - if (!strncmp("--upload-pack=", arg, 14)) {
38 + if (!(-prefixcmp(arg, "--upload-pack="))) {
39 uploadpack = arg + 14;
40 continue;
41 }
42 - if (!strncmp("--exec=", arg, 7)) {
42 + if (!(-prefixcmp(arg, "--exec="))) {
43 uploadpack = arg + 7;
44 continue;
45 }
receive-pack.c
+2 -2
@@ -109,7 +109,7 @@ static int update(struct command *cmd)
109 struct ref_lock *lock;
110
111 cmd->error_string = NULL;
112 - if (!strncmp(name, "refs/", 5) && check_ref_format(name + 5)) {
112 + if (!prefixcmp(name, "refs/") && check_ref_format(name + 5)) {
113 cmd->error_string = "funny refname";
114 return error("refusing to create funny ref '%s' locally",
115 name);
@@ -125,7 +125,7 @@ static int update(struct command *cmd)
125 }
126 if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
127 !is_null_sha1(old_sha1) &&
128 - !strncmp(name, "refs/heads/", 11)) {
128 + !prefixcmp(name, "refs/heads/")) {
129 struct commit *old_commit, *new_commit;
130 struct commit_list *bases, *ent;
131
refs.c
+4 -4
@@ -828,8 +828,8 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
828 goto rollback;
829 }
830
831 - if (!strncmp(oldref, "refs/heads/", 11) &&
832 - !strncmp(newref, "refs/heads/", 11)) {
831 + if (!prefixcmp(oldref, "refs/heads/") &&
832 + !prefixcmp(newref, "refs/heads/")) {
833 char oldsection[1024], newsection[1024];
834
835 snprintf(oldsection, 1024, "branch.%s", oldref + 11);
@@ -894,8 +894,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
894 log_file = git_path("logs/%s", ref_name);
895
896 if (log_all_ref_updates &&
897 - (!strncmp(ref_name, "refs/heads/", 11) ||
898 - !strncmp(ref_name, "refs/remotes/", 13) ||
897 + (!prefixcmp(ref_name, "refs/heads/") ||
898 + !prefixcmp(ref_name, "refs/remotes/") ||
899 !strcmp(ref_name, "HEAD"))) {
900 if (safe_create_leading_directories(log_file) < 0)
901 return error("unable to create directory for %s",
revision.c
+15 -15
@@ -813,11 +813,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
813 const char *arg = argv[i];
814 if (*arg == '-') {
815 int opts;
816 - if (!strncmp(arg, "--max-count=", 12)) {
816 + if (!prefixcmp(arg, "--max-count=")) {
817 revs->max_count = atoi(arg + 12);
818 continue;
819 }
820 - if (!strncmp(arg, "--skip=", 7)) {
820 + if (!prefixcmp(arg, "--skip=")) {
821 revs->skip_count = atoi(arg + 7);
822 continue;
823 }
@@ -836,27 +836,27 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
836 revs->max_count = atoi(arg + 2);
837 continue;
838 }
839 - if (!strncmp(arg, "--max-age=", 10)) {
839 + if (!prefixcmp(arg, "--max-age=")) {
840 revs->max_age = atoi(arg + 10);
841 continue;
842 }
843 - if (!strncmp(arg, "--since=", 8)) {
843 + if (!prefixcmp(arg, "--since=")) {
844 revs->max_age = approxidate(arg + 8);
845 continue;
846 }
847 - if (!strncmp(arg, "--after=", 8)) {
847 + if (!prefixcmp(arg, "--after=")) {
848 revs->max_age = approxidate(arg + 8);
849 continue;
850 }
851 - if (!strncmp(arg, "--min-age=", 10)) {
851 + if (!prefixcmp(arg, "--min-age=")) {
852 revs->min_age = atoi(arg + 10);
853 continue;
854 }
855 - if (!strncmp(arg, "--before=", 9)) {
855 + if (!prefixcmp(arg, "--before=")) {
856 revs->min_age = approxidate(arg + 9);
857 continue;
858 }
859 - if (!strncmp(arg, "--until=", 8)) {
859 + if (!prefixcmp(arg, "--until=")) {
860 revs->min_age = approxidate(arg + 8);
861 continue;
862 }
@@ -944,7 +944,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
944 revs->num_ignore_packed = 0;
945 continue;
946 }
947 - if (!strncmp(arg, "--unpacked=", 11)) {
947 + if (!prefixcmp(arg, "--unpacked=")) {
948 revs->unpacked = 1;
949 add_ignore_packed(revs, arg+11);
950 continue;
@@ -980,7 +980,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
980 revs->verbose_header = 1;
981 continue;
982 }
983 - if (!strncmp(arg, "--pretty", 8)) {
983 + if (!prefixcmp(arg, "--pretty")) {
984 revs->verbose_header = 1;
985 revs->commit_format = get_commit_format(arg+8);
986 continue;
@@ -1005,7 +1005,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1005 revs->abbrev = DEFAULT_ABBREV;
1006 continue;
1007 }
1008 - if (!strncmp(arg, "--abbrev=", 9)) {
1008 + if (!prefixcmp(arg, "--abbrev=")) {
1009 revs->abbrev = strtoul(arg + 9, NULL, 10);
1010 if (revs->abbrev < MINIMUM_ABBREV)
1011 revs->abbrev = MINIMUM_ABBREV;
@@ -1034,15 +1034,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1034 /*
1035 * Grepping the commit log
1036 */
1037 - if (!strncmp(arg, "--author=", 9)) {
1037 + if (!prefixcmp(arg, "--author=")) {
1038 add_header_grep(revs, "author", arg+9);
1039 continue;
1040 }
1041 - if (!strncmp(arg, "--committer=", 12)) {
1041 + if (!prefixcmp(arg, "--committer=")) {
1042 add_header_grep(revs, "committer", arg+12);
1043 continue;
1044 }
1045 - if (!strncmp(arg, "--grep=", 7)) {
1045 + if (!prefixcmp(arg, "--grep=")) {
1046 add_message_grep(revs, arg+7);
1047 continue;
1048 }
@@ -1050,7 +1050,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1050 all_match = 1;
1051 continue;
1052 }
1053 - if (!strncmp(arg, "--encoding=", 11)) {
1053 + if (!prefixcmp(arg, "--encoding=")) {
1054 arg += 11;
1055 if (strcmp(arg, "none"))
1056 git_log_output_encoding = strdup(arg);
send-pack.c
+2 -2
@@ -379,11 +379,11 @@ int main(int argc, char **argv)
379 char *arg = *argv;
380
381 if (*arg == '-') {
382 - if (!strncmp(arg, "--receive-pack=", 15)) {
382 + if (!prefixcmp(arg, "--receive-pack=")) {
383 receivepack = arg + 15;
384 continue;
385 }
386 - if (!strncmp(arg, "--exec=", 7)) {
386 + if (!prefixcmp(arg, "--exec=")) {
387 receivepack = arg + 7;
388 continue;
389 }
setup.c
+1 -1
@@ -251,7 +251,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
251 offset++;
252 cwd[len++] = '/';
253 cwd[len] = 0;
254 - inside_git_dir = !strncmp(cwd + offset, ".git/", 5);
254 + inside_git_dir = !prefixcmp(cwd + offset, ".git/");
255 return cwd + offset;
256 }
257
shell.c
+1 -1
@@ -8,7 +8,7 @@ static int do_generic_cmd(const char *me, char *arg)
8
9 if (!arg || !(arg = sq_dequote(arg)))
10 die("bad argument");
11 - if (strncmp(me, "git-", 4))
11 + if (prefixcmp(me, "git-"))
12 die("bad command");
13
14 my_argv[0] = me + 4;
upload-pack.c
+5 -5
@@ -455,7 +455,7 @@ static int get_common_commits(void)
455 continue;
456 }
457 len = strip(line, len);
458 - if (!strncmp(line, "have ", 5)) {
458 + if (!prefixcmp(line, "have ")) {
459 switch (got_sha1(line+5, sha1)) {
460 case -1: /* they have what we do not */
461 if (multi_ack && ok_to_give_up())
@@ -502,7 +502,7 @@ static void receive_needs(void)
502 if (!len)
503 break;
504
505 - if (!strncmp("shallow ", line, 8)) {
505 + if (!(-prefixcmp(line, "shallow "))) {
506 unsigned char sha1[20];
507 struct object *object;
508 use_thin_pack = 0;
@@ -515,7 +515,7 @@ static void receive_needs(void)
515 add_object_array(object, NULL, &shallows);
516 continue;
517 }
518 - if (!strncmp("deepen ", line, 7)) {
518 + if (!(-prefixcmp(line, "deepen "))) {
519 char *end;
520 use_thin_pack = 0;
521 depth = strtol(line + 7, &end, 0);
@@ -523,7 +523,7 @@ static void receive_needs(void)
523 die("Invalid deepen: %s", line);
524 continue;
525 }
526 - if (strncmp("want ", line, 5) ||
526 + if ((-prefixcmp(line, "want ")) ||
527 get_sha1_hex(line+5, sha1_buf))
528 die("git-upload-pack: protocol error, "
529 "expected to get sha, not '%s'", line);
@@ -656,7 +656,7 @@ int main(int argc, char **argv)
656 strict = 1;
657 continue;
658 }
659 - if (!strncmp(arg, "--timeout=", 10)) {
659 + if (!prefixcmp(arg, "--timeout=")) {
660 timeout = atoi(arg+10);
661 continue;
662 }
wt-status.c
+2 -2
@@ -298,7 +298,7 @@ void wt_status_print(struct wt_status *s)
298 if (s->branch) {
299 const char *on_what = "On branch ";
300 const char *branch_name = s->branch;
301 - if (!strncmp(branch_name, "refs/heads/", 11))
301 + if (!prefixcmp(branch_name, "refs/heads/"))
302 branch_name += 11;
303 else if (!strcmp(branch_name, "HEAD")) {
304 branch_name = "";
@@ -344,7 +344,7 @@ int git_status_config(const char *k, const char *v)
344 wt_status_use_color = git_config_colorbool(k, v);
345 return 0;
346 }
347 - if (!strncmp(k, "status.color.", 13) || !strncmp(k, "color.status.", 13)) {
347 + if (!prefixcmp(k, "status.color.") || !strncmp(k, "color.status.", 13)) {
348 int slot = parse_status_slot(k, 13);
349 color_parse(v, k, wt_status_colors[slot]);
350 }