]> git.ipfire.org Git - thirdparty/git.git/commitdiff
use strpbrk(3) to search for characters from a given set
authorRené Scharfe <l.s.r@web.de>
Sat, 22 Feb 2020 18:51:19 +0000 (19:51 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Feb 2020 17:30:31 +0000 (09:30 -0800)
We can check if certain characters are present in a string by calling
strchr(3) on each of them, or we can pass them all to a single
strpbrk(3) call.  The latter is shorter, less repetitive and slightly
more efficient, so let's do that instead.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/show-branch.c
compat/mingw.c
mailinfo.c
t/helper/test-windows-named-pipe.c

index 35d7f51c236dc0b9a734809a1cee9b04a5f12397..8c90cbb18f072726f03f40f12f6b9731b29da1b6 100644 (file)
@@ -536,7 +536,7 @@ static void append_one_rev(const char *av)
                append_ref(av, &revkey, 0);
                return;
        }
-       if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
+       if (strpbrk(av, "*?[")) {
                /* glob style match */
                int saved_matches = ref_name_cnt;
 
index 402c1ad91c1449c883bfee31b5be5303934a09cc..7ec6c04dfc7ec8ad9d6cac9c4e9ace597d46af8f 100644 (file)
@@ -1232,7 +1232,7 @@ static char *path_lookup(const char *cmd, int exe_only)
        int len = strlen(cmd);
        int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe");
 
-       if (strchr(cmd, '/') || strchr(cmd, '\\'))
+       if (strpbrk(cmd, "/\\"))
                return xstrdup(cmd);
 
        path = mingw_getenv("PATH");
index b395adbdf2a405567bc40c254125265f30b12bbd..eeef190c3d6f9f6e2464953566e9d69d9c1f37f1 100644 (file)
@@ -19,8 +19,7 @@ static void cleanup_space(struct strbuf *sb)
 static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
 {
        struct strbuf *src = name;
-       if (name->len < 3 || 60 < name->len || strchr(name->buf, '@') ||
-               strchr(name->buf, '<') || strchr(name->buf, '>'))
+       if (name->len < 3 || 60 < name->len || strpbrk(name->buf, "@<>"))
                src = email;
        else if (name == out)
                return;
index b4b752b01aaf558b19879ee3e80be1d55e4b2eaa..ae52183e634425321ce11731804c5d0bb1bebee4 100644 (file)
@@ -19,7 +19,7 @@ int cmd__windows_named_pipe(int argc, const char **argv)
        if (argc < 2)
                goto print_usage;
        filename = argv[1];
-       if (strchr(filename, '/') || strchr(filename, '\\'))
+       if (strpbrk(filename, "/\\"))
                goto print_usage;
        strbuf_addf(&pathname, "//./pipe/%s", filename);