replace {pre,suf}fixcmp() with {starts,ends}_with()
Leaving only the function definitions and declarations so that any new topic in flight can still make use of the old functions, replace existing uses of the prefixcmp() and suffixcmp() with new API functions. The change can be recreated by mechanically applying this: $ git grep -l -e prefixcmp -e suffixcmp -- \*.c | grep -v strbuf\\.c | xargs perl -pi -e ' s|!prefixcmp\(|starts_with\(|g; s|prefixcmp\(|!starts_with\(|g; s|!suffixcmp\(|ends_with\(|g; s|suffixcmp\(|!ends_with\(|g; ' on the result of preparatory changes in this series. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Nov 30, 2013 at 21:55 UTC
59556548230e617b837343c2c07e357e688e2ca4
88 files changed
+459
-459
alias.c
+1
-1
@@ -5,7 +5,7 @@ static char *alias_val;
5
6
static int alias_lookup_cb(const char *k, const char *v, void *cb)
7
{
8
- if (!prefixcmp(k, "alias.") && !strcmp(k + 6, alias_key)) {
8
+ if (starts_with(k, "alias.") && !strcmp(k + 6, alias_key)) {
9
if (!v)
10
return config_error_nonbool(k);
11
alias_val = xstrdup(v);
attr.c
+1
-1
@@ -211,7 +211,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
211
name = cp;
212
namelen = strcspn(name, blank);
213
if (strlen(ATTRIBUTE_MACRO_PREFIX) < namelen &&
214
- !prefixcmp(name, ATTRIBUTE_MACRO_PREFIX)) {
214
+ starts_with(name, ATTRIBUTE_MACRO_PREFIX)) {
215
if (!macro_ok) {
216
fprintf(stderr, "%s not allowed: %s:%d\n",
217
name, src, lineno);
bisect.c
+2
-2
@@ -406,9 +406,9 @@ static int register_ref(const char *refname, const unsigned char *sha1,
406
if (!strcmp(refname, "bad")) {
407
current_bad_sha1 = xmalloc(20);
408
hashcpy(current_bad_sha1, sha1);
409
- } else if (!prefixcmp(refname, "good-")) {
409
+ } else if (starts_with(refname, "good-")) {
410
sha1_array_append(&good_revs, sha1);
411
- } else if (!prefixcmp(refname, "skip-")) {
411
+ } else if (starts_with(refname, "skip-")) {
412
sha1_array_append(&skipped_revs, sha1);
413
}
414
branch.c
+2
-2
@@ -50,7 +50,7 @@ static int should_setup_rebase(const char *origin)
50
void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
51
{
52
const char *shortname = remote + 11;
53
- int remote_is_branch = !prefixcmp(remote, "refs/heads/");
53
+ int remote_is_branch = starts_with(remote, "refs/heads/");
54
struct strbuf key = STRBUF_INIT;
55
int rebasing = should_setup_rebase(origin);
56
@@ -272,7 +272,7 @@ void create_branch(const char *head,
272
break;
273
case 1:
274
/* Unique completion -- good, only if it is a real branch */
275
- if (prefixcmp(real_ref, "refs/heads/") &&
275
+ if (!starts_with(real_ref, "refs/heads/") &&
276
validate_remote_tracking_branch(real_ref)) {
277
if (explicit_tracking)
278
die(_(upstream_not_branch), start_name);
builtin/apply.c
+6
-6
@@ -1409,10 +1409,10 @@ static void recount_diff(const char *line, int size, struct fragment *fragment)
1409
case '\\':
1410
continue;
1411
case '@':
1412
- ret = size < 3 || prefixcmp(line, "@@ ");
1412
+ ret = size < 3 || !starts_with(line, "@@ ");
1413
break;
1414
case 'd':
1415
- ret = size < 5 || prefixcmp(line, "diff ");
1415
+ ret = size < 5 || !starts_with(line, "diff ");
1416
break;
1417
default:
1418
ret = -1;
@@ -1798,11 +1798,11 @@ static struct fragment *parse_binary_hunk(char **buf_p,
1798
1799
*status_p = 0;
1800
1801
- if (!prefixcmp(buffer, "delta ")) {
1801
+ if (starts_with(buffer, "delta ")) {
1802
patch_method = BINARY_DELTA_DEFLATED;
1803
origlen = strtoul(buffer + 6, NULL, 10);
1804
}
1805
- else if (!prefixcmp(buffer, "literal ")) {
1805
+ else if (starts_with(buffer, "literal ")) {
1806
patch_method = BINARY_LITERAL_DEFLATED;
1807
origlen = strtoul(buffer + 8, NULL, 10);
1808
}
@@ -3627,12 +3627,12 @@ static int preimage_sha1_in_gitlink_patch(struct patch *p, unsigned char sha1[20
3627
hunk->oldpos == 1 && hunk->oldlines == 1 &&
3628
/* does preimage begin with the heading? */
3629
(preimage = memchr(hunk->patch, '\n', hunk->size)) != NULL &&
3630
- !prefixcmp(++preimage, heading) &&
3630
+ starts_with(++preimage, heading) &&
3631
/* does it record full SHA-1? */
3632
!get_sha1_hex(preimage + sizeof(heading) - 1, sha1) &&
3633
preimage[sizeof(heading) + 40 - 1] == '\n' &&
3634
/* does the abbreviated name on the index line agree with it? */
3635
- !prefixcmp(preimage + sizeof(heading) - 1, p->old_sha1_prefix))
3635
+ starts_with(preimage + sizeof(heading) - 1, p->old_sha1_prefix))
3636
return 0; /* it all looks fine */
3637
3638
/* we may have full object name on the index line */
builtin/archive.c
+2
-2
@@ -57,9 +57,9 @@ static int run_remote_archiver(int argc, const char **argv,
57
if (!buf)
58
die(_("git archive: expected ACK/NAK, got EOF"));
59
if (strcmp(buf, "ACK")) {
60
- if (!prefixcmp(buf, "NACK "))
60
+ if (starts_with(buf, "NACK "))
61
die(_("git archive: NACK %s"), buf + 5);
62
- if (!prefixcmp(buf, "ERR "))
62
+ if (starts_with(buf, "ERR "))
63
die(_("remote error: %s"), buf + 4);
64
die(_("git archive: protocol error"));
65
}
builtin/branch.c
+3
-3
@@ -81,13 +81,13 @@ static int parse_branch_color_slot(const char *var, int ofs)
81
82
static int git_branch_config(const char *var, const char *value, void *cb)
83
{
84
- if (!prefixcmp(var, "column."))
84
+ if (starts_with(var, "column."))
85
return git_column_config(var, value, "branch", &colopts);
86
if (!strcmp(var, "color.branch")) {
87
branch_use_color = git_config_colorbool(var, value);
88
return 0;
89
}
90
- if (!prefixcmp(var, "color.branch.")) {
90
+ if (starts_with(var, "color.branch.")) {
91
int slot = parse_branch_color_slot(var, 13);
92
if (slot < 0)
93
return 0;
@@ -868,7 +868,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
868
if (!strcmp(head, "HEAD")) {
869
detached = 1;
870
} else {
871
- if (prefixcmp(head, "refs/heads/"))
871
+ if (!starts_with(head, "refs/heads/"))
872
die(_("HEAD not found below refs/heads!"));
873
head += 11;
874
}
builtin/checkout.c
+4
-4
@@ -781,7 +781,7 @@ static int switch_branches(const struct checkout_opts *opts,
781
if (!(flag & REF_ISSYMREF))
782
old.path = NULL;
783
784
- if (old.path && !prefixcmp(old.path, "refs/heads/"))
784
+ if (old.path && starts_with(old.path, "refs/heads/"))
785
old.name = old.path + strlen("refs/heads/");
786
787
if (!new->name) {
@@ -816,7 +816,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
816
return 0;
817
}
818
819
- if (!prefixcmp(var, "submodule."))
819
+ if (starts_with(var, "submodule."))
820
return parse_submodule_config_option(var, value);
821
822
return git_xmerge_config(var, value, NULL);
@@ -1151,9 +1151,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1151
const char *argv0 = argv[0];
1152
if (!argc || !strcmp(argv0, "--"))
1153
die (_("--track needs a branch name"));
1154
- if (!prefixcmp(argv0, "refs/"))
1154
+ if (starts_with(argv0, "refs/"))
1155
argv0 += 5;
1156
- if (!prefixcmp(argv0, "remotes/"))
1156
+ if (starts_with(argv0, "remotes/"))
1157
argv0 += 8;
1158
argv0 = strchr(argv0, '/');
1159
if (!argv0 || !argv0[1])
builtin/clean.c
+2
-2
@@ -100,7 +100,7 @@ static int parse_clean_color_slot(const char *var)
100
101
static int git_clean_config(const char *var, const char *value, void *cb)
102
{
103
- if (!prefixcmp(var, "column."))
103
+ if (starts_with(var, "column."))
104
return git_column_config(var, value, "clean", &colopts);
105
106
/* honors the color.interactive* config variables which also
@@ -109,7 +109,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
109
clean_use_color = git_config_colorbool(var, value);
110
return 0;
111
}
112
- if (!prefixcmp(var, "color.interactive.")) {
112
+ if (starts_with(var, "color.interactive.")) {
113
int slot = parse_clean_color_slot(var +
114
strlen("color.interactive."));
115
if (slot < 0)
builtin/clone.c
+4
-4
@@ -508,9 +508,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
508
{
509
const struct ref *ref;
510
for (ref = refs; ref; ref = ref->next) {
511
- if (prefixcmp(ref->name, "refs/tags/"))
511
+ if (!starts_with(ref->name, "refs/tags/"))
512
continue;
513
- if (!suffixcmp(ref->name, "^{}"))
513
+ if (ends_with(ref->name, "^{}"))
514
continue;
515
if (!has_sha1_file(ref->old_sha1))
516
continue;
@@ -578,7 +578,7 @@ static void update_remote_refs(const struct ref *refs,
578
static void update_head(const struct ref *our, const struct ref *remote,
579
const char *msg)
580
{
581
- if (our && !prefixcmp(our->name, "refs/heads/")) {
581
+ if (our && starts_with(our->name, "refs/heads/")) {
582
/* Local default branch link */
583
create_symref("HEAD", our->name, NULL);
584
if (!option_bare) {
@@ -625,7 +625,7 @@ static int checkout(void)
625
if (advice_detached_head)
626
detach_advice(sha1_to_hex(sha1));
627
} else {
628
- if (prefixcmp(head, "refs/heads/"))
628
+ if (!starts_with(head, "refs/heads/"))
629
die(_("HEAD not found below refs/heads!"));
630
}
631
free(head);
builtin/column.c
+1
-1
@@ -34,7 +34,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
34
};
35
36
/* This one is special and must be the first one */
37
- if (argc > 1 && !prefixcmp(argv[1], "--command=")) {
37
+ if (argc > 1 && starts_with(argv[1], "--command=")) {
38
command = argv[1] + 10;
39
git_config(column_config, (void *)command);
40
} else
builtin/commit.c
+5
-5
@@ -733,7 +733,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
733
eol = nl - sb.buf;
734
else
735
eol = sb.len;
736
- if (!prefixcmp(sb.buf + previous, "\nConflicts:\n")) {
736
+ if (starts_with(sb.buf + previous, "\nConflicts:\n")) {
737
ignore_footer = sb.len - previous;
738
break;
739
}
@@ -904,7 +904,7 @@ static int rest_is_empty(struct strbuf *sb, int start)
904
eol = sb->len;
905
906
if (strlen(sign_off_header) <= eol - i &&
907
- !prefixcmp(sb->buf + i, sign_off_header)) {
907
+ starts_with(sb->buf + i, sign_off_header)) {
908
i = eol;
909
continue;
910
}
@@ -1183,7 +1183,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
1183
{
1184
struct wt_status *s = cb;
1185
1186
- if (!prefixcmp(k, "column."))
1186
+ if (starts_with(k, "column."))
1187
return git_column_config(k, v, "status", &s->colopts);
1188
if (!strcmp(k, "status.submodulesummary")) {
1189
int is_bool;
@@ -1211,7 +1211,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
1211
s->display_comment_prefix = git_config_bool(k, v);
1212
return 0;
1213
}
1214
- if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
1214
+ if (starts_with(k, "status.color.") || starts_with(k, "color.status.")) {
1215
int slot = parse_status_slot(k, 13);
1216
if (slot < 0)
1217
return 0;
@@ -1377,7 +1377,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
1377
1378
head = resolve_ref_unsafe("HEAD", junk_sha1, 0, NULL);
1379
printf("[%s%s ",
1380
- !prefixcmp(head, "refs/heads/") ?
1380
+ starts_with(head, "refs/heads/") ?
1381
head + 11 :
1382
!strcmp(head, "HEAD") ?
1383
_("detached HEAD") :
builtin/describe.c
+1
-1
@@ -141,7 +141,7 @@ static void add_to_known_names(const char *path,
141
142
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
143
{
144
- int is_tag = !prefixcmp(path, "refs/tags/");
144
+ int is_tag = starts_with(path, "refs/tags/");
145
unsigned char peeled[20];
146
int is_annotated, prio;
147
builtin/fast-export.c
+1
-1
@@ -476,7 +476,7 @@ static void handle_tag(const char *name, struct tag *tag)
476
}
477
}
478
479
- if (!prefixcmp(name, "refs/tags/"))
479
+ if (starts_with(name, "refs/tags/"))
480
name += 10;
481
printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n",
482
name, tagged_mark,
builtin/fetch-pack.c
+3
-3
@@ -48,11 +48,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
48
for (i = 1; i < argc && *argv[i] == '-'; i++) {
49
const char *arg = argv[i];
50
51
- if (!prefixcmp(arg, "--upload-pack=")) {
51
+ if (starts_with(arg, "--upload-pack=")) {
52
args.uploadpack = arg + 14;
53
continue;
54
}
55
- if (!prefixcmp(arg, "--exec=")) {
55
+ if (starts_with(arg, "--exec=")) {
56
args.uploadpack = arg + 7;
57
continue;
58
}
@@ -85,7 +85,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
85
args.verbose = 1;
86
continue;
87
}
88
- if (!prefixcmp(arg, "--depth=")) {
88
+ if (starts_with(arg, "--depth=")) {
89
args.depth = strtol(arg + 8, NULL, 0);
90
continue;
91
}
builtin/fetch.c
+9
-9
@@ -313,7 +313,7 @@ static int update_local_ref(struct ref *ref,
313
}
314
315
if (!is_null_sha1(ref->old_sha1) &&
316
- !prefixcmp(ref->name, "refs/tags/")) {
316
+ starts_with(ref->name, "refs/tags/")) {
317
int r;
318
r = s_update_ref("updating tag", ref, 0);
319
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
@@ -336,10 +336,10 @@ static int update_local_ref(struct ref *ref,
336
* more likely to follow a standard layout.
337
*/
338
const char *name = remote_ref ? remote_ref->name : "";
339
- if (!prefixcmp(name, "refs/tags/")) {
339
+ if (starts_with(name, "refs/tags/")) {
340
msg = "storing tag";
341
what = _("[new tag]");
342
- } else if (!prefixcmp(name, "refs/heads/")) {
342
+ } else if (starts_with(name, "refs/heads/")) {
343
msg = "storing head";
344
what = _("[new branch]");
345
} else {
@@ -471,15 +471,15 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
471
kind = "";
472
what = "";
473
}
474
- else if (!prefixcmp(rm->name, "refs/heads/")) {
474
+ else if (starts_with(rm->name, "refs/heads/")) {
475
kind = "branch";
476
what = rm->name + 11;
477
}
478
- else if (!prefixcmp(rm->name, "refs/tags/")) {
478
+ else if (starts_with(rm->name, "refs/tags/")) {
479
kind = "tag";
480
what = rm->name + 10;
481
}
482
- else if (!prefixcmp(rm->name, "refs/remotes/")) {
482
+ else if (starts_with(rm->name, "refs/remotes/")) {
483
kind = "remote-tracking branch";
484
what = rm->name + 13;
485
}
@@ -644,7 +644,7 @@ static void find_non_local_tags(struct transport *transport,
644
645
for_each_ref(add_existing, &existing_refs);
646
for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
647
- if (prefixcmp(ref->name, "refs/tags/"))
647
+ if (!starts_with(ref->name, "refs/tags/"))
648
continue;
649
650
/*
@@ -653,7 +653,7 @@ static void find_non_local_tags(struct transport *transport,
653
* to fetch then we can mark the ref entry in the list
654
* as one to ignore by setting util to NULL.
655
*/
656
- if (!suffixcmp(ref->name, "^{}")) {
656
+ if (ends_with(ref->name, "^{}")) {
657
if (item && !has_sha1_file(ref->old_sha1) &&
658
!will_fetch(head, ref->old_sha1) &&
659
!has_sha1_file(item->util) &&
@@ -892,7 +892,7 @@ static int get_remote_group(const char *key, const char *value, void *priv)
892
{
893
struct remote_group_data *g = priv;
894
895
- if (!prefixcmp(key, "remotes.") &&
895
+ if (starts_with(key, "remotes.") &&
896
!strcmp(key + 8, g->name)) {
897
/* split list by white space */
898
int space = strcspn(value, " \t\n");
builtin/fmt-merge-msg.c
+5
-5
@@ -109,7 +109,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
109
if (len < 43 || line[40] != '\t')
110
return 1;
111
112
- if (!prefixcmp(line + 41, "not-for-merge"))
112
+ if (starts_with(line + 41, "not-for-merge"))
113
return 0;
114
115
if (line[41] != '\t')
@@ -155,16 +155,16 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
155
if (pulling_head) {
156
origin = src;
157
src_data->head_status |= 1;
158
- } else if (!prefixcmp(line, "branch ")) {
158
+ } else if (starts_with(line, "branch ")) {
159
origin_data->is_local_branch = 1;
160
origin = line + 7;
161
string_list_append(&src_data->branch, origin);
162
src_data->head_status |= 2;
163
- } else if (!prefixcmp(line, "tag ")) {
163
+ } else if (starts_with(line, "tag ")) {
164
origin = line;
165
string_list_append(&src_data->tag, origin + 4);
166
src_data->head_status |= 2;
167
- } else if (!prefixcmp(line, "remote-tracking branch ")) {
167
+ } else if (starts_with(line, "remote-tracking branch ")) {
168
origin = line + strlen("remote-tracking branch ");
169
string_list_append(&src_data->r_branch, origin);
170
src_data->head_status |= 2;
@@ -605,7 +605,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
605
resolve_refdup("HEAD", head_sha1, 1, NULL);
606
if (!current_branch)
607
die("No current branch");
608
- if (!prefixcmp(current_branch, "refs/heads/"))
608
+ if (starts_with(current_branch, "refs/heads/"))
609
current_branch += 11;
610
611
find_merge_parents(&merge_parents, in, head_sha1);
builtin/for-each-ref.c
+7
-7
@@ -441,7 +441,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
441
if (name[wholen] != 0 &&
442
strcmp(name + wholen, "name") &&
443
strcmp(name + wholen, "email") &&
444
- prefixcmp(name + wholen, "date"))
444
+ !starts_with(name + wholen, "date"))
445
continue;
446
if (!wholine)
447
wholine = find_wholine(who, wholen, buf, sz);
@@ -453,7 +453,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
453
v->s = copy_name(wholine);
454
else if (!strcmp(name + wholen, "email"))
455
v->s = copy_email(wholine);
456
- else if (!prefixcmp(name + wholen, "date"))
456
+ else if (starts_with(name + wholen, "date"))
457
grab_date(wholine, v, name);
458
}
459
@@ -475,7 +475,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
475
if (deref)
476
name++;
477
478
- if (!prefixcmp(name, "creatordate"))
478
+ if (starts_with(name, "creatordate"))
479
grab_date(wholine, v, name);
480
else if (!strcmp(name, "creator"))
481
v->s = copy_line(wholine);
@@ -655,14 +655,14 @@ static void populate_value(struct refinfo *ref)
655
name++;
656
}
657
658
- if (!prefixcmp(name, "refname"))
658
+ if (starts_with(name, "refname"))
659
refname = ref->refname;
660
- else if (!prefixcmp(name, "symref"))
660
+ else if (starts_with(name, "symref"))
661
refname = ref->symref ? ref->symref : "";
662
- else if (!prefixcmp(name, "upstream")) {
662
+ else if (starts_with(name, "upstream")) {
663
struct branch *branch;
664
/* only local branches may have an upstream */
665
- if (prefixcmp(ref->refname, "refs/heads/"))
665
+ if (!starts_with(ref->refname, "refs/heads/"))
666
continue;
667
branch = branch_get(ref->refname + 11);
668
builtin/fsck.c
+3
-3
@@ -442,7 +442,7 @@ static void fsck_dir(int i, char *path)
442
add_sha1_list(sha1, DIRENT_SORT_HINT(de));
443
continue;
444
}
445
- if (!prefixcmp(de->d_name, "tmp_obj_"))
445
+ if (starts_with(de->d_name, "tmp_obj_"))
446
continue;
447
fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
448
}
@@ -484,7 +484,7 @@ static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, in
484
485
static int is_branch(const char *refname)
486
{
487
- return !strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/");
487
+ return !strcmp(refname, "HEAD") || starts_with(refname, "refs/heads/");
488
}
489
490
static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
@@ -566,7 +566,7 @@ static int fsck_head_link(void)
566
if (!strcmp(head_points_at, "HEAD"))
567
/* detached HEAD */
568
null_is_error = 1;
569
- else if (prefixcmp(head_points_at, "refs/heads/"))
569
+ else if (!starts_with(head_points_at, "refs/heads/"))
570
return error("HEAD points to something strange (%s)",
571
head_points_at);
572
if (is_null_sha1(head_sha1)) {
builtin/help.c
+4
-4
@@ -100,7 +100,7 @@ static int check_emacsclient_version(void)
100
*/
101
finish_command(&ec_process);
102
103
- if (prefixcmp(buffer.buf, "emacsclient")) {
103
+ if (!starts_with(buffer.buf, "emacsclient")) {
104
strbuf_release(&buffer);
105
return error(_("Failed to parse emacsclient version."));
106
}
@@ -258,7 +258,7 @@ static int add_man_viewer_info(const char *var, const char *value)
258
259
static int git_help_config(const char *var, const char *value, void *cb)
260
{
261
- if (!prefixcmp(var, "column."))
261
+ if (starts_with(var, "column."))
262
return git_column_config(var, value, "help", &colopts);
263
if (!strcmp(var, "help.format")) {
264
if (!value)
@@ -278,7 +278,7 @@ static int git_help_config(const char *var, const char *value, void *cb)
278
add_man_viewer(value);
279
return 0;
280
}
281
- if (!prefixcmp(var, "man."))
281
+ if (starts_with(var, "man."))
282
return add_man_viewer_info(var, value);
283
284
return git_default_config(var, value, cb);
@@ -306,7 +306,7 @@ static const char *cmd_to_page(const char *git_cmd)
306
{
307
if (!git_cmd)
308
return "git";
309
- else if (!prefixcmp(git_cmd, "git"))
309
+ else if (starts_with(git_cmd, "git"))
310
return git_cmd;
311
else if (is_git_command(git_cmd))
312
return prepend("git-", git_cmd);
builtin/index-pack.c
+4
-4
@@ -1534,9 +1534,9 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1534
stat_only = 1;
1535
} else if (!strcmp(arg, "--keep")) {
1536
keep_msg = "";
1537
- } else if (!prefixcmp(arg, "--keep=")) {
1537
+ } else if (starts_with(arg, "--keep=")) {
1538
keep_msg = arg + 7;
1539
- } else if (!prefixcmp(arg, "--threads=")) {
1539
+ } else if (starts_with(arg, "--threads=")) {
1540
char *end;
1541
nr_threads = strtoul(arg+10, &end, 0);
1542
if (!arg[10] || *end || nr_threads < 0)
@@ -1547,7 +1547,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1547
"ignoring %s"), arg);
1548
nr_threads = 1;
1549
#endif
1550
- } else if (!prefixcmp(arg, "--pack_header=")) {
1550
+ } else if (starts_with(arg, "--pack_header=")) {
1551
struct pack_header *hdr;
1552
char *c;
1553
@@ -1566,7 +1566,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1566
if (index_name || (i+1) >= argc)
1567
usage(index_pack_usage);
1568
index_name = argv[++i];
1569
- } else if (!prefixcmp(arg, "--index-version=")) {
1569
+ } else if (starts_with(arg, "--index-version=")) {
1570
char *c;
1571
opts.version = strtoul(arg + 16, &c, 10);
1572
if (opts.version > 2)
builtin/init-db.c
+1
-1
@@ -266,7 +266,7 @@ static int create_default_files(const char *template_path)
266
/* allow template config file to override the default */
267
if (log_all_ref_updates == -1)
268
git_config_set("core.logallrefupdates", "true");
269
- if (prefixcmp(git_dir, work_tree) ||
269
+ if (!starts_with(git_dir, work_tree) ||
270
strcmp(git_dir + strlen(work_tree), "/.git")) {
271
git_config_set("core.worktree", work_tree);
272
}
builtin/log.c
+4
-4
@@ -391,7 +391,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
391
default_show_root = git_config_bool(var, value);
392
return 0;
393
}
394
- if (!prefixcmp(var, "color.decorate."))
394
+ if (starts_with(var, "color.decorate."))
395
return parse_decorate_color_config(var, 15, value);
396
if (!strcmp(var, "log.mailmap")) {
397
use_mailmap_config = git_config_bool(var, value);
@@ -477,7 +477,7 @@ static int show_tag_object(const unsigned char *sha1, struct rev_info *rev)
477
int new_offset = offset + 1;
478
while (new_offset < size && buf[new_offset++] != '\n')
479
; /* do nothing */
480
- if (!prefixcmp(buf + offset, "tagger "))
480
+ if (starts_with(buf + offset, "tagger "))
481
show_tagger(buf + offset + 7,
482
new_offset - offset - 7, rev);
483
offset = new_offset;
@@ -882,7 +882,7 @@ static char *find_branch_name(struct rev_info *rev)
882
ref = rev->cmdline.rev[positive].name;
883
tip_sha1 = rev->cmdline.rev[positive].item->sha1;
884
if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
885
- !prefixcmp(full_ref, "refs/heads/") &&
885
+ starts_with(full_ref, "refs/heads/") &&
886
!hashcmp(tip_sha1, branch_sha1))
887
branch = xstrdup(full_ref + strlen("refs/heads/"));
888
free(full_ref);
@@ -1388,7 +1388,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1388
unsigned char sha1[20];
1389
const char *ref;
1390
ref = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
1391
- if (ref && !prefixcmp(ref, "refs/heads/"))
1391
+ if (ref && starts_with(ref, "refs/heads/"))
1392
branch_name = xstrdup(ref + strlen("refs/heads/"));
1393
else
1394
branch_name = xstrdup(""); /* no branch */
builtin/ls-remote.c
+2
-2
@@ -50,11 +50,11 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
50
const char *arg = argv[i];
51
52
if (*arg == '-') {
53
- if (!prefixcmp(arg, "--upload-pack=")) {
53
+ if (starts_with(arg, "--upload-pack=")) {
54
uploadpack = arg + 14;
55
continue;
56
}
57
- if (!prefixcmp(arg, "--exec=")) {
57
+ if (starts_with(arg, "--exec=")) {
58
uploadpack = arg + 7;
59
continue;
60
}
builtin/mailinfo.c
+8
-8
@@ -328,11 +328,11 @@ static int check_header(const struct strbuf *line,
328
}
329
330
/* for inbody stuff */
331
- if (!prefixcmp(line->buf, ">From") && isspace(line->buf[5])) {
331
+ if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
332
ret = 1; /* Should this return 0? */
333
goto check_header_out;
334
}
335
- if (!prefixcmp(line->buf, "[PATCH]") && isspace(line->buf[7])) {
335
+ if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
336
for (i = 0; header[i]; i++) {
337
if (!memcmp("Subject", header[i], 7)) {
338
handle_header(&hdr_data[i], line);
@@ -361,7 +361,7 @@ static int is_rfc2822_header(const struct strbuf *line)
361
char *cp = line->buf;
362
363
/* Count mbox From headers as headers */
364
- if (!prefixcmp(cp, "From ") || !prefixcmp(cp, ">From "))
364
+ if (starts_with(cp, "From ") || starts_with(cp, ">From "))
365
return 1;
366
367
while ((ch = *cp++)) {
@@ -671,11 +671,11 @@ static inline int patchbreak(const struct strbuf *line)
671
size_t i;
672
673
/* Beginning of a "diff -" header? */
674
- if (!prefixcmp(line->buf, "diff -"))
674
+ if (starts_with(line->buf, "diff -"))
675
return 1;
676
677
/* CVS "Index: " line? */
678
- if (!prefixcmp(line->buf, "Index: "))
678
+ if (starts_with(line->buf, "Index: "))
679
return 1;
680
681
/*
@@ -685,7 +685,7 @@ static inline int patchbreak(const struct strbuf *line)
685
if (line->len < 4)
686
return 0;
687
688
- if (!prefixcmp(line->buf, "---")) {
688
+ if (starts_with(line->buf, "---")) {
689
/* space followed by a filename? */
690
if (line->buf[3] == ' ' && !isspace(line->buf[4]))
691
return 1;
@@ -986,7 +986,7 @@ static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch)
986
987
static int git_mailinfo_config(const char *var, const char *value, void *unused)
988
{
989
- if (prefixcmp(var, "mailinfo."))
989
+ if (!starts_with(var, "mailinfo."))
990
return git_default_config(var, value, unused);
991
if (!strcmp(var, "mailinfo.scissors")) {
992
use_scissors = git_config_bool(var, value);
@@ -1020,7 +1020,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1020
metainfo_charset = def_charset;
1021
else if (!strcmp(argv[1], "-n"))
1022
metainfo_charset = NULL;
1023
- else if (!prefixcmp(argv[1], "--encoding="))
1023
+ else if (starts_with(argv[1], "--encoding="))
1024
metainfo_charset = argv[1] + 11;
1025
else if (!strcmp(argv[1], "--scissors"))
1026
use_scissors = 1;
builtin/merge-recursive.c
+2
-2
@@ -29,7 +29,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
29
struct commit *result;
30
31
init_merge_options(&o);
32
- if (argv[0] && !suffixcmp(argv[0], "-subtree"))
32
+ if (argv[0] && ends_with(argv[0], "-subtree"))
33
o.subtree_shift = "";
34
35
if (argc < 4)
@@ -38,7 +38,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
38
for (i = 1; i < argc; ++i) {
39
const char *arg = argv[i];
40
41
- if (!prefixcmp(arg, "--")) {
41
+ if (starts_with(arg, "--")) {
42
if (!arg[2])
43
break;
44
if (parse_merge_opt(&o, arg + 2))
builtin/merge.c
+6
-6
@@ -446,17 +446,17 @@ static void merge_name(const char *remote, struct strbuf *msg)
446
die(_("'%s' does not point to a commit"), remote);
447
448
if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {
449
- if (!prefixcmp(found_ref, "refs/heads/")) {
449
+ if (starts_with(found_ref, "refs/heads/")) {
450
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
451
sha1_to_hex(branch_head), remote);
452
goto cleanup;
453
}
454
- if (!prefixcmp(found_ref, "refs/tags/")) {
454
+ if (starts_with(found_ref, "refs/tags/")) {
455
strbuf_addf(msg, "%s\t\ttag '%s' of .\n",
456
sha1_to_hex(branch_head), remote);
457
goto cleanup;
458
}
459
- if (!prefixcmp(found_ref, "refs/remotes/")) {
459
+ if (starts_with(found_ref, "refs/remotes/")) {
460
strbuf_addf(msg, "%s\t\tremote-tracking branch '%s' of .\n",
461
sha1_to_hex(branch_head), remote);
462
goto cleanup;
@@ -570,8 +570,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
570
{
571
int status;
572
573
- if (branch && !prefixcmp(k, "branch.") &&
574
- !prefixcmp(k + 7, branch) &&
573
+ if (branch && starts_with(k, "branch.") &&
574
+ starts_with(k + 7, branch) &&
575
!strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
576
free(branch_mergeoptions);
577
branch_mergeoptions = xstrdup(v);
@@ -1106,7 +1106,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1106
* current branch.
1107
*/
1108
branch = branch_to_free = resolve_refdup("HEAD", head_sha1, 0, &flag);
1109
- if (branch && !prefixcmp(branch, "refs/heads/"))
1109
+ if (branch && starts_with(branch, "refs/heads/"))
1110
branch += 11;
1111
if (!branch || is_null_sha1(head_sha1))
1112
head_commit = NULL;
builtin/name-rev.c
+3
-3
@@ -101,9 +101,9 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
101
{
102
if (shorten_unambiguous)
103
refname = shorten_unambiguous_ref(refname, 0);
104
- else if (!prefixcmp(refname, "refs/heads/"))
104
+ else if (starts_with(refname, "refs/heads/"))
105
refname = refname + 11;
106
- else if (!prefixcmp(refname, "refs/"))
106
+ else if (starts_with(refname, "refs/"))
107
refname = refname + 5;
108
return refname;
109
}
@@ -149,7 +149,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
149
int can_abbreviate_output = data->tags_only && data->name_only;
150
int deref = 0;
151
152
- if (data->tags_only && prefixcmp(path, "refs/tags/"))
152
+ if (data->tags_only && !starts_with(path, "refs/tags/"))
153
return 0;
154
155
if (data->ref_filter) {
builtin/notes.c
+1
-1
@@ -347,7 +347,7 @@ static struct notes_tree *init_notes_check(const char *subcommand)
347
init_notes(NULL, NULL, NULL, 0);
348
t = &default_notes_tree;
349
350
- if (prefixcmp(t->ref, "refs/notes/"))
350
+ if (!starts_with(t->ref, "refs/notes/"))
351
die("Refusing to %s notes in %s (outside of refs/notes/)",
352
subcommand, t->ref);
353
return t;
builtin/pack-objects.c
+1
-1
@@ -2032,7 +2032,7 @@ static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, vo
2032
{
2033
unsigned char peeled[20];
2034
2035
- if (!prefixcmp(path, "refs/tags/") && /* is a tag? */
2035
+ if (starts_with(path, "refs/tags/") && /* is a tag? */
2036
!peel_ref(path, peeled) && /* peelable? */
2037
locate_object_entry(peeled)) /* object packed? */
2038
add_object_entry(sha1, OBJ_TAG, NULL, 0);
builtin/prune.c
+2
-2
@@ -80,7 +80,7 @@ static int prune_dir(int i, char *path)
80
prune_object(path, de->d_name, sha1);
81
continue;
82
}
83
- if (!prefixcmp(de->d_name, "tmp_obj_")) {
83
+ if (starts_with(de->d_name, "tmp_obj_")) {
84
prune_tmp_object(path, de->d_name);
85
continue;
86
}
@@ -119,7 +119,7 @@ static void remove_temporary_files(const char *path)
119
return;
120
}
121
while ((de = readdir(dir)) != NULL)
122
- if (!prefixcmp(de->d_name, "tmp_"))
122
+ if (starts_with(de->d_name, "tmp_"))
123
prune_tmp_object(path, de->d_name);
124
closedir(dir);
125
}
builtin/receive-pack.c
+3
-3
@@ -428,7 +428,7 @@ static const char *update(struct command *cmd)
428
struct ref_lock *lock;
429
430
/* only refs/... are allowed */
431
- if (prefixcmp(name, "refs/") || check_refname_format(name + 5, 0)) {
431
+ if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) {
432
rp_error("refusing to create funny ref '%s' remotely", name);
433
return "funny refname";
434
}
@@ -459,7 +459,7 @@ static const char *update(struct command *cmd)
459
}
460
461
if (!is_null_sha1(old_sha1) && is_null_sha1(new_sha1)) {
462
- if (deny_deletes && !prefixcmp(name, "refs/heads/")) {
462
+ if (deny_deletes && starts_with(name, "refs/heads/")) {
463
rp_error("denying ref deletion for %s", name);
464
return "deletion prohibited";
465
}
@@ -483,7 +483,7 @@ static const char *update(struct command *cmd)
483
484
if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
485
!is_null_sha1(old_sha1) &&
486
- !prefixcmp(name, "refs/heads/")) {
486
+ starts_with(name, "refs/heads/")) {
487
struct object *old_object, *new_object;
488
struct commit *old_commit, *new_commit;
489
builtin/reflog.c
+2
-2
@@ -610,12 +610,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
610
const char *arg = argv[i];
611
if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
612
cb.dry_run = 1;
613
- else if (!prefixcmp(arg, "--expire=")) {
613
+ else if (starts_with(arg, "--expire=")) {
614
if (parse_expiry_date(arg + 9, &cb.expire_total))
615
die(_("'%s' is not a valid timestamp"), arg);
616
explicit_expiry |= EXPIRE_TOTAL;
617
}
618
- else if (!prefixcmp(arg, "--expire-unreachable=")) {
618
+ else if (starts_with(arg, "--expire-unreachable=")) {
619
if (parse_expiry_date(arg + 21, &cb.expire_unreachable))
620
die(_("'%s' is not a valid timestamp"), arg);
621
explicit_expiry |= EXPIRE_UNREACH;
builtin/remote.c
+7
-7
@@ -261,7 +261,7 @@ static const char *abbrev_ref(const char *name, const char *prefix)
261
262
static int config_read_branches(const char *key, const char *value, void *cb)
263
{
264
- if (!prefixcmp(key, "branch.")) {
264
+ if (starts_with(key, "branch.")) {
265
const char *orig_key = key;
266
char *name;
267
struct string_list_item *item;
@@ -269,13 +269,13 @@ static int config_read_branches(const char *key, const char *value, void *cb)
269
enum { REMOTE, MERGE, REBASE } type;
270
271
key += 7;
272
- if (!suffixcmp(key, ".remote")) {
272
+ if (ends_with(key, ".remote")) {
273
name = xstrndup(key, strlen(key) - 7);
274
type = REMOTE;
275
- } else if (!suffixcmp(key, ".merge")) {
275
+ } else if (ends_with(key, ".merge")) {
276
name = xstrndup(key, strlen(key) - 6);
277
type = MERGE;
278
- } else if (!suffixcmp(key, ".rebase")) {
278
+ } else if (ends_with(key, ".rebase")) {
279
name = xstrndup(key, strlen(key) - 7);
280
type = REBASE;
281
} else
@@ -526,9 +526,9 @@ static int add_branch_for_removal(const char *refname,
526
}
527
528
/* don't delete non-remote-tracking refs */
529
- if (prefixcmp(refname, "refs/remotes/")) {
529
+ if (!starts_with(refname, "refs/remotes/")) {
530
/* advise user how to delete local branches */
531
- if (!prefixcmp(refname, "refs/heads/"))
531
+ if (starts_with(refname, "refs/heads/"))
532
string_list_append(branches->skipped,
533
abbrev_branch(refname));
534
/* silently skip over other non-remote refs */
@@ -563,7 +563,7 @@ static int read_remote_branches(const char *refname,
563
const char *symref;
564
565
strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
566
- if (!prefixcmp(refname, buf.buf)) {
566
+ if (starts_with(refname, buf.buf)) {
567
item = string_list_append(rename->remote_branches, xstrdup(refname));
568
symref = resolve_ref_unsafe(refname, orig_sha1, 1, &flag);
569
if (flag & REF_ISSYMREF)
builtin/repack.c
+1
-1
@@ -78,7 +78,7 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list)
78
return;
79
80
while ((e = readdir(dir)) != NULL) {
81
- if (suffixcmp(e->d_name, ".pack"))
81
+ if (!ends_with(e->d_name, ".pack"))
82
continue;
83
84
len = strlen(e->d_name) - strlen(".pack");
builtin/rev-parse.c
+12
-12
@@ -508,7 +508,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
508
}
509
continue;
510
}
511
- if (!prefixcmp(arg, "-n")) {
511
+ if (starts_with(arg, "-n")) {
512
if ((filter & DO_FLAGS) && (filter & DO_REVS))
513
show(arg);
514
continue;
@@ -560,7 +560,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
560
continue;
561
}
562
if (!strcmp(arg, "--short") ||
563
- !prefixcmp(arg, "--short=")) {
563
+ starts_with(arg, "--short=")) {
564
filter &= ~(DO_FLAGS|DO_NOREV);
565
verify = 1;
566
abbrev = DEFAULT_ABBREV;
@@ -588,7 +588,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
588
symbolic = SHOW_SYMBOLIC_FULL;
589
continue;
590
}
591
- if (!prefixcmp(arg, "--abbrev-ref") &&
591
+ if (starts_with(arg, "--abbrev-ref") &&
592
(!arg[12] || arg[12] == '=')) {
593
abbrev_ref = 1;
594
abbrev_ref_strict = warn_ambiguous_refs;
@@ -606,7 +606,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
606
for_each_ref(show_reference, NULL);
607
continue;
608
}
609
- if (!prefixcmp(arg, "--disambiguate=")) {
609
+ if (starts_with(arg, "--disambiguate=")) {
610
for_each_abbrev(arg + 15, show_abbrev, NULL);
611
continue;
612
}
@@ -615,7 +615,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
615
for_each_ref_in("refs/bisect/good", anti_reference, NULL);
616
continue;
617
}
618
- if (!prefixcmp(arg, "--branches=")) {
618
+ if (starts_with(arg, "--branches=")) {
619
for_each_glob_ref_in(show_reference, arg + 11,
620
"refs/heads/", NULL);
621
continue;
@@ -624,7 +624,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
624
for_each_branch_ref(show_reference, NULL);
625
continue;
626
}
627
- if (!prefixcmp(arg, "--tags=")) {
627
+ if (starts_with(arg, "--tags=")) {
628
for_each_glob_ref_in(show_reference, arg + 7,
629
"refs/tags/", NULL);
630
continue;
@@ -633,11 +633,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
633
for_each_tag_ref(show_reference, NULL);
634
continue;
635
}
636
- if (!prefixcmp(arg, "--glob=")) {
636
+ if (starts_with(arg, "--glob=")) {
637
for_each_glob_ref(show_reference, arg + 7, NULL);
638
continue;
639
}
640
- if (!prefixcmp(arg, "--remotes=")) {
640
+ if (starts_with(arg, "--remotes=")) {
641
for_each_glob_ref_in(show_reference, arg + 10,
642
"refs/remotes/", NULL);
643
continue;
@@ -724,19 +724,19 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
724
: "false");
725
continue;
726
}
727
- if (!prefixcmp(arg, "--since=")) {
727
+ if (starts_with(arg, "--since=")) {
728
show_datestring("--max-age=", arg+8);
729
continue;
730
}
731
- if (!prefixcmp(arg, "--after=")) {
731
+ if (starts_with(arg, "--after=")) {
732
show_datestring("--max-age=", arg+8);
733
continue;
734
}
735
- if (!prefixcmp(arg, "--before=")) {
735
+ if (starts_with(arg, "--before=")) {
736
show_datestring("--min-age=", arg+9);
737
continue;
738
}
739
- if (!prefixcmp(arg, "--until=")) {
739
+ if (starts_with(arg, "--until=")) {
740
show_datestring("--min-age=", arg+8);
741
continue;
742
}
builtin/send-pack.c
+4
-4
@@ -115,15 +115,15 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
115
const char *arg = *argv;
116
117
if (*arg == '-') {
118
- if (!prefixcmp(arg, "--receive-pack=")) {
118
+ if (starts_with(arg, "--receive-pack=")) {
119
receivepack = arg + 15;
120
continue;
121
}
122
- if (!prefixcmp(arg, "--exec=")) {
122
+ if (starts_with(arg, "--exec=")) {
123
receivepack = arg + 7;
124
continue;
125
}
126
- if (!prefixcmp(arg, "--remote=")) {
126
+ if (starts_with(arg, "--remote=")) {
127
remote_name = arg + 9;
128
continue;
129
}
@@ -181,7 +181,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
181
exit(1);
182
continue;
183
}
184
- if (!prefixcmp(arg, "--" CAS_OPT_NAME "=")) {
184
+ if (starts_with(arg, "--" CAS_OPT_NAME "=")) {
185
if (parse_push_cas_option(&cas,
186
strchr(arg, '=') + 1, 0) < 0)
187
exit(1);
builtin/shortlog.c
+3
-3
@@ -65,7 +65,7 @@ static void insert_one_record(struct shortlog *log,
65
eol = strchr(oneline, '\n');
66
if (!eol)
67
eol = oneline + strlen(oneline);
68
- if (!prefixcmp(oneline, "[PATCH")) {
68
+ if (starts_with(oneline, "[PATCH")) {
69
char *eob = strchr(oneline, ']');
70
if (eob && (!eol || eob < eol))
71
oneline = eob + 1;
@@ -95,7 +95,7 @@ static void read_from_stdin(struct shortlog *log)
95
96
while (fgets(author, sizeof(author), stdin) != NULL) {
97
if (!(author[0] == 'A' || author[0] == 'a') ||
98
- prefixcmp(author + 1, "uthor: "))
98
+ !starts_with(author + 1, "uthor: "))
99
continue;
100
while (fgets(oneline, sizeof(oneline), stdin) &&
101
oneline[0] != '\n')
@@ -123,7 +123,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
123
else
124
eol++;
125
126
- if (!prefixcmp(buffer, "author "))
126
+ if (starts_with(buffer, "author "))
127
author = buffer + 7;
128
buffer = eol;
129
}
builtin/show-branch.c
+10
-10
@@ -285,7 +285,7 @@ static void show_one_commit(struct commit *commit, int no_name)
285
pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty);
286
pretty_str = pretty.buf;
287
}
288
- if (!prefixcmp(pretty_str, "[PATCH] "))
288
+ if (starts_with(pretty_str, "[PATCH] "))
289
pretty_str += 8;
290
291
if (!no_name) {
@@ -396,7 +396,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f
396
{
397
unsigned char tmp[20];
398
int ofs = 11;
399
- if (prefixcmp(refname, "refs/heads/"))
399
+ if (!starts_with(refname, "refs/heads/"))
400
return 0;
401
/* If both heads/foo and tags/foo exists, get_sha1 would
402
* get confused.
@@ -410,7 +410,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int
410
{
411
unsigned char tmp[20];
412
int ofs = 13;
413
- if (prefixcmp(refname, "refs/remotes/"))
413
+ if (!starts_with(refname, "refs/remotes/"))
414
return 0;
415
/* If both heads/foo and tags/foo exists, get_sha1 would
416
* get confused.
@@ -422,7 +422,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int
422
423
static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
424
{
425
- if (prefixcmp(refname, "refs/tags/"))
425
+ if (!starts_with(refname, "refs/tags/"))
426
return 0;
427
return append_ref(refname + 5, sha1, 0);
428
}
@@ -453,9 +453,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i
453
return 0;
454
if (fnmatch(match_ref_pattern, tail, 0))
455
return 0;
456
- if (!prefixcmp(refname, "refs/heads/"))
456
+ if (starts_with(refname, "refs/heads/"))
457
return append_head_ref(refname, sha1, flag, cb_data);
458
- if (!prefixcmp(refname, "refs/tags/"))
458
+ if (starts_with(refname, "refs/tags/"))
459
return append_tag_ref(refname, sha1, flag, cb_data);
460
return append_ref(refname, sha1, 0);
461
}
@@ -480,11 +480,11 @@ static int rev_is_head(char *head, int headlen, char *name,
480
if ((!head[0]) ||
481
(head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
482
return 0;
483
- if (!prefixcmp(head, "refs/heads/"))
483
+ if (starts_with(head, "refs/heads/"))
484
head += 11;
485
- if (!prefixcmp(name, "refs/heads/"))
485
+ if (starts_with(name, "refs/heads/"))
486
name += 11;
487
- else if (!prefixcmp(name, "heads/"))
487
+ else if (starts_with(name, "heads/"))
488
name += 6;
489
return !strcmp(head, name);
490
}
@@ -813,7 +813,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
813
has_head++;
814
}
815
if (!has_head) {
816
- int offset = !prefixcmp(head, "refs/heads/") ? 11 : 0;
816
+ int offset = starts_with(head, "refs/heads/") ? 11 : 0;
817
append_one_rev(head + offset);
818
}
819
}
builtin/show-ref.c
+3
-3
@@ -37,8 +37,8 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo
37
if (tags_only || heads_only) {
38
int match;
39
40
- match = heads_only && !prefixcmp(refname, "refs/heads/");
41
- match |= tags_only && !prefixcmp(refname, "refs/tags/");
40
+ match = heads_only && starts_with(refname, "refs/heads/");
41
+ match |= tags_only && starts_with(refname, "refs/tags/");
42
if (!match)
43
return 0;
44
}
@@ -210,7 +210,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
210
while (*pattern) {
211
unsigned char sha1[20];
212
213
- if (!prefixcmp(*pattern, "refs/") &&
213
+ if (starts_with(*pattern, "refs/") &&
214
!read_ref(*pattern, sha1)) {
215
if (!quiet)
216
show_one(*pattern, sha1);
builtin/symbolic-ref.c
+1
-1
@@ -65,7 +65,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
65
break;
66
case 2:
67
if (!strcmp(argv[0], "HEAD") &&
68
- prefixcmp(argv[1], "refs/"))
68
+ !starts_with(argv[1], "refs/"))
69
die("Refusing to point HEAD outside of refs/");
70
create_symref(argv[0], argv[1], msg);
71
break;
builtin/tag.c
+1
-1
@@ -259,7 +259,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
259
int status = git_gpg_config(var, value, cb);
260
if (status)
261
return status;
262
- if (!prefixcmp(var, "column."))
262
+ if (starts_with(var, "column."))
263
return git_column_config(var, value, "tag", &colopts);
264
return git_default_config(var, value, cb);
265
}
builtin/unpack-objects.c
+1
-1
@@ -523,7 +523,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
523
strict = 1;
524
continue;
525
}
526
- if (!prefixcmp(arg, "--pack_header=")) {
526
+ if (starts_with(arg, "--pack_header=")) {
527
struct pack_header *hdr;
528
char *c;
529
builtin/update-ref.c
+5
-5
@@ -229,15 +229,15 @@ static void update_refs_stdin(void)
229
die("empty command in input");
230
else if (isspace(*cmd.buf))
231
die("whitespace before command: %s", cmd.buf);
232
- else if (!prefixcmp(cmd.buf, "update "))
232
+ else if (starts_with(cmd.buf, "update "))
233
parse_cmd_update(cmd.buf + 7);
234
- else if (!prefixcmp(cmd.buf, "create "))
234
+ else if (starts_with(cmd.buf, "create "))
235
parse_cmd_create(cmd.buf + 7);
236
- else if (!prefixcmp(cmd.buf, "delete "))
236
+ else if (starts_with(cmd.buf, "delete "))
237
parse_cmd_delete(cmd.buf + 7);
238
- else if (!prefixcmp(cmd.buf, "verify "))
238
+ else if (starts_with(cmd.buf, "verify "))
239
parse_cmd_verify(cmd.buf + 7);
240
- else if (!prefixcmp(cmd.buf, "option "))
240
+ else if (starts_with(cmd.buf, "option "))
241
parse_cmd_option(cmd.buf + 7);
242
else
243
die("unknown command: %s", cmd.buf);
builtin/upload-archive.c
+1
-1
@@ -37,7 +37,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
37
if (sent_argv.argc > MAX_ARGS)
38
die("Too many options (>%d)", MAX_ARGS - 1);
39
40
- if (prefixcmp(buf, arg_cmd))
40
+ if (!starts_with(buf, arg_cmd))
41
die("'argument' token or flush expected");
42
argv_array_push(&sent_argv, buf + strlen(arg_cmd));
43
}
commit.c
+3
-3
@@ -559,7 +559,7 @@ static void record_author_date(struct author_date_slab *author_date,
559
buf;
560
buf = line_end + 1) {
561
line_end = strchrnul(buf, '\n');
562
- if (prefixcmp(buf, "author ")) {
562
+ if (!starts_with(buf, "author ")) {
563
if (!line_end[0] || line_end[1] == '\n')
564
return; /* end of header */
565
continue;
@@ -1106,7 +1106,7 @@ int parse_signed_commit(const unsigned char *sha1,
1106
next = next ? next + 1 : tail;
1107
if (in_signature && line[0] == ' ')
1108
sig = line + 1;
1109
- else if (!prefixcmp(line, gpg_sig_header) &&
1109
+ else if (starts_with(line, gpg_sig_header) &&
1110
line[gpg_sig_header_len] == ' ')
1111
sig = line + gpg_sig_header_len + 1;
1112
if (sig) {
@@ -1186,7 +1186,7 @@ static void parse_gpg_output(struct signature_check *sigc)
1186
for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
1187
const char *found, *next;
1188
1189
- if (!prefixcmp(buf, sigcheck_gpg_status[i].check + 1)) {
1189
+ if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
1190
/* At the very beginning of the buffer */
1191
found = buf + strlen(sigcheck_gpg_status[i].check + 1);
1192
} else {
config.c
+8
-8
@@ -969,25 +969,25 @@ static int git_default_mailmap_config(const char *var, const char *value)
969
970
int git_default_config(const char *var, const char *value, void *dummy)
971
{
972
- if (!prefixcmp(var, "core."))
972
+ if (starts_with(var, "core."))
973
return git_default_core_config(var, value);
974
975
- if (!prefixcmp(var, "user."))
975
+ if (starts_with(var, "user."))
976
return git_ident_config(var, value, dummy);
977
978
- if (!prefixcmp(var, "i18n."))
978
+ if (starts_with(var, "i18n."))
979
return git_default_i18n_config(var, value);
980
981
- if (!prefixcmp(var, "branch."))
981
+ if (starts_with(var, "branch."))
982
return git_default_branch_config(var, value);
983
984
- if (!prefixcmp(var, "push."))
984
+ if (starts_with(var, "push."))
985
return git_default_push_config(var, value);
986
987
- if (!prefixcmp(var, "mailmap."))
987
+ if (starts_with(var, "mailmap."))
988
return git_default_mailmap_config(var, value);
989
990
- if (!prefixcmp(var, "advice."))
990
+ if (starts_with(var, "advice."))
991
return git_default_advice_config(var, value);
992
993
if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
@@ -1872,7 +1872,7 @@ int parse_config_key(const char *var,
1872
const char *dot;
1873
1874
/* Does it start with "section." ? */
1875
- if (prefixcmp(var, section) || var[section_len] != '.')
1875
+ if (!starts_with(var, section) || var[section_len] != '.')
1876
return -1;
1877
1878
/*
connect.c
+1
-1
@@ -145,7 +145,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
145
if (!len)
146
break;
147
148
- if (len > 4 && !prefixcmp(buffer, "ERR "))
148
+ if (len > 4 && starts_with(buffer, "ERR "))
149
die("remote error: %s", buffer + 4);
150
151
if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
connected.c
+1
-1
@@ -38,7 +38,7 @@ int check_everything_connected_with_transport(sha1_iterate_fn fn,
38
if (transport && transport->smart_options &&
39
transport->smart_options->self_contained_and_connected &&
40
transport->pack_lockfile &&
41
- !suffixcmp(transport->pack_lockfile, ".keep")) {
41
+ ends_with(transport->pack_lockfile, ".keep")) {
42
struct strbuf idx_file = STRBUF_INIT;
43
strbuf_addstr(&idx_file, transport->pack_lockfile);
44
strbuf_setlen(&idx_file, idx_file.len - 5); /* ".keep" */
convert.c
+1
-1
@@ -1121,7 +1121,7 @@ static int is_foreign_ident(const char *str)
1121
{
1122
int i;
1123
1124
- if (prefixcmp(str, "$Id: "))
1124
+ if (!starts_with(str, "$Id: "))
1125
return 0;
1126
for (i = 5; str[i]; i++) {
1127
if (isspace(str[i]) && str[i+1] != '$')
daemon.c
+20
-20
@@ -235,7 +235,7 @@ static int service_enabled;
235
236
static int git_daemon_config(const char *var, const char *value, void *cb)
237
{
238
- if (!prefixcmp(var, "daemon.") &&
238
+ if (starts_with(var, "daemon.") &&
239
!strcmp(var + 7, service_looking_at->config_name)) {
240
service_enabled = git_config_bool(var, value);
241
return 0;
@@ -633,7 +633,7 @@ static int execute(void)
633
for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
634
struct daemon_service *s = &(daemon_service[i]);
635
int namelen = strlen(s->name);
636
- if (!prefixcmp(line, "git-") &&
636
+ if (starts_with(line, "git-") &&
637
!strncmp(s->name, line + 4, namelen) &&
638
line[namelen + 4] == ' ') {
639
/*
@@ -1165,11 +1165,11 @@ int main(int argc, char **argv)
1165
for (i = 1; i < argc; i++) {
1166
char *arg = argv[i];
1167
1168
- if (!prefixcmp(arg, "--listen=")) {
1168
+ if (starts_with(arg, "--listen=")) {
1169
string_list_append(&listen_addr, xstrdup_tolower(arg + 9));
1170
continue;
1171
}
1172
- if (!prefixcmp(arg, "--port=")) {
1172
+ if (starts_with(arg, "--port=")) {
1173
char *end;
1174
unsigned long n;
1175
n = strtoul(arg+7, &end, 0);
@@ -1199,19 +1199,19 @@ int main(int argc, char **argv)
1199
export_all_trees = 1;
1200
continue;
1201
}
1202
- if (!prefixcmp(arg, "--access-hook=")) {
1202
+ if (starts_with(arg, "--access-hook=")) {
1203
access_hook = arg + 14;
1204
continue;
1205
}
1206
- if (!prefixcmp(arg, "--timeout=")) {
1206
+ if (starts_with(arg, "--timeout=")) {
1207
timeout = atoi(arg+10);
1208
continue;
1209
}
1210
- if (!prefixcmp(arg, "--init-timeout=")) {
1210
+ if (starts_with(arg, "--init-timeout=")) {
1211
init_timeout = atoi(arg+15);
1212
continue;
1213
}
1214
- if (!prefixcmp(arg, "--max-connections=")) {
1214
+ if (starts_with(arg, "--max-connections=")) {
1215
max_connections = atoi(arg+18);
1216
if (max_connections < 0)
1217
max_connections = 0; /* unlimited */
@@ -1221,7 +1221,7 @@ int main(int argc, char **argv)
1221
strict_paths = 1;
1222
continue;
1223
}
1224
- if (!prefixcmp(arg, "--base-path=")) {
1224
+ if (starts_with(arg, "--base-path=")) {
1225
base_path = arg+12;
1226
continue;
1227
}
@@ -1229,7 +1229,7 @@ int main(int argc, char **argv)
1229
base_path_relaxed = 1;
1230
continue;
1231
}
1232
- if (!prefixcmp(arg, "--interpolated-path=")) {
1232
+ if (starts_with(arg, "--interpolated-path=")) {
1233
interpolated_path = arg+20;
1234
continue;
1235
}
@@ -1241,11 +1241,11 @@ int main(int argc, char **argv)
1241
user_path = "";
1242
continue;
1243
}
1244
- if (!prefixcmp(arg, "--user-path=")) {
1244
+ if (starts_with(arg, "--user-path=")) {
1245
user_path = arg + 12;
1246
continue;
1247
}
1248
- if (!prefixcmp(arg, "--pid-file=")) {
1248
+ if (starts_with(arg, "--pid-file=")) {
1249
pid_file = arg + 11;
1250
continue;
1251
}
@@ -1254,35 +1254,35 @@ int main(int argc, char **argv)
1254
log_syslog = 1;
1255
continue;
1256
}
1257
- if (!prefixcmp(arg, "--user=")) {
1257
+ if (starts_with(arg, "--user=")) {
1258
user_name = arg + 7;
1259
continue;
1260
}
1261
- if (!prefixcmp(arg, "--group=")) {
1261
+ if (starts_with(arg, "--group=")) {
1262
group_name = arg + 8;
1263
continue;
1264
}
1265
- if (!prefixcmp(arg, "--enable=")) {
1265
+ if (starts_with(arg, "--enable=")) {
1266
enable_service(arg + 9, 1);
1267
continue;
1268
}
1269
- if (!prefixcmp(arg, "--disable=")) {
1269
+ if (starts_with(arg, "--disable=")) {
1270
enable_service(arg + 10, 0);
1271
continue;
1272
}
1273
- if (!prefixcmp(arg, "--allow-override=")) {
1273
+ if (starts_with(arg, "--allow-override=")) {
1274
make_service_overridable(arg + 17, 1);
1275
continue;
1276
}
1277
- if (!prefixcmp(arg, "--forbid-override=")) {
1277
+ if (starts_with(arg, "--forbid-override=")) {
1278
make_service_overridable(arg + 18, 0);
1279
continue;
1280
}
1281
- if (!prefixcmp(arg, "--informative-errors")) {
1281
+ if (starts_with(arg, "--informative-errors")) {
1282
informative_errors = 1;
1283
continue;
1284
}
1285
- if (!prefixcmp(arg, "--no-informative-errors")) {
1285
+ if (starts_with(arg, "--no-informative-errors")) {
1286
informative_errors = 0;
1287
continue;
1288
}
diff.c
+28
-28
@@ -235,7 +235,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
235
if (userdiff_config(var, value) < 0)
236
return -1;
237
238
- if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
238
+ if (starts_with(var, "diff.color.") || starts_with(var, "color.diff.")) {
239
int slot = parse_diff_color_slot(var, 11);
240
if (slot < 0)
241
return 0;
@@ -264,7 +264,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
264
return 0;
265
}
266
267
- if (!prefixcmp(var, "submodule."))
267
+ if (starts_with(var, "submodule."))
268
return parse_submodule_config_option(var, value);
269
270
return git_default_config(var, value, cb);
@@ -1215,7 +1215,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
1215
diff_words_append(line, len,
1216
&ecbdata->diff_words->plus);
1217
return;
1218
- } else if (!prefixcmp(line, "\\ ")) {
1218
+ } else if (starts_with(line, "\\ ")) {
1219
/*
1220
* Eat the "no newline at eof" marker as if we
1221
* saw a "+" or "-" line with nothing on it,
@@ -2387,9 +2387,9 @@ static void builtin_diff(const char *name_a,
2387
xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
2388
if (!diffopts)
2389
;
2390
- else if (!prefixcmp(diffopts, "--unified="))
2390
+ else if (starts_with(diffopts, "--unified="))
2391
xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
2392
- else if (!prefixcmp(diffopts, "-u"))
2392
+ else if (starts_with(diffopts, "-u"))
2393
xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
2394
if (o->word_diff)
2395
init_diff_words_data(&ecbdata, o, one, two);
@@ -3391,7 +3391,7 @@ int parse_long_opt(const char *opt, const char **argv,
3391
if (arg[0] != '-' || arg[1] != '-')
3392
return 0;
3393
arg += strlen("--");
3394
- if (prefixcmp(arg, opt))
3394
+ if (!starts_with(arg, opt))
3395
return 0;
3396
arg += strlen(opt);
3397
if (*arg == '=') { /* sticked form: --option=value */
@@ -3422,7 +3422,7 @@ static int stat_opt(struct diff_options *options, const char **av)
3422
3423
switch (*arg) {
3424
case '-':
3425
- if (!prefixcmp(arg, "-width")) {
3425
+ if (starts_with(arg, "-width")) {
3426
arg += strlen("-width");
3427
if (*arg == '=')
3428
width = strtoul(arg + 1, &end, 10);
@@ -3432,7 +3432,7 @@ static int stat_opt(struct diff_options *options, const char **av)
3432
width = strtoul(av[1], &end, 10);
3433
argcount = 2;
3434
}
3435
- } else if (!prefixcmp(arg, "-name-width")) {
3435
+ } else if (starts_with(arg, "-name-width")) {
3436
arg += strlen("-name-width");
3437
if (*arg == '=')
3438
name_width = strtoul(arg + 1, &end, 10);
@@ -3442,7 +3442,7 @@ static int stat_opt(struct diff_options *options, const char **av)
3442
name_width = strtoul(av[1], &end, 10);
3443
argcount = 2;
3444
}
3445
- } else if (!prefixcmp(arg, "-graph-width")) {
3445
+ } else if (starts_with(arg, "-graph-width")) {
3446
arg += strlen("-graph-width");
3447
if (*arg == '=')
3448
graph_width = strtoul(arg + 1, &end, 10);
@@ -3452,7 +3452,7 @@ static int stat_opt(struct diff_options *options, const char **av)
3452
graph_width = strtoul(av[1], &end, 10);
3453
argcount = 2;
3454
}
3455
- } else if (!prefixcmp(arg, "-count")) {
3455
+ } else if (starts_with(arg, "-count")) {
3456
arg += strlen("-count");
3457
if (*arg == '=')
3458
count = strtoul(arg + 1, &end, 10);
@@ -3614,15 +3614,15 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3614
options->output_format |= DIFF_FORMAT_SHORTSTAT;
3615
else if (!strcmp(arg, "-X") || !strcmp(arg, "--dirstat"))
3616
return parse_dirstat_opt(options, "");
3617
- else if (!prefixcmp(arg, "-X"))
3617
+ else if (starts_with(arg, "-X"))
3618
return parse_dirstat_opt(options, arg + 2);
3619
- else if (!prefixcmp(arg, "--dirstat="))
3619
+ else if (starts_with(arg, "--dirstat="))
3620
return parse_dirstat_opt(options, arg + 10);
3621
else if (!strcmp(arg, "--cumulative"))
3622
return parse_dirstat_opt(options, "cumulative");
3623
else if (!strcmp(arg, "--dirstat-by-file"))
3624
return parse_dirstat_opt(options, "files");
3625
- else if (!prefixcmp(arg, "--dirstat-by-file=")) {
3625
+ else if (starts_with(arg, "--dirstat-by-file=")) {
3626
parse_dirstat_opt(options, "files");
3627
return parse_dirstat_opt(options, arg + 18);
3628
}
@@ -3639,17 +3639,17 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3639
options->output_format |= DIFF_FORMAT_NAME_STATUS;
3640
else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
3641
options->output_format |= DIFF_FORMAT_NO_OUTPUT;
3642
- else if (!prefixcmp(arg, "--stat"))
3642
+ else if (starts_with(arg, "--stat"))
3643
/* --stat, --stat-width, --stat-name-width, or --stat-count */
3644
return stat_opt(options, av);
3645
3646
/* renames options */
3647
- else if (!prefixcmp(arg, "-B") || !prefixcmp(arg, "--break-rewrites=") ||
3647
+ else if (starts_with(arg, "-B") || starts_with(arg, "--break-rewrites=") ||
3648
!strcmp(arg, "--break-rewrites")) {
3649
if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
3650
return error("invalid argument to -B: %s", arg+2);
3651
}
3652
- else if (!prefixcmp(arg, "-M") || !prefixcmp(arg, "--find-renames=") ||
3652
+ else if (starts_with(arg, "-M") || starts_with(arg, "--find-renames=") ||
3653
!strcmp(arg, "--find-renames")) {
3654
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
3655
return error("invalid argument to -M: %s", arg+2);
@@ -3658,7 +3658,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3658
else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
3659
options->irreversible_delete = 1;
3660
}
3661
- else if (!prefixcmp(arg, "-C") || !prefixcmp(arg, "--find-copies=") ||
3661
+ else if (starts_with(arg, "-C") || starts_with(arg, "--find-copies=") ||
3662
!strcmp(arg, "--find-copies")) {
3663
if (options->detect_rename == DIFF_DETECT_COPY)
3664
DIFF_OPT_SET(options, FIND_COPIES_HARDER);
@@ -3674,7 +3674,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3674
DIFF_OPT_CLR(options, RENAME_EMPTY);
3675
else if (!strcmp(arg, "--relative"))
3676
DIFF_OPT_SET(options, RELATIVE_NAME);
3677
- else if (!prefixcmp(arg, "--relative=")) {
3677
+ else if (starts_with(arg, "--relative=")) {
3678
DIFF_OPT_SET(options, RELATIVE_NAME);
3679
options->prefix = arg + 11;
3680
}
@@ -3727,7 +3727,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3727
DIFF_OPT_CLR(options, FOLLOW_RENAMES);
3728
else if (!strcmp(arg, "--color"))
3729
options->use_color = 1;
3730
- else if (!prefixcmp(arg, "--color=")) {
3730
+ else if (starts_with(arg, "--color=")) {
3731
int value = git_config_colorbool(NULL, arg+8);
3732
if (value < 0)
3733
return error("option `color' expects \"always\", \"auto\", or \"never\"");
@@ -3739,7 +3739,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3739
options->use_color = 1;
3740
options->word_diff = DIFF_WORDS_COLOR;
3741
}
3742
- else if (!prefixcmp(arg, "--color-words=")) {
3742
+ else if (starts_with(arg, "--color-words=")) {
3743
options->use_color = 1;
3744
options->word_diff = DIFF_WORDS_COLOR;
3745
options->word_regex = arg + 14;
@@ -3748,7 +3748,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3748
if (options->word_diff == DIFF_WORDS_NONE)
3749
options->word_diff = DIFF_WORDS_PLAIN;
3750
}
3751
- else if (!prefixcmp(arg, "--word-diff=")) {
3751
+ else if (starts_with(arg, "--word-diff=")) {
3752
const char *type = arg + 12;
3753
if (!strcmp(type, "plain"))
3754
options->word_diff = DIFF_WORDS_PLAIN;
@@ -3784,12 +3784,12 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3784
else if (!strcmp(arg, "--ignore-submodules")) {
3785
DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
3786
handle_ignore_submodules_arg(options, "all");
3787
- } else if (!prefixcmp(arg, "--ignore-submodules=")) {
3787
+ } else if (starts_with(arg, "--ignore-submodules=")) {
3788
DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
3789
handle_ignore_submodules_arg(options, arg + 20);
3790
} else if (!strcmp(arg, "--submodule"))
3791
DIFF_OPT_SET(options, SUBMODULE_LOG);
3792
- else if (!prefixcmp(arg, "--submodule="))
3792
+ else if (starts_with(arg, "--submodule="))
3793
return parse_submodule_opt(options, arg + 12);
3794
3795
/* misc options */
@@ -3825,7 +3825,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3825
}
3826
else if (!strcmp(arg, "--abbrev"))
3827
options->abbrev = DEFAULT_ABBREV;
3828
- else if (!prefixcmp(arg, "--abbrev=")) {
3828
+ else if (starts_with(arg, "--abbrev=")) {
3829
options->abbrev = strtoul(arg + 9, NULL, 10);
3830
if (options->abbrev < MINIMUM_ABBREV)
3831
options->abbrev = MINIMUM_ABBREV;
@@ -3907,15 +3907,15 @@ static int diff_scoreopt_parse(const char *opt)
3907
cmd = *opt++;
3908
if (cmd == '-') {
3909
/* convert the long-form arguments into short-form versions */
3910
- if (!prefixcmp(opt, "break-rewrites")) {
3910
+ if (starts_with(opt, "break-rewrites")) {
3911
opt += strlen("break-rewrites");
3912
if (*opt == 0 || *opt++ == '=')
3913
cmd = 'B';
3914
- } else if (!prefixcmp(opt, "find-copies")) {
3914
+ } else if (starts_with(opt, "find-copies")) {
3915
opt += strlen("find-copies");
3916
if (*opt == 0 || *opt++ == '=')
3917
cmd = 'C';
3918
- } else if (!prefixcmp(opt, "find-renames")) {
3918
+ } else if (starts_with(opt, "find-renames")) {
3919
opt += strlen("find-renames");
3920
if (*opt == 0 || *opt++ == '=')
3921
cmd = 'M';
@@ -4325,7 +4325,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
4325
int new_len;
4326
4327
/* Ignore line numbers when computing the SHA1 of the patch */
4328
- if (!prefixcmp(line, "@@ -"))
4328
+ if (starts_with(line, "@@ -"))
4329
return;
4330
4331
new_len = remove_space(line, len);
environment.c
+1
-1
@@ -171,7 +171,7 @@ const char *get_git_namespace(void)
171
172
const char *strip_namespace(const char *namespaced_ref)
173
{
174
- if (prefixcmp(namespaced_ref, get_git_namespace()))
174
+ if (!starts_with(namespaced_ref, get_git_namespace()))
175
return NULL;
176
return namespaced_ref + namespace_len;
177
}
fast-import.c
+40
-40
@@ -1877,8 +1877,8 @@ static int read_next_command(void)
1877
return EOF;
1878
1879
if (!seen_data_command
1880
- && prefixcmp(command_buf.buf, "feature ")
1881
- && prefixcmp(command_buf.buf, "option ")) {
1880
+ && !starts_with(command_buf.buf, "feature ")
1881
+ && !starts_with(command_buf.buf, "option ")) {
1882
parse_argv();
1883
}
1884
@@ -1898,7 +1898,7 @@ static int read_next_command(void)
1898
rc->prev->next = rc;
1899
cmd_tail = rc;
1900
}
1901
- if (!prefixcmp(command_buf.buf, "cat-blob ")) {
1901
+ if (starts_with(command_buf.buf, "cat-blob ")) {
1902
parse_cat_blob();
1903
continue;
1904
}
@@ -1917,7 +1917,7 @@ static void skip_optional_lf(void)
1917
1918
static void parse_mark(void)
1919
{
1920
- if (!prefixcmp(command_buf.buf, "mark :")) {
1920
+ if (starts_with(command_buf.buf, "mark :")) {
1921
next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
1922
read_next_command();
1923
}
@@ -1929,10 +1929,10 @@ static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
1929
{
1930
strbuf_reset(sb);
1931
1932
- if (prefixcmp(command_buf.buf, "data "))
1932
+ if (!starts_with(command_buf.buf, "data "))
1933
die("Expected 'data n' command, found: %s", command_buf.buf);
1934
1935
- if (!prefixcmp(command_buf.buf + 5, "<<")) {
1935
+ if (starts_with(command_buf.buf + 5, "<<")) {
1936
char *term = xstrdup(command_buf.buf + 5 + 2);
1937
size_t term_len = command_buf.len - 5 - 2;
1938
@@ -2306,7 +2306,7 @@ static void file_change_m(struct branch *b)
2306
if (*p == ':') {
2307
oe = find_mark(parse_mark_ref_space(&p));
2308
hashcpy(sha1, oe->idx.sha1);
2309
- } else if (!prefixcmp(p, "inline ")) {
2309
+ } else if (starts_with(p, "inline ")) {
2310
inline_data = 1;
2311
oe = NULL; /* not used with inline_data, but makes gcc happy */
2312
p += strlen("inline"); /* advance to space */
@@ -2479,7 +2479,7 @@ static void note_change_n(struct branch *b, unsigned char *old_fanout)
2479
if (*p == ':') {
2480
oe = find_mark(parse_mark_ref_space(&p));
2481
hashcpy(sha1, oe->idx.sha1);
2482
- } else if (!prefixcmp(p, "inline ")) {
2482
+ } else if (starts_with(p, "inline ")) {
2483
inline_data = 1;
2484
oe = NULL; /* not used with inline_data, but makes gcc happy */
2485
p += strlen("inline"); /* advance to space */
@@ -2590,7 +2590,7 @@ static int parse_from(struct branch *b)
2590
const char *from;
2591
struct branch *s;
2592
2593
- if (prefixcmp(command_buf.buf, "from "))
2593
+ if (!starts_with(command_buf.buf, "from "))
2594
return 0;
2595
2596
if (b->branch_tree.tree) {
@@ -2636,7 +2636,7 @@ static struct hash_list *parse_merge(unsigned int *count)
2636
struct branch *s;
2637
2638
*count = 0;
2639
- while (!prefixcmp(command_buf.buf, "merge ")) {
2639
+ while (starts_with(command_buf.buf, "merge ")) {
2640
from = strchr(command_buf.buf, ' ') + 1;
2641
n = xmalloc(sizeof(*n));
2642
s = lookup_branch(from);
@@ -2687,11 +2687,11 @@ static void parse_new_commit(void)
2687
2688
read_next_command();
2689
parse_mark();
2690
- if (!prefixcmp(command_buf.buf, "author ")) {
2690
+ if (starts_with(command_buf.buf, "author ")) {
2691
author = parse_ident(command_buf.buf + 7);
2692
read_next_command();
2693
}
2694
- if (!prefixcmp(command_buf.buf, "committer ")) {
2694
+ if (starts_with(command_buf.buf, "committer ")) {
2695
committer = parse_ident(command_buf.buf + 10);
2696
read_next_command();
2697
}
@@ -2712,19 +2712,19 @@ static void parse_new_commit(void)
2712
2713
/* file_change* */
2714
while (command_buf.len > 0) {
2715
- if (!prefixcmp(command_buf.buf, "M "))
2715
+ if (starts_with(command_buf.buf, "M "))
2716
file_change_m(b);
2717
- else if (!prefixcmp(command_buf.buf, "D "))
2717
+ else if (starts_with(command_buf.buf, "D "))
2718
file_change_d(b);
2719
- else if (!prefixcmp(command_buf.buf, "R "))
2719
+ else if (starts_with(command_buf.buf, "R "))
2720
file_change_cr(b, 1);
2721
- else if (!prefixcmp(command_buf.buf, "C "))
2721
+ else if (starts_with(command_buf.buf, "C "))
2722
file_change_cr(b, 0);
2723
- else if (!prefixcmp(command_buf.buf, "N "))
2723
+ else if (starts_with(command_buf.buf, "N "))
2724
note_change_n(b, &prev_fanout);
2725
else if (!strcmp("deleteall", command_buf.buf))
2726
file_change_deleteall(b);
2727
- else if (!prefixcmp(command_buf.buf, "ls "))
2727
+ else if (starts_with(command_buf.buf, "ls "))
2728
parse_ls(b);
2729
else {
2730
unread_command_buf = 1;
@@ -2793,7 +2793,7 @@ static void parse_new_tag(void)
2793
read_next_command();
2794
2795
/* from ... */
2796
- if (prefixcmp(command_buf.buf, "from "))
2796
+ if (!starts_with(command_buf.buf, "from "))
2797
die("Expected from command, got %s", command_buf.buf);
2798
from = strchr(command_buf.buf, ' ') + 1;
2799
s = lookup_branch(from);
@@ -2821,7 +2821,7 @@ static void parse_new_tag(void)
2821
read_next_command();
2822
2823
/* tagger ... */
2824
- if (!prefixcmp(command_buf.buf, "tagger ")) {
2824
+ if (starts_with(command_buf.buf, "tagger ")) {
2825
tagger = parse_ident(command_buf.buf + 7);
2826
read_next_command();
2827
} else
@@ -3209,7 +3209,7 @@ static void option_export_pack_edges(const char *edges)
3209
3210
static int parse_one_option(const char *option)
3211
{
3212
- if (!prefixcmp(option, "max-pack-size=")) {
3212
+ if (starts_with(option, "max-pack-size=")) {
3213
unsigned long v;
3214
if (!git_parse_ulong(option + 14, &v))
3215
return 0;
@@ -3221,20 +3221,20 @@ static int parse_one_option(const char *option)
3221
v = 1024 * 1024;
3222
}
3223
max_packsize = v;
3224
- } else if (!prefixcmp(option, "big-file-threshold=")) {
3224
+ } else if (starts_with(option, "big-file-threshold=")) {
3225
unsigned long v;
3226
if (!git_parse_ulong(option + 19, &v))
3227
return 0;
3228
big_file_threshold = v;
3229
- } else if (!prefixcmp(option, "depth=")) {
3229
+ } else if (starts_with(option, "depth=")) {
3230
option_depth(option + 6);
3231
- } else if (!prefixcmp(option, "active-branches=")) {
3231
+ } else if (starts_with(option, "active-branches=")) {
3232
option_active_branches(option + 16);
3233
- } else if (!prefixcmp(option, "export-pack-edges=")) {
3233
+ } else if (starts_with(option, "export-pack-edges=")) {
3234
option_export_pack_edges(option + 18);
3235
- } else if (!prefixcmp(option, "quiet")) {
3235
+ } else if (starts_with(option, "quiet")) {
3236
show_stats = 0;
3237
- } else if (!prefixcmp(option, "stats")) {
3237
+ } else if (starts_with(option, "stats")) {
3238
show_stats = 1;
3239
} else {
3240
return 0;
@@ -3245,14 +3245,14 @@ static int parse_one_option(const char *option)
3245
3246
static int parse_one_feature(const char *feature, int from_stream)
3247
{
3248
- if (!prefixcmp(feature, "date-format=")) {
3248
+ if (starts_with(feature, "date-format=")) {
3249
option_date_format(feature + 12);
3250
- } else if (!prefixcmp(feature, "import-marks=")) {
3250
+ } else if (starts_with(feature, "import-marks=")) {
3251
option_import_marks(feature + 13, from_stream, 0);
3252
- } else if (!prefixcmp(feature, "import-marks-if-exists=")) {
3252
+ } else if (starts_with(feature, "import-marks-if-exists=")) {
3253
option_import_marks(feature + strlen("import-marks-if-exists="),
3254
from_stream, 1);
3255
- } else if (!prefixcmp(feature, "export-marks=")) {
3255
+ } else if (starts_with(feature, "export-marks=")) {
3256
option_export_marks(feature + 13);
3257
} else if (!strcmp(feature, "cat-blob")) {
3258
; /* Don't die - this feature is supported */
@@ -3350,7 +3350,7 @@ static void parse_argv(void)
3350
if (parse_one_feature(a + 2, 0))
3351
continue;
3352
3353
- if (!prefixcmp(a + 2, "cat-blob-fd=")) {
3353
+ if (starts_with(a + 2, "cat-blob-fd=")) {
3354
option_cat_blob_fd(a + 2 + strlen("cat-blob-fd="));
3355
continue;
3356
}
@@ -3404,25 +3404,25 @@ int main(int argc, char **argv)
3404
while (read_next_command() != EOF) {
3405
if (!strcmp("blob", command_buf.buf))
3406
parse_new_blob();
3407
- else if (!prefixcmp(command_buf.buf, "ls "))
3407
+ else if (starts_with(command_buf.buf, "ls "))
3408
parse_ls(NULL);
3409
- else if (!prefixcmp(command_buf.buf, "commit "))
3409
+ else if (starts_with(command_buf.buf, "commit "))
3410
parse_new_commit();
3411
- else if (!prefixcmp(command_buf.buf, "tag "))
3411
+ else if (starts_with(command_buf.buf, "tag "))
3412
parse_new_tag();
3413
- else if (!prefixcmp(command_buf.buf, "reset "))
3413
+ else if (starts_with(command_buf.buf, "reset "))
3414
parse_reset_branch();
3415
else if (!strcmp("checkpoint", command_buf.buf))
3416
parse_checkpoint();
3417
else if (!strcmp("done", command_buf.buf))
3418
break;
3419
- else if (!prefixcmp(command_buf.buf, "progress "))
3419
+ else if (starts_with(command_buf.buf, "progress "))
3420
parse_progress();
3421
- else if (!prefixcmp(command_buf.buf, "feature "))
3421
+ else if (starts_with(command_buf.buf, "feature "))
3422
parse_feature();
3423
- else if (!prefixcmp(command_buf.buf, "option git "))
3423
+ else if (starts_with(command_buf.buf, "option git "))
3424
parse_option();
3425
- else if (!prefixcmp(command_buf.buf, "option "))
3425
+ else if (starts_with(command_buf.buf, "option "))
3426
/* ignore non-git options*/;
3427
else
3428
die("Unsupported command: %s", command_buf.buf);
fetch-pack.c
+6
-6
@@ -176,9 +176,9 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd)
176
*/
177
char *line;
178
while ((line = packet_read_line(fd, NULL))) {
179
- if (!prefixcmp(line, "shallow "))
179
+ if (starts_with(line, "shallow "))
180
continue;
181
- if (!prefixcmp(line, "unshallow "))
181
+ if (starts_with(line, "unshallow "))
182
continue;
183
die("git fetch-pack: expected shallow list");
184
}
@@ -194,7 +194,7 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)
194
die("git fetch-pack: expected ACK/NAK, got EOF");
195
if (!strcmp(line, "NAK"))
196
return NAK;
197
- if (!prefixcmp(line, "ACK ")) {
197
+ if (starts_with(line, "ACK ")) {
198
if (!get_sha1_hex(line+4, result_sha1)) {
199
if (len < 45)
200
return ACK;
@@ -323,13 +323,13 @@ static int find_common(struct fetch_pack_args *args,
323
324
send_request(args, fd[1], &req_buf);
325
while ((line = packet_read_line(fd[0], NULL))) {
326
- if (!prefixcmp(line, "shallow ")) {
326
+ if (starts_with(line, "shallow ")) {
327
if (get_sha1_hex(line + 8, sha1))
328
die("invalid shallow line: %s", line);
329
register_shallow(sha1);
330
continue;
331
}
332
- if (!prefixcmp(line, "unshallow ")) {
332
+ if (starts_with(line, "unshallow ")) {
333
if (get_sha1_hex(line + 10, sha1))
334
die("invalid unshallow line: %s", line);
335
if (!lookup_object(sha1))
@@ -523,7 +523,7 @@ static void filter_refs(struct fetch_pack_args *args,
523
}
524
525
if (!keep && args->fetch_all &&
526
- (!args->depth || prefixcmp(ref->name, "refs/tags/")))
526
+ (!args->depth || !starts_with(ref->name, "refs/tags/")))
527
keep = 1;
528
529
if (keep) {
git.c
+6
-6
@@ -54,7 +54,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
54
/*
55
* Check remaining flags.
56
*/
57
- if (!prefixcmp(cmd, "--exec-path")) {
57
+ if (starts_with(cmd, "--exec-path")) {
58
cmd += 11;
59
if (*cmd == '=')
60
git_set_argv_exec_path(cmd + 1);
@@ -92,7 +92,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
92
*envchanged = 1;
93
(*argv)++;
94
(*argc)--;
95
- } else if (!prefixcmp(cmd, "--git-dir=")) {
95
+ } else if (starts_with(cmd, "--git-dir=")) {
96
setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
97
if (envchanged)
98
*envchanged = 1;
@@ -106,7 +106,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
106
*envchanged = 1;
107
(*argv)++;
108
(*argc)--;
109
- } else if (!prefixcmp(cmd, "--namespace=")) {
109
+ } else if (starts_with(cmd, "--namespace=")) {
110
setenv(GIT_NAMESPACE_ENVIRONMENT, cmd + 12, 1);
111
if (envchanged)
112
*envchanged = 1;
@@ -120,7 +120,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
120
*envchanged = 1;
121
(*argv)++;
122
(*argc)--;
123
- } else if (!prefixcmp(cmd, "--work-tree=")) {
123
+ } else if (starts_with(cmd, "--work-tree=")) {
124
setenv(GIT_WORK_TREE_ENVIRONMENT, cmd + 12, 1);
125
if (envchanged)
126
*envchanged = 1;
@@ -566,7 +566,7 @@ int main(int argc, char **av)
566
* So we just directly call the internal command handler, and
567
* die if that one cannot handle it.
568
*/
569
- if (!prefixcmp(cmd, "git-")) {
569
+ if (starts_with(cmd, "git-")) {
570
cmd += 4;
571
argv[0] = cmd;
572
handle_internal_command(argc, argv);
@@ -578,7 +578,7 @@ int main(int argc, char **av)
578
argc--;
579
handle_options(&argv, &argc, NULL);
580
if (argc > 0) {
581
- if (!prefixcmp(argv[0], "--"))
581
+ if (starts_with(argv[0], "--"))
582
argv[0] += 2;
583
} else {
584
/* The user didn't specify a command; give them help */
help.c
+4
-4
@@ -148,7 +148,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
148
while ((de = readdir(dir)) != NULL) {
149
int entlen;
150
151
- if (prefixcmp(de->d_name, prefix))
151
+ if (!starts_with(de->d_name, prefix))
152
continue;
153
154
strbuf_setlen(&buf, len);
@@ -255,7 +255,7 @@ static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
255
if (!strcmp(var, "help.autocorrect"))
256
autocorrect = git_config_int(var,value);
257
/* Also use aliases for command lookup */
258
- if (!prefixcmp(var, "alias."))
258
+ if (starts_with(var, "alias."))
259
add_cmdname(&aliases, var + 6, strlen(var + 6));
260
261
return git_default_config(var, value, cb);
@@ -329,7 +329,7 @@ const char *help_unknown_cmd(const char *cmd)
329
if ((n < ARRAY_SIZE(common_cmds)) && !cmp) {
330
/* Yes, this is one of the common commands */
331
n++; /* use the entry from common_cmds[] */
332
- if (!prefixcmp(candidate, cmd)) {
332
+ if (starts_with(candidate, cmd)) {
333
/* Give prefix match a very good score */
334
main_cmds.names[i]->len = 0;
335
continue;
@@ -414,7 +414,7 @@ static int append_similar_ref(const char *refname, const unsigned char *sha1,
414
struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
415
char *branch = strrchr(refname, '/') + 1;
416
/* A remote branch of the same name is deemed similar */
417
- if (!prefixcmp(refname, "refs/remotes/") &&
417
+ if (starts_with(refname, "refs/remotes/") &&
418
!strcmp(branch, cb->base_ref))
419
string_list_append(cb->similar_refs,
420
refname + strlen("refs/remotes/"));
http-backend.c
+2
-2
@@ -226,7 +226,7 @@ static int http_config(const char *var, const char *value, void *cb)
226
return 0;
227
}
228
229
- if (!prefixcmp(var, "http.")) {
229
+ if (starts_with(var, "http.")) {
230
int i;
231
232
for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
@@ -247,7 +247,7 @@ static struct rpc_service *select_service(const char *name)
247
struct rpc_service *svc = NULL;
248
int i;
249
250
- if (prefixcmp(name, "git-"))
250
+ if (!starts_with(name, "git-"))
251
forbidden("Unsupported service: '%s'", name);
252
253
for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
http-push.c
+2
-2
@@ -771,7 +771,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
771
lock->owner = xmalloc(strlen(ctx->cdata) + 1);
772
strcpy(lock->owner, ctx->cdata);
773
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TIMEOUT)) {
774
- if (!prefixcmp(ctx->cdata, "Second-"))
774
+ if (starts_with(ctx->cdata, "Second-"))
775
lock->timeout =
776
strtol(ctx->cdata + 7, NULL, 10);
777
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
@@ -1579,7 +1579,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
1579
return;
1580
1581
/* If it's a symref, set the refname; otherwise try for a sha1 */
1582
- if (!prefixcmp((char *)buffer.buf, "ref: ")) {
1582
+ if (starts_with((char *)buffer.buf, "ref: ")) {
1583
*symref = xmemdupz((char *)buffer.buf + 5, buffer.len - 6);
1584
} else {
1585
get_sha1_hex(buffer.buf, sha1);
http.c
+5
-5
@@ -460,7 +460,7 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
460
credential_from_url(&http_auth, url);
461
if (!ssl_cert_password_required &&
462
getenv("GIT_SSL_CERT_PASSWORD_PROTECTED") &&
463
- !prefixcmp(url, "https://"))
463
+ starts_with(url, "https://"))
464
ssl_cert_password_required = 1;
465
}
466
@@ -994,7 +994,7 @@ static int update_url_from_redirect(struct strbuf *base,
994
if (!strcmp(asked, got->buf))
995
return 0;
996
997
- if (prefixcmp(asked, base->buf))
997
+ if (!starts_with(asked, base->buf))
998
die("BUG: update_url_from_redirect: %s is not a superset of %s",
999
asked, base->buf);
1000
@@ -1100,7 +1100,7 @@ int http_fetch_ref(const char *base, struct ref *ref)
1100
strbuf_rtrim(&buffer);
1101
if (buffer.len == 40)
1102
ret = get_sha1_hex(buffer.buf, ref->old_sha1);
1103
- else if (!prefixcmp(buffer.buf, "ref: ")) {
1103
+ else if (starts_with(buffer.buf, "ref: ")) {
1104
ref->symref = xstrdup(buffer.buf + 5);
1105
ret = 0;
1106
}
@@ -1201,8 +1201,8 @@ int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
1201
case 'P':
1202
i++;
1203
if (i + 52 <= buf.len &&
1204
- !prefixcmp(data + i, " pack-") &&
1205
- !prefixcmp(data + i + 46, ".pack\n")) {
1204
+ starts_with(data + i, " pack-") &&
1205
+ starts_with(data + i + 46, ".pack\n")) {
1206
get_sha1_hex(data + i + 6, sha1);
1207
fetch_and_setup_pack_index(packs_head, sha1,
1208
base_url);
imap-send.c
+5
-5
@@ -1263,7 +1263,7 @@ static int count_messages(struct strbuf *all_msgs)
1263
char *p = all_msgs->buf;
1264
1265
while (1) {
1266
- if (!prefixcmp(p, "From ")) {
1266
+ if (starts_with(p, "From ")) {
1267
p = strstr(p+5, "\nFrom: ");
1268
if (!p) break;
1269
p = strstr(p+7, "\nDate: ");
@@ -1297,7 +1297,7 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
1297
data = &all_msgs->buf[*ofs];
1298
len = all_msgs->len - *ofs;
1299
1300
- if (len < 5 || prefixcmp(data, "From "))
1300
+ if (len < 5 || !starts_with(data, "From "))
1301
return 0;
1302
1303
p = strchr(data, '\n');
@@ -1339,13 +1339,13 @@ static int git_imap_config(const char *key, const char *val, void *cb)
1339
if (!strcmp("folder", key)) {
1340
imap_folder = xstrdup(val);
1341
} else if (!strcmp("host", key)) {
1342
- if (!prefixcmp(val, "imap:"))
1342
+ if (starts_with(val, "imap:"))
1343
val += 5;
1344
- else if (!prefixcmp(val, "imaps:")) {
1344
+ else if (starts_with(val, "imaps:")) {
1345
val += 6;
1346
server.use_ssl = 1;
1347
}
1348
- if (!prefixcmp(val, "//"))
1348
+ if (starts_with(val, "//"))
1349
val += 2;
1350
server.host = xstrdup(val);
1351
} else if (!strcmp("user", key))
log-tree.c
+4
-4
@@ -98,7 +98,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
98
struct object *obj;
99
enum decoration_type type = DECORATION_NONE;
100
101
- if (!prefixcmp(refname, "refs/replace/")) {
101
+ if (starts_with(refname, "refs/replace/")) {
102
unsigned char original_sha1[20];
103
if (!read_replace_refs)
104
return 0;
@@ -116,11 +116,11 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
116
if (!obj)
117
return 0;
118
119
- if (!prefixcmp(refname, "refs/heads/"))
119
+ if (starts_with(refname, "refs/heads/"))
120
type = DECORATION_REF_LOCAL;
121
- else if (!prefixcmp(refname, "refs/remotes/"))
121
+ else if (starts_with(refname, "refs/remotes/"))
122
type = DECORATION_REF_REMOTE;
123
- else if (!prefixcmp(refname, "refs/tags/"))
123
+ else if (starts_with(refname, "refs/tags/"))
124
type = DECORATION_REF_TAG;
125
else if (!strcmp(refname, "refs/stash"))
126
type = DECORATION_REF_STASH;
merge-recursive.c
+3
-3
@@ -2063,13 +2063,13 @@ int parse_merge_opt(struct merge_options *o, const char *s)
2063
o->recursive_variant = MERGE_RECURSIVE_THEIRS;
2064
else if (!strcmp(s, "subtree"))
2065
o->subtree_shift = "";
2066
- else if (!prefixcmp(s, "subtree="))
2066
+ else if (starts_with(s, "subtree="))
2067
o->subtree_shift = s + strlen("subtree=");
2068
else if (!strcmp(s, "patience"))
2069
o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
2070
else if (!strcmp(s, "histogram"))
2071
o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
2072
- else if (!prefixcmp(s, "diff-algorithm=")) {
2072
+ else if (starts_with(s, "diff-algorithm=")) {
2073
long value = parse_algorithm_value(s + strlen("diff-algorithm="));
2074
if (value < 0)
2075
return -1;
@@ -2088,7 +2088,7 @@ int parse_merge_opt(struct merge_options *o, const char *s)
2088
o->renormalize = 1;
2089
else if (!strcmp(s, "no-renormalize"))
2090
o->renormalize = 0;
2091
- else if (!prefixcmp(s, "rename-threshold=")) {
2091
+ else if (starts_with(s, "rename-threshold=")) {
2092
const char *score = s + strlen("rename-threshold=");
2093
if ((o->rename_score = parse_rename_score(&score)) == -1 || *score != 0)
2094
return -1;
notes-utils.c
+2
-2
@@ -70,7 +70,7 @@ static combine_notes_fn parse_combine_notes_fn(const char *v)
70
static int notes_rewrite_config(const char *k, const char *v, void *cb)
71
{
72
struct notes_rewrite_cfg *c = cb;
73
- if (!prefixcmp(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
73
+ if (starts_with(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
74
c->enabled = git_config_bool(k, v);
75
return 0;
76
} else if (!c->mode_from_env && !strcmp(k, "notes.rewritemode")) {
@@ -85,7 +85,7 @@ static int notes_rewrite_config(const char *k, const char *v, void *cb)
85
} else if (!c->refs_from_env && !strcmp(k, "notes.rewriteref")) {
86
/* note that a refs/ prefix is implied in the
87
* underlying for_each_glob_ref */
88
- if (!prefixcmp(v, "refs/notes/"))
88
+ if (starts_with(v, "refs/notes/"))
89
string_list_add_refs_by_glob(c->refs, v);
90
else
91
warning(_("Refusing to rewrite notes in %s"
notes.c
+4
-4
@@ -1243,9 +1243,9 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
1243
if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
1244
strbuf_addstr(sb, "\nNotes:\n");
1245
} else {
1246
- if (!prefixcmp(ref, "refs/"))
1246
+ if (starts_with(ref, "refs/"))
1247
ref += 5;
1248
- if (!prefixcmp(ref, "notes/"))
1248
+ if (starts_with(ref, "notes/"))
1249
ref += 6;
1250
strbuf_addf(sb, "\nNotes (%s):\n", ref);
1251
}
@@ -1293,9 +1293,9 @@ int copy_note(struct notes_tree *t,
1293
1294
void expand_notes_ref(struct strbuf *sb)
1295
{
1296
- if (!prefixcmp(sb->buf, "refs/notes/"))
1296
+ if (starts_with(sb->buf, "refs/notes/"))
1297
return; /* we're happy */
1298
- else if (!prefixcmp(sb->buf, "notes/"))
1298
+ else if (starts_with(sb->buf, "notes/"))
1299
strbuf_insert(sb, 0, "refs/", 5);
1300
else
1301
strbuf_insert(sb, 0, "refs/notes/", 11);
pager.c
+1
-1
@@ -151,7 +151,7 @@ int decimal_width(int number)
151
static int pager_command_config(const char *var, const char *value, void *data)
152
{
153
struct pager_config *c = data;
154
- if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) {
154
+ if (starts_with(var, "pager.") && !strcmp(var + 6, c->cmd)) {
155
int b = git_config_maybe_bool(var, value);
156
if (b >= 0)
157
c->want = b;
parse-options.c
+6
-6
@@ -273,13 +273,13 @@ is_abbreviated:
273
if (options->flags & PARSE_OPT_NONEG)
274
continue;
275
/* negated and abbreviated very much? */
276
- if (!prefixcmp("no-", arg)) {
276
+ if (starts_with("no-", arg)) {
277
flags |= OPT_UNSET;
278
goto is_abbreviated;
279
}
280
/* negated? */
281
- if (prefixcmp(arg, "no-")) {
282
- if (!prefixcmp(long_name, "no-")) {
281
+ if (!starts_with(arg, "no-")) {
282
+ if (starts_with(long_name, "no-")) {
283
long_name += 3;
284
opt_flags |= OPT_UNSET;
285
goto again;
@@ -289,7 +289,7 @@ is_abbreviated:
289
flags |= OPT_UNSET;
290
rest = skip_prefix(arg + 3, long_name);
291
/* abbreviated and negated? */
292
- if (!rest && !prefixcmp(long_name, arg + 3))
292
+ if (!rest && starts_with(long_name, arg + 3))
293
goto is_abbreviated;
294
if (!rest)
295
continue;
@@ -334,7 +334,7 @@ static void check_typos(const char *arg, const struct option *options)
334
if (strlen(arg) < 3)
335
return;
336
337
- if (!prefixcmp(arg, "no-")) {
337
+ if (starts_with(arg, "no-")) {
338
error ("did you mean `--%s` (with two dashes ?)", arg);
339
exit(129);
340
}
@@ -342,7 +342,7 @@ static void check_typos(const char *arg, const struct option *options)
342
for (; options->type != OPTION_END; options++) {
343
if (!options->long_name)
344
continue;
345
- if (!prefixcmp(options->long_name, arg)) {
345
+ if (starts_with(options->long_name, arg)) {
346
error ("did you mean `--%s` (with two dashes ?)", arg);
347
exit(129);
348
}
pathspec.c
+1
-1
@@ -154,7 +154,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
154
magic |= pathspec_magic[i].bit;
155
break;
156
}
157
- if (!prefixcmp(copyfrom, "prefix:")) {
157
+ if (starts_with(copyfrom, "prefix:")) {
158
char *endptr;
159
pathspec_prefix = strtol(copyfrom + 7,
160
&endptr, 10);
pkt-line.c
+2
-2
@@ -24,8 +24,8 @@ static void packet_trace(const char *buf, unsigned int len, int write)
24
strbuf_addf(&out, "packet: %12s%c ",
25
packet_trace_prefix, write ? '>' : '<');
26
27
- if ((len >= 4 && !prefixcmp(buf, "PACK")) ||
28
- (len >= 5 && !prefixcmp(buf+1, "PACK"))) {
27
+ if ((len >= 4 && starts_with(buf, "PACK")) ||
28
+ (len >= 5 && starts_with(buf+1, "PACK"))) {
29
strbuf_addstr(&out, "PACK ...");
30
unsetenv(trace_key);
31
}
pretty.c
+18
-18
@@ -40,7 +40,7 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
40
const char *fmt;
41
int i;
42
43
- if (prefixcmp(var, "pretty."))
43
+ if (!starts_with(var, "pretty."))
44
return 0;
45
46
name = var + strlen("pretty.");
@@ -67,7 +67,7 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
67
commit_format->name = xstrdup(name);
68
commit_format->format = CMIT_FMT_USERFORMAT;
69
git_config_string(&fmt, var, value);
70
- if (!prefixcmp(fmt, "format:") || !prefixcmp(fmt, "tformat:")) {
70
+ if (starts_with(fmt, "format:") || starts_with(fmt, "tformat:")) {
71
commit_format->is_tformat = fmt[0] == 't';
72
fmt = strchr(fmt, ':') + 1;
73
} else if (strchr(fmt, '%'))
@@ -115,7 +115,7 @@ static struct cmt_fmt_map *find_commit_format_recursive(const char *sought,
115
for (i = 0; i < commit_formats_len; i++) {
116
size_t match_len;
117
118
- if (prefixcmp(commit_formats[i].name, sought))
118
+ if (!starts_with(commit_formats[i].name, sought))
119
continue;
120
121
match_len = strlen(commit_formats[i].name);
@@ -151,7 +151,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
151
rev->commit_format = CMIT_FMT_DEFAULT;
152
return;
153
}
154
- if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) {
154
+ if (starts_with(arg, "format:") || starts_with(arg, "tformat:")) {
155
save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
156
return;
157
}
@@ -840,10 +840,10 @@ static void parse_commit_header(struct format_commit_context *context)
840
841
if (i == eol) {
842
break;
843
- } else if (!prefixcmp(msg + i, "author ")) {
843
+ } else if (starts_with(msg + i, "author ")) {
844
context->author.off = i + 7;
845
context->author.len = eol - i - 7;
846
- } else if (!prefixcmp(msg + i, "committer ")) {
846
+ } else if (starts_with(msg + i, "committer ")) {
847
context->committer.off = i + 10;
848
context->committer.len = eol - i - 10;
849
}
@@ -983,7 +983,7 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
983
984
if (!end)
985
return 0;
986
- if (!prefixcmp(begin, "auto,")) {
986
+ if (starts_with(begin, "auto,")) {
987
if (!want_color(c->pretty_ctx->color))
988
return end - placeholder + 1;
989
begin += 5;
@@ -994,16 +994,16 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
994
strbuf_addstr(sb, color);
995
return end - placeholder + 1;
996
}
997
- if (!prefixcmp(placeholder + 1, "red")) {
997
+ if (starts_with(placeholder + 1, "red")) {
998
strbuf_addstr(sb, GIT_COLOR_RED);
999
return 4;
1000
- } else if (!prefixcmp(placeholder + 1, "green")) {
1000
+ } else if (starts_with(placeholder + 1, "green")) {
1001
strbuf_addstr(sb, GIT_COLOR_GREEN);
1002
return 6;
1003
- } else if (!prefixcmp(placeholder + 1, "blue")) {
1003
+ } else if (starts_with(placeholder + 1, "blue")) {
1004
strbuf_addstr(sb, GIT_COLOR_BLUE);
1005
return 5;
1006
- } else if (!prefixcmp(placeholder + 1, "reset")) {
1006
+ } else if (starts_with(placeholder + 1, "reset")) {
1007
strbuf_addstr(sb, GIT_COLOR_RESET);
1008
return 6;
1009
} else
@@ -1060,11 +1060,11 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
1060
end = strchr(start, ')');
1061
if (!end || end == start)
1062
return 0;
1063
- if (!prefixcmp(start, "trunc)"))
1063
+ if (starts_with(start, "trunc)"))
1064
c->truncate = trunc_right;
1065
- else if (!prefixcmp(start, "ltrunc)"))
1065
+ else if (starts_with(start, "ltrunc)"))
1066
c->truncate = trunc_left;
1067
- else if (!prefixcmp(start, "mtrunc)"))
1067
+ else if (starts_with(start, "mtrunc)"))
1068
c->truncate = trunc_middle;
1069
else
1070
return 0;
@@ -1089,7 +1089,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1089
/* these are independent of the commit */
1090
switch (placeholder[0]) {
1091
case 'C':
1092
- if (!prefixcmp(placeholder + 1, "(auto)")) {
1092
+ if (starts_with(placeholder + 1, "(auto)")) {
1093
c->auto_color = 1;
1094
return 7; /* consumed 7 bytes, "C(auto)" */
1095
} else {
@@ -1556,7 +1556,7 @@ static void pp_header(struct pretty_print_context *pp,
1556
continue;
1557
}
1558
1559
- if (!prefixcmp(line, "parent ")) {
1559
+ if (starts_with(line, "parent ")) {
1560
if (linelen != 48)
1561
die("bad parent line in commit");
1562
continue;
@@ -1580,11 +1580,11 @@ static void pp_header(struct pretty_print_context *pp,
1580
* FULL shows both authors but not dates.
1581
* FULLER shows both authors and dates.
1582
*/
1583
- if (!prefixcmp(line, "author ")) {
1583
+ if (starts_with(line, "author ")) {
1584
strbuf_grow(sb, linelen + 80);
1585
pp_user_info(pp, "Author", sb, line + 7, encoding);
1586
}
1587
- if (!prefixcmp(line, "committer ") &&
1587
+ if (starts_with(line, "committer ") &&
1588
(pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
1589
strbuf_grow(sb, linelen + 80);
1590
pp_user_info(pp, "Commit", sb, line + 10, encoding);
refs.c
+15
-15
@@ -637,7 +637,7 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)
637
struct ref_entry *old_current_ref;
638
int retval;
639
640
- if (prefixcmp(entry->name, data->base))
640
+ if (!starts_with(entry->name, data->base))
641
return 0;
642
643
if (!(data->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
@@ -1042,7 +1042,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
1042
if (refname) {
1043
last = create_ref_entry(refname, sha1, REF_ISPACKED, 1);
1044
if (peeled == PEELED_FULLY ||
1045
- (peeled == PEELED_TAGS && !prefixcmp(refname, "refs/tags/")))
1045
+ (peeled == PEELED_TAGS && starts_with(refname, "refs/tags/")))
1046
last->flag |= REF_KNOWS_PEELED;
1047
add_ref(dir, last);
1048
continue;
@@ -1376,7 +1376,7 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
1376
return NULL;
1377
}
1378
buffer[len] = 0;
1379
- if (!prefixcmp(buffer, "refs/") &&
1379
+ if (starts_with(buffer, "refs/") &&
1380
!check_refname_format(buffer, 0)) {
1381
strcpy(refname_buffer, buffer);
1382
refname = refname_buffer;
@@ -1415,7 +1415,7 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
1415
/*
1416
* Is it a symbolic ref?
1417
*/
1418
- if (prefixcmp(buffer, "ref:")) {
1418
+ if (!starts_with(buffer, "ref:")) {
1419
/*
1420
* Please note that FETCH_HEAD has a second
1421
* line containing other data.
@@ -1837,7 +1837,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
1837
struct ref_filter filter;
1838
int ret;
1839
1840
- if (!prefix && prefixcmp(pattern, "refs/"))
1840
+ if (!prefix && !starts_with(pattern, "refs/"))
1841
strbuf_addstr(&real_pattern, "refs/");
1842
else if (prefix)
1843
strbuf_addstr(&real_pattern, prefix);
@@ -1874,9 +1874,9 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
1874
const char *prettify_refname(const char *name)
1875
{
1876
return name + (
1877
- !prefixcmp(name, "refs/heads/") ? 11 :
1878
- !prefixcmp(name, "refs/tags/") ? 10 :
1879
- !prefixcmp(name, "refs/remotes/") ? 13 :
1877
+ starts_with(name, "refs/heads/") ? 11 :
1878
+ starts_with(name, "refs/tags/") ? 10 :
1879
+ starts_with(name, "refs/remotes/") ? 13 :
1880
0);
1881
}
1882
@@ -2244,7 +2244,7 @@ static int pack_if_possible_fn(struct ref_entry *entry, void *cb_data)
2244
struct pack_refs_cb_data *cb = cb_data;
2245
enum peel_status peel_status;
2246
struct ref_entry *packed_entry;
2247
- int is_tag_ref = !prefixcmp(entry->name, "refs/tags/");
2247
+ int is_tag_ref = starts_with(entry->name, "refs/tags/");
2248
2249
/* ALWAYS pack tags */
2250
if (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref)
@@ -2679,9 +2679,9 @@ int log_ref_setup(const char *refname, char *logfile, int bufsize)
2679
2680
git_snpath(logfile, bufsize, "logs/%s", refname);
2681
if (log_all_ref_updates &&
2682
- (!prefixcmp(refname, "refs/heads/") ||
2683
- !prefixcmp(refname, "refs/remotes/") ||
2684
- !prefixcmp(refname, "refs/notes/") ||
2682
+ (starts_with(refname, "refs/heads/") ||
2683
+ starts_with(refname, "refs/remotes/") ||
2684
+ starts_with(refname, "refs/notes/") ||
2685
!strcmp(refname, "HEAD"))) {
2686
if (safe_create_leading_directories(logfile) < 0)
2687
return error("unable to create directory for %s",
@@ -2751,7 +2751,7 @@ static int log_ref_write(const char *refname, const unsigned char *old_sha1,
2751
2752
static int is_branch(const char *refname)
2753
{
2754
- return !strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/");
2754
+ return !strcmp(refname, "HEAD") || starts_with(refname, "refs/heads/");
2755
}
2756
2757
int write_ref_sha1(struct ref_lock *lock,
@@ -3450,7 +3450,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
3450
{
3451
if (!strcmp("transfer.hiderefs", var) ||
3452
/* NEEDSWORK: use parse_config_key() once both are merged */
3453
- (!prefixcmp(var, section) && var[strlen(section)] == '.' &&
3453
+ (starts_with(var, section) && var[strlen(section)] == '.' &&
3454
!strcmp(var + strlen(section), ".hiderefs"))) {
3455
char *ref;
3456
int len;
@@ -3478,7 +3478,7 @@ int ref_is_hidden(const char *refname)
3478
return 0;
3479
for_each_string_list_item(item, hide_refs) {
3480
int len;
3481
- if (prefixcmp(refname, item->string))
3481
+ if (!starts_with(refname, item->string))
3482
continue;
3483
len = strlen(item->string);
3484
if (!refname[len] || refname[len] == '/')
remote-curl.c
+7
-7
@@ -217,7 +217,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
217
free_discovery(last);
218
219
strbuf_addf(&refs_url, "%sinfo/refs", url.buf);
220
- if ((!prefixcmp(url.buf, "http://") || !prefixcmp(url.buf, "https://")) &&
220
+ if ((starts_with(url.buf, "http://") || starts_with(url.buf, "https://")) &&
221
git_env_bool("GIT_SMART_HTTP", 1)) {
222
maybe_smart = 1;
223
if (!strchr(url.buf, '?'))
@@ -755,7 +755,7 @@ static void parse_fetch(struct strbuf *buf)
755
int alloc_heads = 0, nr_heads = 0;
756
757
do {
758
- if (!prefixcmp(buf->buf, "fetch ")) {
758
+ if (starts_with(buf->buf, "fetch ")) {
759
char *p = buf->buf + strlen("fetch ");
760
char *name;
761
struct ref *ref;
@@ -878,7 +878,7 @@ static void parse_push(struct strbuf *buf)
878
int alloc_spec = 0, nr_spec = 0, i, ret;
879
880
do {
881
- if (!prefixcmp(buf->buf, "push ")) {
881
+ if (starts_with(buf->buf, "push ")) {
882
ALLOC_GROW(specs, nr_spec + 1, alloc_spec);
883
specs[nr_spec++] = xstrdup(buf->buf + 5);
884
}
@@ -941,19 +941,19 @@ int main(int argc, const char **argv)
941
}
942
if (buf.len == 0)
943
break;
944
- if (!prefixcmp(buf.buf, "fetch ")) {
944
+ if (starts_with(buf.buf, "fetch ")) {
945
if (nongit)
946
die("Fetch attempted without a local repo");
947
parse_fetch(&buf);
948
949
- } else if (!strcmp(buf.buf, "list") || !prefixcmp(buf.buf, "list ")) {
949
+ } else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {
950
int for_push = !!strstr(buf.buf + 4, "for-push");
951
output_refs(get_refs(for_push));
952
953
- } else if (!prefixcmp(buf.buf, "push ")) {
953
+ } else if (starts_with(buf.buf, "push ")) {
954
parse_push(&buf);
955
956
- } else if (!prefixcmp(buf.buf, "option ")) {
956
+ } else if (starts_with(buf.buf, "option ")) {
957
char *name = buf.buf + strlen("option ");
958
char *value = strchr(name, ' ');
959
int result;
remote-testsvn.c
+5
-5
@@ -82,7 +82,7 @@ static int parse_rev_note(const char *msg, struct rev_note *res)
82
len = end ? end - msg : strlen(msg);
83
84
key = "Revision-number: ";
85
- if (!prefixcmp(msg, key)) {
85
+ if (starts_with(msg, key)) {
86
long i;
87
char *end;
88
value = msg + strlen(key);
@@ -154,7 +154,7 @@ static void check_or_regenerate_marks(int latestrev)
154
} else {
155
strbuf_addf(&sb, ":%d ", latestrev);
156
while (strbuf_getline(&line, marksfile, '\n') != EOF) {
157
- if (!prefixcmp(line.buf, sb.buf)) {
157
+ if (starts_with(line.buf, sb.buf)) {
158
found++;
159
break;
160
}
@@ -264,7 +264,7 @@ static int do_command(struct strbuf *line)
264
return 1; /* end of command stream, quit */
265
}
266
if (batch_cmd) {
267
- if (prefixcmp(batch_cmd->name, line->buf))
267
+ if (!starts_with(batch_cmd->name, line->buf))
268
die("Active %s batch interrupted by %s", batch_cmd->name, line->buf);
269
/* buffer batch lines */
270
string_list_append(&batchlines, line->buf);
@@ -272,7 +272,7 @@ static int do_command(struct strbuf *line)
272
}
273
274
for (p = input_command_list; p->name; p++) {
275
- if (!prefixcmp(line->buf, p->name) && (strlen(p->name) == line->len ||
275
+ if (starts_with(line->buf, p->name) && (strlen(p->name) == line->len ||
276
line->buf[strlen(p->name)] == ' ')) {
277
if (p->batchable) {
278
batch_cmd = p;
@@ -304,7 +304,7 @@ int main(int argc, char **argv)
304
remote = remote_get(argv[1]);
305
url_in = (argc == 3) ? argv[2] : remote->url[0];
306
307
- if (!prefixcmp(url_in, "file://")) {
307
+ if (starts_with(url_in, "file://")) {
308
dump_from_file = 1;
309
url = url_decode(url_in + sizeof("file://")-1);
310
} else {
remote.c
+23
-23
@@ -76,7 +76,7 @@ static const char *alias_url(const char *url, struct rewrites *r)
76
if (!r->rewrite[i])
77
continue;
78
for (j = 0; j < r->rewrite[i]->instead_of_nr; j++) {
79
- if (!prefixcmp(url, r->rewrite[i]->instead_of[j].s) &&
79
+ if (starts_with(url, r->rewrite[i]->instead_of[j].s) &&
80
(!longest ||
81
longest->len < r->rewrite[i]->instead_of[j].len)) {
82
longest = &(r->rewrite[i]->instead_of[j]);
@@ -239,13 +239,13 @@ static void read_remotes_file(struct remote *remote)
239
int value_list;
240
char *s, *p;
241
242
- if (!prefixcmp(buffer, "URL:")) {
242
+ if (starts_with(buffer, "URL:")) {
243
value_list = 0;
244
s = buffer + 4;
245
- } else if (!prefixcmp(buffer, "Push:")) {
245
+ } else if (starts_with(buffer, "Push:")) {
246
value_list = 1;
247
s = buffer + 5;
248
- } else if (!prefixcmp(buffer, "Pull:")) {
248
+ } else if (starts_with(buffer, "Pull:")) {
249
value_list = 2;
250
s = buffer + 5;
251
} else
@@ -337,7 +337,7 @@ static int handle_config(const char *key, const char *value, void *cb)
337
const char *subkey;
338
struct remote *remote;
339
struct branch *branch;
340
- if (!prefixcmp(key, "branch.")) {
340
+ if (starts_with(key, "branch.")) {
341
name = key + 7;
342
subkey = strrchr(name, '.');
343
if (!subkey)
@@ -361,7 +361,7 @@ static int handle_config(const char *key, const char *value, void *cb)
361
}
362
return 0;
363
}
364
- if (!prefixcmp(key, "url.")) {
364
+ if (starts_with(key, "url.")) {
365
struct rewrite *rewrite;
366
name = key + 4;
367
subkey = strrchr(name, '.');
@@ -380,7 +380,7 @@ static int handle_config(const char *key, const char *value, void *cb)
380
}
381
}
382
383
- if (prefixcmp(key, "remote."))
383
+ if (!starts_with(key, "remote."))
384
return 0;
385
name = key + 7;
386
@@ -487,7 +487,7 @@ static void read_config(void)
487
current_branch = NULL;
488
head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
489
if (head_ref && (flag & REF_ISSYMREF) &&
490
- !prefixcmp(head_ref, "refs/heads/")) {
490
+ starts_with(head_ref, "refs/heads/")) {
491
current_branch =
492
make_branch(head_ref + strlen("refs/heads/"), 0);
493
}
@@ -982,8 +982,8 @@ static int count_refspec_match(const char *pattern,
982
*/
983
if (namelen != patlen &&
984
patlen != namelen - 5 &&
985
- prefixcmp(name, "refs/heads/") &&
986
- prefixcmp(name, "refs/tags/")) {
985
+ !starts_with(name, "refs/heads/") &&
986
+ !starts_with(name, "refs/tags/")) {
987
/* We want to catch the case where only weak
988
* matches are found and there are multiple
989
* matches, and where more than one strong
@@ -1054,9 +1054,9 @@ static char *guess_ref(const char *name, struct ref *peer)
1054
if (!r)
1055
return NULL;
1056
1057
- if (!prefixcmp(r, "refs/heads/"))
1057
+ if (starts_with(r, "refs/heads/"))
1058
strbuf_addstr(&buf, "refs/heads/");
1059
- else if (!prefixcmp(r, "refs/tags/"))
1059
+ else if (starts_with(r, "refs/tags/"))
1060
strbuf_addstr(&buf, "refs/tags/");
1061
else
1062
return NULL;
@@ -1104,7 +1104,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
1104
dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
1105
if (!dst_value ||
1106
((flag & REF_ISSYMREF) &&
1107
- prefixcmp(dst_value, "refs/heads/")))
1107
+ !starts_with(dst_value, "refs/heads/")))
1108
die("%s cannot be resolved to branch.",
1109
matched_src->name);
1110
}
@@ -1193,7 +1193,7 @@ static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref
1193
* including refs outside refs/heads/ hierarchy, but
1194
* that does not make much sense these days.
1195
*/
1196
- if (!send_mirror && prefixcmp(ref->name, "refs/heads/"))
1196
+ if (!send_mirror && !starts_with(ref->name, "refs/heads/"))
1197
return NULL;
1198
name = xstrdup(ref->name);
1199
}
@@ -1248,7 +1248,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
1248
add_to_tips(&sent_tips, ref->peer_ref->new_sha1);
1249
else
1250
add_to_tips(&sent_tips, ref->old_sha1);
1251
- if (!prefixcmp(ref->name, "refs/tags/"))
1251
+ if (starts_with(ref->name, "refs/tags/"))
1252
string_list_append(&dst_tag, ref->name);
1253
}
1254
clear_commit_marks_many(sent_tips.nr, sent_tips.tip, TMP_MARK);
@@ -1257,7 +1257,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
1257
1258
/* Collect tags they do not have. */
1259
for (ref = src; ref; ref = ref->next) {
1260
- if (prefixcmp(ref->name, "refs/tags/"))
1260
+ if (!starts_with(ref->name, "refs/tags/"))
1261
continue; /* not a tag */
1262
if (string_list_has_string(&dst_tag, ref->name))
1263
continue; /* they already have it */
@@ -1481,7 +1481,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
1481
*/
1482
1483
else if (!ref->deletion && !is_null_sha1(ref->old_sha1)) {
1484
- if (!prefixcmp(ref->name, "refs/tags/"))
1484
+ if (starts_with(ref->name, "refs/tags/"))
1485
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
1486
else if (!has_sha1_file(ref->old_sha1))
1487
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
@@ -1607,12 +1607,12 @@ static struct ref *get_local_ref(const char *name)
1607
if (!name || name[0] == '\0')
1608
return NULL;
1609
1610
- if (!prefixcmp(name, "refs/"))
1610
+ if (starts_with(name, "refs/"))
1611
return alloc_ref(name);
1612
1613
- if (!prefixcmp(name, "heads/") ||
1614
- !prefixcmp(name, "tags/") ||
1615
- !prefixcmp(name, "remotes/"))
1613
+ if (starts_with(name, "heads/") ||
1614
+ starts_with(name, "tags/") ||
1615
+ starts_with(name, "remotes/"))
1616
return alloc_ref_with_prefix("refs/", 5, name);
1617
1618
return alloc_ref_with_prefix("refs/heads/", 11, name);
@@ -1647,7 +1647,7 @@ int get_fetch_map(const struct ref *remote_refs,
1647
1648
for (rmp = &ref_map; *rmp; ) {
1649
if ((*rmp)->peer_ref) {
1650
- if (prefixcmp((*rmp)->peer_ref->name, "refs/") ||
1650
+ if (!starts_with((*rmp)->peer_ref->name, "refs/") ||
1651
check_refname_format((*rmp)->peer_ref->name, 0)) {
1652
struct ref *ignore = *rmp;
1653
error("* Ignoring funny ref '%s' locally",
@@ -1931,7 +1931,7 @@ struct ref *guess_remote_head(const struct ref *head,
1931
/* Look for another ref that points there */
1932
for (r = refs; r; r = r->next) {
1933
if (r != head &&
1934
- !prefixcmp(r->name, "refs/heads/") &&
1934
+ starts_with(r->name, "refs/heads/") &&
1935
!hashcmp(r->old_sha1, head->old_sha1)) {
1936
*tail = copy_ref(r);
1937
tail = &((*tail)->next);
revision.c
+19
-19
@@ -1592,9 +1592,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1592
!strcmp(arg, "--tags") || !strcmp(arg, "--remotes") ||
1593
!strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
1594
!strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
1595
- !strcmp(arg, "--bisect") || !prefixcmp(arg, "--glob=") ||
1596
- !prefixcmp(arg, "--branches=") || !prefixcmp(arg, "--tags=") ||
1597
- !prefixcmp(arg, "--remotes=") || !prefixcmp(arg, "--no-walk="))
1595
+ !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") ||
1596
+ starts_with(arg, "--branches=") || starts_with(arg, "--tags=") ||
1597
+ starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk="))
1598
{
1599
unkv[(*unkc)++] = arg;
1600
return 1;
@@ -1617,7 +1617,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1617
revs->max_count = atoi(argv[1]);
1618
revs->no_walk = 0;
1619
return 2;
1620
- } else if (!prefixcmp(arg, "-n")) {
1620
+ } else if (starts_with(arg, "-n")) {
1621
revs->max_count = atoi(arg + 2);
1622
revs->no_walk = 0;
1623
} else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
@@ -1677,7 +1677,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1677
} else if (!strcmp(arg, "--author-date-order")) {
1678
revs->sort_order = REV_SORT_BY_AUTHOR_DATE;
1679
revs->topo_order = 1;
1680
- } else if (!prefixcmp(arg, "--early-output")) {
1680
+ } else if (starts_with(arg, "--early-output")) {
1681
int count = 100;
1682
switch (arg[14]) {
1683
case '=':
@@ -1702,13 +1702,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1702
revs->min_parents = 2;
1703
} else if (!strcmp(arg, "--no-merges")) {
1704
revs->max_parents = 1;
1705
- } else if (!prefixcmp(arg, "--min-parents=")) {
1705
+ } else if (starts_with(arg, "--min-parents=")) {
1706
revs->min_parents = atoi(arg+14);
1707
- } else if (!prefixcmp(arg, "--no-min-parents")) {
1707
+ } else if (starts_with(arg, "--no-min-parents")) {
1708
revs->min_parents = 0;
1709
- } else if (!prefixcmp(arg, "--max-parents=")) {
1709
+ } else if (starts_with(arg, "--max-parents=")) {
1710
revs->max_parents = atoi(arg+14);
1711
- } else if (!prefixcmp(arg, "--no-max-parents")) {
1711
+ } else if (starts_with(arg, "--no-max-parents")) {
1712
revs->max_parents = -1;
1713
} else if (!strcmp(arg, "--boundary")) {
1714
revs->boundary = 1;
@@ -1758,7 +1758,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1758
revs->verify_objects = 1;
1759
} else if (!strcmp(arg, "--unpacked")) {
1760
revs->unpacked = 1;
1761
- } else if (!prefixcmp(arg, "--unpacked=")) {
1761
+ } else if (starts_with(arg, "--unpacked=")) {
1762
die("--unpacked=<packfile> no longer supported.");
1763
} else if (!strcmp(arg, "-r")) {
1764
revs->diff = 1;
@@ -1783,7 +1783,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1783
revs->verbose_header = 1;
1784
revs->pretty_given = 1;
1785
get_commit_format(arg+8, revs);
1786
- } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
1786
+ } else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
1787
/*
1788
* Detached form ("--pretty X" as opposed to "--pretty=X")
1789
* not allowed, since the argument is optional.
@@ -1797,12 +1797,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1797
revs->notes_opt.use_default_notes = 1;
1798
} else if (!strcmp(arg, "--show-signature")) {
1799
revs->show_signature = 1;
1800
- } else if (!prefixcmp(arg, "--show-notes=") ||
1801
- !prefixcmp(arg, "--notes=")) {
1800
+ } else if (starts_with(arg, "--show-notes=") ||
1801
+ starts_with(arg, "--notes=")) {
1802
struct strbuf buf = STRBUF_INIT;
1803
revs->show_notes = 1;
1804
revs->show_notes_given = 1;
1805
- if (!prefixcmp(arg, "--show-notes")) {
1805
+ if (starts_with(arg, "--show-notes")) {
1806
if (revs->notes_opt.use_default_notes < 0)
1807
revs->notes_opt.use_default_notes = 1;
1808
strbuf_addstr(&buf, arg+13);
@@ -1845,7 +1845,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1845
revs->abbrev = 0;
1846
} else if (!strcmp(arg, "--abbrev")) {
1847
revs->abbrev = DEFAULT_ABBREV;
1848
- } else if (!prefixcmp(arg, "--abbrev=")) {
1848
+ } else if (starts_with(arg, "--abbrev=")) {
1849
revs->abbrev = strtoul(arg + 9, NULL, 10);
1850
if (revs->abbrev < MINIMUM_ABBREV)
1851
revs->abbrev = MINIMUM_ABBREV;
@@ -1984,15 +1984,15 @@ static int handle_revision_pseudo_opt(const char *submodule,
1984
init_all_refs_cb(&cb, revs, *flags);
1985
for_each_glob_ref(handle_one_ref, optarg, &cb);
1986
return argcount;
1987
- } else if (!prefixcmp(arg, "--branches=")) {
1987
+ } else if (starts_with(arg, "--branches=")) {
1988
struct all_refs_cb cb;
1989
init_all_refs_cb(&cb, revs, *flags);
1990
for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
1991
- } else if (!prefixcmp(arg, "--tags=")) {
1991
+ } else if (starts_with(arg, "--tags=")) {
1992
struct all_refs_cb cb;
1993
init_all_refs_cb(&cb, revs, *flags);
1994
for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
1995
- } else if (!prefixcmp(arg, "--remotes=")) {
1995
+ } else if (starts_with(arg, "--remotes=")) {
1996
struct all_refs_cb cb;
1997
init_all_refs_cb(&cb, revs, *flags);
1998
for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
@@ -2002,7 +2002,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
2002
*flags ^= UNINTERESTING | BOTTOM;
2003
} else if (!strcmp(arg, "--no-walk")) {
2004
revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
2005
- } else if (!prefixcmp(arg, "--no-walk=")) {
2005
+ } else if (starts_with(arg, "--no-walk=")) {
2006
/*
2007
* Detached form ("--no-walk X" as opposed to "--no-walk=X")
2008
* not allowed, since the argument is optional.
send-pack.c
+2
-2
@@ -109,7 +109,7 @@ static int receive_status(int in, struct ref *refs)
109
struct ref *hint;
110
int ret = 0;
111
char *line = packet_read_line(in, NULL);
112
- if (prefixcmp(line, "unpack "))
112
+ if (!starts_with(line, "unpack "))
113
return error("did not receive remote status");
114
if (strcmp(line, "unpack ok")) {
115
error("unpack failed: %s", line + 7);
@@ -122,7 +122,7 @@ static int receive_status(int in, struct ref *refs)
122
line = packet_read_line(in, NULL);
123
if (!line)
124
break;
125
- if (prefixcmp(line, "ok ") && prefixcmp(line, "ng ")) {
125
+ if (!starts_with(line, "ok ") && !starts_with(line, "ng ")) {
126
error("invalid ref status from remote: %s", line);
127
ret = -1;
128
break;
sequencer.c
+4
-4
@@ -41,7 +41,7 @@ static int is_cherry_picked_from_line(const char *buf, int len)
41
* We only care that it looks roughly like (cherry picked from ...)
42
*/
43
return len > strlen(cherry_picked_prefix) + 1 &&
44
- !prefixcmp(buf, cherry_picked_prefix) && buf[len - 1] == ')';
44
+ starts_with(buf, cherry_picked_prefix) && buf[len - 1] == ')';
45
}
46
47
/*
@@ -180,7 +180,7 @@ static char *get_encoding(const char *message)
180
while (*p && *p != '\n') {
181
for (eol = p + 1; *eol && *eol != '\n'; eol++)
182
; /* do nothing */
183
- if (!prefixcmp(p, "encoding ")) {
183
+ if (starts_with(p, "encoding ")) {
184
char *result = xmalloc(eol - 8 - p);
185
strlcpy(result, p + 9, eol - 8 - p);
186
return result;
@@ -705,10 +705,10 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
705
char *end_of_object_name;
706
int saved, status, padding;
707
708
- if (!prefixcmp(bol, "pick")) {
708
+ if (starts_with(bol, "pick")) {
709
action = REPLAY_PICK;
710
bol += strlen("pick");
711
- } else if (!prefixcmp(bol, "revert")) {
711
+ } else if (starts_with(bol, "revert")) {
712
action = REPLAY_REVERT;
713
bol += strlen("revert");
714
} else
setup.c
+2
-2
@@ -82,7 +82,7 @@ int check_filename(const char *prefix, const char *arg)
82
const char *name;
83
struct stat st;
84
85
- if (!prefixcmp(arg, ":/")) {
85
+ if (starts_with(arg, ":/")) {
86
if (arg[2] == '\0') /* ":/" is root dir, always exists */
87
return 1;
88
name = arg + 2;
@@ -304,7 +304,7 @@ const char *read_gitfile(const char *path)
304
if (len != st.st_size)
305
die("Error reading %s", path);
306
buf[len] = '\0';
307
- if (prefixcmp(buf, "gitdir: "))
307
+ if (!starts_with(buf, "gitdir: "))
308
die("Invalid gitfile format: %s", path);
309
while (buf[len - 1] == '\n' || buf[len - 1] == '\r')
310
len--;
sha1_name.c
+8
-8
@@ -546,7 +546,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
546
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
547
&co_time, &co_tz, &co_cnt)) {
548
if (!len) {
549
- if (!prefixcmp(real_ref, "refs/heads/")) {
549
+ if (starts_with(real_ref, "refs/heads/")) {
550
str = real_ref + 11;
551
len = strlen(real_ref + 11);
552
} else {
@@ -676,15 +676,15 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
676
return -1;
677
678
sp++; /* beginning of type name, or closing brace for empty */
679
- if (!prefixcmp(sp, "commit}"))
679
+ if (starts_with(sp, "commit}"))
680
expected_type = OBJ_COMMIT;
681
- else if (!prefixcmp(sp, "tag}"))
681
+ else if (starts_with(sp, "tag}"))
682
expected_type = OBJ_TAG;
683
- else if (!prefixcmp(sp, "tree}"))
683
+ else if (starts_with(sp, "tree}"))
684
expected_type = OBJ_TREE;
685
- else if (!prefixcmp(sp, "blob}"))
685
+ else if (starts_with(sp, "blob}"))
686
expected_type = OBJ_BLOB;
687
- else if (!prefixcmp(sp, "object}"))
687
+ else if (starts_with(sp, "object}"))
688
expected_type = OBJ_ANY;
689
else if (sp[0] == '}')
690
expected_type = OBJ_NONE;
@@ -911,7 +911,7 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
911
const char *match = NULL, *target = NULL;
912
size_t len;
913
914
- if (!prefixcmp(message, "checkout: moving from ")) {
914
+ if (starts_with(message, "checkout: moving from ")) {
915
match = message + strlen("checkout: moving from ");
916
target = strstr(match, " to ");
917
}
@@ -1304,7 +1304,7 @@ static void diagnose_invalid_index_path(int stage,
1304
1305
static char *resolve_relative_path(const char *rel)
1306
{
1307
- if (prefixcmp(rel, "./") && prefixcmp(rel, "../"))
1307
+ if (!starts_with(rel, "./") && !starts_with(rel, "../"))
1308
return NULL;
1309
1310
if (!startup_info)
shell.c
+1
-1
@@ -15,7 +15,7 @@ static int do_generic_cmd(const char *me, char *arg)
15
setup_path();
16
if (!arg || !(arg = sq_dequote(arg)))
17
die("bad argument");
18
- if (prefixcmp(me, "git-"))
18
+ if (!starts_with(me, "git-"))
19
die("bad command");
20
21
my_argv[0] = me + 4;
submodule.c
+1
-1
@@ -201,7 +201,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
201
202
int submodule_config(const char *var, const char *value, void *cb)
203
{
204
- if (!prefixcmp(var, "submodule."))
204
+ if (starts_with(var, "submodule."))
205
return parse_submodule_config_option(var, value);
206
else if (!strcmp(var, "fetch.recursesubmodules")) {
207
config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
tag.c
+5
-5
@@ -86,7 +86,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
86
return -1;
87
bufptr += 48; /* "object " + sha1 + "\n" */
88
89
- if (prefixcmp(bufptr, "type "))
89
+ if (!starts_with(bufptr, "type "))
90
return -1;
91
bufptr += 5;
92
nl = memchr(bufptr, '\n', tail - bufptr);
@@ -109,7 +109,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
109
item->tagged = NULL;
110
}
111
112
- if (bufptr + 4 < tail && !prefixcmp(bufptr, "tag "))
112
+ if (bufptr + 4 < tail && starts_with(bufptr, "tag "))
113
; /* good */
114
else
115
return -1;
@@ -120,7 +120,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
120
item->tag = xmemdupz(bufptr, nl - bufptr);
121
bufptr = nl + 1;
122
123
- if (bufptr + 7 < tail && !prefixcmp(bufptr, "tagger "))
123
+ if (bufptr + 7 < tail && starts_with(bufptr, "tagger "))
124
item->date = parse_tag_date(bufptr, tail);
125
else
126
item->date = 0;
@@ -160,8 +160,8 @@ size_t parse_signature(const char *buf, unsigned long size)
160
{
161
char *eol;
162
size_t len = 0;
163
- while (len < size && prefixcmp(buf + len, PGP_SIGNATURE) &&
164
- prefixcmp(buf + len, PGP_MESSAGE)) {
163
+ while (len < size && !starts_with(buf + len, PGP_SIGNATURE) &&
164
+ !starts_with(buf + len, PGP_MESSAGE)) {
165
eol = memchr(buf + len, '\n', size - len);
166
len += eol ? eol - (buf + len) + 1 : size - len;
167
}
test-line-buffer.c
+3
-3
@@ -19,7 +19,7 @@ static void handle_command(const char *command, const char *arg, struct line_buf
19
{
20
switch (*command) {
21
case 'b':
22
- if (!prefixcmp(command, "binary ")) {
22
+ if (starts_with(command, "binary ")) {
23
struct strbuf sb = STRBUF_INIT;
24
strbuf_addch(&sb, '>');
25
buffer_read_binary(buf, &sb, strtouint32(arg));
@@ -28,12 +28,12 @@ static void handle_command(const char *command, const char *arg, struct line_buf
28
return;
29
}
30
case 'c':
31
- if (!prefixcmp(command, "copy ")) {
31
+ if (starts_with(command, "copy ")) {
32
buffer_copy_bytes(buf, strtouint32(arg));
33
return;
34
}
35
case 's':
36
- if (!prefixcmp(command, "skip ")) {
36
+ if (starts_with(command, "skip ")) {
37
buffer_skip_bytes(buf, strtouint32(arg));
38
return;
39
}
test-string-list.c
+1
-1
@@ -38,7 +38,7 @@ static void write_list_compact(const struct string_list *list)
38
static int prefix_cb(struct string_list_item *item, void *cb_data)
39
{
40
const char *prefix = (const char *)cb_data;
41
- return !prefixcmp(item->string, prefix);
41
+ return starts_with(item->string, prefix);
42
}
43
44
int main(int argc, char **argv)
transport-helper.c
+8
-8
@@ -190,7 +190,7 @@ static struct child_process *get_helper(struct transport *transport)
190
data->export = 1;
191
else if (!strcmp(capname, "check-connectivity"))
192
data->check_connectivity = 1;
193
- else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
193
+ else if (!data->refspecs && starts_with(capname, "refspec ")) {
194
ALLOC_GROW(refspecs,
195
refspec_nr + 1,
196
refspec_alloc);
@@ -199,17 +199,17 @@ static struct child_process *get_helper(struct transport *transport)
199
data->connect = 1;
200
} else if (!strcmp(capname, "signed-tags")) {
201
data->signed_tags = 1;
202
- } else if (!prefixcmp(capname, "export-marks ")) {
202
+ } else if (starts_with(capname, "export-marks ")) {
203
struct strbuf arg = STRBUF_INIT;
204
strbuf_addstr(&arg, "--export-marks=");
205
strbuf_addstr(&arg, capname + strlen("export-marks "));
206
data->export_marks = strbuf_detach(&arg, NULL);
207
- } else if (!prefixcmp(capname, "import-marks")) {
207
+ } else if (starts_with(capname, "import-marks")) {
208
struct strbuf arg = STRBUF_INIT;
209
strbuf_addstr(&arg, "--import-marks=");
210
strbuf_addstr(&arg, capname + strlen("import-marks "));
211
data->import_marks = strbuf_detach(&arg, NULL);
212
- } else if (!prefixcmp(capname, "no-private-update")) {
212
+ } else if (starts_with(capname, "no-private-update")) {
213
data->no_private_update = 1;
214
} else if (mandatory) {
215
die("Unknown mandatory capability %s. This remote "
@@ -311,7 +311,7 @@ static int set_helper_option(struct transport *transport,
311
312
if (!strcmp(buf.buf, "ok"))
313
ret = 0;
314
- else if (!prefixcmp(buf.buf, "error")) {
314
+ else if (starts_with(buf.buf, "error")) {
315
ret = -1;
316
} else if (!strcmp(buf.buf, "unsupported"))
317
ret = 1;
@@ -375,7 +375,7 @@ static int fetch_with_fetch(struct transport *transport,
375
while (1) {
376
recvline(data, &buf);
377
378
- if (!prefixcmp(buf.buf, "lock ")) {
378
+ if (starts_with(buf.buf, "lock ")) {
379
const char *name = buf.buf + 5;
380
if (transport->pack_lockfile)
381
warning("%s also locked %s", data->name, name);
@@ -646,10 +646,10 @@ static int push_update_ref_status(struct strbuf *buf,
646
char *refname, *msg;
647
int status;
648
649
- if (!prefixcmp(buf->buf, "ok ")) {
649
+ if (starts_with(buf->buf, "ok ")) {
650
status = REF_STATUS_OK;
651
refname = buf->buf + 3;
652
- } else if (!prefixcmp(buf->buf, "error ")) {
652
+ } else if (starts_with(buf->buf, "error ")) {
653
status = REF_STATUS_REMOTE_REJECT;
654
refname = buf->buf + 6;
655
} else
transport.c
+14
-14
@@ -169,13 +169,13 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
169
remotename = ref->name;
170
tmp = resolve_ref_unsafe(localname, sha, 1, &flag);
171
if (tmp && flag & REF_ISSYMREF &&
172
- !prefixcmp(tmp, "refs/heads/"))
172
+ starts_with(tmp, "refs/heads/"))
173
localname = tmp;
174
175
/* Both source and destination must be local branches. */
176
- if (!localname || prefixcmp(localname, "refs/heads/"))
176
+ if (!localname || !starts_with(localname, "refs/heads/"))
177
continue;
178
- if (!remotename || prefixcmp(remotename, "refs/heads/"))
178
+ if (!remotename || !starts_with(remotename, "refs/heads/"))
179
continue;
180
181
if (!pretend)
@@ -191,7 +191,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
191
192
static const char *rsync_url(const char *url)
193
{
194
- return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
194
+ return !starts_with(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
195
}
196
197
static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
@@ -296,8 +296,8 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
296
FILE *f;
297
298
/* when called via for_each_ref(), flags is non-zero */
299
- if (flags && prefixcmp(name, "refs/heads/") &&
300
- prefixcmp(name, "refs/tags/"))
299
+ if (flags && !starts_with(name, "refs/heads/") &&
300
+ !starts_with(name, "refs/tags/"))
301
return 0;
302
303
strbuf_addstr(buf, name);
@@ -652,7 +652,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
652
print_ref_status('-', "[deleted]", ref, NULL, NULL, porcelain);
653
else if (is_null_sha1(ref->old_sha1))
654
print_ref_status('*',
655
- (!prefixcmp(ref->name, "refs/tags/") ? "[new tag]" :
655
+ (starts_with(ref->name, "refs/tags/") ? "[new tag]" :
656
"[new branch]"),
657
ref, ref->peer_ref, NULL, porcelain);
658
else {
@@ -930,13 +930,13 @@ struct transport *transport_get(struct remote *remote, const char *url)
930
931
while (is_urlschemechar(p == url, *p))
932
p++;
933
- if (!prefixcmp(p, "::"))
933
+ if (starts_with(p, "::"))
934
helper = xstrndup(url, p - url);
935
}
936
937
if (helper) {
938
transport_helper_init(ret, helper);
939
- } else if (!prefixcmp(url, "rsync:")) {
939
+ } else if (starts_with(url, "rsync:")) {
940
ret->get_refs_list = get_refs_via_rsync;
941
ret->fetch = fetch_objs_via_rsync;
942
ret->push = rsync_transport_push;
@@ -949,11 +949,11 @@ struct transport *transport_get(struct remote *remote, const char *url)
949
ret->disconnect = close_bundle;
950
ret->smart_options = NULL;
951
} else if (!is_url(url)
952
- || !prefixcmp(url, "file://")
953
- || !prefixcmp(url, "git://")
954
- || !prefixcmp(url, "ssh://")
955
- || !prefixcmp(url, "git+ssh://")
956
- || !prefixcmp(url, "ssh+git://")) {
952
+ || starts_with(url, "file://")
953
+ || starts_with(url, "git://")
954
+ || starts_with(url, "ssh://")
955
+ || starts_with(url, "git+ssh://")
956
+ || starts_with(url, "ssh+git://")) {
957
/* These are builtin smart transports. */
958
struct git_transport_data *data = xcalloc(1, sizeof(*data));
959
ret->data = data;
upload-pack.c
+5
-5
@@ -394,7 +394,7 @@ static int get_common_commits(void)
394
got_other = 0;
395
continue;
396
}
397
- if (!prefixcmp(line, "have ")) {
397
+ if (starts_with(line, "have ")) {
398
switch (got_sha1(line+5, sha1)) {
399
case -1: /* they have what we do not */
400
got_other = 1;
@@ -540,7 +540,7 @@ static void receive_needs(void)
540
if (!line)
541
break;
542
543
- if (!prefixcmp(line, "shallow ")) {
543
+ if (starts_with(line, "shallow ")) {
544
unsigned char sha1[20];
545
struct object *object;
546
if (get_sha1_hex(line + 8, sha1))
@@ -556,14 +556,14 @@ static void receive_needs(void)
556
}
557
continue;
558
}
559
- if (!prefixcmp(line, "deepen ")) {
559
+ if (starts_with(line, "deepen ")) {
560
char *end;
561
depth = strtol(line + 7, &end, 0);
562
if (end == line + 7 || depth <= 0)
563
die("Invalid deepen: %s", line);
564
continue;
565
}
566
- if (prefixcmp(line, "want ") ||
566
+ if (!starts_with(line, "want ") ||
567
get_sha1_hex(line+5, sha1_buf))
568
die("git upload-pack: protocol error, "
569
"expected to get sha, not '%s'", line);
@@ -815,7 +815,7 @@ int main(int argc, char **argv)
815
strict = 1;
816
continue;
817
}
818
- if (!prefixcmp(arg, "--timeout=")) {
818
+ if (starts_with(arg, "--timeout=")) {
819
timeout = atoi(arg+10);
820
daemon_mode = 1;
821
continue;
wt-status.c
+8
-8
@@ -803,7 +803,7 @@ static void wt_status_print_tracking(struct wt_status *s)
803
int i;
804
805
assert(s->branch && !s->is_initial);
806
- if (prefixcmp(s->branch, "refs/heads/"))
806
+ if (!starts_with(s->branch, "refs/heads/"))
807
return;
808
branch = branch_get(s->branch + 11);
809
if (!format_tracking_info(branch, &sb))
@@ -1062,9 +1062,9 @@ static char *read_and_strip_branch(const char *path)
1062
strbuf_setlen(&sb, sb.len - 1);
1063
if (!sb.len)
1064
goto got_nothing;
1065
- if (!prefixcmp(sb.buf, "refs/heads/"))
1065
+ if (starts_with(sb.buf, "refs/heads/"))
1066
strbuf_remove(&sb,0, strlen("refs/heads/"));
1067
- else if (!prefixcmp(sb.buf, "refs/"))
1067
+ else if (starts_with(sb.buf, "refs/"))
1068
;
1069
else if (!get_sha1_hex(sb.buf, sha1)) {
1070
const char *abbrev;
@@ -1094,7 +1094,7 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
1094
struct grab_1st_switch_cbdata *cb = cb_data;
1095
const char *target = NULL, *end;
1096
1097
- if (prefixcmp(message, "checkout: moving from "))
1097
+ if (!starts_with(message, "checkout: moving from "))
1098
return 0;
1099
message += strlen("checkout: moving from ");
1100
target = strstr(message, " to ");
@@ -1129,9 +1129,9 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1129
((commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&
1130
!hashcmp(cb.nsha1, commit->object.sha1)))) {
1131
int ofs;
1132
- if (!prefixcmp(ref, "refs/tags/"))
1132
+ if (starts_with(ref, "refs/tags/"))
1133
ofs = strlen("refs/tags/");
1134
- else if (!prefixcmp(ref, "refs/remotes/"))
1134
+ else if (starts_with(ref, "refs/remotes/"))
1135
ofs = strlen("refs/remotes/");
1136
else
1137
ofs = 0;
@@ -1220,7 +1220,7 @@ void wt_status_print(struct wt_status *s)
1220
if (s->branch) {
1221
const char *on_what = _("On branch ");
1222
const char *branch_name = s->branch;
1223
- if (!prefixcmp(branch_name, "refs/heads/"))
1223
+ if (starts_with(branch_name, "refs/heads/"))
1224
branch_name += 11;
1225
else if (!strcmp(branch_name, "HEAD")) {
1226
branch_status_color = color(WT_STATUS_NOBRANCH, s);
@@ -1421,7 +1421,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1421
return;
1422
branch_name = s->branch;
1423
1424
- if (!prefixcmp(branch_name, "refs/heads/"))
1424
+ if (starts_with(branch_name, "refs/heads/"))
1425
branch_name += 11;
1426
else if (!strcmp(branch_name, "HEAD")) {
1427
branch_name = _("HEAD (no branch)");