Code

prefixcmp(): fix-up mechanical conversion.
authorJunio C Hamano <junkio@cox.net>
Tue, 20 Feb 2007 09:54:00 +0000 (01:54 -0800)
committerJunio C Hamano <junkio@cox.net>
Wed, 21 Feb 2007 06:03:15 +0000 (22:03 -0800)
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>
13 files changed:
builtin-archive.c
builtin-blame.c
builtin-grep.c
builtin-pack-objects.c
builtin-push.c
builtin-rerere.c
builtin-show-branch.c
builtin-tar-tree.c
daemon.c
fast-import.c
fetch-pack.c
peek-remote.c
upload-pack.c

index 0c56de069830f1881e952fa620cc10068fa4431a..8ea6cb1efc4f988fb09051852f9e51fc88b5efd7 100644 (file)
@@ -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;
index db311bfba948206fbdc9087ebdf4d6cf585c1522..530b97f97d2661d53a39d2101eeadd86be2e6b00 100644 (file)
@@ -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);
index cec22047c97a59dc37eb877073b69de1bec05a6b..f35f2d023cf56cb3c75c817455cfc53a98175f54 100644 (file)
@@ -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;
index 71113d8fb37ebd994fb42a6776d0bbe31979f510..b5ed9ce2c89daab7a69d399a6599e203dc04971a 100644 (file)
@@ -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)
@@ -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;
index 2b98ba32310810462151b233053b99b0b5ab627a..979efcc45fca1a39b125e02d14b1f5d096f813ba 100644 (file)
@@ -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
index 978105b4973a96be5cba559c1bbcc7f7e24d83ce..dd1d4c1c1de310629282bcb772139e1edec22bf4 100644 (file)
@@ -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 ?
index bf6aee49f7e4fbb8dd15372f5876320d3daf41e8..402a8f79300eced54cf4024b8d10f4fd766996a1 100644 (file)
@@ -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);
 }
index 28f8c1c164c25c8256de6b343b00edbf5d61be55..b04719ef20929d40ef0c898c37616a5e7316f272 100644 (file)
@@ -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--;
index cdbc23f63d0570fbb857357ec8b6aa2a97f2e32b..e74ecac952fa0d399a1ed0c426a9e27d96b3ddcb 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -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] == ' ') {
                        /*
index 8e192c299139545edee152eaed44e09f2d405e87..5d040fdb001c05daab19d4b6e239512cbdb07aba 100644 (file)
@@ -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();
        }
@@ -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;
@@ -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 {
@@ -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) {
@@ -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);
@@ -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();
        }
@@ -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);
@@ -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);
@@ -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);
 
@@ -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();
index 1fd2c3adfb5328f0fd34fc6fb1fca42c924bd514..41bdd27b8fce5dd0656b9dcc71e6768f0b4796c6 100644 (file)
@@ -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))
@@ -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;
                        }
@@ -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;
index 7b66228a22f7ddeeb652924e5f42df5e63b2a7b4..96bfac498bdc58c90c9bc136a1df7bac9bfa0d92 100644 (file)
@@ -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;
                        }
index d7876cade9b4fede8c480d6656f30f71c44cbfd9..804bbb6c9eb788714afb493e331341206cebaaf3 100644 (file)
@@ -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;
@@ -515,7 +515,7 @@ 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);
@@ -523,7 +523,7 @@ static void receive_needs(void)
                                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);