Skip to content

Commit

Permalink
prefixcmp(): fix-up mechanical conversion.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Feb 21, 2007
1 parent cc44c76 commit 599065a
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion builtin-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static int run_remote_archiver(const char *remote, int argc,

for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!(-prefixcmp(arg, "--exec="))) {
if (!prefixcmp(arg, "--exec=")) {
if (exec_at)
die("multiple --exec specified");
exec = arg + 7;
Expand Down
6 changes: 3 additions & 3 deletions builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -2097,17 +2097,17 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
output_option |= OUTPUT_LONG_OBJECT_NAME;
else if (!strcmp("-S", arg) && ++i < argc)
revs_file = argv[i];
else if (!(-prefixcmp(arg, "-M"))) {
else if (!prefixcmp(arg, "-M")) {
opt |= PICKAXE_BLAME_MOVE;
blame_move_score = parse_score(arg+2);
}
else if (!(-prefixcmp(arg, "-C"))) {
else if (!prefixcmp(arg, "-C")) {
if (opt & PICKAXE_BLAME_COPY)
opt |= PICKAXE_BLAME_COPY_HARDER;
opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
blame_copy_score = parse_score(arg+2);
}
else if (!(-prefixcmp(arg, "-L"))) {
else if (!prefixcmp(arg, "-L")) {
if (!arg[2]) {
if (++i >= argc)
usage(blame_usage);
Expand Down
6 changes: 3 additions & 3 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
opt.word_regexp = 1;
continue;
}
if (!(-prefixcmp(arg, "-A")) ||
!(-prefixcmp(arg, "-B")) ||
!(-prefixcmp(arg, "-C")) ||
if (!prefixcmp(arg, "-A") ||
!prefixcmp(arg, "-B") ||
!prefixcmp(arg, "-C") ||
(arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {
unsigned num;
const char *scan;
Expand Down
6 changes: 3 additions & 3 deletions builtin-pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,14 +1579,14 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
incremental = 1;
continue;
}
if (!(-prefixcmp(arg, "--window="))) {
if (!prefixcmp(arg, "--window=")) {
char *end;
window = strtoul(arg+9, &end, 0);
if (!arg[9] || *end)
usage(pack_usage);
continue;
}
if (!(-prefixcmp(arg, "--depth="))) {
if (!prefixcmp(arg, "--depth=")) {
char *end;
depth = strtoul(arg+8, &end, 0);
if (!arg[8] || *end)
Expand Down Expand Up @@ -1622,7 +1622,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp("--unpacked", arg) ||
!(-prefixcmp(arg, "--unpacked=")) ||
!prefixcmp(arg, "--unpacked=") ||
!strcmp("--reflog", arg) ||
!strcmp("--all", arg)) {
use_internal_rev_list = 1;
Expand Down
4 changes: 2 additions & 2 deletions builtin-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
int is_refspec;
char *s, *p;

if (!(-prefixcmp(buffer, "URL:"))) {
if (!prefixcmp(buffer, "URL:")) {
is_refspec = 0;
s = buffer + 4;
} else if (!(-prefixcmp(buffer, "Push:"))) {
} else if (!prefixcmp(buffer, "Push:")) {
is_refspec = 1;
s = buffer + 5;
} else
Expand Down
6 changes: 3 additions & 3 deletions builtin-rerere.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ static int handle_file(const char *path,
SHA1_Init(&ctx);

while (fgets(buf, sizeof(buf), f)) {
if (!(-prefixcmp(buf, "<<<<<<< ")))
if (!prefixcmp(buf, "<<<<<<< "))
hunk = 1;
else if (!(-prefixcmp(buf, "=======")))
else if (!prefixcmp(buf, "======="))
hunk = 2;
else if (!(-prefixcmp(buf, ">>>>>>> "))) {
else if (!prefixcmp(buf, ">>>>>>> ")) {
hunk_no++;
hunk = 0;
if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
Expand Down
4 changes: 2 additions & 2 deletions builtin-show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i
return 0;
if (fnmatch(match_ref_pattern, tail, 0))
return 0;
if (!(-prefixcmp(refname, "refs/heads/")))
if (!prefixcmp(refname, "refs/heads/"))
return append_head_ref(refname, sha1, flag, cb_data);
if (!(-prefixcmp(refname, "refs/tags/")))
if (!prefixcmp(refname, "refs/tags/"))
return append_tag_ref(refname, sha1, flag, cb_data);
return append_ref(refname, sha1, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion builtin-tar-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
nargv[nargc++] = "git-archive";
nargv[nargc++] = "--format=tar";

if (2 <= argc && !(-prefixcmp(argv[1], "--remote="))) {
if (2 <= argc && !prefixcmp(argv[1], "--remote=")) {
nargv[nargc++] = argv[1];
argv++;
argc--;
Expand Down
2 changes: 1 addition & 1 deletion daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ static int execute(struct sockaddr *addr)
for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
struct daemon_service *s = &(daemon_service[i]);
int namelen = strlen(s->name);
if (!(-prefixcmp(line, "git-")) &&
if (!prefixcmp(line, "git-") &&
!strncmp(s->name, line + 4, namelen) &&
line[namelen + 4] == ' ') {
/*
Expand Down
30 changes: 15 additions & 15 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ static void read_next_command(void)

static void cmd_mark(void)
{
if (!(-prefixcmp(command_buf.buf, "mark :"))) {
if (!prefixcmp(command_buf.buf, "mark :")) {
next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
read_next_command();
}
Expand All @@ -1405,10 +1405,10 @@ static void *cmd_data (size_t *size)
size_t length;
char *buffer;

if ((-prefixcmp(command_buf.buf, "data ")))
if (prefixcmp(command_buf.buf, "data "))
die("Expected 'data n' command, found: %s", command_buf.buf);

if (!(-prefixcmp(command_buf.buf + 5, "<<"))) {
if (!prefixcmp(command_buf.buf + 5, "<<")) {
char *term = xstrdup(command_buf.buf + 5 + 2);
size_t sz = 8192, term_len = command_buf.len - 5 - 2;
length = 0;
Expand Down Expand Up @@ -1595,7 +1595,7 @@ static void file_change_m(struct branch *b)
oe = find_mark(strtoumax(p + 1, &x, 10));
hashcpy(sha1, oe->sha1);
p = x;
} else if (!(-prefixcmp(p, "inline"))) {
} else if (!prefixcmp(p, "inline")) {
inline_data = 1;
p += 6;
} else {
Expand Down Expand Up @@ -1668,7 +1668,7 @@ static void cmd_from(struct branch *b)
const char *from;
struct branch *s;

if ((-prefixcmp(command_buf.buf, "from ")))
if (prefixcmp(command_buf.buf, "from "))
return;

if (b->branch_tree.tree) {
Expand Down Expand Up @@ -1734,7 +1734,7 @@ static struct hash_list *cmd_merge(unsigned int *count)
struct branch *s;

*count = 0;
while (!(-prefixcmp(command_buf.buf, "merge "))) {
while (!prefixcmp(command_buf.buf, "merge ")) {
from = strchr(command_buf.buf, ' ') + 1;
n = xmalloc(sizeof(*n));
s = lookup_branch(from);
Expand Down Expand Up @@ -1780,11 +1780,11 @@ static void cmd_new_commit(void)

read_next_command();
cmd_mark();
if (!(-prefixcmp(command_buf.buf, "author "))) {
if (!prefixcmp(command_buf.buf, "author ")) {
author = parse_ident(command_buf.buf + 7);
read_next_command();
}
if (!(-prefixcmp(command_buf.buf, "committer "))) {
if (!prefixcmp(command_buf.buf, "committer ")) {
committer = parse_ident(command_buf.buf + 10);
read_next_command();
}
Expand All @@ -1805,9 +1805,9 @@ static void cmd_new_commit(void)
for (;;) {
if (1 == command_buf.len)
break;
else if (!(-prefixcmp(command_buf.buf, "M ")))
else if (!prefixcmp(command_buf.buf, "M "))
file_change_m(b);
else if (!(-prefixcmp(command_buf.buf, "D ")))
else if (!prefixcmp(command_buf.buf, "D "))
file_change_d(b);
else if (!strcmp("deleteall", command_buf.buf))
file_change_deleteall(b);
Expand Down Expand Up @@ -1877,7 +1877,7 @@ static void cmd_new_tag(void)
read_next_command();

/* from ... */
if ((-prefixcmp(command_buf.buf, "from ")))
if (prefixcmp(command_buf.buf, "from "))
die("Expected from command, got %s", command_buf.buf);
from = strchr(command_buf.buf, ' ') + 1;
s = lookup_branch(from);
Expand All @@ -1904,7 +1904,7 @@ static void cmd_new_tag(void)
read_next_command();

/* tagger ... */
if ((-prefixcmp(command_buf.buf, "tagger ")))
if (prefixcmp(command_buf.buf, "tagger "))
die("Expected tagger command, got %s", command_buf.buf);
tagger = parse_ident(command_buf.buf + 7);

Expand Down Expand Up @@ -2033,11 +2033,11 @@ int main(int argc, const char **argv)
break;
else if (!strcmp("blob", command_buf.buf))
cmd_new_blob();
else if (!(-prefixcmp(command_buf.buf, "commit ")))
else if (!prefixcmp(command_buf.buf, "commit "))
cmd_new_commit();
else if (!(-prefixcmp(command_buf.buf, "tag ")))
else if (!prefixcmp(command_buf.buf, "tag "))
cmd_new_tag();
else if (!(-prefixcmp(command_buf.buf, "reset ")))
else if (!prefixcmp(command_buf.buf, "reset "))
cmd_reset_branch();
else if (!strcmp("checkpoint", command_buf.buf))
cmd_checkpoint();
Expand Down
10 changes: 5 additions & 5 deletions fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ static int find_common(int fd[2], unsigned char *result_sha1,
int len;

while ((len = packet_read_line(fd[0], line, sizeof(line)))) {
if (!(-prefixcmp(line, "shallow "))) {
if (!prefixcmp(line, "shallow ")) {
if (get_sha1_hex(line + 8, sha1))
die("invalid shallow line: %s", line);
register_shallow(sha1);
continue;
}
if (!(-prefixcmp(line, "unshallow "))) {
if (!prefixcmp(line, "unshallow ")) {
if (get_sha1_hex(line + 10, sha1))
die("invalid unshallow line: %s", line);
if (!lookup_object(sha1))
Expand Down Expand Up @@ -683,11 +683,11 @@ int main(int argc, char **argv)
char *arg = argv[i];

if (*arg == '-') {
if (!(-prefixcmp(arg, "--upload-pack="))) {
if (!prefixcmp(arg, "--upload-pack=")) {
uploadpack = arg + 14;
continue;
}
if (!(-prefixcmp(arg, "--exec="))) {
if (!prefixcmp(arg, "--exec=")) {
uploadpack = arg + 7;
continue;
}
Expand All @@ -712,7 +712,7 @@ int main(int argc, char **argv)
verbose = 1;
continue;
}
if (!(-prefixcmp(arg, "--depth="))) {
if (!prefixcmp(arg, "--depth=")) {
depth = strtol(arg + 8, NULL, 0);
if (stat(git_path("shallow"), &st))
st.st_mtime = 0;
Expand Down
4 changes: 2 additions & 2 deletions peek-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ int main(int argc, char **argv)
char *arg = argv[i];

if (*arg == '-') {
if (!(-prefixcmp(arg, "--upload-pack="))) {
if (!prefixcmp(arg, "--upload-pack=")) {
uploadpack = arg + 14;
continue;
}
if (!(-prefixcmp(arg, "--exec="))) {
if (!prefixcmp(arg, "--exec=")) {
uploadpack = arg + 7;
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions upload-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static void receive_needs(void)
if (!len)
break;

if (!(-prefixcmp(line, "shallow "))) {
if (!prefixcmp(line, "shallow ")) {
unsigned char sha1[20];
struct object *object;
use_thin_pack = 0;
Expand All @@ -515,15 +515,15 @@ static void receive_needs(void)
add_object_array(object, NULL, &shallows);
continue;
}
if (!(-prefixcmp(line, "deepen "))) {
if (!prefixcmp(line, "deepen ")) {
char *end;
use_thin_pack = 0;
depth = strtol(line + 7, &end, 0);
if (end == line + 7 || depth <= 0)
die("Invalid deepen: %s", line);
continue;
}
if ((-prefixcmp(line, "want ")) ||
if (prefixcmp(line, "want ") ||
get_sha1_hex(line+5, sha1_buf))
die("git-upload-pack: protocol error, "
"expected to get sha, not '%s'", line);
Expand Down

0 comments on commit 599065a

Please sign in to comment.