Commit 74a24005 by nulltoken

refs: use constants for well-known names

parent acd17006
......@@ -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");
}
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment