{"thread":{"id":"10143","subject":"[PATCH 1/3] Change \"refs/\" references to symbolic constants","startedAt":"2007-10-04T21:10:13Z","lastAt":"2007-10-04T21:10:13Z","messageCount":1,"participants":["Andy Parkins"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"54873","messageId":"200710042210.13877.andyparkins@gmail.com","threadId":"10143","inReplyTo":null,"subject":"[PATCH 1/3] Change \"refs/\" references to symbolic constants","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-10-04T21:10:13Z","receivedAt":"2007-10-04T21:10:13Z","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-fetch--tool.c   |   10 +++++-----\n builtin-fmt-merge-msg.c |    5 +++--\n builtin-fsck.c          |    4 ++--\n builtin-init-db.c       |   15 ++++++++-------\n builtin-name-rev.c      |   14 +++++++-------\n builtin-pack-refs.c     |    2 +-\n builtin-push.c          |    6 +++---\n builtin-show-branch.c   |   34 +++++++++++++++++-----------------\n builtin-show-ref.c      |    6 +++---\n builtin-tag.c           |    4 ++--\n connect.c               |   10 +++++-----\n fetch-pack.c            |    6 +++---\n http-fetch.c            |   33 +++++++++++++++++----------------\n http-push.c             |   42 +++++++++++++++++++++---------------------\n local-fetch.c           |   13 +++++++------\n path.c                  |    5 +++--\n receive-pack.c          |    4 ++--\n reflog-walk.c           |    6 +++---\n refs.c                  |   18 +++++++++---------\n refs.h                  |   17 +++++++++++++++++\n remote.c                |   14 +++++++-------\n setup.c                 |    5 +++--\n sha1_name.c             |   10 +++++-----\n wt-status.c             |    5 +++--\n 26 files changed, 171 insertions(+), 147 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 3da8b55..3cb8aee 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -92,12 +92,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@@ -189,15 +189,15 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,\n \tint len;\n \n \t/* Detect kind */\n-\tif (!prefixcmp(refname, \"refs/heads/\")) {\n+\tif (!prefixcmp(refname, PATH_REFS_HEADS)) {\n \t\tkind = REF_LOCAL_BRANCH;\n-\t\trefname += 11;\n-\t} else if (!prefixcmp(refname, \"refs/remotes/\")) {\n+\t\trefname += STRLEN_PATH_REFS_HEADS;\n+\t} else if (!prefixcmp(refname, PATH_REFS_REMOTES)) {\n \t\tkind = REF_REMOTE_BRANCH;\n-\t\trefname += 13;\n-\t} else if (!prefixcmp(refname, \"refs/tags/\")) {\n+\t\trefname += STRLEN_PATH_REFS_REMOTES;\n+\t} else if (!prefixcmp(refname, 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@@ -399,7 +399,7 @@ static void create_branch(const char *name, const char *start_name,\n \tchar *real_ref, 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@@ -468,13 +468,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@@ -601,9 +601,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tdetached = 1;\n \t}\n \telse {\n-\t\tif (prefixcmp(head, \"refs/heads/\"))\n-\t\t\tdie(\"HEAD not found below refs/heads!\");\n-\t\thead += 11;\n+\t\tif (prefixcmp(head, 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 669110c..b6f5b45 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -53,7 +53,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 (!prefixcmp(path, \"refs/tags/\")) {\n+\tif (!prefixcmp(path, PATH_REFS_TAGS)) {\n \t\tif (object->type == OBJ_TAG)\n \t\t\tprio = 2;\n \t\telse\ndiff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\nindex 1e43d79..cdb64cc 100644\n--- a/builtin-fetch--tool.c\n+++ b/builtin-fetch--tool.c\n@@ -64,7 +64,7 @@ static int update_local_ref(const char *name,\n \t\tchar *msg;\n \tjust_store:\n \t\t/* new ref */\n-\t\tif (!strncmp(name, \"refs/tags/\", 10))\n+\t\tif (!prefixcmp(name, PATH_REFS_TAGS))\n \t\t\tmsg = \"storing tag\";\n \t\telse\n \t\t\tmsg = \"storing head\";\n@@ -82,7 +82,7 @@ static int update_local_ref(const char *name,\n \t\treturn 0;\n \t}\n \n-\tif (!strncmp(name, \"refs/tags/\", 10)) {\n+\tif (!prefixcmp(name, PATH_REFS_TAGS)) {\n \t\tfprintf(stderr, \"* %s: updating with %s\\n\", name, note);\n \t\tshow_new(type, sha1_new);\n \t\treturn update_ref_env(\"updating tag\", name, sha1_new, NULL);\n@@ -139,15 +139,15 @@ static int append_fetch_head(FILE *fp,\n \t\tkind = \"\";\n \t\twhat = \"\";\n \t}\n-\telse if (!strncmp(remote_name, \"refs/heads/\", 11)) {\n+\telse if (!prefixcmp(remote_name, PATH_REFS_HEADS)) {\n \t\tkind = \"branch\";\n \t\twhat = remote_name + 11;\n \t}\n-\telse if (!strncmp(remote_name, \"refs/tags/\", 10)) {\n+\telse if (!prefixcmp(remote_name, PATH_REFS_TAGS)) {\n \t\tkind = \"tag\";\n \t\twhat = remote_name + 10;\n \t}\n-\telse if (!strncmp(remote_name, \"refs/remotes/\", 13)) {\n+\telse if (!prefixcmp(remote_name, PATH_REFS_REMOTES)) {\n \t\tkind = \"remote branch\";\n \t\twhat = remote_name + 13;\n \t}\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex 8a3c962..98a1fab 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@@ -277,8 +278,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 (!prefixcmp(current_branch, \"refs/heads/\"))\n-\t\tcurrent_branch += 11;\n+\tif (!prefixcmp(current_branch, 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 8d12287..83a2d0c 100644\n--- a/builtin-fsck.c\n+++ b/builtin-fsck.c\n@@ -629,14 +629,14 @@ static int fsck_head_link(void)\n \tif (!strcmp(head_points_at, \"HEAD\"))\n \t\t/* detached HEAD */\n \t\tnull_is_error = 1;\n-\telse if (prefixcmp(head_points_at, \"refs/heads/\"))\n+\telse if (prefixcmp(head_points_at, 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)) {\n \t\tif (null_is_error)\n \t\t\treturn error(\"HEAD: detached HEAD points at nothing\");\n \t\tfprintf(stderr, \"notice: HEAD points to an unborn branch (%s)\\n\",\n-\t\t\thead_points_at + 11);\n+\t\t\thead_points_at + STRLEN_PATH_REFS_HEADS);\n \t}\n \treturn 0;\n }\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 763fa55..1f3c0dd 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@@ -194,11 +195,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@@ -217,11 +218,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@@ -232,7 +233,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 03083e9..56c13d0 100644\n--- a/builtin-name-rev.c\n+++ b/builtin-name-rev.c\n@@ -96,7 +96,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 && prefixcmp(path, \"refs/tags/\"))\n+\tif (data->tags_only && prefixcmp(path, PATH_REFS_TAGS))\n \t\treturn 0;\n \n \tif (data->ref_filter && fnmatch(data->ref_filter, path, 0))\n@@ -112,14 +112,14 @@ 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 (!prefixcmp(path, \"refs/heads/\"))\n-\t\t\tpath = path + 11;\n+\t\tif (!prefixcmp(path, PATH_REFS_HEADS))\n+\t\t\tpath = path + STRLEN_PATH_REFS_HEADS;\n \t\telse if (data->tags_only\n \t\t    && data->name_only\n-\t\t    && !prefixcmp(path, \"refs/tags/\"))\n-\t\t\tpath = path + 10;\n-\t\telse if (!prefixcmp(path, \"refs/\"))\n-\t\t\tpath = path + 5;\n+\t\t    && !prefixcmp(path, PATH_REFS_TAGS))\n+\t\t\tpath = path + STRLEN_PATH_REFS_TAGS;\n+\t\telse if (!prefixcmp(path, 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 09df4e1..23b4c4e 100644\n--- a/builtin-pack-refs.c\n+++ b/builtin-pack-refs.c\n@@ -39,7 +39,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 = !prefixcmp(path, \"refs/tags/\");\n+\tis_tag_ref = !prefixcmp(path, PATH_REFS_TAGS);\n \n \t/* ALWAYS pack refs that were already packed or are tags */\n \tif (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref && !(flags & REF_ISPACKED))\ndiff --git a/builtin-push.c b/builtin-push.c\nindex 88c5024..2fdae7a 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -33,9 +33,9 @@ static void set_refspecs(const char **refs, int nr)\n \t\t\tint len;\n \t\t\tif (nr <= ++i)\n \t\t\t\tdie(\"tag shorthand without <tag>\");\n-\t\t\tlen = strlen(refs[i]) + 11;\n+\t\t\tlen = strlen(refs[i]) + STRLEN_PATH_REFS_TAGS + 1;\n \t\t\ttag = xmalloc(len);\n-\t\t\tstrcpy(tag, \"refs/tags/\");\n+\t\t\tstrcpy(tag, PATH_REFS_TAGS);\n \t\t\tstrcat(tag, refs[i]);\n \t\t\tref = tag;\n \t\t}\n@@ -148,7 +148,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"--tags\")) {\n-\t\t\tadd_refspec(\"refs/tags/*\");\n+\t\t\tadd_refspec(PATH_REFS_TAGS \"*\");\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg, \"--force\") || !strcmp(arg, \"-f\")) {\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 07a0c23..c01acdb 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -379,36 +379,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 (prefixcmp(refname, \"refs/heads/\"))\n+\tint ofs = STRLEN_PATH_REFS_HEADS;\n+\tif (prefixcmp(refname, PATH_REFS_HEADS))\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 (prefixcmp(refname, \"refs/remotes/\"))\n+\tint ofs = STRLEN_PATH_REFS_REMOTES;\n+\tif (prefixcmp(refname, PATH_REFS_REMOTES))\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 (prefixcmp(refname, \"refs/tags/\"))\n+\tif (prefixcmp(refname, 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@@ -437,9 +437,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, PATH_REFS_HEADS))\n \t\treturn append_head_ref(refname, sha1, flag, cb_data);\n-\tif (!prefixcmp(refname, \"refs/tags/\"))\n+\tif (!prefixcmp(refname, PATH_REFS_TAGS))\n \t\treturn append_tag_ref(refname, sha1, flag, cb_data);\n \treturn append_ref(refname, sha1, 0);\n }\n@@ -464,12 +464,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 (!prefixcmp(head, \"refs/heads/\"))\n-\t\thead += 11;\n-\tif (!prefixcmp(name, \"refs/heads/\"))\n-\t\tname += 11;\n-\telse if (!prefixcmp(name, \"heads/\"))\n-\t\tname += 6;\n+\tif (!prefixcmp(head, PATH_REFS_HEADS))\n+\t\thead += STRLEN_PATH_REFS_HEADS;\n+\tif (!prefixcmp(name, PATH_REFS_HEADS))\n+\t\tname += STRLEN_PATH_REFS_HEADS;\n+\telse if (!prefixcmp(name, PATH_HEADS))\n+\t\tname += STRLEN_PATH_HEADS;\n \treturn !strcmp(head, name);\n }\n \n@@ -780,7 +780,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 65051d1..d463d80 100644\n--- a/builtin-show-ref.c\n+++ b/builtin-show-ref.c\n@@ -29,8 +29,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 && !prefixcmp(refname, \"refs/heads/\");\n-\t\tmatch |= tags_only && !prefixcmp(refname, \"refs/tags/\");\n+\t\tmatch = heads_only && !prefixcmp(refname, PATH_REFS_HEADS);\n+\t\tmatch |= tags_only && !prefixcmp(refname, PATH_REFS_TAGS);\n \t\tif (!match)\n \t\t\treturn 0;\n \t}\n@@ -227,7 +227,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)\n \t\twhile (*pattern) {\n \t\t\tunsigned char sha1[20];\n \n-\t\t\tif (!prefixcmp(*pattern, \"refs/\") &&\n+\t\t\tif (!prefixcmp(*pattern, 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/builtin-tag.c b/builtin-tag.c\nindex 66e5a58..7cf7e02 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -139,7 +139,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn)\n \tunsigned char sha1[20];\n \n \tfor (p = argv; *p; p++) {\n-\t\tif (snprintf(ref, sizeof(ref), \"refs/tags/%s\", *p)\n+\t\tif (snprintf(ref, sizeof(ref), PATH_REFS_TAGS \"%s\", *p)\n \t\t\t\t\t>= sizeof(ref)) {\n \t\t\terror(\"tag name too long: %.*s...\", 50, *p);\n \t\t\thad_error = 1;\n@@ -408,7 +408,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tif (get_sha1(object_ref, object))\n \t\tdie(\"Failed to resolve '%s' as a valid ref.\", object_ref);\n \n-\tif (snprintf(ref, sizeof(ref), \"refs/tags/%s\", tag) > sizeof(ref) - 1)\n+\tif (snprintf(ref, sizeof(ref), PATH_REFS_TAGS \"%s\", tag) > sizeof(ref) - 1)\n \t\tdie(\"tag name too long: %.*s...\", 50, tag);\n \tif (check_ref_format(ref))\n \t\tdie(\"'%s' is not a valid tag name.\", tag);\ndiff --git a/connect.c b/connect.c\nindex 06d279e..94c2d60 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -13,23 +13,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 */\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 9c81305..c3b7ef6 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -344,11 +344,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 || prefixcmp(ref->name, \"refs/tags/\") )) {\n+\t\t\t (!depth || prefixcmp(ref->name, 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 202fae0..2680fbd 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@@ -157,12 +158,12 @@ static void start_object_request(struct object_request *obj_req)\n \n \tSHA1_Init(&obj_req->c);\n \n-\turl = xmalloc(strlen(obj_req->repo->base) + 51);\n-\tobj_req->url = xmalloc(strlen(obj_req->repo->base) + 51);\n+\turl = xmalloc(strlen(obj_req->repo->base) + STRLEN_PATH_OBJECTS + 43);\n+\tobj_req->url = xmalloc(strlen(obj_req->repo->base) + STRLEN_PATH_OBJECTS + 43);\n \tstrcpy(url, obj_req->repo->base);\n \tposn = url + strlen(obj_req->repo->base);\n-\tstrcpy(posn, \"/objects/\");\n-\tposn += 9;\n+\tstrcpy(posn, \"/\" PATH_OBJECTS);\n+\tposn += 1 + STRLEN_PATH_OBJECTS;\n \tmemcpy(posn, hex, 2);\n \tposn += 2;\n \t*(posn++) = '/';\n@@ -398,8 +399,8 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1)\n \tif (get_verbosely)\n \t\tfprintf(stderr, \"Getting index for pack %s\\n\", hex);\n \n-\turl = xmalloc(strlen(repo->base) + 64);\n-\tsprintf(url, \"%s/objects/pack/pack-%s.idx\", repo->base, hex);\n+\turl = xmalloc(strlen(repo->base) + STRLEN_PATH_OBJECTS + 56);\n+\tsprintf(url, \"%s/\" PATH_OBJECTS \"pack/pack-%s.idx\", repo->base, hex);\n \n \tfilename = sha1_pack_index_name(sha1);\n \tsnprintf(tmpfile, sizeof(tmpfile), \"%s.temp\", filename);\n@@ -478,7 +479,7 @@ static void process_alternates_response(void *callback_data)\n \n \t\t\t/* Try reusing the slot to get non-http alternates */\n \t\t\talt_req->http_specific = 0;\n-\t\t\tsprintf(alt_req->url, \"%s/objects/info/alternates\",\n+\t\t\tsprintf(alt_req->url, \"%s/\" PATH_OBJECTS \"info/alternates\",\n \t\t\t\tbase);\n \t\t\tcurl_easy_setopt(slot->curl, CURLOPT_URL,\n \t\t\t\t\t alt_req->url);\n@@ -625,8 +626,8 @@ static void fetch_alternates(const char *base)\n \tif (get_verbosely)\n \t\tfprintf(stderr, \"Getting alternates list for %s\\n\", base);\n \n-\turl = xmalloc(strlen(base) + 31);\n-\tsprintf(url, \"%s/objects/info/http-alternates\", base);\n+\turl = xmalloc(strlen(base) + STRLEN_PATH_OBJECTS + 23);\n+\tsprintf(url, \"%s/\" PATH_OBJECTS \"info/http-alternates\", base);\n \n \t/* Use a callback to process the result, since another request\n \t   may fail and need to have alternates loaded before continuing */\n@@ -675,8 +676,8 @@ static int fetch_indices(struct alt_base *repo)\n \tif (get_verbosely)\n \t\tfprintf(stderr, \"Getting pack list for %s\\n\", repo->base);\n \n-\turl = xmalloc(strlen(repo->base) + 21);\n-\tsprintf(url, \"%s/objects/info/packs\", repo->base);\n+\turl = xmalloc(strlen(repo->base) + STRLEN_PATH_OBJECTS + 13);\n+\tsprintf(url, \"%s/\" PATH_OBJECTS \"info/packs\", repo->base);\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n@@ -757,8 +758,8 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)\n \t\t\tsha1_to_hex(sha1));\n \t}\n \n-\turl = xmalloc(strlen(repo->base) + 65);\n-\tsprintf(url, \"%s/objects/pack/pack-%s.pack\",\n+\turl = xmalloc(strlen(repo->base) + STRLEN_PATH_OBJECTS + 57);\n+\tsprintf(url, \"%s/\" PATH_OBJECTS \"pack/pack-%s.pack\",\n \t\trepo->base, sha1_to_hex(target->sha1));\n \n \tfilename = sha1_pack_name(target->sha1);\n@@ -930,14 +931,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 + 7; /* \"/refs/\" + NUL */\n+\tlen = baselen + STRLEN_PATH_REFS + 2; /* \"/\" + \"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/\", 6);\n-\tfor (cp = ref, dp = qref + baselen + 6; (ch = *cp) != 0; cp++) {\n+\tmemcpy(qref + baselen, \"/\" PATH_REFS, STRLEN_PATH_REFS + 1);\n+\tfor (cp = ref, dp = qref + baselen + STRLEN_PATH_REFS + 1; (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 276e1eb..e70c4ea 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -272,12 +272,12 @@ static void start_fetch_loose(struct transfer_request *request)\n \n \tSHA1_Init(&request->c);\n \n-\turl = xmalloc(strlen(remote->url) + 50);\n-\trequest->url = xmalloc(strlen(remote->url) + 50);\n+\turl = xmalloc(strlen(remote->url) + 42 + STRLEN_PATH_OBJECTS);\n+\trequest->url = xmalloc(strlen(remote->url) + 42 + STRLEN_PATH_OBJECTS);\n \tstrcpy(url, remote->url);\n \tposn = url + strlen(remote->url);\n-\tstrcpy(posn, \"objects/\");\n-\tposn += 8;\n+\tstrcpy(posn, PATH_OBJECTS);\n+\tposn += STRLEN_PATH_OBJECTS;\n \tmemcpy(posn, hex, 2);\n \tposn += 2;\n \t*(posn++) = '/';\n@@ -357,11 +357,11 @@ static void start_mkcol(struct transfer_request *request)\n \tstruct active_request_slot *slot;\n \tchar *posn;\n \n-\trequest->url = xmalloc(strlen(remote->url) + 13);\n+\trequest->url = xmalloc(strlen(remote->url) + STRLEN_PATH_OBJECTS + 5);\n \tstrcpy(request->url, remote->url);\n \tposn = request->url + strlen(remote->url);\n-\tstrcpy(posn, \"objects/\");\n-\tposn += 8;\n+\tstrcpy(posn, PATH_OBJECTS);\n+\tposn += STRLEN_PATH_OBJECTS;\n \tmemcpy(posn, hex, 2);\n \tposn += 2;\n \tstrcpy(posn, \"/\");\n@@ -415,8 +415,8 @@ static void start_fetch_packed(struct transfer_request *request)\n \tsnprintf(request->tmpfile, sizeof(request->tmpfile),\n \t\t \"%s.temp\", filename);\n \n-\turl = xmalloc(strlen(remote->url) + 64);\n-\tsprintf(url, \"%sobjects/pack/pack-%s.pack\",\n+\turl = xmalloc(strlen(remote->url) + STRLEN_PATH_OBJECTS + 56);\n+\tsprintf(url, \"%s\" PATH_OBJECTS \"pack/pack-%s.pack\",\n \t\tremote->url, sha1_to_hex(target->sha1));\n \n \t/* Make sure there isn't another open request for this pack */\n@@ -519,11 +519,11 @@ static void start_put(struct transfer_request *request)\n \trequest->buffer.posn = 0;\n \n \trequest->url = xmalloc(strlen(remote->url) +\n-\t\t\t       strlen(request->lock->token) + 51);\n+\t\t\t       strlen(request->lock->token) + STRLEN_PATH_OBJECTS + 43);\n \tstrcpy(request->url, remote->url);\n \tposn = request->url + strlen(remote->url);\n-\tstrcpy(posn, \"objects/\");\n-\tposn += 8;\n+\tstrcpy(posn, PATH_OBJECTS);\n+\tposn += STRLEN_PATH_OBJECTS;\n \tmemcpy(posn, hex, 2);\n \tposn += 2;\n \t*(posn++) = '/';\n@@ -922,8 +922,8 @@ static int fetch_index(unsigned char *sha1)\n \tstruct slot_results results;\n \n \t/* Don't use the index if the pack isn't there */\n-\turl = xmalloc(strlen(remote->url) + 64);\n-\tsprintf(url, \"%sobjects/pack/pack-%s.pack\", remote->url, hex);\n+\turl = xmalloc(strlen(remote->url) + STRLEN_PATH_OBJECTS + 56);\n+\tsprintf(url, \"%s\" PATH_OBJECTS \"pack/pack-%s.pack\", remote->url, hex);\n \tslot = get_active_slot();\n \tslot->results = &results;\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n@@ -945,7 +945,7 @@ static int fetch_index(unsigned char *sha1)\n \tif (push_verbosely)\n \t\tfprintf(stderr, \"Getting index for pack %s\\n\", hex);\n \n-\tsprintf(url, \"%sobjects/pack/pack-%s.idx\", remote->url, hex);\n+\tsprintf(url, \"%s\" PATH_OBJECTS \"pack/pack-%s.idx\", remote->url, hex);\n \n \tfilename = sha1_pack_index_name(sha1);\n \tsnprintf(tmpfile, sizeof(tmpfile), \"%s.temp\", filename);\n@@ -1029,8 +1029,8 @@ static int fetch_indices(void)\n \tif (push_verbosely)\n \t\tfprintf(stderr, \"Getting pack list\\n\");\n \n-\turl = xmalloc(strlen(remote->url) + 20);\n-\tsprintf(url, \"%sobjects/info/packs\", remote->url);\n+\turl = xmalloc(strlen(remote->url) + STRLEN_PATH_OBJECTS + 12);\n+\tsprintf(url, \"%s\" PATH_OBJECTS \"info/packs\", remote->url);\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n@@ -1612,7 +1612,7 @@ static void remote_ls(const char *path, int flags,\n \n static void get_remote_object_list(unsigned char parent)\n {\n-\tchar path[] = \"objects/XX/\";\n+\tchar path[] = PATH_OBJECTS \"XX/\";\n \tstatic const char hex[] = \"0123456789abcdef\";\n \tunsigned int val = parent;\n \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);\n@@ -2370,7 +2370,7 @@ int main(int argc, char **argv)\n \t/* Check whether the remote has server info files */\n \tremote->can_update_info_refs = 0;\n \tremote->has_info_refs = remote_exists(\"info/refs\");\n-\tremote->has_info_packs = remote_exists(\"objects/info/packs\");\n+\tremote->has_info_packs = remote_exists(PATH_OBJECTS \"info/packs\");\n \tif (remote->has_info_refs) {\n \t\tinfo_ref_lock = lock_remote(\"info/refs\", LOCK_TIME);\n \t\tif (info_ref_lock)\ndiff --git a/local-fetch.c b/local-fetch.c\nindex bf7ec6c..67dc065 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@@ -23,7 +24,7 @@ static void setup_index(unsigned char *sha1)\n \tstruct packed_git *new_pack;\n \tchar filename[PATH_MAX];\n \tstrcpy(filename, path);\n-\tstrcat(filename, \"/objects/pack/pack-\");\n+\tstrcat(filename, \"/\" PATH_OBJECTS \"pack/pack-\");\n \tstrcat(filename, sha1_to_hex(sha1));\n \tstrcat(filename, \".idx\");\n \tnew_pack = parse_pack_index_file(sha1, filename);\n@@ -37,7 +38,7 @@ static int setup_indices(void)\n \tstruct dirent *de;\n \tchar filename[PATH_MAX];\n \tunsigned char sha1[20];\n-\tsprintf(filename, \"%s/objects/pack/\", path);\n+\tsprintf(filename, \"%s/\" PATH_OBJECTS \"pack/\", path);\n \tdir = opendir(filename);\n \tif (!dir)\n \t\treturn -1;\n@@ -122,11 +123,11 @@ static int fetch_pack(const unsigned char *sha1)\n \t\tfprintf(stderr, \" which contains %s\\n\",\n \t\t\tsha1_to_hex(sha1));\n \t}\n-\tsprintf(filename, \"%s/objects/pack/pack-%s.pack\",\n+\tsprintf(filename, \"%s/\" PATH_OBJECTS \"pack/pack-%s.pack\",\n \t\tpath, sha1_to_hex(target->sha1));\n \tcopy_file(filename, sha1_pack_name(target->sha1),\n \t\t  sha1_to_hex(target->sha1), 1);\n-\tsprintf(filename, \"%s/objects/pack/pack-%s.idx\",\n+\tsprintf(filename, \"%s/\" PATH_OBJECTS \"pack/pack-%s.idx\",\n \t\tpath, sha1_to_hex(target->sha1));\n \tcopy_file(filename, sha1_pack_index_name(target->sha1),\n \t\t  sha1_to_hex(target->sha1), 1);\n@@ -143,7 +144,7 @@ static int fetch_file(const unsigned char *sha1)\n \n \tif (object_name_start < 0) {\n \t\tstrcpy(filename, path); /* e.g. git.git */\n-\t\tstrcat(filename, \"/objects/\");\n+\t\tstrcat(filename, \"/\" PATH_OBJECTS);\n \t\tobject_name_start = strlen(filename);\n \t}\n \tfilename[object_name_start+0] = hex[0];\n@@ -169,7 +170,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 4260952..d330bbc 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@@ -99,7 +100,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 >= STRLEN_PATH_REFS && !memcmp(PATH_REFS, buffer, STRLEN_PATH_REFS))\n \t\t\treturn 0;\n \t\treturn -1;\n \t}\n@@ -123,7 +124,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 d3c422b..114ea38 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -165,7 +165,7 @@ static const char *update(struct command *cmd)\n \tunsigned char *new_sha1 = cmd->new_sha1;\n \tstruct ref_lock *lock;\n \n-\tif (!prefixcmp(name, \"refs/\") && check_ref_format(name + 5)) {\n+\tif (!prefixcmp(name, PATH_REFS) && check_ref_format(name + STRLEN_PATH_REFS)) {\n \t\terror(\"refusing to create funny ref '%s' locally\", name);\n \t\treturn \"funny refname\";\n \t}\n@@ -177,7 +177,7 @@ static const char *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    !prefixcmp(name, \"refs/heads/\")) {\n+\t    !prefixcmp(name, 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 ee1456b..98cf8ef 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 07e260c..5891609 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -409,7 +409,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@@ -561,22 +561,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@@ -588,7 +588,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@@ -824,7 +824,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, 0, NULL);\n }\n \n@@ -1078,8 +1078,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    (!prefixcmp(ref_name, \"refs/heads/\") ||\n-\t     !prefixcmp(ref_name, \"refs/remotes/\") ||\n+\t    (!prefixcmp(ref_name,  PATH_REFS_HEADS) ||\n+\t     !prefixcmp(ref_name, PATH_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/refs.h b/refs.h\nindex 6eb98a4..1025d04 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/remote.c b/remote.c\nindex bb774d0..b8922c7 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -211,8 +211,8 @@ static void read_config(void)\n \tcurrent_branch = NULL;\n \thead_ref = resolve_ref(\"HEAD\", sha1, 0, &flag);\n \tif (head_ref && (flag & REF_ISSYMREF) &&\n-\t    !prefixcmp(head_ref, \"refs/heads/\")) {\n-\t\tcurrent_branch = head_ref + strlen(\"refs/heads/\");\n+\t    !prefixcmp(head_ref, PATH_REFS_HEADS)) {\n+\t\tcurrent_branch = head_ref + STRLEN_PATH_REFS_HEADS;\n \t\tcurrent_branch_len = strlen(current_branch);\n \t}\n \tgit_config(handle_config);\n@@ -398,9 +398,9 @@ static int count_refspec_match(const char *pattern,\n \t\t * at the remote site.\n \t\t */\n \t\tif (namelen != patlen &&\n-\t\t    patlen != namelen - 5 &&\n-\t\t    prefixcmp(name, \"refs/heads/\") &&\n-\t\t    prefixcmp(name, \"refs/tags/\")) {\n+\t\t    patlen != namelen - STRLEN_PATH_REFS &&\n+\t\t    prefixcmp(name, PATH_REFS_HEADS) &&\n+\t\t    prefixcmp(name, 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@@ -511,7 +511,7 @@ static int match_explicit(struct ref *src, struct ref *dst,\n \tcase 1:\n \t\tbreak;\n \tcase 0:\n-\t\tif (!memcmp(dst_value, \"refs/\", 5))\n+\t\tif (!prefixcmp(dst_value, PATH_REFS))\n \t\t\tmatched_dst = make_linked_ref(dst_value, dst_tail);\n \t\telse\n \t\t\terror(\"dst refspec %s does not match any \"\n@@ -594,7 +594,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,\n \t\t\tif (!pat)\n \t\t\t\tcontinue;\n \t\t}\n-\t\telse if (prefixcmp(src->name, \"refs/heads/\"))\n+\t\telse if (prefixcmp(src->name, PATH_REFS_HEADS))\n \t\t\t/*\n \t\t\t * \"matching refs\"; traditionally we pushed everything\n \t\t\t * including refs outside refs/heads/ hierarchy, but\ndiff --git a/setup.c b/setup.c\nindex 06004f1..c8912d2 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"dir.h\"\n+#include \"refs.h\"\n \n static int inside_git_dir = -1;\n static int inside_work_tree = -1;\n@@ -158,12 +159,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 2d727d5..649e438 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -241,11 +241,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 10ce6ee..93dee72 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@@ -311,8 +312,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 (!prefixcmp(branch_name, \"refs/heads/\"))\n-\t\t\tbranch_name += 11;\n+\t\tif (!prefixcmp(branch_name, 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.3.rc5.11.g312e\n"}]}