{"thread":{"id":"6884","subject":"[PATCH] Change \"refs/\" references to symbolic constants","startedAt":"2007-02-19T18:39:05Z","lastAt":"2007-02-21T12:41:25Z","messageCount":30,"participants":["Andy Parkins","Bill Lear","Junio C Hamano","Shawn O. Pearce","Krzysztof Halasa","Johannes Schindelin","David Kågedal","Simon 'corecode' Schubert","Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35017","messageId":"200702191839.05784.andyparkins@gmail.com","threadId":"6884","inReplyTo":null,"subject":"[PATCH] Change \"refs/\" references to symbolic constants","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-02-19T18:39:05Z","receivedAt":"2007-02-19T18:39:05Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Changed repeated use of the same constants for the ref paths to be\nsymbolic constants.  I've defined them in refs.h\n\n  refs/ is now PATH_REFS\n  refs/heads/ is now PATH_REFS_HEADS\n  refs/tags/ is now PATH_REFS_TAGS\n  refs/remotes/ is now PATH_REFS_REMOTES\n\nI've changed all references to them and made constants for the string\nlengths as well.  This has clarified the code in some places; for\nexample:\n\n - len = strlen(refs[i]) + 11;\n + len = strlen(refs[i]) + STRLEN_PATH_REFS_TAGS + 1;\n\nIn this case 11 isn't STRLEN_PATH_REFS_HEADS, as it is in most other\ncases, it's TAGS + 1.  With the change to symbolic constants it's much\nclearer what is happening.\n\nSigned-off-by: Andy Parkins <andyparkins@gmail.com>\n---\n builtin-branch.c        |   28 ++++++++++++++--------------\n builtin-describe.c      |    2 +-\n builtin-fmt-merge-msg.c |    5 +++--\n builtin-fsck.c          |    2 +-\n builtin-init-db.c       |   15 ++++++++-------\n builtin-name-rev.c      |   10 +++++-----\n builtin-pack-refs.c     |    2 +-\n builtin-push.c          |    8 ++++----\n builtin-show-branch.c   |   34 +++++++++++++++++-----------------\n builtin-show-ref.c      |    6 +++---\n connect.c               |   18 +++++++++---------\n fetch-pack.c            |    6 +++---\n http-fetch.c            |    7 ++++---\n http-push.c             |    4 ++--\n local-fetch.c           |    3 ++-\n path.c                  |    5 +++--\n receive-pack.c          |    4 ++--\n reflog-walk.c           |    6 +++---\n refs.c                  |   26 +++++++++++++-------------\n refs.h                  |   17 +++++++++++++++++\n setup.c                 |    5 +++--\n sha1_name.c             |   10 +++++-----\n wt-status.c             |    5 +++--\n 23 files changed, 126 insertions(+), 102 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex d0e7209..928f1fe 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -85,12 +85,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)\n \n \tswitch (kinds) {\n \tcase REF_REMOTE_BRANCH:\n-\t\tfmt = \"refs/remotes/%s\";\n+\t\tfmt = PATH_REFS_REMOTES \"%s\";\n \t\tremote = \"remote \";\n \t\tforce = 1;\n \t\tbreak;\n \tcase REF_LOCAL_BRANCH:\n-\t\tfmt = \"refs/heads/%s\";\n+\t\tfmt = PATH_REFS_HEADS \"%s\";\n \t\tremote = \"\";\n \t\tbreak;\n \tdefault:\n@@ -178,15 +178,15 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,\n \tint len;\n \n \t/* Detect kind */\n-\tif (!strncmp(refname, \"refs/heads/\", 11)) {\n+\tif (!strncmp(refname, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS)) {\n \t\tkind = REF_LOCAL_BRANCH;\n-\t\trefname += 11;\n-\t} else if (!strncmp(refname, \"refs/remotes/\", 13)) {\n+\t\trefname += STRLEN_PATH_REFS_HEADS;\n+\t} else if (!strncmp(refname, PATH_REFS_REMOTES, STRLEN_PATH_REFS_REMOTES)) {\n \t\tkind = REF_REMOTE_BRANCH;\n-\t\trefname += 13;\n-\t} else if (!strncmp(refname, \"refs/tags/\", 10)) {\n+\t\trefname += STRLEN_PATH_REFS_REMOTES;\n+\t} else if (!strncmp(refname, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS)) {\n \t\tkind = REF_TAG;\n-\t\trefname += 10;\n+\t\trefname += STRLEN_PATH_REFS_TAGS;\n \t}\n \n \t/* Don't add types the caller doesn't want */\n@@ -318,7 +318,7 @@ static void create_branch(const char *name, const char *start_name,\n \tchar ref[PATH_MAX], msg[PATH_MAX + 20];\n \tint forcing = 0;\n \n-\tsnprintf(ref, sizeof ref, \"refs/heads/%s\", name);\n+\tsnprintf(ref, sizeof ref, PATH_REFS_HEADS \"%s\", name);\n \tif (check_ref_format(ref))\n \t\tdie(\"'%s' is not a valid branch name.\", name);\n \n@@ -366,13 +366,13 @@ static void rename_branch(const char *oldname, const char *newname, int force)\n \tif (!oldname)\n \t\tdie(\"cannot rename the current branch while not on any.\");\n \n-\tif (snprintf(oldref, sizeof(oldref), \"refs/heads/%s\", oldname) > sizeof(oldref))\n+\tif (snprintf(oldref, sizeof(oldref), PATH_REFS_HEADS \"%s\", oldname) > sizeof(oldref))\n \t\tdie(\"Old branchname too long\");\n \n \tif (check_ref_format(oldref))\n \t\tdie(\"Invalid branch name: %s\", oldref);\n \n-\tif (snprintf(newref, sizeof(newref), \"refs/heads/%s\", newname) > sizeof(newref))\n+\tif (snprintf(newref, sizeof(newref), PATH_REFS_HEADS \"%s\", newname) > sizeof(newref))\n \t\tdie(\"New branchname too long\");\n \n \tif (check_ref_format(newref))\n@@ -476,9 +476,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tdetached = 1;\n \t}\n \telse {\n-\t\tif (strncmp(head, \"refs/heads/\", 11))\n-\t\t\tdie(\"HEAD not found below refs/heads!\");\n-\t\thead += 11;\n+\t\tif (strncmp(head, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS))\n+\t\t\tdie(\"HEAD not found below \" PATH_REFS_HEADS \"!\");\n+\t\thead += STRLEN_PATH_REFS_HEADS;\n \t}\n \n \tif (delete)\ndiff --git a/builtin-describe.c b/builtin-describe.c\nindex bcc6456..0f78363 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -52,7 +52,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void\n \t * If --tags, then any tags are used.\n \t * Otherwise only annotated tags are used.\n \t */\n-\tif (!strncmp(path, \"refs/tags/\", 10)) {\n+\tif (!strncmp(path, PATH_TAGS, STRLEN_PATH_TAGS)) {\n \t\tif (object->type == OBJ_TAG)\n \t\t\tprio = 2;\n \t\telse\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex 87d3d63..d0615b5 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -4,6 +4,7 @@\n #include \"diff.h\"\n #include \"revision.h\"\n #include \"tag.h\"\n+#include \"refs.h\"\n \n static const char *fmt_merge_msg_usage =\n \t\"git-fmt-merge-msg [--summary] [--no-summary] [--file <file>]\";\n@@ -280,8 +281,8 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \tcurrent_branch = resolve_ref(\"HEAD\", head_sha1, 1, NULL);\n \tif (!current_branch)\n \t\tdie(\"No current branch\");\n-\tif (!strncmp(current_branch, \"refs/heads/\", 11))\n-\t\tcurrent_branch += 11;\n+\tif (!strncmp(current_branch, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS))\n+\t\tcurrent_branch += STRLEN_PATH_REFS_HEADS;\n \n \twhile (fgets(line, sizeof(line), in)) {\n \t\ti++;\ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 6da3814..0109816 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -546,7 +546,7 @@ static int fsck_head_link(void)\n \n \tif (!head_points_at || !(flag & REF_ISSYMREF))\n \t\treturn error(\"HEAD is not a symbolic ref\");\n-\tif (strncmp(head_points_at, \"refs/heads/\", 11))\n+\tif (strncmp(head_points_at, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS))\n \t\treturn error(\"HEAD points to something strange (%s)\",\n \t\t\t     head_points_at);\n \tif (is_null_sha1(sha1))\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 12e43d0..4e5c881 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -5,6 +5,7 @@\n  */\n #include \"cache.h\"\n #include \"builtin.h\"\n+#include \"refs.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates/\"\n@@ -193,11 +194,11 @@ static int create_default_files(const char *git_dir, const char *template_path)\n \t/*\n \t * Create .git/refs/{heads,tags}\n \t */\n-\tstrcpy(path + len, \"refs\");\n+\tstrcpy(path + len, PATH_REFS);\n \tsafe_create_dir(path, 1);\n-\tstrcpy(path + len, \"refs/heads\");\n+\tstrcpy(path + len, PATH_REFS_HEADS);\n \tsafe_create_dir(path, 1);\n-\tstrcpy(path + len, \"refs/tags\");\n+\tstrcpy(path + len, PATH_REFS_TAGS);\n \tsafe_create_dir(path, 1);\n \n \t/* First copy the templates -- we might have the default\n@@ -216,11 +217,11 @@ static int create_default_files(const char *git_dir, const char *template_path)\n \tif (shared_repository) {\n \t\tpath[len] = 0;\n \t\tadjust_shared_perm(path);\n-\t\tstrcpy(path + len, \"refs\");\n+\t\tstrcpy(path + len, PATH_REFS);\n \t\tadjust_shared_perm(path);\n-\t\tstrcpy(path + len, \"refs/heads\");\n+\t\tstrcpy(path + len, PATH_REFS_HEADS);\n \t\tadjust_shared_perm(path);\n-\t\tstrcpy(path + len, \"refs/tags\");\n+\t\tstrcpy(path + len, PATH_REFS_TAGS);\n \t\tadjust_shared_perm(path);\n \t}\n \n@@ -231,7 +232,7 @@ static int create_default_files(const char *git_dir, const char *template_path)\n \tstrcpy(path + len, \"HEAD\");\n \treinit = !read_ref(\"HEAD\", sha1);\n \tif (!reinit) {\n-\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n+\t\tif (create_symref(\"HEAD\", PATH_REFS_HEADS \"master\", NULL) < 0)\n \t\t\texit(1);\n \t}\n \ndiff --git a/builtin-name-rev.c b/builtin-name-rev.c\nindex 36f1ba6..47a0f6d 100644\n--- a/builtin-name-rev.c\n+++ b/builtin-name-rev.c\n@@ -85,7 +85,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void\n \tstruct name_ref_data *data = cb_data;\n \tint deref = 0;\n \n-\tif (data->tags_only && strncmp(path, \"refs/tags/\", 10))\n+\tif (data->tags_only && strncmp(path, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS))\n \t\treturn 0;\n \n \tif (data->ref_filter && fnmatch(data->ref_filter, path, 0))\n@@ -101,10 +101,10 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void\n \tif (o && o->type == OBJ_COMMIT) {\n \t\tstruct commit *commit = (struct commit *)o;\n \n-\t\tif (!strncmp(path, \"refs/heads/\", 11))\n-\t\t\tpath = path + 11;\n-\t\telse if (!strncmp(path, \"refs/\", 5))\n-\t\t\tpath = path + 5;\n+\t\tif (!strncmp(path, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS))\n+\t\t\tpath = path + STRLEN_PATH_REFS_HEADS;\n+\t\telse if (!strncmp(path, PATH_REFS, STRLEN_PATH_REFS))\n+\t\t\tpath = path + STRLEN_PATH_REFS;\n \n \t\tname_rev(commit, xstrdup(path), 0, 0, deref);\n \t}\ndiff --git a/builtin-pack-refs.c b/builtin-pack-refs.c\nindex 3de9b3e..ac7543d 100644\n--- a/builtin-pack-refs.c\n+++ b/builtin-pack-refs.c\n@@ -36,7 +36,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,\n \t/* Do not pack the symbolic refs */\n \tif ((flags & REF_ISSYMREF))\n \t\treturn 0;\n-\tis_tag_ref = !strncmp(path, \"refs/tags/\", 10);\n+\tis_tag_ref = !strncmp(path, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS);\n \n \t/* ALWAYS pack refs that were already packed or are tags */\n \tif (!cb->all && !is_tag_ref && !(flags & REF_ISPACKED))\ndiff --git a/builtin-push.c b/builtin-push.c\nindex c45649e..caeb9ae 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -30,9 +30,9 @@ static void add_refspec(const char *ref)\n static int expand_one_ref(const char *ref, const unsigned char *sha1, int flag, void *cb_data)\n {\n \t/* Ignore the \"refs/\" at the beginning of the refname */\n-\tref += 5;\n+\tref += STRLEN_PATH_REFS;\n \n-\tif (!strncmp(ref, \"tags/\", 5))\n+\tif (!strncmp(ref, PATH_TAGS, STRLEN_PATH_TAGS))\n \t\tadd_refspec(xstrdup(ref));\n \treturn 0;\n }\n@@ -123,9 +123,9 @@ static void set_refspecs(const char **refs, int nr)\n \t\t\t\tint len;\n \t\t\t\tif (nr <= ++i)\n \t\t\t\t\tdie(\"tag shorthand without <tag>\");\n-\t\t\t\tlen = strlen(refs[i]) + 11;\n+\t\t\t\tlen = strlen(refs[i]) + STRLEN_PATH_REFS_TAGS + 1;\n \t\t\t\ttag = xmalloc(len);\n-\t\t\t\tstrcpy(tag, \"refs/tags/\");\n+\t\t\t\tstrcpy(tag, PATH_REFS_TAGS);\n \t\t\t\tstrcat(tag, refs[i]);\n \t\t\t\tref = tag;\n \t\t\t}\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 0d94e40..9995780 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -377,36 +377,36 @@ static int append_ref(const char *refname, const unsigned char *sha1,\n static int append_head_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n {\n \tunsigned char tmp[20];\n-\tint ofs = 11;\n-\tif (strncmp(refname, \"refs/heads/\", ofs))\n+\tint ofs = STRLEN_PATH_REFS_HEADS;\n+\tif (strncmp(refname, PATH_REFS_HEADS, ofs))\n \t\treturn 0;\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n \tif (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))\n-\t\tofs = 5;\n+\t\tofs = STRLEN_PATH_REFS;\n \treturn append_ref(refname + ofs, sha1, 0);\n }\n \n static int append_remote_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n {\n \tunsigned char tmp[20];\n-\tint ofs = 13;\n-\tif (strncmp(refname, \"refs/remotes/\", ofs))\n+\tint ofs = STRLEN_PATH_REFS_REMOTES;\n+\tif (strncmp(refname, PATH_REFS_REMOTES, ofs))\n \t\treturn 0;\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n \tif (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))\n-\t\tofs = 5;\n+\t\tofs = STRLEN_PATH_REFS;\n \treturn append_ref(refname + ofs, sha1, 0);\n }\n \n static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n {\n-\tif (strncmp(refname, \"refs/tags/\", 10))\n+\tif (strncmp(refname, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS))\n \t\treturn 0;\n-\treturn append_ref(refname + 5, sha1, 0);\n+\treturn append_ref(refname + STRLEN_PATH_REFS, sha1, 0);\n }\n \n static const char *match_ref_pattern = NULL;\n@@ -435,9 +435,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i\n \t\treturn 0;\n \tif (fnmatch(match_ref_pattern, tail, 0))\n \t\treturn 0;\n-\tif (!strncmp(\"refs/heads/\", refname, 11))\n+\tif (!strncmp(PATH_REFS_HEADS, refname, STRLEN_PATH_REFS_HEADS))\n \t\treturn append_head_ref(refname, sha1, flag, cb_data);\n-\tif (!strncmp(\"refs/tags/\", refname, 10))\n+\tif (!strncmp(PATH_REFS_TAGS, refname, STRLEN_PATH_REFS_TAGS))\n \t\treturn append_tag_ref(refname, sha1, flag, cb_data);\n \treturn append_ref(refname, sha1, 0);\n }\n@@ -462,12 +462,12 @@ static int rev_is_head(char *head, int headlen, char *name,\n \tif ((!head[0]) ||\n \t    (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))\n \t\treturn 0;\n-\tif (!strncmp(head, \"refs/heads/\", 11))\n-\t\thead += 11;\n-\tif (!strncmp(name, \"refs/heads/\", 11))\n-\t\tname += 11;\n-\telse if (!strncmp(name, \"heads/\", 6))\n-\t\tname += 6;\n+\tif (!strncmp(head, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS))\n+\t\thead += STRLEN_PATH_REFS_HEADS;\n+\tif (!strncmp(name, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS))\n+\t\tname += STRLEN_PATH_REFS_HEADS;\n+\telse if (!strncmp(name, PATH_HEADS, STRLEN_PATH_HEADS))\n+\t\tname += STRLEN_PATH_HEADS;\n \treturn !strcmp(head, name);\n }\n \n@@ -777,7 +777,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\thas_head++;\n \t\t}\n \t\tif (!has_head) {\n-\t\t\tint pfxlen = strlen(\"refs/heads/\");\n+\t\t\tint pfxlen = STRLEN_PATH_REFS_HEADS;\n \t\t\tappend_one_rev(head + pfxlen);\n \t\t}\n \t}\ndiff --git a/builtin-show-ref.c b/builtin-show-ref.c\nindex 853f13f..2c20cde 100644\n--- a/builtin-show-ref.c\n+++ b/builtin-show-ref.c\n@@ -28,8 +28,8 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo\n \tif (tags_only || heads_only) {\n \t\tint match;\n \n-\t\tmatch = heads_only && !strncmp(refname, \"refs/heads/\", 11);\n-\t\tmatch |= tags_only && !strncmp(refname, \"refs/tags/\", 10);\n+\t\tmatch = heads_only && !strncmp(refname, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS);\n+\t\tmatch |= tags_only && !strncmp(refname, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS);\n \t\tif (!match)\n \t\t\treturn 0;\n \t}\n@@ -224,7 +224,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)\n \t\tunsigned char sha1[20];\n \n \t\twhile (*pattern) {\n-\t\t\tif (!strncmp(*pattern, \"refs/\", 5) &&\n+\t\t\tif (!strncmp(*pattern, PATH_REFS, STRLEN_PATH_REFS) &&\n \t\t\t    resolve_ref(*pattern, sha1, 1, NULL)) {\n \t\t\t\tif (!quiet)\n \t\t\t\t\tshow_one(*pattern, sha1);\ndiff --git a/connect.c b/connect.c\nindex 7844888..8701de0 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -11,23 +11,23 @@ static int check_ref(const char *name, int len, unsigned int flags)\n \tif (!flags)\n \t\treturn 1;\n \n-\tif (len < 5 || memcmp(name, \"refs/\", 5))\n+\tif (len < STRLEN_PATH_REFS || memcmp(name, PATH_REFS, STRLEN_PATH_REFS))\n \t\treturn 0;\n \n \t/* Skip the \"refs/\" part */\n-\tname += 5;\n-\tlen -= 5;\n+\tname += STRLEN_PATH_REFS;\n+\tlen -= STRLEN_PATH_REFS;\n \n \t/* REF_NORMAL means that we don't want the magic fake tag refs */\n \tif ((flags & REF_NORMAL) && check_ref_format(name) < 0)\n \t\treturn 0;\n \n \t/* REF_HEADS means that we want regular branch heads */\n-\tif ((flags & REF_HEADS) && !memcmp(name, \"heads/\", 6))\n+\tif ((flags & REF_HEADS) && !memcmp(name, PATH_HEADS, STRLEN_PATH_HEADS))\n \t\treturn 1;\n \n \t/* REF_TAGS means that we want tags */\n-\tif ((flags & REF_TAGS) && !memcmp(name, \"tags/\", 5))\n+\tif ((flags & REF_TAGS) && !memcmp(name, PATH_TAGS, STRLEN_PATH_TAGS))\n \t\treturn 1;\n \n \t/* All type bits clear means that we are ok with anything */\n@@ -196,8 +196,8 @@ static int count_refspec_match(const char *pattern,\n \t\t */\n \t\tif (namelen != patlen &&\n \t\t    patlen != namelen - 5 &&\n-\t\t    strncmp(name, \"refs/heads/\", 11) &&\n-\t\t    strncmp(name, \"refs/tags/\", 10)) {\n+\t\t    strncmp(name, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS) &&\n+\t\t    strncmp(name, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS)) {\n \t\t\t/* We want to catch the case where only weak\n \t\t\t * matches are found and there are multiple\n \t\t\t * matches, and where more than one strong\n@@ -284,7 +284,7 @@ static int match_explicit_refs(struct ref *src, struct ref *dst,\n \t\tcase 1:\n \t\t\tbreak;\n \t\tcase 0:\n-\t\t\tif (!memcmp(rs[i].dst, \"refs/\", 5)) {\n+\t\t\tif (!memcmp(rs[i].dst, PATH_REFS, STRLEN_PATH_REFS)) {\n \t\t\t\tint len = strlen(rs[i].dst) + 1;\n \t\t\t\tmatched_dst = xcalloc(1, sizeof(*dst) + len);\n \t\t\t\tmemcpy(matched_dst->name, rs[i].dst, len);\n@@ -305,7 +305,7 @@ static int match_explicit_refs(struct ref *src, struct ref *dst,\n \t\t\t\terrs = 1;\n \t\t\t\terror(\"dst refspec %s does not match any \"\n \t\t\t\t      \"existing ref on the remote and does \"\n-\t\t\t\t      \"not start with refs/.\", rs[i].dst);\n+\t\t\t\t      \"not start with \" PATH_REFS \".\", rs[i].dst);\n \t\t\t}\n \t\t\tbreak;\n \t\tdefault:\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex c787106..14a74d2 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -342,11 +342,11 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)\n \n \tfor (ref = *refs; ref; ref = next) {\n \t\tnext = ref->next;\n-\t\tif (!memcmp(ref->name, \"refs/\", 5) &&\n-\t\t    check_ref_format(ref->name + 5))\n+\t\tif (!memcmp(ref->name, PATH_REFS, STRLEN_PATH_REFS) &&\n+\t\t    check_ref_format(ref->name + STRLEN_PATH_REFS))\n \t\t\t; /* trash */\n \t\telse if (fetch_all &&\n-\t\t\t (!depth || strncmp(ref->name, \"refs/tags/\", 10) )) {\n+\t\t\t (!depth || strncmp(ref->name, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS) )) {\n \t\t\t*newtail = ref;\n \t\t\tref->next = NULL;\n \t\t\tnewtail = &ref->next;\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 9f790a0..79ef85a 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -3,6 +3,7 @@\n #include \"pack.h\"\n #include \"fetch.h\"\n #include \"http.h\"\n+#include \"refs.h\"\n \n #define PREV_BUF_SIZE 4096\n #define RANGE_HEADER_SIZE 30\n@@ -938,14 +939,14 @@ static char *quote_ref_url(const char *base, const char *ref)\n \tint len, baselen, ch;\n \n \tbaselen = strlen(base);\n-\tlen = baselen + 6; /* \"refs/\" + NUL */\n+\tlen = baselen + STRLEN_PATH_REFS + 1; /* \"refs/\" + NUL */\n \tfor (cp = ref; (ch = *cp) != 0; cp++, len++)\n \t\tif (needs_quote(ch))\n \t\t\tlen += 2; /* extra two hex plus replacement % */\n \tqref = xmalloc(len);\n \tmemcpy(qref, base, baselen);\n-\tmemcpy(qref + baselen, \"refs/\", 5);\n-\tfor (cp = ref, dp = qref + baselen + 5; (ch = *cp) != 0; cp++) {\n+\tmemcpy(qref + baselen, PATH_REFS, STRLEN_PATH_REFS);\n+\tfor (cp = ref, dp = qref + baselen + STRLEN_PATH_REFS; (ch = *cp) != 0; cp++) {\n \t\tif (needs_quote(ch)) {\n \t\t\t*dp++ = '%';\n \t\t\t*dp++ = hex((ch >> 4) & 0xF);\ndiff --git a/http-push.c b/http-push.c\nindex b128c01..37d2f50 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1922,7 +1922,7 @@ static void get_local_heads(void)\n static void get_dav_remote_heads(void)\n {\n \tremote_tail = &remote_refs;\n-\tremote_ls(\"refs/\", (PROCESS_FILES | PROCESS_DIRS | RECURSIVE), process_ls_ref, NULL);\n+\tremote_ls(PATH_REFS, (PROCESS_FILES | PROCESS_DIRS | RECURSIVE), process_ls_ref, NULL);\n }\n \n static int is_zero_sha1(const unsigned char *sha1)\n@@ -2066,7 +2066,7 @@ static void update_remote_info_refs(struct remote_lock *lock)\n \tbuffer.buffer = xcalloc(1, 4096);\n \tbuffer.size = 4096;\n \tbuffer.posn = 0;\n-\tremote_ls(\"refs/\", (PROCESS_FILES | RECURSIVE),\n+\tremote_ls(PATH_REFS, (PROCESS_FILES | RECURSIVE),\n \t\t  add_remote_info_ref, &buffer);\n \tif (!aborted) {\n \t\tif_header = xmalloc(strlen(lock->token) + 25);\ndiff --git a/local-fetch.c b/local-fetch.c\nindex 7cfe8b3..7b80a31 100644\n--- a/local-fetch.c\n+++ b/local-fetch.c\n@@ -4,6 +4,7 @@\n #include \"cache.h\"\n #include \"commit.h\"\n #include \"fetch.h\"\n+#include \"refs.h\"\n \n static int use_link;\n static int use_symlink;\n@@ -174,7 +175,7 @@ int fetch_ref(char *ref, unsigned char *sha1)\n \tint ifd;\n \n \tif (ref_name_start < 0) {\n-\t\tsprintf(filename, \"%s/refs/\", path);\n+\t\tsprintf(filename, \"%s/\" PATH_REFS, path);\n \t\tref_name_start = strlen(filename);\n \t}\n \tstrcpy(filename + ref_name_start, ref);\ndiff --git a/path.c b/path.c\nindex c5d25a4..dfbae16 100644\n--- a/path.c\n+++ b/path.c\n@@ -11,6 +11,7 @@\n  * which is what it's designed for.\n  */\n #include \"cache.h\"\n+#include \"refs.h\"\n \n static char bad_path[] = \"/bad-path/\";\n \n@@ -103,7 +104,7 @@ int validate_headref(const char *path)\n \t/* Make sure it is a \"refs/..\" symlink */\n \tif (S_ISLNK(st.st_mode)) {\n \t\tlen = readlink(path, buffer, sizeof(buffer)-1);\n-\t\tif (len >= 5 && !memcmp(\"refs/\", buffer, 5))\n+\t\tif (len >= 5 && !memcmp(PATH_REFS, buffer, STRLEN_PATH_REFS))\n \t\t\treturn 0;\n \t\treturn -1;\n \t}\n@@ -127,7 +128,7 @@ int validate_headref(const char *path)\n \t\tlen -= 4;\n \t\twhile (len && isspace(*buf))\n \t\t\tbuf++, len--;\n-\t\tif (len >= 5 && !memcmp(\"refs/\", buf, 5))\n+\t\tif (len >= STRLEN_PATH_REFS && !memcmp(PATH_REFS, buf, STRLEN_PATH_REFS))\n \t\t\treturn 0;\n \t}\n \ndiff --git a/receive-pack.c b/receive-pack.c\nindex 7311c82..6fd9f60 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -109,7 +109,7 @@ static int update(struct command *cmd)\n \tstruct ref_lock *lock;\n \n \tcmd->error_string = NULL;\n-\tif (!strncmp(name, \"refs/\", 5) && check_ref_format(name + 5)) {\n+\tif (!strncmp(name, PATH_REFS, STRLEN_PATH_REFS) && check_ref_format(name + STRLEN_PATH_REFS)) {\n \t\tcmd->error_string = \"funny refname\";\n \t\treturn error(\"refusing to create funny ref '%s' locally\",\n \t\t\t     name);\n@@ -125,7 +125,7 @@ static int update(struct command *cmd)\n \t}\n \tif (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&\n \t    !is_null_sha1(old_sha1) &&\n-\t    !strncmp(name, \"refs/heads/\", 11)) {\n+\t    !strncmp(name, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS)) {\n \t\tstruct commit *old_commit, *new_commit;\n \t\tstruct commit_list *bases, *ent;\n \ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex c983858..c05a404 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -55,11 +55,11 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)\n \t}\n \tif (reflogs->nr == 0) {\n \t\tint len = strlen(ref);\n-\t\tchar *refname = xmalloc(len + 12);\n-\t\tsprintf(refname, \"refs/%s\", ref);\n+\t\tchar *refname = xmalloc(len + STRLEN_PATH_REFS_HEADS + 1);\n+\t\tsprintf(refname, PATH_REFS \"%s\", ref);\n \t\tfor_each_reflog_ent(refname, read_one_reflog, reflogs);\n \t\tif (reflogs->nr == 0) {\n-\t\t\tsprintf(refname, \"refs/heads/%s\", ref);\n+\t\t\tsprintf(refname, PATH_REFS_HEADS \"%s\", ref);\n \t\t\tfor_each_reflog_ent(refname, read_one_reflog, reflogs);\n \t\t}\n \t\tfree(refname);\ndiff --git a/refs.c b/refs.c\nindex 6387703..997b360 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -261,7 +261,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *\n \t\t/* Follow \"normalized\" - ie \"refs/..\" symlinks by hand */\n \t\tif (S_ISLNK(st.st_mode)) {\n \t\t\tlen = readlink(path, buffer, sizeof(buffer)-1);\n-\t\t\tif (len >= 5 && !memcmp(\"refs/\", buffer, 5)) {\n+\t\t\tif (len >= STRLEN_PATH_REFS && !memcmp(PATH_REFS, buffer, STRLEN_PATH_REFS)) {\n \t\t\t\tbuffer[len] = 0;\n \t\t\t\tstrcpy(ref_buffer, buffer);\n \t\t\t\tref = ref_buffer;\n@@ -413,22 +413,22 @@ int head_ref(each_ref_fn fn, void *cb_data)\n \n int for_each_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(\"refs/\", fn, 0, cb_data);\n+\treturn do_for_each_ref(PATH_REFS, fn, 0, cb_data);\n }\n \n int for_each_tag_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(\"refs/tags/\", fn, 10, cb_data);\n+\treturn do_for_each_ref(PATH_REFS_TAGS, fn, STRLEN_PATH_REFS_TAGS, cb_data);\n }\n \n int for_each_branch_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(\"refs/heads/\", fn, 11, cb_data);\n+\treturn do_for_each_ref(PATH_REFS_HEADS, fn, STRLEN_PATH_REFS_HEADS, cb_data);\n }\n \n int for_each_remote_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(\"refs/remotes/\", fn, 13, cb_data);\n+\treturn do_for_each_ref(PATH_REFS_REMOTES, fn, STRLEN_PATH_REFS_REMOTES, cb_data);\n }\n \n /* NEEDSWORK: This is only used by ssh-upload and it should go; the\n@@ -440,7 +440,7 @@ int get_ref_sha1(const char *ref, unsigned char *sha1)\n {\n \tif (check_ref_format(ref))\n \t\treturn -1;\n-\treturn read_ref(mkpath(\"refs/%s\", ref), sha1);\n+\treturn read_ref(mkpath(PATH_REFS \"%s\", ref), sha1);\n }\n \n /*\n@@ -657,7 +657,7 @@ struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)\n \tchar refpath[PATH_MAX];\n \tif (check_ref_format(ref))\n \t\treturn NULL;\n-\tstrcpy(refpath, mkpath(\"refs/%s\", ref));\n+\tstrcpy(refpath, mkpath(PATH_REFS \"%s\", ref));\n \treturn lock_ref_sha1_basic(refpath, old_sha1, NULL);\n }\n \n@@ -828,12 +828,12 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)\n \t\tgoto rollback;\n \t}\n \n-\tif (!strncmp(oldref, \"refs/heads/\", 11) &&\n-\t\t\t!strncmp(newref, \"refs/heads/\", 11)) {\n+\tif (!strncmp(oldref, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS) &&\n+\t\t\t!strncmp(newref, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS)) {\n \t\tchar oldsection[1024], newsection[1024];\n \n-\t\tsnprintf(oldsection, 1024, \"branch.%s\", oldref + 11);\n-\t\tsnprintf(newsection, 1024, \"branch.%s\", newref + 11);\n+\t\tsnprintf(oldsection, 1024, \"branch.%s\", oldref + STRLEN_PATH_REFS_HEADS);\n+\t\tsnprintf(newsection, 1024, \"branch.%s\", newref + STRLEN_PATH_REFS_HEADS);\n \t\tif (git_config_rename_section(oldsection, newsection) < 0)\n \t\t\treturn 1;\n \t}\n@@ -894,8 +894,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,\n \tlog_file = git_path(\"logs/%s\", ref_name);\n \n \tif (log_all_ref_updates &&\n-\t    (!strncmp(ref_name, \"refs/heads/\", 11) ||\n-\t     !strncmp(ref_name, \"refs/remotes/\", 13) ||\n+\t    (!strncmp(ref_name,  PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS) ||\n+\t     !strncmp(ref_name, PATH_REFS_REMOTES, STRLEN_PATH_REFS_HEADS) ||\n \t     !strcmp(ref_name, \"HEAD\"))) {\n \t\tif (safe_create_leading_directories(log_file) < 0)\n \t\t\treturn error(\"unable to create directory for %s\",\ndiff --git a/refs.h b/refs.h\nindex acedffc..a986b42 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -13,6 +13,23 @@ struct ref_lock {\n #define REF_ISSYMREF 01\n #define REF_ISPACKED 02\n \n+#define PATH_OBJECTS             \"objects/\"\n+#define STRLEN_PATH_OBJECTS      8\n+#define PATH_REFS                \"refs/\"\n+#define STRLEN_PATH_REFS         5\n+#define PATH_HEADS               \"heads/\"\n+#define STRLEN_PATH_HEADS        6\n+#define PATH_TAGS                \"tags/\"\n+#define STRLEN_PATH_TAGS         5\n+#define PATH_REMOTES             \"remotes/\"\n+#define STRLEN_PATH_REMOTES      8\n+#define PATH_REFS_HEADS          PATH_REFS PATH_HEADS\n+#define STRLEN_PATH_REFS_HEADS   (STRLEN_PATH_REFS+STRLEN_PATH_HEADS)\n+#define PATH_REFS_TAGS           PATH_REFS PATH_TAGS\n+#define STRLEN_PATH_REFS_TAGS    (STRLEN_PATH_REFS+STRLEN_PATH_TAGS)\n+#define PATH_REFS_REMOTES        PATH_REFS PATH_REMOTES\n+#define STRLEN_PATH_REFS_REMOTES (STRLEN_PATH_REFS+STRLEN_PATH_REMOTES)\n+\n /*\n  * Calls the specified function for each ref file until it returns nonzero,\n  * and returns the value\ndiff --git a/setup.c b/setup.c\nindex e9d3f5a..782fc07 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"refs.h\"\n \n const char *prefix_path(const char *prefix, int len, const char *path)\n {\n@@ -154,12 +155,12 @@ static int is_git_directory(const char *suspect)\n \t\t\treturn 0;\n \t}\n \telse {\n-\t\tstrcpy(path + len, \"/objects\");\n+\t\tstrcpy(path + len, \"/\" PATH_OBJECTS);\n \t\tif (access(path, X_OK))\n \t\t\treturn 0;\n \t}\n \n-\tstrcpy(path + len, \"/refs\");\n+\tstrcpy(path + len, \"/\" PATH_REFS);\n \tif (access(path, X_OK))\n \t\treturn 0;\n \ndiff --git a/sha1_name.c b/sha1_name.c\nindex a7efa96..add6123 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -237,11 +237,11 @@ static int ambiguous_path(const char *path, int len)\n \n static const char *ref_fmt[] = {\n \t\"%.*s\",\n-\t\"refs/%.*s\",\n-\t\"refs/tags/%.*s\",\n-\t\"refs/heads/%.*s\",\n-\t\"refs/remotes/%.*s\",\n-\t\"refs/remotes/%.*s/HEAD\",\n+\tPATH_REFS \"%.*s\",\n+\tPATH_REFS_TAGS \"%.*s\",\n+\tPATH_REFS_HEADS \"%.*s\",\n+\tPATH_REFS_REMOTES \"%.*s\",\n+\tPATH_REFS_REMOTES \"%.*s/HEAD\",\n \tNULL\n };\n \ndiff --git a/wt-status.c b/wt-status.c\nindex 2879c3d..9f2705c 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -7,6 +7,7 @@\n #include \"diff.h\"\n #include \"revision.h\"\n #include \"diffcore.h\"\n+#include \"refs.h\"\n \n int wt_status_use_color = 0;\n static char wt_status_colors[][COLOR_MAXLEN] = {\n@@ -298,8 +299,8 @@ void wt_status_print(struct wt_status *s)\n \tif (s->branch) {\n \t\tconst char *on_what = \"On branch \";\n \t\tconst char *branch_name = s->branch;\n-\t\tif (!strncmp(branch_name, \"refs/heads/\", 11))\n-\t\t\tbranch_name += 11;\n+\t\tif (!strncmp(branch_name, PATH_REFS_HEADS, STRLEN_PATH_REFS_HEADS))\n+\t\t\tbranch_name += STRLEN_PATH_REFS_HEADS;\n \t\telse if (!strcmp(branch_name, \"HEAD\")) {\n \t\t\tbranch_name = \"\";\n \t\t\ton_what = \"Not currently on any branch.\";\n-- \n1.5.0.rc4.gb4d2\n"},{"id":"35018","messageId":"17881.62094.56975.799862@lisa.zopyra.com","threadId":"6884","inReplyTo":"200702191839.05784.andyparkins@gmail.com","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Bill Lear","fromEmail":"rael@zopyra.com","sentAt":"2007-02-19T18:55:10Z","receivedAt":"2007-02-19T18:55:10Z","isPatch":true,"sender":{"key":"rael@zopyra.com","avatar":"https://gravatar.com/avatar/c4f2d2790ca3828d3b4e7dfebabf61d2fe94fd82fa49cdac2a5295dd2d46a874?d=mp&s=160"},"body":"On Monday, February 19, 2007 at 18:39:05 (+0000) Andy Parkins writes:\n>...\n>+#define PATH_REMOTES             \"remotes/\"\n>+#define STRLEN_PATH_REMOTES      8\n>...\n\nWould this be less error-prone, and just as efficient?:\n\n#define PATH_REMOTES \"remotes/\"\n#define LIT_STRLEN(S) ((sizeof(S) / sizeof(S[0])) -1)\n#define STRLEN_PATH_REMOTES LIT_STRLEN(PATH_REMOTES)\n\n\nBill\n"},{"id":"35022","messageId":"200702192001.46669.andyparkins@gmail.com","threadId":"6884","inReplyTo":"17881.62094.56975.799862@lisa.zopyra.com","subject":"[PATCH] Replace literal STRLEN_ #defines in refs.h with compiler evaluated expressions","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-02-19T20:01:46Z","receivedAt":"2007-02-19T20:01:46Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Bill Lear pointed out that the following:\n\n #define PATH_REMOTES             \"remotes/\"\n #define STRLEN_PATH_REMOTES      8\n\nCould be replaced by the less error-prone\n\n #define PATH_REMOTES \"remotes/\"\n #define LIT_STRLEN(S) ((sizeof(S) / sizeof(S[0])) -1)\n #define STRLEN_PATH_REMOTES LIT_STRLEN(PATH_REMOTES)\n\nwhich is what this patch does.\n\nSigned-off-by: Andy Parkins <andyparkins@gmail.com>\n---\n\nOn top of my previous patch.\n\n\n refs.h |   11 ++++++-----\n 1 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/refs.h b/refs.h\nindex a986b42..6761095 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -13,16 +13,17 @@ struct ref_lock {\n #define REF_ISSYMREF 01\n #define REF_ISPACKED 02\n \n+#define LIT_STRLEN(S)            ((sizeof(S) / sizeof(S[0])) -1)\n #define PATH_OBJECTS             \"objects/\"\n-#define STRLEN_PATH_OBJECTS      8\n+#define STRLEN_PATH_OBJECTS      LIT_STRLEN(PATH_OBJECTS)\n #define PATH_REFS                \"refs/\"\n-#define STRLEN_PATH_REFS         5\n+#define STRLEN_PATH_REFS         LIT_STRLEN(PATH_REFS)\n #define PATH_HEADS               \"heads/\"\n-#define STRLEN_PATH_HEADS        6\n+#define STRLEN_PATH_HEADS        LIT_STRLEN(PATH_HEADS)\n #define PATH_TAGS                \"tags/\"\n-#define STRLEN_PATH_TAGS         5\n+#define STRLEN_PATH_TAGS         LIT_STRLEN(PATH_TAGS)\n #define PATH_REMOTES             \"remotes/\"\n-#define STRLEN_PATH_REMOTES      8\n+#define STRLEN_PATH_REMOTES      LIT_STRLEN(PATH_REMOTES)\n #define PATH_REFS_HEADS          PATH_REFS PATH_HEADS\n #define STRLEN_PATH_REFS_HEADS   (STRLEN_PATH_REFS+STRLEN_PATH_HEADS)\n #define PATH_REFS_TAGS           PATH_REFS PATH_TAGS\n-- \n1.5.0.rc4.gb4d2\n"},{"id":"35023","messageId":"7vlkit7vy5.fsf@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"200702191839.05784.andyparkins@gmail.com","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-19T20:07:30Z","receivedAt":"2007-02-19T20:07:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> writes:\n\n> Changed repeated use of the same constants for the ref paths to be\n> symbolic constants.  I've defined them in refs.h\n>\n>   refs/ is now PATH_REFS\n>   refs/heads/ is now PATH_REFS_HEADS\n>   refs/tags/ is now PATH_REFS_TAGS\n>   refs/remotes/ is now PATH_REFS_REMOTES\n\nYour example:\n\n> ...  This has clarified the code in some places; for\n> example:\n>\n>  - len = strlen(refs[i]) + 11;\n>  + len = strlen(refs[i]) + STRLEN_PATH_REFS_TAGS + 1;\n\nshows that you've carefully looked at what the code does,\ninstead of mindlessly replacing, which is a very good sign, but\nhow much testing has this seen, I wonder.\n\n> diff --git a/builtin-describe.c b/builtin-describe.c\n> index bcc6456..0f78363 100644\n> --- a/builtin-describe.c\n> +++ b/builtin-describe.c\n> @@ -52,7 +52,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void\n>  \t * If --tags, then any tags are used.\n>  \t * Otherwise only annotated tags are used.\n>  \t */\n> -\tif (!strncmp(path, \"refs/tags/\", 10)) {\n> +\tif (!strncmp(path, PATH_TAGS, STRLEN_PATH_TAGS)) {\n>  \t\tif (object->type == OBJ_TAG)\n>  \t\t\tprio = 2;\n>  \t\telse\n\nThis is PATH_REFS_TAGS isn't it?\n\n> @@ -231,7 +232,7 @@ static int create_default_files(const char *git_dir, const char *template_path)\n>  \tstrcpy(path + len, \"HEAD\");\n>  \treinit = !read_ref(\"HEAD\", sha1);\n>  \tif (!reinit) {\n> -\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n> +\t\tif (create_symref(\"HEAD\", PATH_REFS_HEADS \"master\", NULL) < 0)\n>  \t\t\texit(1);\n>  \t}\n>  \n\nI mildly mind this one, as it hurts grep-ability.  I know this is one\nof the the only two places in git that 'master' branch is treated\nspecially (and I think we would like to keep it that way --- that's\nwhy I want to be able to grep for \"refs/heads/master\" and see very few\nhits), so introducing PATH_REFS_HEADS_MASTER is probably not very\nproductive either, but...  hmmmm.\n\n> diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c\n> index 3de9b3e..ac7543d 100644\n> --- a/builtin-pack-refs.c\n> +++ b/builtin-pack-refs.c\n> @@ -36,7 +36,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,\n>  \t/* Do not pack the symbolic refs */\n>  \tif ((flags & REF_ISSYMREF))\n>  \t\treturn 0;\n> -\tis_tag_ref = !strncmp(path, \"refs/tags/\", 10);\n> +\tis_tag_ref = !strncmp(path, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS);\n\nThese repeated strncmp(p, X, STRLEN_X) almost makes me wonder if we\nwant to introduce:\n\n\tinline int prefixcmp(a, b)\n        {\n        \treturn (strncmp(a, b, strlen(b));\n        }\n\nwith clever preprocessor optimization to have compiler do strlen()\nwhen b is a string literal.\n"},{"id":"35026","messageId":"20070219201249.GC27565@spearce.org","threadId":"6884","inReplyTo":"7vlkit7vy5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-19T20:12:49Z","receivedAt":"2007-02-19T20:12:49Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> > diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c\n> > index 3de9b3e..ac7543d 100644\n> > --- a/builtin-pack-refs.c\n> > +++ b/builtin-pack-refs.c\n> > @@ -36,7 +36,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,\n> >  \t/* Do not pack the symbolic refs */\n> >  \tif ((flags & REF_ISSYMREF))\n> >  \t\treturn 0;\n> > -\tis_tag_ref = !strncmp(path, \"refs/tags/\", 10);\n> > +\tis_tag_ref = !strncmp(path, PATH_REFS_TAGS, STRLEN_PATH_REFS_TAGS);\n> \n> These repeated strncmp(p, X, STRLEN_X) almost makes me wonder if we\n> want to introduce:\n> \n> \tinline int prefixcmp(a, b)\n>         {\n>         \treturn (strncmp(a, b, strlen(b));\n>         }\n> \n> with clever preprocessor optimization to have compiler do strlen()\n> when b is a string literal.\n\nThis may be worthwhile.  We use strncmp so often in Git that I\ntend to write strncmp even when I mean strcmp.  Yes, my fingers are\ntrained to write strncmp, and only strncmp...  *sigh* At least the\ncompiler checks for me.  ;-)\n\n-- \nShawn.\n"},{"id":"35030","messageId":"m3fy91q3bq.fsf@maximus.localdomain","threadId":"6884","inReplyTo":"17881.62094.56975.799862@lisa.zopyra.com","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Krzysztof Halasa","fromEmail":"khc@pm.waw.pl","sentAt":"2007-02-19T20:50:49Z","receivedAt":"2007-02-19T20:50:49Z","isPatch":true,"sender":{"key":"khc@pm.waw.pl","avatar":null},"body":"Bill Lear <rael@zopyra.com> writes:\n\n> Would this be less error-prone, and just as efficient?:\n>\n> #define PATH_REMOTES \"remotes/\"\n> #define LIT_STRLEN(S) ((sizeof(S) / sizeof(S[0])) -1)\n> #define STRLEN_PATH_REMOTES LIT_STRLEN(PATH_REMOTES)\n\nsizeof(char) is always 1.\n-- \nKrzysztof Halasa\n"},{"id":"35031","messageId":"20070219205647.GB27722@spearce.org","threadId":"6884","inReplyTo":"m3fy91q3bq.fsf@maximus.localdomain","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-19T20:56:47Z","receivedAt":"2007-02-19T20:56:47Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Krzysztof Halasa <khc@pm.waw.pl> wrote:\n> Bill Lear <rael@zopyra.com> writes:\n> \n> > Would this be less error-prone, and just as efficient?:\n> >\n> > #define PATH_REMOTES \"remotes/\"\n> > #define LIT_STRLEN(S) ((sizeof(S) / sizeof(S[0])) -1)\n> > #define STRLEN_PATH_REMOTES LIT_STRLEN(PATH_REMOTES)\n> \n> sizeof(char) is always 1.\n\nExcept when someone does something silly, like say:\n\n\t#define char double\n\n:-)\n\n-- \nShawn.\n"},{"id":"35034","messageId":"Pine.LNX.4.63.0702192307240.14047@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6884","inReplyTo":"7vlkit7vy5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-19T22:08:32Z","receivedAt":"2007-02-19T22:08:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 19 Feb 2007, Junio C Hamano wrote:\n\n> These repeated strncmp(p, X, STRLEN_X) almost makes me wonder if we want \n> to introduce:\n> \n> \tinline int prefixcmp(a, b)\n>         {\n>         \treturn (strncmp(a, b, strlen(b));\n>         }\n> \n> with clever preprocessor optimization to have compiler do strlen() when \n> b is a string literal.\n\nI am in favour of that. BTW I remember that Han-Wen suggested this some \ntime ago, too.\n\nCiao,\nDscho\n"},{"id":"35092","messageId":"200702200841.26578.andyparkins@gmail.com","threadId":"6884","inReplyTo":"7vlkit7vy5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-02-20T08:41:24Z","receivedAt":"2007-02-20T08:41:24Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Monday 2007 February 19 20:07, Junio C Hamano wrote:\n\n> >  - len = strlen(refs[i]) + 11;\n> >  + len = strlen(refs[i]) + STRLEN_PATH_REFS_TAGS + 1;\n>\n> shows that you've carefully looked at what the code does,\n> instead of mindlessly replacing, which is a very good sign, but\n> how much testing has this seen, I wonder.\n\nNot huge quantities.  The patch is so wide-spread, that I've checked it \ncompiles, and I've run with it for a bit.  However, I could not swear to \nhaving checked every path...\n\n\n> > diff --git a/builtin-describe.c b/builtin-describe.c\n> > index bcc6456..0f78363 100644\n> > --- a/builtin-describe.c\n> > +++ b/builtin-describe.c\n> > @@ -52,7 +52,7 @@ static int get_name(const char *path, const unsigned\n> > char *sha1, int flag, void * If --tags, then any tags are used.\n> >  \t * Otherwise only annotated tags are used.\n> >  \t */\n> > -\tif (!strncmp(path, \"refs/tags/\", 10)) {\n> > +\tif (!strncmp(path, PATH_TAGS, STRLEN_PATH_TAGS)) {\n> >  \t\tif (object->type == OBJ_TAG)\n> >  \t\t\tprio = 2;\n> >  \t\telse\n>\n> This is PATH_REFS_TAGS isn't it?\n\n<shame> Yes.\n\n> I mildly mind this one, as it hurts grep-ability.  I know this is one\n> of the the only two places in git that 'master' branch is treated\n> specially (and I think we would like to keep it that way --- that's\n\nThe output of \n $ git-grep \"master\" -- '*.c' '*.h'\nIs not that big, so those special treatments can be easily found irrespective \nof my patch.\n\n> why I want to be able to grep for \"refs/heads/master\" and see very few\n> hits), so introducing PATH_REFS_HEADS_MASTER is probably not very\n> productive either, but...  hmmmm.\n\nAs I've said before, I'm against /any/ special treatment of master other than \nas a default branch name in a newly initialised repository.  \nPATH_REFS_HEADS_MASTER is closer to master not being special than without so \nI'd be in favour of that.\n\n> These repeated strncmp(p, X, STRLEN_X) almost makes me wonder if we\n> want to introduce:\n>\n> \tinline int prefixcmp(a, b)\n>         {\n>         \treturn (strncmp(a, b, strlen(b));\n>         }\n>\n> with clever preprocessor optimization to have compiler do strlen()\n> when b is a string literal.\n\nWow; that would be clever - regardless of whether this patch is acceptable or \nnot.\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIEE\nandyparkins@gmail.com\n"},{"id":"35094","messageId":"7vlkitxkrq.fsf@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"200702200841.26578.andyparkins@gmail.com","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T09:04:25Z","receivedAt":"2007-02-20T09:04:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> writes:\n\n> As I've said before, I'm against /any/ special treatment of\n> master other than as a default branch name in a newly\n> initialised repository.  PATH_REFS_HEADS_MASTER is closer to\n> master not being special than without so I'd be in favour of\n> that.\n\nOk.\n\n>> These repeated strncmp(p, X, STRLEN_X) almost makes me wonder if we\n>> want to introduce:\n>>\n>> \tinline int prefixcmp(a, b)\n>>         {\n>>         \treturn (strncmp(a, b, strlen(b));\n>>         }\n>>\n>> with clever preprocessor optimization to have compiler do strlen()\n>> when b is a string literal.\n>\n> Wow; that would be clever - regardless of whether this patch\n> is acceptable or not.\n\nActually GCC seems to be clever enough.  It appears that I do\nnot even have to do prefixcmp_0() below; prefixcmp_1() seems to\ngenerate good code, with GCC 4.1.2 prerelease on my x86_64.\n\n-- >8 --\n#include <string.h>\nstatic inline int prefixcmp_0(const char *a, const char *b)\n{\n\tif (__builtin_constant_p(b))\n\t\treturn strncmp(a, b, sizeof(b) - 1);\n\telse\n\t\treturn strncmp(a, b, strlen(b));\n}\n\nstatic inline prefixcmp_1(const char *a, const char *b)\n{\n\treturn strncmp(a, b, strlen(b));\n}\n\nvoid foo(const char *s, const char *t, int *a, int *b, int *c, int *d)\n{\n\t*a = prefixcmp_0(s, \"abcdefg\");\n\t*b = prefixcmp_0(s, t);\n\t*c = prefixcmp_1(s, \"ABCDEFGH\");\n\t*d = prefixcmp_1(s, t);\n}\n-- 8< --\n"},{"id":"35097","messageId":"200702200942.18654.andyparkins@gmail.com","threadId":"6884","inReplyTo":"7vlkit7vy5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-02-20T09:42:17Z","receivedAt":"2007-02-20T09:42:17Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Monday 2007 February 19 20:07, Junio C Hamano wrote:\n\n> > -\tif (!strncmp(path, \"refs/tags/\", 10)) {\n> > +\tif (!strncmp(path, PATH_TAGS, STRLEN_PATH_TAGS)) {\n> >  \t\tif (object->type == OBJ_TAG)\n> >  \t\t\tprio = 2;\n> >  \t\telse\n>\n> This is PATH_REFS_TAGS isn't it?\n\nI'm uncomfortable that this one managed to get through; in view of this \nmistake if you are thinking of applying this - don't.  I'm going to review \nthe patch itself line by line.\n\nAlso - I should learn how to run the tests - is \"make test\" good enough or is \nthere something special I should do?\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIEE\nandyparkins@gmail.com\n"},{"id":"35099","messageId":"7vfy91ximy.fsf@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"200702200942.18654.andyparkins@gmail.com","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T09:50:29Z","receivedAt":"2007-02-20T09:50:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> writes:\n\n> On Monday 2007 February 19 20:07, Junio C Hamano wrote:\n>\n>> > -\tif (!strncmp(path, \"refs/tags/\", 10)) {\n>> > +\tif (!strncmp(path, PATH_TAGS, STRLEN_PATH_TAGS)) {\n>> >  \t\tif (object->type == OBJ_TAG)\n>> >  \t\t\tprio = 2;\n>> >  \t\telse\n>>\n>> This is PATH_REFS_TAGS isn't it?\n>\n> I'm uncomfortable that this one managed to get through; in view of this \n> mistake if you are thinking of applying this - don't.  I'm going to review \n> the patch itself line by line.\n\nI'd send the prefixcmp() patches first, as yours would touch the\nsame lines.\n\n> Also - I should learn how to run the tests - is \"make test\"\n> good enough or is there something special I should do?\n\nShould be enough.\n"},{"id":"35100","messageId":"7vbqjpxilh.fsf_-_@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"200702200942.18654.andyparkins@gmail.com","subject":"[PATCH 1/4] Add prefixcmp()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T09:51:22Z","receivedAt":"2007-02-20T09:51:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"We have too many strncmp(a, b, strlen(b)).\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n git-compat-util.h |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 9863cf6..0a9ac56 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -279,4 +279,9 @@ static inline int sane_case(int x, int high)\n \treturn x;\n }\n \n+static inline int prefixcmp(const char *a, const char *b)\n+{\n+\treturn strncmp(a, b, strlen(b));\n+}\n+\n #endif\n-- \n1.5.0.1.571.ge5a1a\n"},{"id":"35101","messageId":"7v3b51xihy.fsf_-_@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"200702200942.18654.andyparkins@gmail.com","subject":"[PATCH 2/4] Mechanical conversion to use prefixcmp()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T09:53:29Z","receivedAt":"2007-02-20T09:53:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This mechanically converts strncmp() to use prefixcmp(), but only when\nthe parameters match specific patterns, so that they can be verified\neasily.  Leftover from this will be fixed in a separate step, including\nidiotic conversions like\n\n\tif (!strncmp(\"foo\", arg, 3))\n\n  =>\n\n\tif (!(-prefixcmp(arg, \"foo\")))\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * This was done by using this script in px.perl\n\n   #!/usr/bin/perl -i.bak -p\n   if (/strncmp\\(([^,]+), \"([^\\\\\"]*)\", (\\d+)\\)/ && (length($2) == $3)) {\n           s|strncmp\\(([^,]+), \"([^\\\\\"]*)\", (\\d+)\\)|prefixcmp($1, \"$2\")|;\n   }\n   if (/strncmp\\(\"([^\\\\\"]*)\", ([^,]+), (\\d+)\\)/ && (length($1) == $3)) {\n           s|strncmp\\(\"([^\\\\\"]*)\", ([^,]+), (\\d+)\\)|(-prefixcmp($2, \"$1\"))|;\n   }\n\n   and running:\n\n   $ git grep -l strncmp -- '*.c' | xargs perl px.perl\n\n builtin-apply.c          |   12 ++++++------\n builtin-archive.c        |   10 +++++-----\n builtin-blame.c          |    6 +++---\n builtin-branch.c         |   12 ++++++------\n builtin-checkout-index.c |    4 ++--\n builtin-describe.c       |    6 +++---\n builtin-fmt-merge-msg.c  |   10 +++++-----\n builtin-for-each-ref.c   |    6 +++---\n builtin-fsck.c           |    2 +-\n builtin-grep.c           |    6 +++---\n builtin-init-db.c        |    4 ++--\n builtin-log.c            |   12 ++++++------\n builtin-ls-files.c       |    8 ++++----\n builtin-mailinfo.c       |    2 +-\n builtin-name-rev.c       |    8 ++++----\n builtin-pack-objects.c   |    6 +++---\n builtin-pack-refs.c      |    2 +-\n builtin-push.c           |   18 +++++++++---------\n builtin-read-tree.c      |    4 ++--\n builtin-reflog.c         |    4 ++--\n builtin-rerere.c         |    6 +++---\n builtin-rev-parse.c      |   10 +++++-----\n builtin-shortlog.c       |    6 +++---\n builtin-show-branch.c    |   20 ++++++++++----------\n builtin-show-ref.c       |   12 ++++++------\n builtin-tar-tree.c       |    2 +-\n builtin-unpack-objects.c |    2 +-\n builtin-write-tree.c     |    2 +-\n connect.c                |    6 +++---\n daemon.c                 |   32 ++++++++++++++++----------------\n diff.c                   |   30 +++++++++++++++---------------\n exec_cmd.c               |    2 +-\n fast-import.c            |   42 +++++++++++++++++++++---------------------\n fetch-pack.c             |   12 ++++++------\n git.c                    |   10 +++++-----\n help.c                   |    4 ++--\n http-fetch.c             |    2 +-\n http-push.c              |    8 ++++----\n index-pack.c             |    4 ++--\n peek-remote.c            |    4 ++--\n receive-pack.c           |    4 ++--\n refs.c                   |    8 ++++----\n revision.c               |   30 +++++++++++++++---------------\n send-pack.c              |    4 ++--\n setup.c                  |    2 +-\n shell.c                  |    2 +-\n upload-pack.c            |   10 +++++-----\n wt-status.c              |    4 ++--\n 48 files changed, 211 insertions(+), 211 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex abe3538..d678178 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -1129,11 +1129,11 @@ static struct fragment *parse_binary_hunk(char **buf_p,\n \n \t*status_p = 0;\n \n-\tif (!strncmp(buffer, \"delta \", 6)) {\n+\tif (!prefixcmp(buffer, \"delta \")) {\n \t\tpatch_method = BINARY_DELTA_DEFLATED;\n \t\toriglen = strtoul(buffer + 6, NULL, 10);\n \t}\n-\telse if (!strncmp(buffer, \"literal \", 8)) {\n+\telse if (!prefixcmp(buffer, \"literal \")) {\n \t\tpatch_method = BINARY_LITERAL_DEFLATED;\n \t\toriglen = strtoul(buffer + 8, NULL, 10);\n \t}\n@@ -2608,14 +2608,14 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \t\t\tread_stdin = 0;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--exclude=\", 10)) {\n+\t\tif (!prefixcmp(arg, \"--exclude=\")) {\n \t\t\tstruct excludes *x = xmalloc(sizeof(*x));\n \t\t\tx->path = arg + 10;\n \t\t\tx->next = excludes;\n \t\t\texcludes = x;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"-p\", 2)) {\n+\t\tif (!prefixcmp(arg, \"-p\")) {\n \t\t\tp_value = atoi(arg + 2);\n \t\t\tcontinue;\n \t\t}\n@@ -2669,13 +2669,13 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \t\t\tline_termination = 0;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"-C\", 2)) {\n+\t\tif (!prefixcmp(arg, \"-C\")) {\n \t\t\tp_context = strtoul(arg + 2, &end, 0);\n \t\t\tif (*end != '\\0')\n \t\t\t\tdie(\"unrecognized context count '%s'\", arg + 2);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--whitespace=\", 13)) {\n+\t\tif (!prefixcmp(arg, \"--whitespace=\")) {\n \t\t\twhitespace_option = arg + 13;\n \t\t\tparse_whitespace_option(arg + 13);\n \t\t\tcontinue;\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex f613ac2..0c56de0 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -35,7 +35,7 @@ static int run_remote_archiver(const char *remote, int argc,\n \n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n-\t\tif (!strncmp(\"--exec=\", arg, 7)) {\n+\t\tif (!(-prefixcmp(arg, \"--exec=\"))) {\n \t\t\tif (exec_at)\n \t\t\t\tdie(\"multiple --exec specified\");\n \t\t\texec = arg + 7;\n@@ -62,7 +62,7 @@ static int run_remote_archiver(const char *remote, int argc,\n \tif (buf[len-1] == '\\n')\n \t\tbuf[--len] = 0;\n \tif (strcmp(buf, \"ACK\")) {\n-\t\tif (len > 5 && !strncmp(buf, \"NACK \", 5))\n+\t\tif (len > 5 && !prefixcmp(buf, \"NACK \"))\n \t\t\tdie(\"git-archive: NACK %s\", buf + 5);\n \t\tdie(\"git-archive: protocol error\");\n \t}\n@@ -166,11 +166,11 @@ int parse_archive_args(int argc, const char **argv, struct archiver *ar)\n \t\t\tverbose = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--format=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--format=\")) {\n \t\t\tformat = arg + 9;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--prefix=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--prefix=\")) {\n \t\t\tbase = arg + 9;\n \t\t\tcontinue;\n \t\t}\n@@ -218,7 +218,7 @@ static const char *extract_remote_arg(int *ac, const char **av)\n \t\tif (!strcmp(arg, \"--\"))\n \t\t\tno_more_options = 1;\n \t\tif (!no_more_options) {\n-\t\t\tif (!strncmp(arg, \"--remote=\", 9)) {\n+\t\t\tif (!prefixcmp(arg, \"--remote=\")) {\n \t\t\t\tif (remote)\n \t\t\t\t\tdie(\"Multiple --remote specified\");\n \t\t\t\tremote = arg + 9;\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 5669a16..db311bf 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -2097,17 +2097,17 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\t\toutput_option |= OUTPUT_LONG_OBJECT_NAME;\n \t\telse if (!strcmp(\"-S\", arg) && ++i < argc)\n \t\t\trevs_file = argv[i];\n-\t\telse if (!strncmp(\"-M\", arg, 2)) {\n+\t\telse if (!(-prefixcmp(arg, \"-M\"))) {\n \t\t\topt |= PICKAXE_BLAME_MOVE;\n \t\t\tblame_move_score = parse_score(arg+2);\n \t\t}\n-\t\telse if (!strncmp(\"-C\", arg, 2)) {\n+\t\telse if (!(-prefixcmp(arg, \"-C\"))) {\n \t\t\tif (opt & PICKAXE_BLAME_COPY)\n \t\t\t\topt |= PICKAXE_BLAME_COPY_HARDER;\n \t\t\topt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;\n \t\t\tblame_copy_score = parse_score(arg+2);\n \t\t}\n-\t\telse if (!strncmp(\"-L\", arg, 2)) {\n+\t\telse if (!(-prefixcmp(arg, \"-L\"))) {\n \t\t\tif (!arg[2]) {\n \t\t\t\tif (++i >= argc)\n \t\t\t\t\tusage(blame_usage);\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex d0e7209..d0179b0 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -59,7 +59,7 @@ int git_branch_config(const char *var, const char *value)\n \t\tbranch_use_color = git_config_colorbool(var, value);\n \t\treturn 0;\n \t}\n-\tif (!strncmp(var, \"color.branch.\", 13)) {\n+\tif (!prefixcmp(var, \"color.branch.\")) {\n \t\tint slot = parse_branch_color_slot(var, 13);\n \t\tcolor_parse(value, var, branch_colors[slot]);\n \t\treturn 0;\n@@ -178,13 +178,13 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,\n \tint len;\n \n \t/* Detect kind */\n-\tif (!strncmp(refname, \"refs/heads/\", 11)) {\n+\tif (!prefixcmp(refname, \"refs/heads/\")) {\n \t\tkind = REF_LOCAL_BRANCH;\n \t\trefname += 11;\n-\t} else if (!strncmp(refname, \"refs/remotes/\", 13)) {\n+\t} else if (!prefixcmp(refname, \"refs/remotes/\")) {\n \t\tkind = REF_REMOTE_BRANCH;\n \t\trefname += 13;\n-\t} else if (!strncmp(refname, \"refs/tags/\", 10)) {\n+\t} else if (!prefixcmp(refname, \"refs/tags/\")) {\n \t\tkind = REF_TAG;\n \t\trefname += 10;\n \t}\n@@ -446,7 +446,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\t\treflog = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--abbrev=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--abbrev=\")) {\n \t\t\tabbrev = atoi(arg+9);\n \t\t\tcontinue;\n \t\t}\n@@ -476,7 +476,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tdetached = 1;\n \t}\n \telse {\n-\t\tif (strncmp(head, \"refs/heads/\", 11))\n+\t\tif (prefixcmp(head, \"refs/heads/\"))\n \t\t\tdie(\"HEAD not found below refs/heads!\");\n \t\thead += 11;\n \t}\ndiff --git a/builtin-checkout-index.c b/builtin-checkout-index.c\nindex b097c88..afe4b0e 100644\n--- a/builtin-checkout-index.c\n+++ b/builtin-checkout-index.c\n@@ -223,12 +223,12 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)\n \t\t\tto_tempfile = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--prefix=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--prefix=\")) {\n \t\t\tstate.base_dir = arg+9;\n \t\t\tstate.base_dir_len = strlen(state.base_dir);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--stage=\", 8)) {\n+\t\tif (!prefixcmp(arg, \"--stage=\")) {\n \t\t\tif (!strcmp(arg + 8, \"all\")) {\n \t\t\t\tto_tempfile = 1;\n \t\t\t\tcheckout_stage = CHECKOUT_ALL;\ndiff --git a/builtin-describe.c b/builtin-describe.c\nindex bcc6456..165917e 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -52,7 +52,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void\n \t * If --tags, then any tags are used.\n \t * Otherwise only annotated tags are used.\n \t */\n-\tif (!strncmp(path, \"refs/tags/\", 10)) {\n+\tif (!prefixcmp(path, \"refs/tags/\")) {\n \t\tif (object->type == OBJ_TAG)\n \t\t\tprio = 2;\n \t\telse\n@@ -254,12 +254,12 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tall = 1;\n \t\telse if (!strcmp(arg, \"--tags\"))\n \t\t\ttags = 1;\n-\t\telse if (!strncmp(arg, \"--abbrev=\", 9)) {\n+\t\telse if (!prefixcmp(arg, \"--abbrev=\")) {\n \t\t\tabbrev = strtoul(arg + 9, NULL, 10);\n \t\t\tif (abbrev != 0 && (abbrev < MINIMUM_ABBREV || 40 < abbrev))\n \t\t\t\tabbrev = DEFAULT_ABBREV;\n \t\t}\n-\t\telse if (!strncmp(arg, \"--candidates=\", 13)) {\n+\t\telse if (!prefixcmp(arg, \"--candidates=\")) {\n \t\t\tmax_candidates = strtoul(arg + 13, NULL, 10);\n \t\t\tif (max_candidates < 1)\n \t\t\t\tmax_candidates = 1;\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex 87d3d63..1489883 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -81,7 +81,7 @@ static int handle_line(char *line)\n \tif (len < 43 || line[40] != '\\t')\n \t\treturn 1;\n \n-\tif (!strncmp(line + 41, \"not-for-merge\", 13))\n+\tif (!prefixcmp(line + 41, \"not-for-merge\"))\n \t\treturn 0;\n \n \tif (line[41] != '\\t')\n@@ -119,15 +119,15 @@ static int handle_line(char *line)\n \tif (pulling_head) {\n \t\torigin = xstrdup(src);\n \t\tsrc_data->head_status |= 1;\n-\t} else if (!strncmp(line, \"branch \", 7)) {\n+\t} else if (!prefixcmp(line, \"branch \")) {\n \t\torigin = xstrdup(line + 7);\n \t\tappend_to_list(&src_data->branch, origin, NULL);\n \t\tsrc_data->head_status |= 2;\n-\t} else if (!strncmp(line, \"tag \", 4)) {\n+\t} else if (!prefixcmp(line, \"tag \")) {\n \t\torigin = line;\n \t\tappend_to_list(&src_data->tag, xstrdup(origin + 4), NULL);\n \t\tsrc_data->head_status |= 2;\n-\t} else if (!strncmp(line, \"remote branch \", 14)) {\n+\t} else if (!prefixcmp(line, \"remote branch \")) {\n \t\torigin = xstrdup(line + 14);\n \t\tappend_to_list(&src_data->r_branch, origin, NULL);\n \t\tsrc_data->head_status |= 2;\n@@ -280,7 +280,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)\n \tcurrent_branch = resolve_ref(\"HEAD\", head_sha1, 1, NULL);\n \tif (!current_branch)\n \t\tdie(\"No current branch\");\n-\tif (!strncmp(current_branch, \"refs/heads/\", 11))\n+\tif (!prefixcmp(current_branch, \"refs/heads/\"))\n \t\tcurrent_branch += 11;\n \n \twhile (fgets(line, sizeof(line), in)) {\ndiff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c\nindex 16c785f..ac0b9f6 100644\n--- a/builtin-for-each-ref.c\n+++ b/builtin-for-each-ref.c\n@@ -814,7 +814,7 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix)\n \t\t\ti++;\n \t\t\tbreak;\n \t\t}\n-\t\tif (!strncmp(arg, \"--format=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--format=\")) {\n \t\t\tif (format)\n \t\t\t\tdie(\"more than one --format?\");\n \t\t\tformat = arg + 9;\n@@ -844,7 +844,7 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix)\n \t\t\tquote_style = QUOTE_TCL;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--count=\", 8)) {\n+\t\tif (!prefixcmp(arg, \"--count=\")) {\n \t\t\tif (maxcount)\n \t\t\t\tdie(\"more than one --count?\");\n \t\t\tmaxcount = atoi(arg + 8);\n@@ -852,7 +852,7 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix)\n \t\t\t\tdie(\"The number %s did not parse\", arg);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--sort=\", 7)) {\n+\t\tif (!prefixcmp(arg, \"--sort=\")) {\n \t\t\tstruct ref_sort *s = xcalloc(1, sizeof(*s));\n \t\t\tint len;\n \ndiff --git a/builtin-fsck.c b/builtin-fsck.c\nindex 6da3814..6abf498 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -546,7 +546,7 @@ static int fsck_head_link(void)\n \n \tif (!head_points_at || !(flag & REF_ISSYMREF))\n \t\treturn error(\"HEAD is not a symbolic ref\");\n-\tif (strncmp(head_points_at, \"refs/heads/\", 11))\n+\tif (prefixcmp(head_points_at, \"refs/heads/\"))\n \t\treturn error(\"HEAD points to something strange (%s)\",\n \t\t\t     head_points_at);\n \tif (is_null_sha1(sha1))\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 2bfbdb7..cec2204 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -527,9 +527,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\topt.word_regexp = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(\"-A\", arg, 2) ||\n-\t\t    !strncmp(\"-B\", arg, 2) ||\n-\t\t    !strncmp(\"-C\", arg, 2) ||\n+\t\tif (!(-prefixcmp(arg, \"-A\")) ||\n+\t\t    !(-prefixcmp(arg, \"-B\")) ||\n+\t\t    !(-prefixcmp(arg, \"-C\")) ||\n \t\t    (arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {\n \t\t\tunsigned num;\n \t\t\tconst char *scan;\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 12e43d0..4df9fd0 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -283,11 +283,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \n \tfor (i = 1; i < argc; i++, argv++) {\n \t\tconst char *arg = argv[1];\n-\t\tif (!strncmp(arg, \"--template=\", 11))\n+\t\tif (!prefixcmp(arg, \"--template=\"))\n \t\t\ttemplate_dir = arg+11;\n \t\telse if (!strcmp(arg, \"--shared\"))\n \t\t\tshared_repository = PERM_GROUP;\n-\t\telse if (!strncmp(arg, \"--shared=\", 9))\n+\t\telse if (!prefixcmp(arg, \"--shared=\"))\n \t\t\tshared_repository = git_config_perm(\"arg\", arg+9);\n \t\telse\n \t\t\tusage(init_db_usage);\ndiff --git a/builtin-log.c b/builtin-log.c\nindex af2de54..ad1e8c0 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -32,7 +32,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,\n \t\trev->always_show_header = 0;\n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n-\t\tif (!strncmp(arg, \"--encoding=\", 11)) {\n+\t\tif (!prefixcmp(arg, \"--encoding=\")) {\n \t\t\targ += 11;\n \t\t\tif (strcmp(arg, \"none\"))\n \t\t\t\tgit_log_output_encoding = strdup(arg);\n@@ -287,7 +287,7 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)\n \n \t\tsol += 2;\n \t\t/* strip [PATCH] or [PATCH blabla] */\n-\t\tif (!keep_subject && !strncmp(sol, \"[PATCH\", 6)) {\n+\t\tif (!keep_subject && !prefixcmp(sol, \"[PATCH\")) {\n \t\t\tchar *eos = strchr(sol + 6, ']');\n \t\t\tif (eos) {\n \t\t\t\twhile (isspace(*eos))\n@@ -435,7 +435,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\telse if (!strcmp(argv[i], \"-n\") ||\n \t\t\t\t!strcmp(argv[i], \"--numbered\"))\n \t\t\tnumbered = 1;\n-\t\telse if (!strncmp(argv[i], \"--start-number=\", 15))\n+\t\telse if (!prefixcmp(argv[i], \"--start-number=\"))\n \t\t\tstart_number = strtol(argv[i] + 15, NULL, 10);\n \t\telse if (!strcmp(argv[i], \"--start-number\")) {\n \t\t\ti++;\n@@ -471,13 +471,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t}\n \t\telse if (!strcmp(argv[i], \"--attach\"))\n \t\t\trev.mime_boundary = git_version_string;\n-\t\telse if (!strncmp(argv[i], \"--attach=\", 9))\n+\t\telse if (!prefixcmp(argv[i], \"--attach=\"))\n \t\t\trev.mime_boundary = argv[i] + 9;\n \t\telse if (!strcmp(argv[i], \"--ignore-if-in-upstream\"))\n \t\t\tignore_if_in_upstream = 1;\n \t\telse if (!strcmp(argv[i], \"--thread\"))\n \t\t\tthread = 1;\n-\t\telse if (!strncmp(argv[i], \"--in-reply-to=\", 14))\n+\t\telse if (!prefixcmp(argv[i], \"--in-reply-to=\"))\n \t\t\tin_reply_to = argv[i] + 14;\n \t\telse if (!strcmp(argv[i], \"--in-reply-to\")) {\n \t\t\ti++;\n@@ -485,7 +485,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t\tdie(\"Need a Message-Id for --in-reply-to\");\n \t\t\tin_reply_to = argv[i];\n \t\t}\n-\t\telse if (!strncmp(argv[i], \"--suffix=\", 9))\n+\t\telse if (!prefixcmp(argv[i], \"--suffix=\"))\n \t\t\tfmt_patch_suffix = argv[i] + 9;\n \t\telse\n \t\t\targv[j++] = argv[i];\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex ac89eb2..4e1d5af 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -406,7 +406,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\t\tadd_exclude(argv[++i], \"\", 0, &dir.exclude_list[EXC_CMDL]);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--exclude=\", 10)) {\n+\t\tif (!prefixcmp(arg, \"--exclude=\")) {\n \t\t\texc_given = 1;\n \t\t\tadd_exclude(arg+10, \"\", 0, &dir.exclude_list[EXC_CMDL]);\n \t\t\tcontinue;\n@@ -416,12 +416,12 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\t\tadd_excludes_from_file(&dir, argv[++i]);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--exclude-from=\", 15)) {\n+\t\tif (!prefixcmp(arg, \"--exclude-from=\")) {\n \t\t\texc_given = 1;\n \t\t\tadd_excludes_from_file(&dir, arg+15);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--exclude-per-directory=\", 24)) {\n+\t\tif (!prefixcmp(arg, \"--exclude-per-directory=\")) {\n \t\t\texc_given = 1;\n \t\t\tdir.exclude_per_dir = arg + 24;\n \t\t\tcontinue;\n@@ -434,7 +434,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\t\terror_unmatch = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--abbrev=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--abbrev=\")) {\n \t\t\tabbrev = strtoul(arg+9, NULL, 10);\n \t\t\tif (abbrev && abbrev < MINIMUM_ABBREV)\n \t\t\t\tabbrev = MINIMUM_ABBREV;\ndiff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\nindex 583da38..6ee6b0b 100644\n--- a/builtin-mailinfo.c\n+++ b/builtin-mailinfo.c\n@@ -811,7 +811,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)\n \t\t\tmetainfo_charset = def_charset;\n \t\telse if (!strcmp(argv[1], \"-n\"))\n \t\t\tmetainfo_charset = NULL;\n-\t\telse if (!strncmp(argv[1], \"--encoding=\", 11))\n+\t\telse if (!prefixcmp(argv[1], \"--encoding=\"))\n \t\t\tmetainfo_charset = argv[1] + 11;\n \t\telse\n \t\t\tusage(mailinfo_usage);\ndiff --git a/builtin-name-rev.c b/builtin-name-rev.c\nindex 36f1ba6..2c3d14c 100644\n--- a/builtin-name-rev.c\n+++ b/builtin-name-rev.c\n@@ -85,7 +85,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void\n \tstruct name_ref_data *data = cb_data;\n \tint deref = 0;\n \n-\tif (data->tags_only && strncmp(path, \"refs/tags/\", 10))\n+\tif (data->tags_only && prefixcmp(path, \"refs/tags/\"))\n \t\treturn 0;\n \n \tif (data->ref_filter && fnmatch(data->ref_filter, path, 0))\n@@ -101,9 +101,9 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void\n \tif (o && o->type == OBJ_COMMIT) {\n \t\tstruct commit *commit = (struct commit *)o;\n \n-\t\tif (!strncmp(path, \"refs/heads/\", 11))\n+\t\tif (!prefixcmp(path, \"refs/heads/\"))\n \t\t\tpath = path + 11;\n-\t\telse if (!strncmp(path, \"refs/\", 5))\n+\t\telse if (!prefixcmp(path, \"refs/\"))\n \t\t\tpath = path + 5;\n \n \t\tname_rev(commit, xstrdup(path), 0, 0, deref);\n@@ -156,7 +156,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)\n \t\t\t} else if (!strcmp(*argv, \"--tags\")) {\n \t\t\t\tdata.tags_only = 1;\n \t\t\t\tcontinue;\n-\t\t\t} else  if (!strncmp(*argv, \"--refs=\", 7)) {\n+\t\t\t} else  if (!prefixcmp(*argv, \"--refs=\")) {\n \t\t\t\tdata.ref_filter = *argv + 7;\n \t\t\t\tcontinue;\n \t\t\t} else if (!strcmp(*argv, \"--all\")) {\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 3824ee3..71113d8 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -1579,14 +1579,14 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t\tincremental = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(\"--window=\", arg, 9)) {\n+\t\tif (!(-prefixcmp(arg, \"--window=\"))) {\n \t\t\tchar *end;\n \t\t\twindow = strtoul(arg+9, &end, 0);\n \t\t\tif (!arg[9] || *end)\n \t\t\t\tusage(pack_usage);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(\"--depth=\", arg, 8)) {\n+\t\tif (!(-prefixcmp(arg, \"--depth=\"))) {\n \t\t\tchar *end;\n \t\t\tdepth = strtoul(arg+8, &end, 0);\n \t\t\tif (!arg[8] || *end)\n@@ -1622,7 +1622,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(\"--unpacked\", arg) ||\n-\t\t    !strncmp(\"--unpacked=\", arg, 11) ||\n+\t\t    !(-prefixcmp(arg, \"--unpacked=\")) ||\n \t\t    !strcmp(\"--reflog\", arg) ||\n \t\t    !strcmp(\"--all\", arg)) {\n \t\t\tuse_internal_rev_list = 1;\ndiff --git a/builtin-pack-refs.c b/builtin-pack-refs.c\nindex 3de9b3e..d080e30 100644\n--- a/builtin-pack-refs.c\n+++ b/builtin-pack-refs.c\n@@ -36,7 +36,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,\n \t/* Do not pack the symbolic refs */\n \tif ((flags & REF_ISSYMREF))\n \t\treturn 0;\n-\tis_tag_ref = !strncmp(path, \"refs/tags/\", 10);\n+\tis_tag_ref = !prefixcmp(path, \"refs/tags/\");\n \n \t/* ALWAYS pack refs that were already packed or are tags */\n \tif (!cb->all && !is_tag_ref && !(flags & REF_ISPACKED))\ndiff --git a/builtin-push.c b/builtin-push.c\nindex c45649e..2b98ba3 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -32,7 +32,7 @@ static int expand_one_ref(const char *ref, const unsigned char *sha1, int flag,\n \t/* Ignore the \"refs/\" at the beginning of the refname */\n \tref += 5;\n \n-\tif (!strncmp(ref, \"tags/\", 5))\n+\tif (!prefixcmp(ref, \"tags/\"))\n \t\tadd_refspec(xstrdup(ref));\n \treturn 0;\n }\n@@ -149,10 +149,10 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])\n \t\tint is_refspec;\n \t\tchar *s, *p;\n \n-\t\tif (!strncmp(\"URL:\", buffer, 4)) {\n+\t\tif (!(-prefixcmp(buffer, \"URL:\"))) {\n \t\t\tis_refspec = 0;\n \t\t\ts = buffer + 4;\n-\t\t} else if (!strncmp(\"Push:\", buffer, 5)) {\n+\t\t} else if (!(-prefixcmp(buffer, \"Push:\"))) {\n \t\t\tis_refspec = 1;\n \t\t\ts = buffer + 5;\n \t\t} else\n@@ -195,7 +195,7 @@ static int config_get_receivepack;\n \n static int get_remote_config(const char* key, const char* value)\n {\n-\tif (!strncmp(key, \"remote.\", 7) &&\n+\tif (!prefixcmp(key, \"remote.\") &&\n \t    !strncmp(key + 7, config_repo, config_repo_len)) {\n \t\tif (!strcmp(key + 7 + config_repo_len, \".url\")) {\n \t\t\tif (config_current_uri < MAX_URI)\n@@ -324,8 +324,8 @@ static int do_push(const char *repo)\n \t\tconst char **dest_refspec = refspec;\n \t\tconst char *dest = uri[i];\n \t\tconst char *sender = \"git-send-pack\";\n-\t\tif (!strncmp(dest, \"http://\", 7) ||\n-\t\t    !strncmp(dest, \"https://\", 8))\n+\t\tif (!prefixcmp(dest, \"http://\") ||\n+\t\t    !prefixcmp(dest, \"https://\"))\n \t\t\tsender = \"git-http-push\";\n \t\telse if (thin)\n \t\t\targv[dest_argc++] = \"--thin\";\n@@ -373,7 +373,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)\n \t\t\tverbose=1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--repo=\", 7)) {\n+\t\tif (!prefixcmp(arg, \"--repo=\")) {\n \t\t\trepo = arg+7;\n \t\t\tcontinue;\n \t\t}\n@@ -397,11 +397,11 @@ int cmd_push(int argc, const char **argv, const char *prefix)\n \t\t\tthin = 0;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--receive-pack=\", 15)) {\n+\t\tif (!prefixcmp(arg, \"--receive-pack=\")) {\n \t\t\treceivepack = arg;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--exec=\", 7)) {\n+\t\tif (!prefixcmp(arg, \"--exec=\")) {\n \t\t\treceivepack = arg;\n \t\t\tcontinue;\n \t\t}\ndiff --git a/builtin-read-tree.c b/builtin-read-tree.c\nindex 8ba436d..e477155 100644\n--- a/builtin-read-tree.c\n+++ b/builtin-read-tree.c\n@@ -133,7 +133,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)\n \t\t *  entries and put the entries from the tree under the\n \t\t * given subdirectory.\n \t\t */\n-\t\tif (!strncmp(arg, \"--prefix=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--prefix=\")) {\n \t\t\tif (stage || opts.merge || opts.prefix)\n \t\t\t\tusage(read_tree_usage);\n \t\t\topts.prefix = arg + 9;\n@@ -179,7 +179,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (!strncmp(arg, \"--exclude-per-directory=\", 24)) {\n+\t\tif (!prefixcmp(arg, \"--exclude-per-directory=\")) {\n \t\t\tstruct dir_struct *dir;\n \n \t\t\tif (opts.dir)\ndiff --git a/builtin-reflog.c b/builtin-reflog.c\nindex 3415551..cefb40d 100644\n--- a/builtin-reflog.c\n+++ b/builtin-reflog.c\n@@ -321,9 +321,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)\n \t\tconst char *arg = argv[i];\n \t\tif (!strcmp(arg, \"--dry-run\") || !strcmp(arg, \"-n\"))\n \t\t\tcb.dry_run = 1;\n-\t\telse if (!strncmp(arg, \"--expire=\", 9))\n+\t\telse if (!prefixcmp(arg, \"--expire=\"))\n \t\t\tcb.expire_total = approxidate(arg + 9);\n-\t\telse if (!strncmp(arg, \"--expire-unreachable=\", 21))\n+\t\telse if (!prefixcmp(arg, \"--expire-unreachable=\"))\n \t\t\tcb.expire_unreachable = approxidate(arg + 21);\n \t\telse if (!strcmp(arg, \"--stale-fix\"))\n \t\t\tcb.stalefix = 1;\ndiff --git a/builtin-rerere.c b/builtin-rerere.c\nindex 318d959..978105b 100644\n--- a/builtin-rerere.c\n+++ b/builtin-rerere.c\n@@ -105,11 +105,11 @@ static int handle_file(const char *path,\n \t\tSHA1_Init(&ctx);\n \n \twhile (fgets(buf, sizeof(buf), f)) {\n-\t\tif (!strncmp(\"<<<<<<< \", buf, 8))\n+\t\tif (!(-prefixcmp(buf, \"<<<<<<< \")))\n \t\t\thunk = 1;\n-\t\telse if (!strncmp(\"=======\", buf, 7))\n+\t\telse if (!(-prefixcmp(buf, \"=======\")))\n \t\t\thunk = 2;\n-\t\telse if (!strncmp(\">>>>>>> \", buf, 8)) {\n+\t\telse if (!(-prefixcmp(buf, \">>>>>>> \"))) {\n \t\t\thunk_no++;\n \t\t\thunk = 0;\n \t\t\tif (memcmp(one->ptr, two->ptr, one->nr < two->nr ?\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex d53deaa..a1c3411 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -274,7 +274,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--short\") ||\n-\t\t\t    !strncmp(arg, \"--short=\", 8)) {\n+\t\t\t    !prefixcmp(arg, \"--short=\")) {\n \t\t\t\tfilter &= ~(DO_FLAGS|DO_NOREV);\n \t\t\t\tverify = 1;\n \t\t\t\tabbrev = DEFAULT_ABBREV;\n@@ -352,19 +352,19 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t\t\t: \"false\");\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--since=\", 8)) {\n+\t\t\tif (!prefixcmp(arg, \"--since=\")) {\n \t\t\t\tshow_datestring(\"--max-age=\", arg+8);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--after=\", 8)) {\n+\t\t\tif (!prefixcmp(arg, \"--after=\")) {\n \t\t\t\tshow_datestring(\"--max-age=\", arg+8);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--before=\", 9)) {\n+\t\t\tif (!prefixcmp(arg, \"--before=\")) {\n \t\t\t\tshow_datestring(\"--min-age=\", arg+9);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--until=\", 8)) {\n+\t\t\tif (!prefixcmp(arg, \"--until=\")) {\n \t\t\t\tshow_datestring(\"--min-age=\", arg+8);\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/builtin-shortlog.c b/builtin-shortlog.c\nindex edb4042..2f71a2a 100644\n--- a/builtin-shortlog.c\n+++ b/builtin-shortlog.c\n@@ -124,7 +124,7 @@ static void insert_author_oneline(struct path_list *list,\n \telse\n \t\tfree(buffer);\n \n-\tif (!strncmp(oneline, \"[PATCH\", 6)) {\n+\tif (!prefixcmp(oneline, \"[PATCH\")) {\n \t\tchar *eob = strchr(oneline, ']');\n \n \t\tif (eob) {\n@@ -179,7 +179,7 @@ static void read_from_stdin(struct path_list *list)\n \twhile (fgets(buffer, sizeof(buffer), stdin) != NULL) {\n \t\tchar *bob;\n \t\tif ((buffer[0] == 'A' || buffer[0] == 'a') &&\n-\t\t\t\t!strncmp(buffer + 1, \"uthor: \", 7) &&\n+\t\t\t\t!prefixcmp(buffer + 1, \"uthor: \") &&\n \t\t\t\t(bob = strchr(buffer + 7, '<')) != NULL) {\n \t\t\tchar buffer2[1024], offset = 0;\n \n@@ -230,7 +230,7 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list)\n \t\t\telse\n \t\t\t\teol++;\n \n-\t\t\tif (!strncmp(buffer, \"author \", 7)) {\n+\t\t\tif (!prefixcmp(buffer, \"author \")) {\n \t\t\t\tchar *bracket = strchr(buffer, '<');\n \n \t\t\t\tif (bracket == NULL || bracket > eol)\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 0d94e40..bf6aee4 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -266,7 +266,7 @@ static void show_one_commit(struct commit *commit, int no_name)\n \t\t\t\t    pretty, sizeof(pretty), 0, NULL, NULL, 0);\n \telse\n \t\tstrcpy(pretty, \"(unavailable)\");\n-\tif (!strncmp(pretty, \"[PATCH] \", 8))\n+\tif (!prefixcmp(pretty, \"[PATCH] \"))\n \t\tcp = pretty + 8;\n \telse\n \t\tcp = pretty;\n@@ -404,7 +404,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int\n \n static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n {\n-\tif (strncmp(refname, \"refs/tags/\", 10))\n+\tif (prefixcmp(refname, \"refs/tags/\"))\n \t\treturn 0;\n \treturn append_ref(refname + 5, sha1, 0);\n }\n@@ -435,9 +435,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i\n \t\treturn 0;\n \tif (fnmatch(match_ref_pattern, tail, 0))\n \t\treturn 0;\n-\tif (!strncmp(\"refs/heads/\", refname, 11))\n+\tif (!(-prefixcmp(refname, \"refs/heads/\")))\n \t\treturn append_head_ref(refname, sha1, flag, cb_data);\n-\tif (!strncmp(\"refs/tags/\", refname, 10))\n+\tif (!(-prefixcmp(refname, \"refs/tags/\")))\n \t\treturn append_tag_ref(refname, sha1, flag, cb_data);\n \treturn append_ref(refname, sha1, 0);\n }\n@@ -462,11 +462,11 @@ static int rev_is_head(char *head, int headlen, char *name,\n \tif ((!head[0]) ||\n \t    (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))\n \t\treturn 0;\n-\tif (!strncmp(head, \"refs/heads/\", 11))\n+\tif (!prefixcmp(head, \"refs/heads/\"))\n \t\thead += 11;\n-\tif (!strncmp(name, \"refs/heads/\", 11))\n+\tif (!prefixcmp(name, \"refs/heads/\"))\n \t\tname += 11;\n-\telse if (!strncmp(name, \"heads/\", 6))\n+\telse if (!prefixcmp(name, \"heads/\"))\n \t\tname += 6;\n \treturn !strcmp(head, name);\n }\n@@ -635,7 +635,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\twith_current_branch = 1;\n \t\telse if (!strcmp(arg, \"--sha1-name\"))\n \t\t\tsha1_name = 1;\n-\t\telse if (!strncmp(arg, \"--more=\", 7))\n+\t\telse if (!prefixcmp(arg, \"--more=\"))\n \t\t\textra = atoi(arg + 7);\n \t\telse if (!strcmp(arg, \"--merge-base\"))\n \t\t\tmerge_base = 1;\n@@ -652,9 +652,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\telse if (!strcmp(arg, \"--reflog\") || !strcmp(arg, \"-g\")) {\n \t\t\treflog = DEFAULT_REFLOG;\n \t\t}\n-\t\telse if (!strncmp(arg, \"--reflog=\", 9))\n+\t\telse if (!prefixcmp(arg, \"--reflog=\"))\n \t\t\tparse_reflog_param(arg + 9, &reflog, &reflog_base);\n-\t\telse if (!strncmp(arg, \"-g=\", 3))\n+\t\telse if (!prefixcmp(arg, \"-g=\"))\n \t\t\tparse_reflog_param(arg + 3, &reflog, &reflog_base);\n \t\telse\n \t\t\tusage(show_branch_usage);\ndiff --git a/builtin-show-ref.c b/builtin-show-ref.c\nindex 853f13f..ae0eddd 100644\n--- a/builtin-show-ref.c\n+++ b/builtin-show-ref.c\n@@ -28,8 +28,8 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo\n \tif (tags_only || heads_only) {\n \t\tint match;\n \n-\t\tmatch = heads_only && !strncmp(refname, \"refs/heads/\", 11);\n-\t\tmatch |= tags_only && !strncmp(refname, \"refs/tags/\", 10);\n+\t\tmatch = heads_only && !prefixcmp(refname, \"refs/heads/\");\n+\t\tmatch |= tags_only && !prefixcmp(refname, \"refs/tags/\");\n \t\tif (!match)\n \t\t\treturn 0;\n \t}\n@@ -178,8 +178,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)\n \t\t\thash_only = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--hash=\", 7) ||\n-\t\t    (!strncmp(arg, \"--abbrev\", 8) &&\n+\t\tif (!prefixcmp(arg, \"--hash=\") ||\n+\t\t    (!prefixcmp(arg, \"--abbrev\") &&\n \t\t     (arg[8] == '=' || arg[8] == '\\0'))) {\n \t\t\tif (arg[2] != 'h' && !arg[8])\n \t\t\t\t/* --abbrev only */\n@@ -215,7 +215,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)\n \t\t}\n \t\tif (!strcmp(arg, \"--exclude-existing\"))\n \t\t\treturn exclude_existing(NULL);\n-\t\tif (!strncmp(arg, \"--exclude-existing=\", 19))\n+\t\tif (!prefixcmp(arg, \"--exclude-existing=\"))\n \t\t\treturn exclude_existing(arg + 19);\n \t\tusage(show_ref_usage);\n \t}\n@@ -224,7 +224,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)\n \t\tunsigned char sha1[20];\n \n \t\twhile (*pattern) {\n-\t\t\tif (!strncmp(*pattern, \"refs/\", 5) &&\n+\t\t\tif (!prefixcmp(*pattern, \"refs/\") &&\n \t\t\t    resolve_ref(*pattern, sha1, 1, NULL)) {\n \t\t\t\tif (!quiet)\n \t\t\t\t\tshow_one(*pattern, sha1);\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex 8055dda..28f8c1c 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -31,7 +31,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)\n \tnargv[nargc++] = \"git-archive\";\n \tnargv[nargc++] = \"--format=tar\";\n \n-\tif (2 <= argc && !strncmp(\"--remote=\", argv[1], 9)) {\n+\tif (2 <= argc && !(-prefixcmp(argv[1], \"--remote=\"))) {\n \t\tnargv[nargc++] = argv[1];\n \t\targv++;\n \t\targc--;\ndiff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\nindex d351e02..8f8e898 100644\n--- a/builtin-unpack-objects.c\n+++ b/builtin-unpack-objects.c\n@@ -369,7 +369,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)\n \t\t\t\trecover = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--pack_header=\", 14)) {\n+\t\t\tif (!prefixcmp(arg, \"--pack_header=\")) {\n \t\t\t\tstruct pack_header *hdr;\n \t\t\t\tchar *c;\n \ndiff --git a/builtin-write-tree.c b/builtin-write-tree.c\nindex 50670dc..90fc1cf 100644\n--- a/builtin-write-tree.c\n+++ b/builtin-write-tree.c\n@@ -70,7 +70,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)\n \t\tconst char *arg = argv[1];\n \t\tif (!strcmp(arg, \"--missing-ok\"))\n \t\t\tmissing_ok = 1;\n-\t\telse if (!strncmp(arg, \"--prefix=\", 9))\n+\t\telse if (!prefixcmp(arg, \"--prefix=\"))\n \t\t\tprefix = arg + 9;\n \t\telse\n \t\t\tusage(write_tree_usage);\ndiff --git a/connect.c b/connect.c\nindex 7844888..8a8a13b 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -96,7 +96,7 @@ int get_ack(int fd, unsigned char *result_sha1)\n \t\tline[--len] = 0;\n \tif (!strcmp(line, \"NAK\"))\n \t\treturn 0;\n-\tif (!strncmp(line, \"ACK \", 4)) {\n+\tif (!prefixcmp(line, \"ACK \")) {\n \t\tif (!get_sha1_hex(line+4, result_sha1)) {\n \t\t\tif (strstr(line+45, \"continue\"))\n \t\t\t\treturn 2;\n@@ -196,8 +196,8 @@ static int count_refspec_match(const char *pattern,\n \t\t */\n \t\tif (namelen != patlen &&\n \t\t    patlen != namelen - 5 &&\n-\t\t    strncmp(name, \"refs/heads/\", 11) &&\n-\t\t    strncmp(name, \"refs/tags/\", 10)) {\n+\t\t    prefixcmp(name, \"refs/heads/\") &&\n+\t\t    prefixcmp(name, \"refs/tags/\")) {\n \t\t\t/* We want to catch the case where only weak\n \t\t\t * matches are found and there are multiple\n \t\t\t * matches, and where more than one strong\ndiff --git a/daemon.c b/daemon.c\nindex 66f8d6f..cdbc23f 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -286,7 +286,7 @@ static int service_enabled;\n \n static int git_daemon_config(const char *var, const char *value)\n {\n-\tif (!strncmp(var, \"daemon.\", 7) &&\n+\tif (!prefixcmp(var, \"daemon.\") &&\n \t    !strcmp(var + 7, service_looking_at->config_name)) {\n \t\tservice_enabled = git_config_bool(var, value);\n \t\treturn 0;\n@@ -562,7 +562,7 @@ static int execute(struct sockaddr *addr)\n \tfor (i = 0; i < ARRAY_SIZE(daemon_service); i++) {\n \t\tstruct daemon_service *s = &(daemon_service[i]);\n \t\tint namelen = strlen(s->name);\n-\t\tif (!strncmp(\"git-\", line, 4) &&\n+\t\tif (!(-prefixcmp(line, \"git-\")) &&\n \t\t    !strncmp(s->name, line + 4, namelen) &&\n \t\t    line[namelen + 4] == ' ') {\n \t\t\t/*\n@@ -1011,7 +1011,7 @@ int main(int argc, char **argv)\n \tfor (i = 1; i < argc; i++) {\n \t\tchar *arg = argv[i];\n \n-\t\tif (!strncmp(arg, \"--listen=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--listen=\")) {\n \t\t    char *p = arg + 9;\n \t\t    char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);\n \t\t    while (*p)\n@@ -1019,7 +1019,7 @@ int main(int argc, char **argv)\n \t\t    *ph = 0;\n \t\t    continue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--port=\", 7)) {\n+\t\tif (!prefixcmp(arg, \"--port=\")) {\n \t\t\tchar *end;\n \t\t\tunsigned long n;\n \t\t\tn = strtoul(arg+7, &end, 0);\n@@ -1045,11 +1045,11 @@ int main(int argc, char **argv)\n \t\t\texport_all_trees = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--timeout=\", 10)) {\n+\t\tif (!prefixcmp(arg, \"--timeout=\")) {\n \t\t\ttimeout = atoi(arg+10);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--init-timeout=\", 15)) {\n+\t\tif (!prefixcmp(arg, \"--init-timeout=\")) {\n \t\t\tinit_timeout = atoi(arg+15);\n \t\t\tcontinue;\n \t\t}\n@@ -1057,11 +1057,11 @@ int main(int argc, char **argv)\n \t\t\tstrict_paths = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--base-path=\", 12)) {\n+\t\tif (!prefixcmp(arg, \"--base-path=\")) {\n \t\t\tbase_path = arg+12;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--interpolated-path=\", 20)) {\n+\t\tif (!prefixcmp(arg, \"--interpolated-path=\")) {\n \t\t\tinterpolated_path = arg+20;\n \t\t\tcontinue;\n \t\t}\n@@ -1073,11 +1073,11 @@ int main(int argc, char **argv)\n \t\t\tuser_path = \"\";\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--user-path=\", 12)) {\n+\t\tif (!prefixcmp(arg, \"--user-path=\")) {\n \t\t\tuser_path = arg + 12;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--pid-file=\", 11)) {\n+\t\tif (!prefixcmp(arg, \"--pid-file=\")) {\n \t\t\tpid_file = arg + 11;\n \t\t\tcontinue;\n \t\t}\n@@ -1086,27 +1086,27 @@ int main(int argc, char **argv)\n \t\t\tlog_syslog = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--user=\", 7)) {\n+\t\tif (!prefixcmp(arg, \"--user=\")) {\n \t\t\tuser_name = arg + 7;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--group=\", 8)) {\n+\t\tif (!prefixcmp(arg, \"--group=\")) {\n \t\t\tgroup_name = arg + 8;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--enable=\", 9)) {\n+\t\tif (!prefixcmp(arg, \"--enable=\")) {\n \t\t\tenable_service(arg + 9, 1);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--disable=\", 10)) {\n+\t\tif (!prefixcmp(arg, \"--disable=\")) {\n \t\t\tenable_service(arg + 10, 0);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--allow-override=\", 17)) {\n+\t\tif (!prefixcmp(arg, \"--allow-override=\")) {\n \t\t\tmake_service_overridable(arg + 17, 1);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--forbid-override=\", 18)) {\n+\t\tif (!prefixcmp(arg, \"--forbid-override=\")) {\n \t\t\tmake_service_overridable(arg + 18, 0);\n \t\t\tcontinue;\n \t\t}\ndiff --git a/diff.c b/diff.c\nindex 07589c3..fad13ab 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -77,7 +77,7 @@ int git_diff_ui_config(const char *var, const char *value)\n \t\t\tdiff_detect_rename_default = DIFF_DETECT_RENAME;\n \t\treturn 0;\n \t}\n-\tif (!strncmp(var, \"diff.color.\", 11) || !strncmp(var, \"color.diff.\", 11)) {\n+\tif (!prefixcmp(var, \"diff.color.\") || !strncmp(var, \"color.diff.\", 11)) {\n \t\tint slot = parse_diff_color_slot(var, 11);\n \t\tcolor_parse(value, var, diff_colors[slot]);\n \t\treturn 0;\n@@ -1119,9 +1119,9 @@ static void builtin_diff(const char *name_a,\n \t\txecfg.flags = XDL_EMIT_FUNCNAMES;\n \t\tif (!diffopts)\n \t\t\t;\n-\t\telse if (!strncmp(diffopts, \"--unified=\", 10))\n+\t\telse if (!prefixcmp(diffopts, \"--unified=\"))\n \t\t\txecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);\n-\t\telse if (!strncmp(diffopts, \"-u\", 2))\n+\t\telse if (!prefixcmp(diffopts, \"-u\"))\n \t\t\txecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);\n \t\tecb.outf = xdiff_outf;\n \t\tecb.priv = &ecbdata;\n@@ -1957,7 +1957,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \telse if (!strcmp(arg, \"--shortstat\")) {\n \t\toptions->output_format |= DIFF_FORMAT_SHORTSTAT;\n \t}\n-\telse if (!strncmp(arg, \"--stat\", 6)) {\n+\telse if (!prefixcmp(arg, \"--stat\")) {\n \t\tchar *end;\n \t\tint width = options->stat_width;\n \t\tint name_width = options->stat_name_width;\n@@ -1966,9 +1966,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \n \t\tswitch (*arg) {\n \t\tcase '-':\n-\t\t\tif (!strncmp(arg, \"-width=\", 7))\n+\t\t\tif (!prefixcmp(arg, \"-width=\"))\n \t\t\t\twidth = strtoul(arg + 7, &end, 10);\n-\t\t\telse if (!strncmp(arg, \"-name-width=\", 12))\n+\t\t\telse if (!prefixcmp(arg, \"-name-width=\"))\n \t\t\t\tname_width = strtoul(arg + 12, &end, 10);\n \t\t\tbreak;\n \t\tcase '=':\n@@ -1993,7 +1993,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t}\n \telse if (!strcmp(arg, \"-z\"))\n \t\toptions->line_termination = 0;\n-\telse if (!strncmp(arg, \"-l\", 2))\n+\telse if (!prefixcmp(arg, \"-l\"))\n \t\toptions->rename_limit = strtoul(arg+2, NULL, 10);\n \telse if (!strcmp(arg, \"--full-index\"))\n \t\toptions->full_index = 1;\n@@ -2010,31 +2010,31 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\toptions->output_format |= DIFF_FORMAT_NAME_STATUS;\n \telse if (!strcmp(arg, \"-R\"))\n \t\toptions->reverse_diff = 1;\n-\telse if (!strncmp(arg, \"-S\", 2))\n+\telse if (!prefixcmp(arg, \"-S\"))\n \t\toptions->pickaxe = arg + 2;\n \telse if (!strcmp(arg, \"-s\")) {\n \t\toptions->output_format |= DIFF_FORMAT_NO_OUTPUT;\n \t}\n-\telse if (!strncmp(arg, \"-O\", 2))\n+\telse if (!prefixcmp(arg, \"-O\"))\n \t\toptions->orderfile = arg + 2;\n-\telse if (!strncmp(arg, \"--diff-filter=\", 14))\n+\telse if (!prefixcmp(arg, \"--diff-filter=\"))\n \t\toptions->filter = arg + 14;\n \telse if (!strcmp(arg, \"--pickaxe-all\"))\n \t\toptions->pickaxe_opts = DIFF_PICKAXE_ALL;\n \telse if (!strcmp(arg, \"--pickaxe-regex\"))\n \t\toptions->pickaxe_opts = DIFF_PICKAXE_REGEX;\n-\telse if (!strncmp(arg, \"-B\", 2)) {\n+\telse if (!prefixcmp(arg, \"-B\")) {\n \t\tif ((options->break_opt =\n \t\t     diff_scoreopt_parse(arg)) == -1)\n \t\t\treturn -1;\n \t}\n-\telse if (!strncmp(arg, \"-M\", 2)) {\n+\telse if (!prefixcmp(arg, \"-M\")) {\n \t\tif ((options->rename_score =\n \t\t     diff_scoreopt_parse(arg)) == -1)\n \t\t\treturn -1;\n \t\toptions->detect_rename = DIFF_DETECT_RENAME;\n \t}\n-\telse if (!strncmp(arg, \"-C\", 2)) {\n+\telse if (!prefixcmp(arg, \"-C\")) {\n \t\tif ((options->rename_score =\n \t\t     diff_scoreopt_parse(arg)) == -1)\n \t\t\treturn -1;\n@@ -2044,7 +2044,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\toptions->find_copies_harder = 1;\n \telse if (!strcmp(arg, \"--abbrev\"))\n \t\toptions->abbrev = DEFAULT_ABBREV;\n-\telse if (!strncmp(arg, \"--abbrev=\", 9)) {\n+\telse if (!prefixcmp(arg, \"--abbrev=\")) {\n \t\toptions->abbrev = strtoul(arg + 9, NULL, 10);\n \t\tif (options->abbrev < MINIMUM_ABBREV)\n \t\t\toptions->abbrev = MINIMUM_ABBREV;\n@@ -2553,7 +2553,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)\n \tint new_len;\n \n \t/* Ignore line numbers when computing the SHA1 of the patch */\n-\tif (!strncmp(line, \"@@ -\", 4))\n+\tif (!prefixcmp(line, \"@@ -\"))\n \t\treturn;\n \n \tnew_len = remove_space(line, len);\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex 3996bce..9b74ed2 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -56,7 +56,7 @@ int execv_git_cmd(const char **argv)\n \t\t\tlen = strlen(git_command);\n \n \t\t\t/* Trivial cleanup */\n-\t\t\twhile (!strncmp(exec_dir, \"./\", 2)) {\n+\t\t\twhile (!prefixcmp(exec_dir, \"./\")) {\n \t\t\t\texec_dir += 2;\n \t\t\t\twhile (*exec_dir == '/')\n \t\t\t\t\texec_dir++;\ndiff --git a/fast-import.c b/fast-import.c\nindex ad32300..ee7c04c 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1397,7 +1397,7 @@ static void read_next_command(void)\n \n static void cmd_mark(void)\n {\n-\tif (!strncmp(\"mark :\", command_buf.buf, 6)) {\n+\tif (!(-prefixcmp(command_buf.buf, \"mark :\"))) {\n \t\tnext_mark = strtoumax(command_buf.buf + 6, NULL, 10);\n \t\tread_next_command();\n \t}\n@@ -1410,10 +1410,10 @@ static void *cmd_data (size_t *size)\n \tsize_t length;\n \tchar *buffer;\n \n-\tif (strncmp(\"data \", command_buf.buf, 5))\n+\tif ((-prefixcmp(command_buf.buf, \"data \")))\n \t\tdie(\"Expected 'data n' command, found: %s\", command_buf.buf);\n \n-\tif (!strncmp(\"<<\", command_buf.buf + 5, 2)) {\n+\tif (!(-prefixcmp(command_buf.buf + 5, \"<<\"))) {\n \t\tchar *term = xstrdup(command_buf.buf + 5 + 2);\n \t\tsize_t sz = 8192, term_len = command_buf.len - 5 - 2;\n \t\tlength = 0;\n@@ -1600,7 +1600,7 @@ static void file_change_m(struct branch *b)\n \t\toe = find_mark(strtoumax(p + 1, &x, 10));\n \t\thashcpy(sha1, oe->sha1);\n \t\tp = x;\n-\t} else if (!strncmp(\"inline\", p, 6)) {\n+\t} else if (!(-prefixcmp(p, \"inline\"))) {\n \t\tinline_data = 1;\n \t\tp += 6;\n \t} else {\n@@ -1673,7 +1673,7 @@ static void cmd_from(struct branch *b)\n \tconst char *from;\n \tstruct branch *s;\n \n-\tif (strncmp(\"from \", command_buf.buf, 5))\n+\tif ((-prefixcmp(command_buf.buf, \"from \")))\n \t\treturn;\n \n \tif (b->branch_tree.tree) {\n@@ -1739,7 +1739,7 @@ static struct hash_list *cmd_merge(unsigned int *count)\n \tstruct branch *s;\n \n \t*count = 0;\n-\twhile (!strncmp(\"merge \", command_buf.buf, 6)) {\n+\twhile (!(-prefixcmp(command_buf.buf, \"merge \"))) {\n \t\tfrom = strchr(command_buf.buf, ' ') + 1;\n \t\tn = xmalloc(sizeof(*n));\n \t\ts = lookup_branch(from);\n@@ -1785,11 +1785,11 @@ static void cmd_new_commit(void)\n \n \tread_next_command();\n \tcmd_mark();\n-\tif (!strncmp(\"author \", command_buf.buf, 7)) {\n+\tif (!(-prefixcmp(command_buf.buf, \"author \"))) {\n \t\tauthor = parse_ident(command_buf.buf + 7);\n \t\tread_next_command();\n \t}\n-\tif (!strncmp(\"committer \", command_buf.buf, 10)) {\n+\tif (!(-prefixcmp(command_buf.buf, \"committer \"))) {\n \t\tcommitter = parse_ident(command_buf.buf + 10);\n \t\tread_next_command();\n \t}\n@@ -1810,9 +1810,9 @@ static void cmd_new_commit(void)\n \tfor (;;) {\n \t\tif (1 == command_buf.len)\n \t\t\tbreak;\n-\t\telse if (!strncmp(\"M \", command_buf.buf, 2))\n+\t\telse if (!(-prefixcmp(command_buf.buf, \"M \")))\n \t\t\tfile_change_m(b);\n-\t\telse if (!strncmp(\"D \", command_buf.buf, 2))\n+\t\telse if (!(-prefixcmp(command_buf.buf, \"D \")))\n \t\t\tfile_change_d(b);\n \t\telse if (!strcmp(\"deleteall\", command_buf.buf))\n \t\t\tfile_change_deleteall(b);\n@@ -1882,7 +1882,7 @@ static void cmd_new_tag(void)\n \tread_next_command();\n \n \t/* from ... */\n-\tif (strncmp(\"from \", command_buf.buf, 5))\n+\tif ((-prefixcmp(command_buf.buf, \"from \")))\n \t\tdie(\"Expected from command, got %s\", command_buf.buf);\n \tfrom = strchr(command_buf.buf, ' ') + 1;\n \ts = lookup_branch(from);\n@@ -1909,7 +1909,7 @@ static void cmd_new_tag(void)\n \tread_next_command();\n \n \t/* tagger ... */\n-\tif (strncmp(\"tagger \", command_buf.buf, 7))\n+\tif ((-prefixcmp(command_buf.buf, \"tagger \")))\n \t\tdie(\"Expected tagger command, got %s\", command_buf.buf);\n \ttagger = parse_ident(command_buf.buf + 7);\n \n@@ -1986,7 +1986,7 @@ int main(int argc, const char **argv)\n \n \t\tif (*a != '-' || !strcmp(a, \"--\"))\n \t\t\tbreak;\n-\t\telse if (!strncmp(a, \"--date-format=\", 14)) {\n+\t\telse if (!prefixcmp(a, \"--date-format=\")) {\n \t\t\tconst char *fmt = a + 14;\n \t\t\tif (!strcmp(fmt, \"raw\"))\n \t\t\t\twhenspec = WHENSPEC_RAW;\n@@ -1997,15 +1997,15 @@ int main(int argc, const char **argv)\n \t\t\telse\n \t\t\t\tdie(\"unknown --date-format argument %s\", fmt);\n \t\t}\n-\t\telse if (!strncmp(a, \"--max-pack-size=\", 16))\n+\t\telse if (!prefixcmp(a, \"--max-pack-size=\"))\n \t\t\tmax_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024;\n-\t\telse if (!strncmp(a, \"--depth=\", 8))\n+\t\telse if (!prefixcmp(a, \"--depth=\"))\n \t\t\tmax_depth = strtoul(a + 8, NULL, 0);\n-\t\telse if (!strncmp(a, \"--active-branches=\", 18))\n+\t\telse if (!prefixcmp(a, \"--active-branches=\"))\n \t\t\tmax_active_branches = strtoul(a + 18, NULL, 0);\n-\t\telse if (!strncmp(a, \"--export-marks=\", 15))\n+\t\telse if (!prefixcmp(a, \"--export-marks=\"))\n \t\t\tmark_file = a + 15;\n-\t\telse if (!strncmp(a, \"--export-pack-edges=\", 20)) {\n+\t\telse if (!prefixcmp(a, \"--export-pack-edges=\")) {\n \t\t\tif (pack_edges)\n \t\t\t\tfclose(pack_edges);\n \t\t\tpack_edges = fopen(a + 20, \"a\");\n@@ -2038,11 +2038,11 @@ int main(int argc, const char **argv)\n \t\t\tbreak;\n \t\telse if (!strcmp(\"blob\", command_buf.buf))\n \t\t\tcmd_new_blob();\n-\t\telse if (!strncmp(\"commit \", command_buf.buf, 7))\n+\t\telse if (!(-prefixcmp(command_buf.buf, \"commit \")))\n \t\t\tcmd_new_commit();\n-\t\telse if (!strncmp(\"tag \", command_buf.buf, 4))\n+\t\telse if (!(-prefixcmp(command_buf.buf, \"tag \")))\n \t\t\tcmd_new_tag();\n-\t\telse if (!strncmp(\"reset \", command_buf.buf, 6))\n+\t\telse if (!(-prefixcmp(command_buf.buf, \"reset \")))\n \t\t\tcmd_reset_branch();\n \t\telse if (!strcmp(\"checkpoint\", command_buf.buf))\n \t\t\tcmd_checkpoint();\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex c787106..1fd2c3a 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -198,13 +198,13 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \t\tint len;\n \n \t\twhile ((len = packet_read_line(fd[0], line, sizeof(line)))) {\n-\t\t\tif (!strncmp(\"shallow \", line, 8)) {\n+\t\t\tif (!(-prefixcmp(line, \"shallow \"))) {\n \t\t\t\tif (get_sha1_hex(line + 8, sha1))\n \t\t\t\t\tdie(\"invalid shallow line: %s\", line);\n \t\t\t\tregister_shallow(sha1);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(\"unshallow \", line, 10)) {\n+\t\t\tif (!(-prefixcmp(line, \"unshallow \"))) {\n \t\t\t\tif (get_sha1_hex(line + 10, sha1))\n \t\t\t\t\tdie(\"invalid unshallow line: %s\", line);\n \t\t\t\tif (!lookup_object(sha1))\n@@ -346,7 +346,7 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)\n \t\t    check_ref_format(ref->name + 5))\n \t\t\t; /* trash */\n \t\telse if (fetch_all &&\n-\t\t\t (!depth || strncmp(ref->name, \"refs/tags/\", 10) )) {\n+\t\t\t (!depth || prefixcmp(ref->name, \"refs/tags/\") )) {\n \t\t\t*newtail = ref;\n \t\t\tref->next = NULL;\n \t\t\tnewtail = &ref->next;\n@@ -683,11 +683,11 @@ int main(int argc, char **argv)\n \t\tchar *arg = argv[i];\n \n \t\tif (*arg == '-') {\n-\t\t\tif (!strncmp(\"--upload-pack=\", arg, 14)) {\n+\t\t\tif (!(-prefixcmp(arg, \"--upload-pack=\"))) {\n \t\t\t\tuploadpack = arg + 14;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(\"--exec=\", arg, 7)) {\n+\t\t\tif (!(-prefixcmp(arg, \"--exec=\"))) {\n \t\t\t\tuploadpack = arg + 7;\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -712,7 +712,7 @@ int main(int argc, char **argv)\n \t\t\t\tverbose = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(\"--depth=\", arg, 8)) {\n+\t\t\tif (!(-prefixcmp(arg, \"--depth=\"))) {\n \t\t\t\tdepth = strtol(arg + 8, NULL, 0);\n \t\t\t\tif (stat(git_path(\"shallow\"), &st))\n \t\t\t\t\tst.st_mtime = 0;\ndiff --git a/git.c b/git.c\nindex 4dd1967..1fad852 100644\n--- a/git.c\n+++ b/git.c\n@@ -48,7 +48,7 @@ static int handle_options(const char*** argv, int* argc)\n \t\t/*\n \t\t * Check remaining flags.\n \t\t */\n-\t\tif (!strncmp(cmd, \"--exec-path\", 11)) {\n+\t\tif (!prefixcmp(cmd, \"--exec-path\")) {\n \t\t\tcmd += 11;\n \t\t\tif (*cmd == '=')\n \t\t\t\tgit_set_exec_path(cmd + 1);\n@@ -66,7 +66,7 @@ static int handle_options(const char*** argv, int* argc)\n \t\t\tsetenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);\n \t\t\t(*argv)++;\n \t\t\t(*argc)--;\n-\t\t} else if (!strncmp(cmd, \"--git-dir=\", 10)) {\n+\t\t} else if (!prefixcmp(cmd, \"--git-dir=\")) {\n \t\t\tsetenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);\n \t\t} else if (!strcmp(cmd, \"--bare\")) {\n \t\t\tstatic char git_dir[PATH_MAX+1];\n@@ -88,7 +88,7 @@ static char *alias_string;\n \n static int git_alias_config(const char *var, const char *value)\n {\n-\tif (!strncmp(var, \"alias.\", 6) && !strcmp(var + 6, alias_command)) {\n+\tif (!prefixcmp(var, \"alias.\") && !strcmp(var + 6, alias_command)) {\n \t\talias_string = xstrdup(value);\n \t}\n \treturn 0;\n@@ -348,7 +348,7 @@ int main(int argc, const char **argv, char **envp)\n \t * So we just directly call the internal command handler, and\n \t * die if that one cannot handle it.\n \t */\n-\tif (!strncmp(cmd, \"git-\", 4)) {\n+\tif (!prefixcmp(cmd, \"git-\")) {\n \t\tcmd += 4;\n \t\targv[0] = cmd;\n \t\thandle_internal_command(argc, argv, envp);\n@@ -360,7 +360,7 @@ int main(int argc, const char **argv, char **envp)\n \targc--;\n \thandle_options(&argv, &argc);\n \tif (argc > 0) {\n-\t\tif (!strncmp(argv[0], \"--\", 2))\n+\t\tif (!prefixcmp(argv[0], \"--\"))\n \t\t\targv[0] += 2;\n \t} else {\n \t\t/* Default command: \"help\" */\ndiff --git a/help.c b/help.c\nindex b667463..0893fea 100644\n--- a/help.c\n+++ b/help.c\n@@ -130,7 +130,7 @@ static void list_commands(const char *exec_path, const char *pattern)\n \t\tstruct stat st;\n \t\tint entlen;\n \n-\t\tif (strncmp(de->d_name, \"git-\", 4))\n+\t\tif (prefixcmp(de->d_name, \"git-\"))\n \t\t\tcontinue;\n \t\tstrcpy(path+dirlen, de->d_name);\n \t\tif (stat(path, &st) || /* stat, not lstat */\n@@ -179,7 +179,7 @@ static void show_man_page(const char *git_cmd)\n {\n \tconst char *page;\n \n-\tif (!strncmp(git_cmd, \"git\", 3))\n+\tif (!prefixcmp(git_cmd, \"git\"))\n \t\tpage = git_cmd;\n \telse {\n \t\tint page_len = strlen(git_cmd) + 4;\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 9f790a0..d9a4561 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -717,7 +717,7 @@ static int fetch_indices(struct alt_base *repo)\n \t\tcase 'P':\n \t\t\ti++;\n \t\t\tif (i + 52 <= buffer.posn &&\n-\t\t\t    !strncmp(data + i, \" pack-\", 6) &&\n+\t\t\t    !prefixcmp(data + i, \" pack-\") &&\n \t\t\t    !strncmp(data + i + 46, \".pack\\n\", 6)) {\n \t\t\t\tget_sha1_hex(data + i + 6, sha1);\n \t\t\t\tsetup_index(repo, sha1);\ndiff --git a/http-push.c b/http-push.c\nindex b128c01..eb77c9a 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1060,7 +1060,7 @@ static int fetch_indices(void)\n \t\tcase 'P':\n \t\t\ti++;\n \t\t\tif (i + 52 < buffer.posn &&\n-\t\t\t    !strncmp(data + i, \" pack-\", 6) &&\n+\t\t\t    !prefixcmp(data + i, \" pack-\") &&\n \t\t\t    !strncmp(data + i + 46, \".pack\\n\", 6)) {\n \t\t\t\tget_sha1_hex(data + i + 6, sha1);\n \t\t\t\tsetup_index(sha1);\n@@ -1206,11 +1206,11 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)\n \t\t\tlock->owner = xmalloc(strlen(ctx->cdata) + 1);\n \t\t\tstrcpy(lock->owner, ctx->cdata);\n \t\t} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TIMEOUT)) {\n-\t\t\tif (!strncmp(ctx->cdata, \"Second-\", 7))\n+\t\t\tif (!prefixcmp(ctx->cdata, \"Second-\"))\n \t\t\t\tlock->timeout =\n \t\t\t\t\tstrtol(ctx->cdata + 7, NULL, 10);\n \t\t} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {\n-\t\t\tif (!strncmp(ctx->cdata, \"opaquelocktoken:\", 16)) {\n+\t\t\tif (!prefixcmp(ctx->cdata, \"opaquelocktoken:\")) {\n \t\t\t\tlock->token = xmalloc(strlen(ctx->cdata) - 15);\n \t\t\t\tstrcpy(lock->token, ctx->cdata + 16);\n \t\t\t}\n@@ -2168,7 +2168,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)\n \t\treturn;\n \n \t/* If it's a symref, set the refname; otherwise try for a sha1 */\n-\tif (!strncmp((char *)buffer.buffer, \"ref: \", 5)) {\n+\tif (!prefixcmp((char *)buffer.buffer, \"ref: \")) {\n \t\t*symref = xmalloc(buffer.posn - 5);\n \t\tstrlcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5);\n \t} else {\ndiff --git a/index-pack.c b/index-pack.c\nindex 72e0962..fa9a0e7 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -849,9 +849,9 @@ int main(int argc, char **argv)\n \t\t\t\tfix_thin_pack = 1;\n \t\t\t} else if (!strcmp(arg, \"--keep\")) {\n \t\t\t\tkeep_msg = \"\";\n-\t\t\t} else if (!strncmp(arg, \"--keep=\", 7)) {\n+\t\t\t} else if (!prefixcmp(arg, \"--keep=\")) {\n \t\t\t\tkeep_msg = arg + 7;\n-\t\t\t} else if (!strncmp(arg, \"--pack_header=\", 14)) {\n+\t\t\t} else if (!prefixcmp(arg, \"--pack_header=\")) {\n \t\t\t\tstruct pack_header *hdr;\n \t\t\t\tchar *c;\n \ndiff --git a/peek-remote.c b/peek-remote.c\nindex ef3c76c..7b66228 100644\n--- a/peek-remote.c\n+++ b/peek-remote.c\n@@ -35,11 +35,11 @@ int main(int argc, char **argv)\n \t\tchar *arg = argv[i];\n \n \t\tif (*arg == '-') {\n-\t\t\tif (!strncmp(\"--upload-pack=\", arg, 14)) {\n+\t\t\tif (!(-prefixcmp(arg, \"--upload-pack=\"))) {\n \t\t\t\tuploadpack = arg + 14;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(\"--exec=\", arg, 7)) {\n+\t\t\tif (!(-prefixcmp(arg, \"--exec=\"))) {\n \t\t\t\tuploadpack = arg + 7;\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/receive-pack.c b/receive-pack.c\nindex 7311c82..7f1dcc0 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -109,7 +109,7 @@ static int update(struct command *cmd)\n \tstruct ref_lock *lock;\n \n \tcmd->error_string = NULL;\n-\tif (!strncmp(name, \"refs/\", 5) && check_ref_format(name + 5)) {\n+\tif (!prefixcmp(name, \"refs/\") && check_ref_format(name + 5)) {\n \t\tcmd->error_string = \"funny refname\";\n \t\treturn error(\"refusing to create funny ref '%s' locally\",\n \t\t\t     name);\n@@ -125,7 +125,7 @@ static int update(struct command *cmd)\n \t}\n \tif (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&\n \t    !is_null_sha1(old_sha1) &&\n-\t    !strncmp(name, \"refs/heads/\", 11)) {\n+\t    !prefixcmp(name, \"refs/heads/\")) {\n \t\tstruct commit *old_commit, *new_commit;\n \t\tstruct commit_list *bases, *ent;\n \ndiff --git a/refs.c b/refs.c\nindex 6387703..d347876 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -828,8 +828,8 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)\n \t\tgoto rollback;\n \t}\n \n-\tif (!strncmp(oldref, \"refs/heads/\", 11) &&\n-\t\t\t!strncmp(newref, \"refs/heads/\", 11)) {\n+\tif (!prefixcmp(oldref, \"refs/heads/\") &&\n+\t\t\t!prefixcmp(newref, \"refs/heads/\")) {\n \t\tchar oldsection[1024], newsection[1024];\n \n \t\tsnprintf(oldsection, 1024, \"branch.%s\", oldref + 11);\n@@ -894,8 +894,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,\n \tlog_file = git_path(\"logs/%s\", ref_name);\n \n \tif (log_all_ref_updates &&\n-\t    (!strncmp(ref_name, \"refs/heads/\", 11) ||\n-\t     !strncmp(ref_name, \"refs/remotes/\", 13) ||\n+\t    (!prefixcmp(ref_name, \"refs/heads/\") ||\n+\t     !prefixcmp(ref_name, \"refs/remotes/\") ||\n \t     !strcmp(ref_name, \"HEAD\"))) {\n \t\tif (safe_create_leading_directories(log_file) < 0)\n \t\t\treturn error(\"unable to create directory for %s\",\ndiff --git a/revision.c b/revision.c\nindex 5b1794b..abab3b9 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -813,11 +813,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\tconst char *arg = argv[i];\n \t\tif (*arg == '-') {\n \t\t\tint opts;\n-\t\t\tif (!strncmp(arg, \"--max-count=\", 12)) {\n+\t\t\tif (!prefixcmp(arg, \"--max-count=\")) {\n \t\t\t\trevs->max_count = atoi(arg + 12);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--skip=\", 7)) {\n+\t\t\tif (!prefixcmp(arg, \"--skip=\")) {\n \t\t\t\trevs->skip_count = atoi(arg + 7);\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -836,27 +836,27 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t\t\trevs->max_count = atoi(arg + 2);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--max-age=\", 10)) {\n+\t\t\tif (!prefixcmp(arg, \"--max-age=\")) {\n \t\t\t\trevs->max_age = atoi(arg + 10);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--since=\", 8)) {\n+\t\t\tif (!prefixcmp(arg, \"--since=\")) {\n \t\t\t\trevs->max_age = approxidate(arg + 8);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--after=\", 8)) {\n+\t\t\tif (!prefixcmp(arg, \"--after=\")) {\n \t\t\t\trevs->max_age = approxidate(arg + 8);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--min-age=\", 10)) {\n+\t\t\tif (!prefixcmp(arg, \"--min-age=\")) {\n \t\t\t\trevs->min_age = atoi(arg + 10);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--before=\", 9)) {\n+\t\t\tif (!prefixcmp(arg, \"--before=\")) {\n \t\t\t\trevs->min_age = approxidate(arg + 9);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--until=\", 8)) {\n+\t\t\tif (!prefixcmp(arg, \"--until=\")) {\n \t\t\t\trevs->min_age = approxidate(arg + 8);\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -944,7 +944,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t\t\trevs->num_ignore_packed = 0;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--unpacked=\", 11)) {\n+\t\t\tif (!prefixcmp(arg, \"--unpacked=\")) {\n \t\t\t\trevs->unpacked = 1;\n \t\t\t\tadd_ignore_packed(revs, arg+11);\n \t\t\t\tcontinue;\n@@ -980,7 +980,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t\t\trevs->verbose_header = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--pretty\", 8)) {\n+\t\t\tif (!prefixcmp(arg, \"--pretty\")) {\n \t\t\t\trevs->verbose_header = 1;\n \t\t\t\trevs->commit_format = get_commit_format(arg+8);\n \t\t\t\tcontinue;\n@@ -1005,7 +1005,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t\t\trevs->abbrev = DEFAULT_ABBREV;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--abbrev=\", 9)) {\n+\t\t\tif (!prefixcmp(arg, \"--abbrev=\")) {\n \t\t\t\trevs->abbrev = strtoul(arg + 9, NULL, 10);\n \t\t\t\tif (revs->abbrev < MINIMUM_ABBREV)\n \t\t\t\t\trevs->abbrev = MINIMUM_ABBREV;\n@@ -1034,15 +1034,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t\t/*\n \t\t\t * Grepping the commit log\n \t\t\t */\n-\t\t\tif (!strncmp(arg, \"--author=\", 9)) {\n+\t\t\tif (!prefixcmp(arg, \"--author=\")) {\n \t\t\t\tadd_header_grep(revs, \"author\", arg+9);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--committer=\", 12)) {\n+\t\t\tif (!prefixcmp(arg, \"--committer=\")) {\n \t\t\t\tadd_header_grep(revs, \"committer\", arg+12);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--grep=\", 7)) {\n+\t\t\tif (!prefixcmp(arg, \"--grep=\")) {\n \t\t\t\tadd_message_grep(revs, arg+7);\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -1050,7 +1050,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t\t\tall_match = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--encoding=\", 11)) {\n+\t\t\tif (!prefixcmp(arg, \"--encoding=\")) {\n \t\t\t\targ += 11;\n \t\t\t\tif (strcmp(arg, \"none\"))\n \t\t\t\t\tgit_log_output_encoding = strdup(arg);\ndiff --git a/send-pack.c b/send-pack.c\nindex 33e69db..512b660 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -379,11 +379,11 @@ int main(int argc, char **argv)\n \t\tchar *arg = *argv;\n \n \t\tif (*arg == '-') {\n-\t\t\tif (!strncmp(arg, \"--receive-pack=\", 15)) {\n+\t\t\tif (!prefixcmp(arg, \"--receive-pack=\")) {\n \t\t\t\treceivepack = arg + 15;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg, \"--exec=\", 7)) {\n+\t\t\tif (!prefixcmp(arg, \"--exec=\")) {\n \t\t\t\treceivepack = arg + 7;\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/setup.c b/setup.c\nindex e9d3f5a..dda67d2 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -251,7 +251,7 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \toffset++;\n \tcwd[len++] = '/';\n \tcwd[len] = 0;\n-\tinside_git_dir = !strncmp(cwd + offset, \".git/\", 5);\n+\tinside_git_dir = !prefixcmp(cwd + offset, \".git/\");\n \treturn cwd + offset;\n }\n \ndiff --git a/shell.c b/shell.c\nindex 8c08cf0..c983fc7 100644\n--- a/shell.c\n+++ b/shell.c\n@@ -8,7 +8,7 @@ static int do_generic_cmd(const char *me, char *arg)\n \n \tif (!arg || !(arg = sq_dequote(arg)))\n \t\tdie(\"bad argument\");\n-\tif (strncmp(me, \"git-\", 4))\n+\tif (prefixcmp(me, \"git-\"))\n \t\tdie(\"bad command\");\n \n \tmy_argv[0] = me + 4;\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 3648aae..d7876ca 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -455,7 +455,7 @@ static int get_common_commits(void)\n \t\t\tcontinue;\n \t\t}\n \t\tlen = strip(line, len);\n-\t\tif (!strncmp(line, \"have \", 5)) {\n+\t\tif (!prefixcmp(line, \"have \")) {\n \t\t\tswitch (got_sha1(line+5, sha1)) {\n \t\t\tcase -1: /* they have what we do not */\n \t\t\t\tif (multi_ack && ok_to_give_up())\n@@ -502,7 +502,7 @@ static void receive_needs(void)\n \t\tif (!len)\n \t\t\tbreak;\n \n-\t\tif (!strncmp(\"shallow \", line, 8)) {\n+\t\tif (!(-prefixcmp(line, \"shallow \"))) {\n \t\t\tunsigned char sha1[20];\n \t\t\tstruct object *object;\n \t\t\tuse_thin_pack = 0;\n@@ -515,7 +515,7 @@ static void receive_needs(void)\n \t\t\tadd_object_array(object, NULL, &shallows);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(\"deepen \", line, 7)) {\n+\t\tif (!(-prefixcmp(line, \"deepen \"))) {\n \t\t\tchar *end;\n \t\t\tuse_thin_pack = 0;\n \t\t\tdepth = strtol(line + 7, &end, 0);\n@@ -523,7 +523,7 @@ static void receive_needs(void)\n \t\t\t\tdie(\"Invalid deepen: %s\", line);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (strncmp(\"want \", line, 5) ||\n+\t\tif ((-prefixcmp(line, \"want \")) ||\n \t\t    get_sha1_hex(line+5, sha1_buf))\n \t\t\tdie(\"git-upload-pack: protocol error, \"\n \t\t\t    \"expected to get sha, not '%s'\", line);\n@@ -656,7 +656,7 @@ int main(int argc, char **argv)\n \t\t\tstrict = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg, \"--timeout=\", 10)) {\n+\t\tif (!prefixcmp(arg, \"--timeout=\")) {\n \t\t\ttimeout = atoi(arg+10);\n \t\t\tcontinue;\n \t\t}\ndiff --git a/wt-status.c b/wt-status.c\nindex 2879c3d..d17a6ba 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -298,7 +298,7 @@ void wt_status_print(struct wt_status *s)\n \tif (s->branch) {\n \t\tconst char *on_what = \"On branch \";\n \t\tconst char *branch_name = s->branch;\n-\t\tif (!strncmp(branch_name, \"refs/heads/\", 11))\n+\t\tif (!prefixcmp(branch_name, \"refs/heads/\"))\n \t\t\tbranch_name += 11;\n \t\telse if (!strcmp(branch_name, \"HEAD\")) {\n \t\t\tbranch_name = \"\";\n@@ -344,7 +344,7 @@ int git_status_config(const char *k, const char *v)\n \t\twt_status_use_color = git_config_colorbool(k, v);\n \t\treturn 0;\n \t}\n-\tif (!strncmp(k, \"status.color.\", 13) || !strncmp(k, \"color.status.\", 13)) {\n+\tif (!prefixcmp(k, \"status.color.\") || !strncmp(k, \"color.status.\", 13)) {\n \t\tint slot = parse_status_slot(k, 13);\n \t\tcolor_parse(v, k, wt_status_colors[slot]);\n \t}\n-- \n1.5.0.1.571.ge5a1a\n"},{"id":"35102","messageId":"7vy7mtw3wn.fsf_-_@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"200702200942.18654.andyparkins@gmail.com","subject":"[PATCH 3/4] prefixcmp(): fix-up mechanical conversion.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T09:54:00Z","receivedAt":"2007-02-20T09:54:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Previous step converted use of strncmp() with literal string\nmechanically even when the result is only used as a boolean (not\ncomparison):\n\n\tif (!strncmp(\"foo\", arg, 3)) ==> if (!(-prefixcmp(arg, \"foo\")))\n\nThis step manually cleans them up.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n builtin-archive.c      |    2 +-\n builtin-blame.c        |    6 +++---\n builtin-grep.c         |    6 +++---\n builtin-pack-objects.c |    6 +++---\n builtin-push.c         |    4 ++--\n builtin-rerere.c       |    6 +++---\n builtin-show-branch.c  |    4 ++--\n builtin-tar-tree.c     |    2 +-\n daemon.c               |    2 +-\n fast-import.c          |   30 +++++++++++++++---------------\n fetch-pack.c           |   10 +++++-----\n peek-remote.c          |    4 ++--\n upload-pack.c          |    6 +++---\n 13 files changed, 44 insertions(+), 44 deletions(-)\n\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex 0c56de0..8ea6cb1 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -35,7 +35,7 @@ static int run_remote_archiver(const char *remote, int argc,\n \n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n-\t\tif (!(-prefixcmp(arg, \"--exec=\"))) {\n+\t\tif (!prefixcmp(arg, \"--exec=\")) {\n \t\t\tif (exec_at)\n \t\t\t\tdie(\"multiple --exec specified\");\n \t\t\texec = arg + 7;\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex db311bf..530b97f 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -2097,17 +2097,17 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\t\toutput_option |= OUTPUT_LONG_OBJECT_NAME;\n \t\telse if (!strcmp(\"-S\", arg) && ++i < argc)\n \t\t\trevs_file = argv[i];\n-\t\telse if (!(-prefixcmp(arg, \"-M\"))) {\n+\t\telse if (!prefixcmp(arg, \"-M\")) {\n \t\t\topt |= PICKAXE_BLAME_MOVE;\n \t\t\tblame_move_score = parse_score(arg+2);\n \t\t}\n-\t\telse if (!(-prefixcmp(arg, \"-C\"))) {\n+\t\telse if (!prefixcmp(arg, \"-C\")) {\n \t\t\tif (opt & PICKAXE_BLAME_COPY)\n \t\t\t\topt |= PICKAXE_BLAME_COPY_HARDER;\n \t\t\topt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;\n \t\t\tblame_copy_score = parse_score(arg+2);\n \t\t}\n-\t\telse if (!(-prefixcmp(arg, \"-L\"))) {\n+\t\telse if (!prefixcmp(arg, \"-L\")) {\n \t\t\tif (!arg[2]) {\n \t\t\t\tif (++i >= argc)\n \t\t\t\t\tusage(blame_usage);\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex cec2204..f35f2d0 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -527,9 +527,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\topt.word_regexp = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!(-prefixcmp(arg, \"-A\")) ||\n-\t\t    !(-prefixcmp(arg, \"-B\")) ||\n-\t\t    !(-prefixcmp(arg, \"-C\")) ||\n+\t\tif (!prefixcmp(arg, \"-A\") ||\n+\t\t    !prefixcmp(arg, \"-B\") ||\n+\t\t    !prefixcmp(arg, \"-C\") ||\n \t\t    (arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {\n \t\t\tunsigned num;\n \t\t\tconst char *scan;\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 71113d8..b5ed9ce 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -1579,14 +1579,14 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t\tincremental = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!(-prefixcmp(arg, \"--window=\"))) {\n+\t\tif (!prefixcmp(arg, \"--window=\")) {\n \t\t\tchar *end;\n \t\t\twindow = strtoul(arg+9, &end, 0);\n \t\t\tif (!arg[9] || *end)\n \t\t\t\tusage(pack_usage);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!(-prefixcmp(arg, \"--depth=\"))) {\n+\t\tif (!prefixcmp(arg, \"--depth=\")) {\n \t\t\tchar *end;\n \t\t\tdepth = strtoul(arg+8, &end, 0);\n \t\t\tif (!arg[8] || *end)\n@@ -1622,7 +1622,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(\"--unpacked\", arg) ||\n-\t\t    !(-prefixcmp(arg, \"--unpacked=\")) ||\n+\t\t    !prefixcmp(arg, \"--unpacked=\") ||\n \t\t    !strcmp(\"--reflog\", arg) ||\n \t\t    !strcmp(\"--all\", arg)) {\n \t\t\tuse_internal_rev_list = 1;\ndiff --git a/builtin-push.c b/builtin-push.c\nindex 2b98ba3..979efcc 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -149,10 +149,10 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])\n \t\tint is_refspec;\n \t\tchar *s, *p;\n \n-\t\tif (!(-prefixcmp(buffer, \"URL:\"))) {\n+\t\tif (!prefixcmp(buffer, \"URL:\")) {\n \t\t\tis_refspec = 0;\n \t\t\ts = buffer + 4;\n-\t\t} else if (!(-prefixcmp(buffer, \"Push:\"))) {\n+\t\t} else if (!prefixcmp(buffer, \"Push:\")) {\n \t\t\tis_refspec = 1;\n \t\t\ts = buffer + 5;\n \t\t} else\ndiff --git a/builtin-rerere.c b/builtin-rerere.c\nindex 978105b..dd1d4c1 100644\n--- a/builtin-rerere.c\n+++ b/builtin-rerere.c\n@@ -105,11 +105,11 @@ static int handle_file(const char *path,\n \t\tSHA1_Init(&ctx);\n \n \twhile (fgets(buf, sizeof(buf), f)) {\n-\t\tif (!(-prefixcmp(buf, \"<<<<<<< \")))\n+\t\tif (!prefixcmp(buf, \"<<<<<<< \"))\n \t\t\thunk = 1;\n-\t\telse if (!(-prefixcmp(buf, \"=======\")))\n+\t\telse if (!prefixcmp(buf, \"=======\"))\n \t\t\thunk = 2;\n-\t\telse if (!(-prefixcmp(buf, \">>>>>>> \"))) {\n+\t\telse if (!prefixcmp(buf, \">>>>>>> \")) {\n \t\t\thunk_no++;\n \t\t\thunk = 0;\n \t\t\tif (memcmp(one->ptr, two->ptr, one->nr < two->nr ?\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex bf6aee4..402a8f7 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -435,9 +435,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i\n \t\treturn 0;\n \tif (fnmatch(match_ref_pattern, tail, 0))\n \t\treturn 0;\n-\tif (!(-prefixcmp(refname, \"refs/heads/\")))\n+\tif (!prefixcmp(refname, \"refs/heads/\"))\n \t\treturn append_head_ref(refname, sha1, flag, cb_data);\n-\tif (!(-prefixcmp(refname, \"refs/tags/\")))\n+\tif (!prefixcmp(refname, \"refs/tags/\"))\n \t\treturn append_tag_ref(refname, sha1, flag, cb_data);\n \treturn append_ref(refname, sha1, 0);\n }\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex 28f8c1c..b04719e 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -31,7 +31,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)\n \tnargv[nargc++] = \"git-archive\";\n \tnargv[nargc++] = \"--format=tar\";\n \n-\tif (2 <= argc && !(-prefixcmp(argv[1], \"--remote=\"))) {\n+\tif (2 <= argc && !prefixcmp(argv[1], \"--remote=\")) {\n \t\tnargv[nargc++] = argv[1];\n \t\targv++;\n \t\targc--;\ndiff --git a/daemon.c b/daemon.c\nindex cdbc23f..e74ecac 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -562,7 +562,7 @@ static int execute(struct sockaddr *addr)\n \tfor (i = 0; i < ARRAY_SIZE(daemon_service); i++) {\n \t\tstruct daemon_service *s = &(daemon_service[i]);\n \t\tint namelen = strlen(s->name);\n-\t\tif (!(-prefixcmp(line, \"git-\")) &&\n+\t\tif (!prefixcmp(line, \"git-\") &&\n \t\t    !strncmp(s->name, line + 4, namelen) &&\n \t\t    line[namelen + 4] == ' ') {\n \t\t\t/*\ndiff --git a/fast-import.c b/fast-import.c\nindex ee7c04c..580eadc 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1397,7 +1397,7 @@ static void read_next_command(void)\n \n static void cmd_mark(void)\n {\n-\tif (!(-prefixcmp(command_buf.buf, \"mark :\"))) {\n+\tif (!prefixcmp(command_buf.buf, \"mark :\")) {\n \t\tnext_mark = strtoumax(command_buf.buf + 6, NULL, 10);\n \t\tread_next_command();\n \t}\n@@ -1410,10 +1410,10 @@ static void *cmd_data (size_t *size)\n \tsize_t length;\n \tchar *buffer;\n \n-\tif ((-prefixcmp(command_buf.buf, \"data \")))\n+\tif (prefixcmp(command_buf.buf, \"data \"))\n \t\tdie(\"Expected 'data n' command, found: %s\", command_buf.buf);\n \n-\tif (!(-prefixcmp(command_buf.buf + 5, \"<<\"))) {\n+\tif (!prefixcmp(command_buf.buf + 5, \"<<\")) {\n \t\tchar *term = xstrdup(command_buf.buf + 5 + 2);\n \t\tsize_t sz = 8192, term_len = command_buf.len - 5 - 2;\n \t\tlength = 0;\n@@ -1600,7 +1600,7 @@ static void file_change_m(struct branch *b)\n \t\toe = find_mark(strtoumax(p + 1, &x, 10));\n \t\thashcpy(sha1, oe->sha1);\n \t\tp = x;\n-\t} else if (!(-prefixcmp(p, \"inline\"))) {\n+\t} else if (!prefixcmp(p, \"inline\")) {\n \t\tinline_data = 1;\n \t\tp += 6;\n \t} else {\n@@ -1673,7 +1673,7 @@ static void cmd_from(struct branch *b)\n \tconst char *from;\n \tstruct branch *s;\n \n-\tif ((-prefixcmp(command_buf.buf, \"from \")))\n+\tif (prefixcmp(command_buf.buf, \"from \"))\n \t\treturn;\n \n \tif (b->branch_tree.tree) {\n@@ -1739,7 +1739,7 @@ static struct hash_list *cmd_merge(unsigned int *count)\n \tstruct branch *s;\n \n \t*count = 0;\n-\twhile (!(-prefixcmp(command_buf.buf, \"merge \"))) {\n+\twhile (!prefixcmp(command_buf.buf, \"merge \")) {\n \t\tfrom = strchr(command_buf.buf, ' ') + 1;\n \t\tn = xmalloc(sizeof(*n));\n \t\ts = lookup_branch(from);\n@@ -1785,11 +1785,11 @@ static void cmd_new_commit(void)\n \n \tread_next_command();\n \tcmd_mark();\n-\tif (!(-prefixcmp(command_buf.buf, \"author \"))) {\n+\tif (!prefixcmp(command_buf.buf, \"author \")) {\n \t\tauthor = parse_ident(command_buf.buf + 7);\n \t\tread_next_command();\n \t}\n-\tif (!(-prefixcmp(command_buf.buf, \"committer \"))) {\n+\tif (!prefixcmp(command_buf.buf, \"committer \")) {\n \t\tcommitter = parse_ident(command_buf.buf + 10);\n \t\tread_next_command();\n \t}\n@@ -1810,9 +1810,9 @@ static void cmd_new_commit(void)\n \tfor (;;) {\n \t\tif (1 == command_buf.len)\n \t\t\tbreak;\n-\t\telse if (!(-prefixcmp(command_buf.buf, \"M \")))\n+\t\telse if (!prefixcmp(command_buf.buf, \"M \"))\n \t\t\tfile_change_m(b);\n-\t\telse if (!(-prefixcmp(command_buf.buf, \"D \")))\n+\t\telse if (!prefixcmp(command_buf.buf, \"D \"))\n \t\t\tfile_change_d(b);\n \t\telse if (!strcmp(\"deleteall\", command_buf.buf))\n \t\t\tfile_change_deleteall(b);\n@@ -1882,7 +1882,7 @@ static void cmd_new_tag(void)\n \tread_next_command();\n \n \t/* from ... */\n-\tif ((-prefixcmp(command_buf.buf, \"from \")))\n+\tif (prefixcmp(command_buf.buf, \"from \"))\n \t\tdie(\"Expected from command, got %s\", command_buf.buf);\n \tfrom = strchr(command_buf.buf, ' ') + 1;\n \ts = lookup_branch(from);\n@@ -1909,7 +1909,7 @@ static void cmd_new_tag(void)\n \tread_next_command();\n \n \t/* tagger ... */\n-\tif ((-prefixcmp(command_buf.buf, \"tagger \")))\n+\tif (prefixcmp(command_buf.buf, \"tagger \"))\n \t\tdie(\"Expected tagger command, got %s\", command_buf.buf);\n \ttagger = parse_ident(command_buf.buf + 7);\n \n@@ -2038,11 +2038,11 @@ int main(int argc, const char **argv)\n \t\t\tbreak;\n \t\telse if (!strcmp(\"blob\", command_buf.buf))\n \t\t\tcmd_new_blob();\n-\t\telse if (!(-prefixcmp(command_buf.buf, \"commit \")))\n+\t\telse if (!prefixcmp(command_buf.buf, \"commit \"))\n \t\t\tcmd_new_commit();\n-\t\telse if (!(-prefixcmp(command_buf.buf, \"tag \")))\n+\t\telse if (!prefixcmp(command_buf.buf, \"tag \"))\n \t\t\tcmd_new_tag();\n-\t\telse if (!(-prefixcmp(command_buf.buf, \"reset \")))\n+\t\telse if (!prefixcmp(command_buf.buf, \"reset \"))\n \t\t\tcmd_reset_branch();\n \t\telse if (!strcmp(\"checkpoint\", command_buf.buf))\n \t\t\tcmd_checkpoint();\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 1fd2c3a..41bdd27 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -198,13 +198,13 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \t\tint len;\n \n \t\twhile ((len = packet_read_line(fd[0], line, sizeof(line)))) {\n-\t\t\tif (!(-prefixcmp(line, \"shallow \"))) {\n+\t\t\tif (!prefixcmp(line, \"shallow \")) {\n \t\t\t\tif (get_sha1_hex(line + 8, sha1))\n \t\t\t\t\tdie(\"invalid shallow line: %s\", line);\n \t\t\t\tregister_shallow(sha1);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!(-prefixcmp(line, \"unshallow \"))) {\n+\t\t\tif (!prefixcmp(line, \"unshallow \")) {\n \t\t\t\tif (get_sha1_hex(line + 10, sha1))\n \t\t\t\t\tdie(\"invalid unshallow line: %s\", line);\n \t\t\t\tif (!lookup_object(sha1))\n@@ -683,11 +683,11 @@ int main(int argc, char **argv)\n \t\tchar *arg = argv[i];\n \n \t\tif (*arg == '-') {\n-\t\t\tif (!(-prefixcmp(arg, \"--upload-pack=\"))) {\n+\t\t\tif (!prefixcmp(arg, \"--upload-pack=\")) {\n \t\t\t\tuploadpack = arg + 14;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!(-prefixcmp(arg, \"--exec=\"))) {\n+\t\t\tif (!prefixcmp(arg, \"--exec=\")) {\n \t\t\t\tuploadpack = arg + 7;\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -712,7 +712,7 @@ int main(int argc, char **argv)\n \t\t\t\tverbose = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!(-prefixcmp(arg, \"--depth=\"))) {\n+\t\t\tif (!prefixcmp(arg, \"--depth=\")) {\n \t\t\t\tdepth = strtol(arg + 8, NULL, 0);\n \t\t\t\tif (stat(git_path(\"shallow\"), &st))\n \t\t\t\t\tst.st_mtime = 0;\ndiff --git a/peek-remote.c b/peek-remote.c\nindex 7b66228..96bfac4 100644\n--- a/peek-remote.c\n+++ b/peek-remote.c\n@@ -35,11 +35,11 @@ int main(int argc, char **argv)\n \t\tchar *arg = argv[i];\n \n \t\tif (*arg == '-') {\n-\t\t\tif (!(-prefixcmp(arg, \"--upload-pack=\"))) {\n+\t\t\tif (!prefixcmp(arg, \"--upload-pack=\")) {\n \t\t\t\tuploadpack = arg + 14;\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!(-prefixcmp(arg, \"--exec=\"))) {\n+\t\t\tif (!prefixcmp(arg, \"--exec=\")) {\n \t\t\t\tuploadpack = arg + 7;\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/upload-pack.c b/upload-pack.c\nindex d7876ca..804bbb6 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -502,7 +502,7 @@ static void receive_needs(void)\n \t\tif (!len)\n \t\t\tbreak;\n \n-\t\tif (!(-prefixcmp(line, \"shallow \"))) {\n+\t\tif (!prefixcmp(line, \"shallow \")) {\n \t\t\tunsigned char sha1[20];\n \t\t\tstruct object *object;\n \t\t\tuse_thin_pack = 0;\n@@ -515,7 +515,7 @@ static void receive_needs(void)\n \t\t\tadd_object_array(object, NULL, &shallows);\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!(-prefixcmp(line, \"deepen \"))) {\n+\t\tif (!prefixcmp(line, \"deepen \")) {\n \t\t\tchar *end;\n \t\t\tuse_thin_pack = 0;\n \t\t\tdepth = strtol(line + 7, &end, 0);\n@@ -523,7 +523,7 @@ static void receive_needs(void)\n \t\t\t\tdie(\"Invalid deepen: %s\", line);\n \t\t\tcontinue;\n \t\t}\n-\t\tif ((-prefixcmp(line, \"want \")) ||\n+\t\tif (prefixcmp(line, \"want \") ||\n \t\t    get_sha1_hex(line+5, sha1_buf))\n \t\t\tdie(\"git-upload-pack: protocol error, \"\n \t\t\t    \"expected to get sha, not '%s'\", line);\n-- \n1.5.0.1.571.ge5a1a\n"},{"id":"35103","messageId":"7vtzxhw3us.fsf_-_@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"200702200942.18654.andyparkins@gmail.com","subject":"[PATCH 4/4] prefixcmp(): fix-up leftover strncmp().","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T09:55:07Z","receivedAt":"2007-02-20T09:55:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"There were instances of strncmp() that were formatted improperly\n(e.g. whitespace around parameter before closing parenthesis)\nthat caused the earlier mechanical conversion step to miss\nthem.  This step cleans them up.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * This concludes the series.  I'll go over these line by line\n   tomorrow for the last time, and then will apply them.\n\n builtin-ls-tree.c     |    2 +-\n builtin-rev-parse.c   |    2 +-\n builtin-show-branch.c |    4 ++--\n diff.c                |    2 +-\n http-fetch.c          |    2 +-\n http-push.c           |    2 +-\n imap-send.c           |    8 ++++----\n revision.c            |    2 +-\n wt-status.c           |    2 +-\n 9 files changed, 13 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin-ls-tree.c b/builtin-ls-tree.c\nindex 201defd..6472610 100644\n--- a/builtin-ls-tree.c\n+++ b/builtin-ls-tree.c\n@@ -118,7 +118,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)\n \t\t\t\tchomp_prefix = 0;\n \t\t\t\tbreak;\n \t\t\t}\n-\t\t\tif (!strncmp(argv[1]+2, \"abbrev=\",7)) {\n+\t\t\tif (!prefixcmp(argv[1]+2, \"abbrev=\")) {\n \t\t\t\tabbrev = strtoul(argv[1]+9, NULL, 10);\n \t\t\t\tif (abbrev && abbrev < MINIMUM_ABBREV)\n \t\t\t\t\tabbrev = MINIMUM_ABBREV;\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex a1c3411..37addb2 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -233,7 +233,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t}\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!strncmp(arg,\"-n\",2)) {\n+\t\tif (!prefixcmp(arg, \"-n\")) {\n \t\t\tif ((filter & DO_FLAGS) && (filter & DO_REVS))\n \t\t\t\tshow(arg);\n \t\t\tcontinue;\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 402a8f7..67ae6ba 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -378,7 +378,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f\n {\n \tunsigned char tmp[20];\n \tint ofs = 11;\n-\tif (strncmp(refname, \"refs/heads/\", ofs))\n+\tif (prefixcmp(refname, \"refs/heads/\"))\n \t\treturn 0;\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n@@ -392,7 +392,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int\n {\n \tunsigned char tmp[20];\n \tint ofs = 13;\n-\tif (strncmp(refname, \"refs/remotes/\", ofs))\n+\tif (prefixcmp(refname, \"refs/remotes/\"))\n \t\treturn 0;\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\ndiff --git a/diff.c b/diff.c\nindex fad13ab..c3afee2 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -77,7 +77,7 @@ int git_diff_ui_config(const char *var, const char *value)\n \t\t\tdiff_detect_rename_default = DIFF_DETECT_RENAME;\n \t\treturn 0;\n \t}\n-\tif (!prefixcmp(var, \"diff.color.\") || !strncmp(var, \"color.diff.\", 11)) {\n+\tif (!prefixcmp(var, \"diff.color.\") || !prefixcmp(var, \"color.diff.\")) {\n \t\tint slot = parse_diff_color_slot(var, 11);\n \t\tcolor_parse(value, var, diff_colors[slot]);\n \t\treturn 0;\ndiff --git a/http-fetch.c b/http-fetch.c\nindex d9a4561..e6cd11d 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -718,7 +718,7 @@ static int fetch_indices(struct alt_base *repo)\n \t\t\ti++;\n \t\t\tif (i + 52 <= buffer.posn &&\n \t\t\t    !prefixcmp(data + i, \" pack-\") &&\n-\t\t\t    !strncmp(data + i + 46, \".pack\\n\", 6)) {\n+\t\t\t    !prefixcmp(data + i + 46, \".pack\\n\")) {\n \t\t\t\tget_sha1_hex(data + i + 6, sha1);\n \t\t\t\tsetup_index(repo, sha1);\n \t\t\t\ti += 51;\ndiff --git a/http-push.c b/http-push.c\nindex eb77c9a..9ad6fd0 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1061,7 +1061,7 @@ static int fetch_indices(void)\n \t\t\ti++;\n \t\t\tif (i + 52 < buffer.posn &&\n \t\t\t    !prefixcmp(data + i, \" pack-\") &&\n-\t\t\t    !strncmp(data + i + 46, \".pack\\n\", 6)) {\n+\t\t\t    !prefixcmp(data + i + 46, \".pack\\n\")) {\n \t\t\t\tget_sha1_hex(data + i + 6, sha1);\n \t\t\t\tsetup_index(sha1);\n \t\t\t\ti += 51;\ndiff --git a/imap-send.c b/imap-send.c\nindex 3eaf025..84df2fa 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1192,7 +1192,7 @@ count_messages( msg_data_t *msg )\n \tchar *p = msg->data;\n \n \twhile (1) {\n-\t\tif (!strncmp( \"From \", p, 5 )) {\n+\t\tif (!prefixcmp(p, \"From \")) {\n \t\t\tcount++;\n \t\t\tp += 5;\n \t\t}\n@@ -1216,7 +1216,7 @@ split_msg( msg_data_t *all_msgs, msg_data_t *msg, int *ofs )\n \tdata = &all_msgs->data[ *ofs ];\n \tmsg->len = all_msgs->len - *ofs;\n \n-\tif (msg->len < 5 || strncmp( data, \"From \", 5 ))\n+\tif (msg->len < 5 || prefixcmp(data, \"From \"))\n \t\treturn 0;\n \n \tp = strchr( data, '\\n' );\n@@ -1267,12 +1267,12 @@ git_imap_config(const char *key, const char *val)\n \t\timap_folder = xstrdup( val );\n \t} else if (!strcmp( \"host\", key )) {\n \t\t{\n-\t\t\tif (!strncmp( \"imap:\", val, 5 ))\n+\t\t\tif (!prefixcmp(val, \"imap:\"))\n \t\t\t\tval += 5;\n \t\t\tif (!server.port)\n \t\t\t\tserver.port = 143;\n \t\t}\n-\t\tif (!strncmp( \"//\", val, 2 ))\n+\t\tif (!prefixcmp(val, \"//\"))\n \t\t\tval += 2;\n \t\tserver.host = xstrdup( val );\n \t}\ndiff --git a/revision.c b/revision.c\nindex abab3b9..622afe3 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -832,7 +832,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t\t\trevs->max_count = atoi(argv[++i]);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tif (!strncmp(arg,\"-n\",2)) {\n+\t\t\tif (!prefixcmp(arg, \"-n\")) {\n \t\t\t\trevs->max_count = atoi(arg + 2);\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/wt-status.c b/wt-status.c\nindex d17a6ba..035e546 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -344,7 +344,7 @@ int git_status_config(const char *k, const char *v)\n \t\twt_status_use_color = git_config_colorbool(k, v);\n \t\treturn 0;\n \t}\n-\tif (!prefixcmp(k, \"status.color.\") || !strncmp(k, \"color.status.\", 13)) {\n+\tif (!prefixcmp(k, \"status.color.\") || !prefixcmp(k, \"color.status.\")) {\n \t\tint slot = parse_status_slot(k, 13);\n \t\tcolor_parse(v, k, wt_status_colors[slot]);\n \t}\n-- \n1.5.0.1.571.ge5a1a\n"},{"id":"35104","messageId":"87mz3916xh.fsf@morpheus.local","threadId":"6884","inReplyTo":"7vbqjpxilh.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/4] Add prefixcmp()","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2007-02-20T10:04:26Z","receivedAt":"2007-02-20T10:04:26Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> We have too many strncmp(a, b, strlen(b)).\n>\n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n> ---\n>  git-compat-util.h |    5 +++++\n>  1 files changed, 5 insertions(+), 0 deletions(-)\n>\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 9863cf6..0a9ac56 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -279,4 +279,9 @@ static inline int sane_case(int x, int high)\n>  \treturn x;\n>  }\n>  \n> +static inline int prefixcmp(const char *a, const char *b)\n> +{\n> +\treturn strncmp(a, b, strlen(b));\n> +}\n> +\n>  #endif\n\nIs it just me, or coudln't this be a little more self-documenting.  I\nfind it annoying to have to read through a functions implementation to\nfigure out what to pass to it.\n\nIf a doc comment is too much, just naming the parameters is often\nenough.\n\n+static inline int prefixcmp(const char *s, const char *prefix)\n\n-- \nDavid Kågedal\n"},{"id":"35106","messageId":"7vk5ydw2po.fsf@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"7v3b51xihy.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/4] Mechanical conversion to use prefixcmp()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T10:19:47Z","receivedAt":"2007-02-20T10:19:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> This mechanically converts strncmp() to use prefixcmp(),\n> ...\n>  * This was done by using this script in px.perl\n>\n>    #!/usr/bin/perl -i.bak -p\n>    if (/strncmp\\(([^,]+), \"([^\\\\\"]*)\", (\\d+)\\)/ && (length($2) == $3)) {\n>            s|strncmp\\(([^,]+), \"([^\\\\\"]*)\", (\\d+)\\)|prefixcmp($1, \"$2\")|;\n>    }\n>    if (/strncmp\\(\"([^\\\\\"]*)\", ([^,]+), (\\d+)\\)/ && (length($1) == $3)) {\n>            s|strncmp\\(\"([^\\\\\"]*)\", ([^,]+), (\\d+)\\)|(-prefixcmp($2, \"$1\"))|;\n>    }\n>\n>    and running:\n>\n>    $ git grep -l strncmp -- '*.c' | xargs perl px.perl\n\nTwo useless comments to add.\n\n (1) Yes, I have seen the \"Oh, I lost my data doing this silly\n     thing\" thread that mentioned the risk of using xargs ;-).\n     In general, piping output from git commands that give list\n     of paths (e.g. \"grep\", \"ls-files\", \"diff --name-only\" and\n     \"ls-tree -r --name-only\") to xargs should be a much safer\n     practice, and people should get into the habit of doing so,\n     instead of using \"find | xargs\".\n\n (2) This multi-step \"mechanical conversion followed by manual\n     fixup\" is a trick I picked up from Linus.  The replacement\n     regexp quoted above are designed to be stricter than\n     necessary to catch only the safe conversion target, while\n     accepting false negatives.  Doing the conversion this way,\n     I do not have to worry too much about auditing 1800 lines\n     of diff in [PATCH 2/4], as long as I make sure the above\n     regexp is strict enough (although I did look at all 1800\n     lines of diff before committing this).  Manual conversions\n     in later steps do need to be looked at much more carefully\n     than the result of this step, of course.\n"},{"id":"35107","messageId":"7vfy91w2nt.fsf@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"87mz3916xh.fsf@morpheus.local","subject":"Re: [PATCH 1/4] Add prefixcmp()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T10:20:54Z","receivedAt":"2007-02-20T10:20:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> Junio C Hamano <junkio@cox.net> writes:\n>\n>> We have too many strncmp(a, b, strlen(b)).\n>>\n>> Signed-off-by: Junio C Hamano <junkio@cox.net>\n>> ---\n>>  git-compat-util.h |    5 +++++\n>>  1 files changed, 5 insertions(+), 0 deletions(-)\n>>\n>> diff --git a/git-compat-util.h b/git-compat-util.h\n>> index 9863cf6..0a9ac56 100644\n>> --- a/git-compat-util.h\n>> +++ b/git-compat-util.h\n>> @@ -279,4 +279,9 @@ static inline int sane_case(int x, int high)\n>>  \treturn x;\n>>  }\n>>  \n>> +static inline int prefixcmp(const char *a, const char *b)\n>> +{\n>> +\treturn strncmp(a, b, strlen(b));\n>> +}\n>> +\n>>  #endif\n>\n> Is it just me, or coudln't this be a little more self-documenting.  I\n> find it annoying to have to read through a functions implementation to\n> figure out what to pass to it.\n>\n> If a doc comment is too much, just naming the parameters is often\n> enough.\n>\n> +static inline int prefixcmp(const char *s, const char *prefix)\n\nThanks.  That is much much better.\n"},{"id":"35108","messageId":"200702201021.58754.andyparkins@gmail.com","threadId":"6884","inReplyTo":"7vfy91ximy.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-02-20T10:21:57Z","receivedAt":"2007-02-20T10:21:57Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Tuesday 2007 February 20 09:50, Junio C Hamano wrote:\n\n> I'd send the prefixcmp() patches first, as yours would touch the\n> same lines.\n\nOkay.\n\nYour prefixcmp() point about them being used so regularly made me wonder if \nthe following would improve readability:\n\nstatic inline ref_is_head(const char *a)\n{\n    return (prefixcmp(a, PATH_REFS_HEADS) == 0);\n}\nstatic inline ref_is_tag(const char *a)\n{\n    return (prefixcmp(a, PATH_REFS_TAGS) == 0);\n}\nstatic inline ref_is_remote(const char *a)\n{\n    return (prefixcmp(a, PATH_REFS_REMOTES) == 0);\n}\n\nwhich would in turn convert:\n\n   if (!strncmp(head, \"refs/heads/\", 11))\n       head += 11;\n\ninto\n\n   if (ref_is_head(head))\n       head += STRLEN_PATH_REFS_HEADS;\n\nwhich expresses the intent of the code far more clearly.\n\n\n\nAndy\n\n-- \nDr Andy Parkins, M Eng (hons), MIEE\nandyparkins@gmail.com\n"},{"id":"35109","messageId":"7vabz9w270.fsf@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"200702201021.58754.andyparkins@gmail.com","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-20T10:30:59Z","receivedAt":"2007-02-20T10:30:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> writes:\n\n> Your prefixcmp() point about them being used so regularly made me wonder if \n> the following would improve readability:\n>\n> static inline ref_is_head(const char *a)\n> {\n>     return (prefixcmp(a, PATH_REFS_HEADS) == 0);\n> }\n> ...\n>    if (ref_is_head(head))\n>        head += STRLEN_PATH_REFS_HEADS;\n>\n> which expresses the intent of the code far more clearly.\n\nIf we _were_ doing the inline function, I would actually prefer:\n\n        static inline ref_is_head(const char *ref)\n        {\n\t\treturn !prefixcmp(ref, PATH_REFS_HEADS);\n        }\n\nBut at least to me,\n\n\tif (!prefixcmp(head, PATH_REFS_HEADS))\n\t\thead += strlen(PATH_REFS_HEADS);\n\nis easier to follow than:\n\n        if (ref_is_head(head))\n                head += STRLEN_PATH_REFS_HEADS;\n"},{"id":"35110","messageId":"200702201057.21398.andyparkins@gmail.com","threadId":"6884","inReplyTo":"7vabz9w270.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-02-20T10:57:06Z","receivedAt":"2007-02-20T10:57:06Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Tuesday 2007 February 20 10:30, Junio C Hamano wrote:\n\n> If we _were_ doing the inline function, I would actually prefer:\n>\n>         static inline ref_is_head(const char *ref)\n>         {\n> \t\treturn !prefixcmp(ref, PATH_REFS_HEADS);\n>         }\n\nAs you brought it up...\n\nI've never really liked \"!\" on strcmp() lines (but I accept that that is the \ntradition in git) because it implies the the output of prefixcmp is boolean, \nbut it's actually ternary.  strcmp() (I think), should be thought of as \noutputting\n\nenum {\n STRING1_LESS_THAN_STRING2,\n STRINGS_EQUAL,\n STRING1_GREATER_THAN_STRING2\n}\n\nGiven that, it makes me uncomfortable to use !strcmp().  Of course in the case \nof strcmp(), that form is so well known that it makes very little difference \nto the reader.\n\nI have similar feelings about\n\n if( !something )\n\nbeing incorrect when you meant\n\n if( something == NULL )\n\nWhile they are identical in what they generate, they send a different message \nto someone reading the code.\n\nRegardless, I'm not so stubborn as to refuse to go with the flow...\n\n> But at least to me,\n>\n> \tif (!prefixcmp(head, PATH_REFS_HEADS))\n> \t\thead += strlen(PATH_REFS_HEADS);\n>\n> is easier to follow than:\n>\n>         if (ref_is_head(head))\n>                 head += STRLEN_PATH_REFS_HEADS;\n\nFine.  I don't really mind - and it's less work on my patch :-)\n\nMy argument in favour of the ref_is_head() method is that the prefixcmp() \nmethod requires knowledge from the caller about how you tell whether a given \nref is a head - the second pushes that information further down the call \ntree, abstracting it out just a little more.\n\nAs I say though - it's not a problem for me.\n\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIEE\nandyparkins@gmail.com\n"},{"id":"35112","messageId":"Pine.LNX.4.63.0702201235350.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6884","inReplyTo":"200702201057.21398.andyparkins@gmail.com","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-20T11:37:48Z","receivedAt":"2007-02-20T11:37:48Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 20 Feb 2007, Andy Parkins wrote:\n\n> I've never really liked \"!\" on strcmp() lines (but I accept that that is the \n> tradition in git) because it implies the the output of prefixcmp is boolean, \n> but it's actually ternary.\n\nActually, it's not even ternary, but to the return value should only be \nhandled in terms of >0, ==0, <0.\n\nAh, and if \"!\" implies a boolean, then why is \"!!\" a common construct? \nBecause \"!\" really does not imply a boolean.\n\nCiao,\nDscho\n"},{"id":"35113","messageId":"Pine.LNX.4.63.0702201243000.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6884","inReplyTo":"7v3b51xihy.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/4] Mechanical conversion to use prefixcmp()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-20T11:53:32Z","receivedAt":"2007-02-20T11:53:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 20 Feb 2007, Junio C Hamano wrote:\n\n>    #!/usr/bin/perl -i.bak -p\n>    if (/strncmp\\(([^,]+), \"([^\\\\\"]*)\", (\\d+)\\)/ && (length($2) == $3)) {\n>            s|strncmp\\(([^,]+), \"([^\\\\\"]*)\", (\\d+)\\)|prefixcmp($1, \"$2\")|;\n>    }\n>    if (/strncmp\\(\"([^\\\\\"]*)\", ([^,]+), (\\d+)\\)/ && (length($1) == $3)) {\n>            s|strncmp\\(\"([^\\\\\"]*)\", ([^,]+), (\\d+)\\)|(-prefixcmp($2, \"$1\"))|;\n>    }\n\nHa, I did it by\n\n$ perl -pi.bup -e \\\n 's/strncmp\\( *(\"[^\"]*\"), *([^\"]*), *[0-9]* *\\)/prefixcmp\\($2, $1\\)/g' \\\n $(git ls-files)\n\nand\n\n$ perl -pi.bup -e \\\n 's/strncmp\\( *([^\"]*), *(\"[^\"]*\"), *[0-9]* *\\)/prefixcmp\\($1, $2\\)/g' \\\n $(git-ls-files)\n\nOf course, I missed the two ,ofs ones, but a git grep -n strncmp brought \nthese up.\n\nCiao,\nDscho\n"},{"id":"35114","messageId":"45DAE893.9030204@fs.ei.tum.de","threadId":"6884","inReplyTo":"Pine.LNX.4.63.0702201235350.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Simon 'corecode' Schubert","fromEmail":"corecode@fs.ei.tum.de","sentAt":"2007-02-20T12:24:51Z","receivedAt":"2007-02-20T12:24:51Z","isPatch":true,"sender":{"key":"corecode@fs.ei.tum.de","avatar":"https://gravatar.com/avatar/eff9dbf0cdac0d1e6a6cd7ed0e50763edcb376b493b5253a35ff167918ad79e1?d=mp&s=160"},"body":"Johannes Schindelin wrote:\n>> I've never really liked \"!\" on strcmp() lines (but I accept that that is the \n>> tradition in git) because it implies the the output of prefixcmp is boolean, \n>> but it's actually ternary.\n> \n> Actually, it's not even ternary, but to the return value should only be \n> handled in terms of >0, ==0, <0.\n> \n> Ah, and if \"!\" implies a boolean, then why is \"!!\" a common construct? \n> Because \"!\" really does not imply a boolean.\n\nDepends on how you look at it.  I code using semantics which use expressions only as boolean if they are really are.  So NULL pointers are not treated like a boolean, and neither are errno nor strcmp.  For me that's part of good, readable style, but people/groups of course are free to disagree.  Even after so many years of breathing C, I find   \"if (!strcmp(foo, bar))\" misleading, suggesting \"not compare\", which translates to \"not equal\".  Of course I know it, and can work with it, but in my own code I'd never write this.  I don't see any gain except some obfuscation.\n\ncheers\n  simon\n\n-- \nServe - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /\"\\\nWork - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \\ /\nParty Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \\\nDude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \\\n\n"},{"id":"35117","messageId":"Pine.LNX.4.63.0702201420550.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6884","inReplyTo":"45DAE893.9030204@fs.ei.tum.de","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-20T13:26:06Z","receivedAt":"2007-02-20T13:26:06Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 20 Feb 2007, Simon 'corecode' Schubert wrote:\n\n> Johannes Schindelin wrote:\n> > > I've never really liked \"!\" on strcmp() lines (but I accept that that is\n> > > the tradition in git) because it implies the the output of prefixcmp is\n> > > boolean, but it's actually ternary.\n> > \n> > Actually, it's not even ternary, but to the return value should only be\n> > handled in terms of >0, ==0, <0.\n> > \n> > Ah, and if \"!\" implies a boolean, then why is \"!!\" a common construct?\n> > Because \"!\" really does not imply a boolean.\n> \n> Depends on how you look at it.  I code using semantics which use \n> expressions only as boolean if they are really are.\n\nThere are no booleans in C.\n\nAlso, you just state that the construct is not common for _you_. It is \nreally quite common in C. Why? Because it is a short way to say _exactly_ \nwhat you want. Like when you say \"BTW\" instead of \"by the way\". It is not \nonly quicker to type, it is also quicker to read.\n\n> Even after so many years of breathing C, I find \"if (!strcmp(foo, bar))\" \n> misleading, suggesting \"not compare\", which translates to \"not equal\".\n\nNo, in plain English \"!strcmp(\"nothing\", u)\" translates to \"nothing \ncompares to u.\n\nIn mathematics, which is the basis of computer languages, \"not compare\" \nmeans something completely different yet: \"a\" does not compare to \"b\" \nmeans that they cannot be compared at all, i.e. the statement \"a<b\" is \nneither true nor false.\n\nSo, we have -- as so often -- a case, where somebody says \"it is obvious \nhow this expression translates to English\", but really, it is not. So, why \nnot stay in the context, and interpret it like millions of programmers \nbefore us? Or do you want to start another Babel?\n\nCiao,\nDscho\n"},{"id":"35118","messageId":"200702201326.46015.andyparkins@gmail.com","threadId":"6884","inReplyTo":"Pine.LNX.4.63.0702201235350.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-02-20T13:26:44Z","receivedAt":"2007-02-20T13:26:44Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Tuesday 2007 February 20 11:37, Johannes Schindelin wrote:\n\n> Actually, it's not even ternary, but to the return value should only be\n> handled in terms of >0, ==0, <0.\n\nApologies, I'm not using ternary in the sense of the number 0, 1 and 2; I'm \nusing it in the sense of there being three possible outcomes - which there \nare.  This is similar to how operators are categorised into unary, binary and \nternary categories.  I use ternary to mean \"having three states or elements\", \nrather than \"having the value 0, 1 or 2\".\n\n> Ah, and if \"!\" implies a boolean, then why is \"!!\" a common construct?\n> Because \"!\" really does not imply a boolean.\n\nBoolean expressions are those that have two possible states - \"true\" \nor \"false\".  There are no real booleans in C, so they are faked.  The two \nboolean states in C are represented by\n\n False = Equal to zero\n True = Not equal to zero\n\nNow, the !! construction you suggest is perfectly in keeping with this \ndefinition.  Ironically, the only reason you need the !! construction is \nbecause of this integer-as-boolean trait of C.\n\nSo, to get a boolean in C you use a standard integer (say).  My contention is \nthat to improve clarity you should not mix integer-as-boolean and \ninteger-as-integer, even though C will accept it when you do.\n\n i = 10;\n while( i )\n   i--;\n\nThis is bad, it abuses the fact that C will let you treat an integer as a \nboolean.  while() takes a boolean expression as it's argument, so I think \nthat you should always hand it something that would be a boolean output (even \nthough C doesn't care if you don't).\n\n i = 10;\n while( i > 0 )\n  i--;\n\nThis makes it clear to the reader that i is not boolean.  Obviously this is a \ntrivial example; no one would have any trouble understanding either of the \ntwo examples.  When things start to get bigger and more complicated though, \nmore clarity is always better than less clarity.  The principle I try to \nfollow is that code is write-once-read-many.  If you save yourself two \nkeystrokes at the expense of the clarity you gain for the 100 times you read \nthat code, then you have made a false economy.\n\nIn the end - I don't care - I was only countering Junio's \"I prefer !strcmp\", \nwith my reasons why I don't like it.  I do not expect git to change to my \npreferred coding style, and I do try to keep to the coding style that the git \nproject uses.  To my mind, inconsistency is a worse offence than anything \nelse in a project, so it's always better to go with what is established.\n\n\n\nAndy\n\n-- \nDr Andy Parkins, M Eng (hons), MIEE\nandyparkins@gmail.com\n"},{"id":"35121","messageId":"alpine.LRH.0.82.0702201040460.31945@xanadu.home","threadId":"6884","inReplyTo":"200702201057.21398.andyparkins@gmail.com","subject":"Re: [PATCH] Change \"refs/\" references to symbolic constants","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-02-20T15:46:07Z","receivedAt":"2007-02-20T15:46:07Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Tue, 20 Feb 2007, Andy Parkins wrote:\n\n> On Tuesday 2007 February 20 10:30, Junio C Hamano wrote:\n> \n> > But at least to me,\n> >\n> > \tif (!prefixcmp(head, PATH_REFS_HEADS))\n> > \t\thead += strlen(PATH_REFS_HEADS);\n> >\n> > is easier to follow than:\n> >\n> >         if (ref_is_head(head))\n> >                 head += STRLEN_PATH_REFS_HEADS;\n\nDitto for me.\n\n> Fine.  I don't really mind - and it's less work on my patch :-)\n> \n> My argument in favour of the ref_is_head() method is that the prefixcmp() \n> method requires knowledge from the caller about how you tell whether a given \n> ref is a head - the second pushes that information further down the call \n> tree, abstracting it out just a little more.\n\nThat's the problem though.  Too much abstraction hides away the purpose.  \nWith prefixcmp() it shows that the code cares about a string prefix.  \nWith ref_is_head() you don't know what is happening there since that \nmight be many things like a pointer comparison, etc. and you have to \nlook ref_is_head() implementation to be sure.\n\n\nNicolas\n"},{"id":"35164","messageId":"7v7iuct3ic.fsf@assigned-by-dhcp.cox.net","threadId":"6884","inReplyTo":"Pine.LNX.4.63.0702201243000.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 2/4] Mechanical conversion to use prefixcmp()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-21T06:43:07Z","receivedAt":"2007-02-21T06:43:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Ha, I did it by\n>\n> $ perl -pi.bup -e \\\n>  's/strncmp\\( *(\"[^\"]*\"), *([^\"]*), *[0-9]* *\\)/prefixcmp\\($2, $1\\)/g' \\\n>  $(git ls-files)\n>\n> and\n>\n> $ perl -pi.bup -e \\\n>  's/strncmp\\( *([^\"]*), *(\"[^\"]*\"), *[0-9]* *\\)/prefixcmp\\($1, $2\\)/g' \\\n>  $(git-ls-files)\n>\n> Of course, I missed the two ,ofs ones, but a git grep -n strncmp brought \n> these up.\n\nI think you totally missed my point.  I wanted to make sure that\nthings like these do not go unnoticed:\n\n        if (!strncmp(arg, \"--foo==\", 6))\n\tif (strncmp(line, \"foo\\nbar\", 8))\n\nBoth are probably incorrectly written code in the original, but\nprobably would _happen_ to be working (for a certain definition\nof \"working\" -- the former probably wanted to make sure the\nparameter is of form \"--foo=something\", and the latter wanted to\ncheck the line has the 7 bytes terminated with NUL).  But your\nconversion would make them actually start behaving incorrectly.\n\nAnd the worst part of this is that the change that caused to\nexpose these bugs would be literally _buried_ in 1800 lines of\n\"mechanical conversion\" patch which is mind-numbing to audit.\n\nThat's why you are better off writing mechanical conversion\nscript in stricter than seemingly necessary to catch only the\nsafe conversion target, while accepting false negatives.\n"},{"id":"35176","messageId":"Pine.LNX.4.63.0702211340490.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6884","inReplyTo":"7v7iuct3ic.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/4] Mechanical conversion to use prefixcmp()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-21T12:41:25Z","receivedAt":"2007-02-21T12:41:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 20 Feb 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > Ha, I did it by\n> >\n> > $ perl -pi.bup -e \\\n> >  's/strncmp\\( *(\"[^\"]*\"), *([^\"]*), *[0-9]* *\\)/prefixcmp\\($2, $1\\)/g' \\\n> >  $(git ls-files)\n> >\n> > and\n> >\n> > $ perl -pi.bup -e \\\n> >  's/strncmp\\( *([^\"]*), *(\"[^\"]*\"), *[0-9]* *\\)/prefixcmp\\($1, $2\\)/g' \\\n> >  $(git-ls-files)\n> >\n> > Of course, I missed the two ,ofs ones, but a git grep -n strncmp brought \n> > these up.\n> \n> I think you totally missed my point.  I wanted to make sure that\n> things like these do not go unnoticed:\n> \n>         if (!strncmp(arg, \"--foo==\", 6))\n> \tif (strncmp(line, \"foo\\nbar\", 8))\n> \n> Both are probably incorrectly written code in the original, but\n> probably would _happen_ to be working (for a certain definition\n> of \"working\" -- the former probably wanted to make sure the\n> parameter is of form \"--foo=something\", and the latter wanted to\n> check the line has the 7 bytes terminated with NUL).  But your\n> conversion would make them actually start behaving incorrectly.\n> \n> And the worst part of this is that the change that caused to\n> expose these bugs would be literally _buried_ in 1800 lines of\n> \"mechanical conversion\" patch which is mind-numbing to audit.\n> \n> That's why you are better off writing mechanical conversion\n> script in stricter than seemingly necessary to catch only the\n> safe conversion target, while accepting false negatives.\n\nAll true. I thought fixing them without checking was fine, but you are \nright: better safe than sorry.\n\nCiao,\nDscho\n"}]}