refs: use constants for well-known names
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
diff --git a/src/clone.c b/src/clone.c
index 80a13d0..9dfc22c 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -50,7 +50,7 @@ static int create_tracking_branch(git_repository *repo, const git_oid *target, c
git_buf merge_target = GIT_BUF_INIT;
if (!git_buf_printf(&remote, "branch.%s.remote", name) &&
!git_buf_printf(&merge, "branch.%s.merge", name) &&
- !git_buf_printf(&merge_target, "refs/heads/%s", name) &&
+ !git_buf_printf(&merge_target, GIT_REFS_HEADS_DIR "%s", name) &&
!git_config_set_string(cfg, git_buf_cstr(&remote), "origin") &&
!git_config_set_string(cfg, git_buf_cstr(&merge), git_buf_cstr(&merge_target))) {
retcode = 0;
@@ -77,7 +77,7 @@ static int reference_matches_remote_head(const char *head_name, void *payload)
if (!git_reference_name_to_oid(&oid, head_info->repo, head_name) &&
!git_oid_cmp(&head_info->remote_head_oid, &oid)) {
git_buf_puts(&head_info->branchname,
- head_name+strlen("refs/remotes/origin/"));
+ head_name+strlen(GIT_REFS_REMOTES_DIR "origin/"));
}
return 0;
}
@@ -90,7 +90,7 @@ static int update_head_to_new_branch(git_repository *repo, const git_oid *target
git_reference *head;
if (!git_reference_lookup(&head, repo, GIT_HEAD_FILE)) {
git_buf targetbuf = GIT_BUF_INIT;
- if (!git_buf_printf(&targetbuf, "refs/heads/%s", name)) {
+ if (!git_buf_printf(&targetbuf, GIT_REFS_HEADS_DIR "%s", name)) {
retcode = git_reference_set_target(head, git_buf_cstr(&targetbuf));
}
git_buf_free(&targetbuf);
@@ -115,7 +115,7 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote)
head_info.repo = repo;
/* Check to see if "master" matches the remote head */
- if (!git_reference_name_to_oid(&oid, repo, "refs/remotes/origin/master") &&
+ if (!git_reference_name_to_oid(&oid, repo, GIT_REFS_REMOTES_DIR "origin/master") &&
!git_oid_cmp(&remote_head->oid, &oid)) {
retcode = update_head_to_new_branch(repo, &oid, "master");
}
diff --git a/src/refs.c b/src/refs.c
index bd6fbee..2a3b8dd 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1404,7 +1404,7 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
git_reference_free(head);
head = NULL;
- if (git_reference_create_symbolic(&head, ref->owner, "HEAD", new_name, 1) < 0) {
+ if (git_reference_create_symbolic(&head, ref->owner, GIT_HEAD_FILE, new_name, 1) < 0) {
giterr_set(GITERR_REFERENCE,
"Failed to update HEAD after renaming reference");
goto cleanup;
diff --git a/src/repository.c b/src/repository.c
index 1a46db0..1641129 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -654,10 +654,10 @@ static int repo_init_create_head(const char *git_dir, const char *ref_name)
if (!ref_name)
ref_name = GIT_BRANCH_MASTER;
- if (git__prefixcmp(ref_name, "refs/") == 0)
+ if (git__prefixcmp(ref_name, GIT_REFS_DIR) == 0)
fmt = "ref: %s\n";
else
- fmt = "ref: refs/heads/%s\n";
+ fmt = "ref: " GIT_REFS_HEADS_DIR "%s\n";
if (git_filebuf_printf(&ref, fmt, ref_name) < 0 ||
git_filebuf_commit(&ref, GIT_REFS_FILE_MODE) < 0)
@@ -1219,7 +1219,7 @@ int git_repository_is_empty(git_repository *repo)
git_reference *head = NULL, *branch = NULL;
int error;
- if (git_reference_lookup(&head, repo, "HEAD") < 0)
+ if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0)
return -1;
if (git_reference_type(head) != GIT_REF_SYMBOLIC) {
@@ -1227,7 +1227,7 @@ int git_repository_is_empty(git_repository *repo)
return 0;
}
- if (strcmp(git_reference_target(head), "refs/heads/master") != 0) {
+ if (strcmp(git_reference_target(head), GIT_REFS_HEADS_DIR "master") != 0) {
git_reference_free(head);
return 0;
}
diff --git a/src/revparse.c b/src/revparse.c
index 5e2db99..191f637 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -28,11 +28,11 @@ static int disambiguate_refname(git_reference **out, git_repository *repo, const
static const char* formatters[] = {
"%s",
- "refs/%s",
- "refs/tags/%s",
- "refs/heads/%s",
- "refs/remotes/%s",
- "refs/remotes/%s/HEAD",
+ GIT_REFS_DIR "%s",
+ GIT_REFS_TAGS_DIR "%s",
+ GIT_REFS_HEADS_DIR "%s",
+ GIT_REFS_REMOTES_DIR "%s",
+ GIT_REFS_REMOTES_DIR "%s/" GIT_HEAD_FILE,
NULL
};
@@ -520,7 +520,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_
if (spec_oid == NULL) {
// TODO: @carlosmn: The glob should be refs/* but this makes git_revwalk_next() fails
- if (git_revwalk_push_glob(walk, "refs/heads/*") < 0)
+ if (git_revwalk_push_glob(walk, GIT_REFS_HEADS_DIR "*") < 0)
goto cleanup;
} else if (git_revwalk_push(walk, spec_oid) < 0)
goto cleanup;
diff --git a/src/submodule.c b/src/submodule.c
index a216249..1805286 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1315,7 +1315,7 @@ static int lookup_head_remote(git_buf *url, git_repository *repo)
/* remote should refer to something like refs/remotes/ORIGIN/BRANCH */
if (git_reference_type(remote) != GIT_REF_SYMBOLIC ||
- git__prefixcmp(git_reference_target(remote), "refs/remotes/") != 0)
+ git__prefixcmp(git_reference_target(remote), GIT_REFS_REMOTES_DIR) != 0)
{
giterr_set(GITERR_SUBMODULE,
"Cannot resolve relative URL when HEAD is not symbolic");
@@ -1323,7 +1323,7 @@ static int lookup_head_remote(git_buf *url, git_repository *repo)
goto cleanup;
}
- scan = tgt = git_reference_target(remote) + strlen("refs/remotes/");
+ scan = tgt = git_reference_target(remote) + strlen(GIT_REFS_REMOTES_DIR);
while (*scan && (*scan != '/' || (scan > tgt && scan[-1] != '\\')))
scan++; /* find non-escaped slash to end ORIGIN name */