prefixcmp(): fix-up mechanical conversion.
Previous step converted use of strncmp() with literal string mechanically even when the result is only used as a boolean: if (!strncmp("foo", arg, 3)) ==> if (!(-prefixcmp(arg, "foo"))) This step manually cleans them up to read: if (!prefixcmp(arg, "foo")) Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 20, 2007 at 01:54 UTC
599065a3bb94ae9f48e3808b8fafc8443017af28
13 files changed
+44
-44
builtin-archive.c
+1
-1
@@ -35,7 +35,7 @@ static int run_remote_archiver(const char *remote, int argc,
35
36
for (i = 1; i < argc; i++) {
37
const char *arg = argv[i];
38
- if (!(-prefixcmp(arg, "--exec="))) {
38
+ if (!prefixcmp(arg, "--exec=")) {
39
if (exec_at)
40
die("multiple --exec specified");
41
exec = arg + 7;
builtin-blame.c
+3
-3
@@ -2097,17 +2097,17 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2097
output_option |= OUTPUT_LONG_OBJECT_NAME;
2098
else if (!strcmp("-S", arg) && ++i < argc)
2099
revs_file = argv[i];
2100
- else if (!(-prefixcmp(arg, "-M"))) {
2100
+ else if (!prefixcmp(arg, "-M")) {
2101
opt |= PICKAXE_BLAME_MOVE;
2102
blame_move_score = parse_score(arg+2);
2103
}
2104
- else if (!(-prefixcmp(arg, "-C"))) {
2104
+ else if (!prefixcmp(arg, "-C")) {
2105
if (opt & PICKAXE_BLAME_COPY)
2106
opt |= PICKAXE_BLAME_COPY_HARDER;
2107
opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
2108
blame_copy_score = parse_score(arg+2);
2109
}
2110
- else if (!(-prefixcmp(arg, "-L"))) {
2110
+ else if (!prefixcmp(arg, "-L")) {
2111
if (!arg[2]) {
2112
if (++i >= argc)
2113
usage(blame_usage);
builtin-grep.c
+3
-3
@@ -527,9 +527,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
527
opt.word_regexp = 1;
528
continue;
529
}
530
- if (!(-prefixcmp(arg, "-A")) ||
531
- !(-prefixcmp(arg, "-B")) ||
532
- !(-prefixcmp(arg, "-C")) ||
530
+ if (!prefixcmp(arg, "-A") ||
531
+ !prefixcmp(arg, "-B") ||
532
+ !prefixcmp(arg, "-C") ||
533
(arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {
534
unsigned num;
535
const char *scan;
builtin-pack-objects.c
+3
-3
@@ -1579,14 +1579,14 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1579
incremental = 1;
1580
continue;
1581
}
1582
- if (!(-prefixcmp(arg, "--window="))) {
1582
+ if (!prefixcmp(arg, "--window=")) {
1583
char *end;
1584
window = strtoul(arg+9, &end, 0);
1585
if (!arg[9] || *end)
1586
usage(pack_usage);
1587
continue;
1588
}
1589
- if (!(-prefixcmp(arg, "--depth="))) {
1589
+ if (!prefixcmp(arg, "--depth=")) {
1590
char *end;
1591
depth = strtoul(arg+8, &end, 0);
1592
if (!arg[8] || *end)
@@ -1622,7 +1622,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1622
continue;
1623
}
1624
if (!strcmp("--unpacked", arg) ||
1625
- !(-prefixcmp(arg, "--unpacked=")) ||
1625
+ !prefixcmp(arg, "--unpacked=") ||
1626
!strcmp("--reflog", arg) ||
1627
!strcmp("--all", arg)) {
1628
use_internal_rev_list = 1;
builtin-push.c
+2
-2
@@ -149,10 +149,10 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
149
int is_refspec;
150
char *s, *p;
151
152
- if (!(-prefixcmp(buffer, "URL:"))) {
152
+ if (!prefixcmp(buffer, "URL:")) {
153
is_refspec = 0;
154
s = buffer + 4;
155
- } else if (!(-prefixcmp(buffer, "Push:"))) {
155
+ } else if (!prefixcmp(buffer, "Push:")) {
156
is_refspec = 1;
157
s = buffer + 5;
158
} else
builtin-rerere.c
+3
-3
@@ -105,11 +105,11 @@ static int handle_file(const char *path,
105
SHA1_Init(&ctx);
106
107
while (fgets(buf, sizeof(buf), f)) {
108
- if (!(-prefixcmp(buf, "<<<<<<< ")))
108
+ if (!prefixcmp(buf, "<<<<<<< "))
109
hunk = 1;
110
- else if (!(-prefixcmp(buf, "=======")))
110
+ else if (!prefixcmp(buf, "======="))
111
hunk = 2;
112
- else if (!(-prefixcmp(buf, ">>>>>>> "))) {
112
+ else if (!prefixcmp(buf, ">>>>>>> ")) {
113
hunk_no++;
114
hunk = 0;
115
if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
builtin-show-branch.c
+2
-2
@@ -435,9 +435,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i
435
return 0;
436
if (fnmatch(match_ref_pattern, tail, 0))
437
return 0;
438
- if (!(-prefixcmp(refname, "refs/heads/")))
438
+ if (!prefixcmp(refname, "refs/heads/"))
439
return append_head_ref(refname, sha1, flag, cb_data);
440
- if (!(-prefixcmp(refname, "refs/tags/")))
440
+ if (!prefixcmp(refname, "refs/tags/"))
441
return append_tag_ref(refname, sha1, flag, cb_data);
442
return append_ref(refname, sha1, 0);
443
}
builtin-tar-tree.c
+1
-1
@@ -31,7 +31,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
31
nargv[nargc++] = "git-archive";
32
nargv[nargc++] = "--format=tar";
33
34
- if (2 <= argc && !(-prefixcmp(argv[1], "--remote="))) {
34
+ if (2 <= argc && !prefixcmp(argv[1], "--remote=")) {
35
nargv[nargc++] = argv[1];
36
argv++;
37
argc--;
daemon.c
+1
-1
@@ -562,7 +562,7 @@ static int execute(struct sockaddr *addr)
562
for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
563
struct daemon_service *s = &(daemon_service[i]);
564
int namelen = strlen(s->name);
565
- if (!(-prefixcmp(line, "git-")) &&
565
+ if (!prefixcmp(line, "git-") &&
566
!strncmp(s->name, line + 4, namelen) &&
567
line[namelen + 4] == ' ') {
568
/*
fast-import.c
+15
-15
@@ -1392,7 +1392,7 @@ static void read_next_command(void)
1392
1393
static void cmd_mark(void)
1394
{
1395
- if (!(-prefixcmp(command_buf.buf, "mark :"))) {
1395
+ if (!prefixcmp(command_buf.buf, "mark :")) {
1396
next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
1397
read_next_command();
1398
}
@@ -1405,10 +1405,10 @@ static void *cmd_data (size_t *size)
1405
size_t length;
1406
char *buffer;
1407
1408
- if ((-prefixcmp(command_buf.buf, "data ")))
1408
+ if (prefixcmp(command_buf.buf, "data "))
1409
die("Expected 'data n' command, found: %s", command_buf.buf);
1410
1411
- if (!(-prefixcmp(command_buf.buf + 5, "<<"))) {
1411
+ if (!prefixcmp(command_buf.buf + 5, "<<")) {
1412
char *term = xstrdup(command_buf.buf + 5 + 2);
1413
size_t sz = 8192, term_len = command_buf.len - 5 - 2;
1414
length = 0;
@@ -1595,7 +1595,7 @@ static void file_change_m(struct branch *b)
1595
oe = find_mark(strtoumax(p + 1, &x, 10));
1596
hashcpy(sha1, oe->sha1);
1597
p = x;
1598
- } else if (!(-prefixcmp(p, "inline"))) {
1598
+ } else if (!prefixcmp(p, "inline")) {
1599
inline_data = 1;
1600
p += 6;
1601
} else {
@@ -1668,7 +1668,7 @@ static void cmd_from(struct branch *b)
1668
const char *from;
1669
struct branch *s;
1670
1671
- if ((-prefixcmp(command_buf.buf, "from ")))
1671
+ if (prefixcmp(command_buf.buf, "from "))
1672
return;
1673
1674
if (b->branch_tree.tree) {
@@ -1734,7 +1734,7 @@ static struct hash_list *cmd_merge(unsigned int *count)
1734
struct branch *s;
1735
1736
*count = 0;
1737
- while (!(-prefixcmp(command_buf.buf, "merge "))) {
1737
+ while (!prefixcmp(command_buf.buf, "merge ")) {
1738
from = strchr(command_buf.buf, ' ') + 1;
1739
n = xmalloc(sizeof(*n));
1740
s = lookup_branch(from);
@@ -1780,11 +1780,11 @@ static void cmd_new_commit(void)
1780
1781
read_next_command();
1782
cmd_mark();
1783
- if (!(-prefixcmp(command_buf.buf, "author "))) {
1783
+ if (!prefixcmp(command_buf.buf, "author ")) {
1784
author = parse_ident(command_buf.buf + 7);
1785
read_next_command();
1786
}
1787
- if (!(-prefixcmp(command_buf.buf, "committer "))) {
1787
+ if (!prefixcmp(command_buf.buf, "committer ")) {
1788
committer = parse_ident(command_buf.buf + 10);
1789
read_next_command();
1790
}
@@ -1805,9 +1805,9 @@ static void cmd_new_commit(void)
1805
for (;;) {
1806
if (1 == command_buf.len)
1807
break;
1808
- else if (!(-prefixcmp(command_buf.buf, "M ")))
1808
+ else if (!prefixcmp(command_buf.buf, "M "))
1809
file_change_m(b);
1810
- else if (!(-prefixcmp(command_buf.buf, "D ")))
1810
+ else if (!prefixcmp(command_buf.buf, "D "))
1811
file_change_d(b);
1812
else if (!strcmp("deleteall", command_buf.buf))
1813
file_change_deleteall(b);
@@ -1877,7 +1877,7 @@ static void cmd_new_tag(void)
1877
read_next_command();
1878
1879
/* from ... */
1880
- if ((-prefixcmp(command_buf.buf, "from ")))
1880
+ if (prefixcmp(command_buf.buf, "from "))
1881
die("Expected from command, got %s", command_buf.buf);
1882
from = strchr(command_buf.buf, ' ') + 1;
1883
s = lookup_branch(from);
@@ -1904,7 +1904,7 @@ static void cmd_new_tag(void)
1904
read_next_command();
1905
1906
/* tagger ... */
1907
- if ((-prefixcmp(command_buf.buf, "tagger ")))
1907
+ if (prefixcmp(command_buf.buf, "tagger "))
1908
die("Expected tagger command, got %s", command_buf.buf);
1909
tagger = parse_ident(command_buf.buf + 7);
1910
@@ -2033,11 +2033,11 @@ int main(int argc, const char **argv)
2033
break;
2034
else if (!strcmp("blob", command_buf.buf))
2035
cmd_new_blob();
2036
- else if (!(-prefixcmp(command_buf.buf, "commit ")))
2036
+ else if (!prefixcmp(command_buf.buf, "commit "))
2037
cmd_new_commit();
2038
- else if (!(-prefixcmp(command_buf.buf, "tag ")))
2038
+ else if (!prefixcmp(command_buf.buf, "tag "))
2039
cmd_new_tag();
2040
- else if (!(-prefixcmp(command_buf.buf, "reset ")))
2040
+ else if (!prefixcmp(command_buf.buf, "reset "))
2041
cmd_reset_branch();
2042
else if (!strcmp("checkpoint", command_buf.buf))
2043
cmd_checkpoint();
fetch-pack.c
+5
-5
@@ -198,13 +198,13 @@ static int find_common(int fd[2], unsigned char *result_sha1,
198
int len;
199
200
while ((len = packet_read_line(fd[0], line, sizeof(line)))) {
201
- if (!(-prefixcmp(line, "shallow "))) {
201
+ if (!prefixcmp(line, "shallow ")) {
202
if (get_sha1_hex(line + 8, sha1))
203
die("invalid shallow line: %s", line);
204
register_shallow(sha1);
205
continue;
206
}
207
- if (!(-prefixcmp(line, "unshallow "))) {
207
+ if (!prefixcmp(line, "unshallow ")) {
208
if (get_sha1_hex(line + 10, sha1))
209
die("invalid unshallow line: %s", line);
210
if (!lookup_object(sha1))
@@ -683,11 +683,11 @@ int main(int argc, char **argv)
683
char *arg = argv[i];
684
685
if (*arg == '-') {
686
- if (!(-prefixcmp(arg, "--upload-pack="))) {
686
+ if (!prefixcmp(arg, "--upload-pack=")) {
687
uploadpack = arg + 14;
688
continue;
689
}
690
- if (!(-prefixcmp(arg, "--exec="))) {
690
+ if (!prefixcmp(arg, "--exec=")) {
691
uploadpack = arg + 7;
692
continue;
693
}
@@ -712,7 +712,7 @@ int main(int argc, char **argv)
712
verbose = 1;
713
continue;
714
}
715
- if (!(-prefixcmp(arg, "--depth="))) {
715
+ if (!prefixcmp(arg, "--depth=")) {
716
depth = strtol(arg + 8, NULL, 0);
717
if (stat(git_path("shallow"), &st))
718
st.st_mtime = 0;
peek-remote.c
+2
-2
@@ -35,11 +35,11 @@ int main(int argc, char **argv)
35
char *arg = argv[i];
36
37
if (*arg == '-') {
38
- if (!(-prefixcmp(arg, "--upload-pack="))) {
38
+ if (!prefixcmp(arg, "--upload-pack=")) {
39
uploadpack = arg + 14;
40
continue;
41
}
42
- if (!(-prefixcmp(arg, "--exec="))) {
42
+ if (!prefixcmp(arg, "--exec=")) {
43
uploadpack = arg + 7;
44
continue;
45
}
upload-pack.c
+3
-3
@@ -502,7 +502,7 @@ static void receive_needs(void)
502
if (!len)
503
break;
504
505
- if (!(-prefixcmp(line, "shallow "))) {
505
+ if (!prefixcmp(line, "shallow ")) {
506
unsigned char sha1[20];
507
struct object *object;
508
use_thin_pack = 0;
@@ -515,7 +515,7 @@ static void receive_needs(void)
515
add_object_array(object, NULL, &shallows);
516
continue;
517
}
518
- if (!(-prefixcmp(line, "deepen "))) {
518
+ if (!prefixcmp(line, "deepen ")) {
519
char *end;
520
use_thin_pack = 0;
521
depth = strtol(line + 7, &end, 0);
@@ -523,7 +523,7 @@ static void receive_needs(void)
523
die("Invalid deepen: %s", line);
524
continue;
525
}
526
- if ((-prefixcmp(line, "want ")) ||
526
+ if (prefixcmp(line, "want ") ||
527
get_sha1_hex(line+5, sha1_buf))
528
die("git-upload-pack: protocol error, "
529
"expected to get sha, not '%s'", line);