Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libgit2/annotated_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int git_annotated_commit_from_head(

*out = NULL;

if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
if ((error = git_reference_lookup(&head, repo, GIT_HEAD_REF)) < 0)
return -1;

error = git_annotated_commit_from_ref(out, repo, head);
Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static int branch_is_checked_out(git_repository *worktree, void *payload)
if (git_repository_is_bare(worktree))
return 0;

if ((error = git_reference_lookup(&head, worktree, GIT_HEAD_FILE)) < 0) {
if ((error = git_reference_lookup(&head, worktree, GIT_HEAD_REF)) < 0) {
if (error == GIT_ENOTFOUND)
error = 0;
goto out;
Expand Down
36 changes: 17 additions & 19 deletions src/libgit2/cherrypick.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,9 @@

static int write_cherrypick_head(
git_repository *repo,
const char *commit_oidstr)
const git_oid *commit)
{
git_filebuf file = GIT_FILEBUF_INIT;
git_str file_path = GIT_STR_INIT;
int error = 0;

if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
error = git_filebuf_commit(&file);

if (error < 0)
git_filebuf_cleanup(&file);

git_str_dispose(&file_path);

return error;
return git_reference_create(NULL, repo, GIT_CHERRYPICK_HEAD_REF, commit, 1, NULL);
}

static int write_merge_msg(
Expand Down Expand Up @@ -98,9 +84,21 @@ static int cherrypick_normalize_opts(

static int cherrypick_state_cleanup(git_repository *repo)
{
const char *state_files[] = { GIT_CHERRYPICK_HEAD_FILE, GIT_MERGE_MSG_FILE };
const char *state_files[] = { GIT_MERGE_MSG_FILE };
int error;

if ((error = git_repository__cleanup_files(repo, state_files,
ARRAY_SIZE(state_files))) < 0)
goto out;

return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
if ((error = git_reference_remove(repo, GIT_CHERRYPICK_HEAD_REF)) < 0) {
if (error != GIT_ENOTFOUND)
goto out;
error = 0;
}

out:
return error;
}

static int cherrypick_seterr(git_commit *commit, const char *fmt)
Expand Down Expand Up @@ -199,7 +197,7 @@ int git_cherrypick(
(error = git_str_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 ||
(error = cherrypick_normalize_opts(repo, &opts, given_opts, git_str_cstr(&their_label))) < 0 ||
(error = git_indexwriter_init_for_operation(&indexwriter, repo, &opts.checkout_opts.checkout_strategy)) < 0 ||
(error = write_cherrypick_head(repo, commit_oidstr)) < 0 ||
(error = write_cherrypick_head(repo, git_commit_id(commit))) < 0 ||
(error = git_repository_head(&our_ref, repo)) < 0 ||
(error = git_reference_peel((git_object **)&our_commit, our_ref, GIT_OBJECT_COMMIT)) < 0 ||
(error = git_cherrypick_commit(&index, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 ||
Expand Down
4 changes: 2 additions & 2 deletions src/libgit2/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static int update_remote_head(
"%s%s/%s",
GIT_REFS_REMOTES_DIR,
git_remote_name(remote),
GIT_HEAD_FILE)) < 0)
GIT_HEAD_REF)) < 0)
goto cleanup;

error = git_reference_symbolic_create(
Expand Down Expand Up @@ -226,7 +226,7 @@ static int update_head_to_remote(
return error;

/* We cloned an empty repository or one with an unborn HEAD */
if (refs_len == 0 || strcmp(refs[0]->name, GIT_HEAD_FILE))
if (refs_len == 0 || strcmp(refs[0]->name, GIT_HEAD_REF))
return update_head_to_default(repo);

/* We know we have HEAD, let's see where it points */
Expand Down
27 changes: 19 additions & 8 deletions src/libgit2/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "config_list.h"
#include "config_parse.h"
#include "filebuf.h"
#include "refdb.h"
#include "regexp.h"
#include "sysdir.h"
#include "wildmatch.h"
Expand Down Expand Up @@ -665,27 +666,34 @@ static int conditional_match_onbranch(
const char *condition)
{
git_str reference = GIT_STR_INIT, buf = GIT_STR_INIT;
git_reference *ref = NULL;
git_refdb *refdb = NULL;
int error;

GIT_UNUSED(cfg_file);

/*
* NOTE: you cannot use `git_repository_head` here. Looking up the
* HEAD reference will create the ODB, which causes us to read the
* NOTE: we cannot use higher-level functions like
* `git_repository_head` here, as these will cause us to read the
* repo's config for keys like core.precomposeUnicode. As we're
* just parsing the config right now, though, this would result in
* an endless recursion.
*
* Instead, we use lower-level functionality to do so and use the refdb
* directly. This requires that the refdb does not perform any config
* lookups when initializing or when reading a single ref.
*/

if ((error = git_str_joinpath(&buf, git_repository_path(repo), GIT_HEAD_FILE)) < 0 ||
(error = git_futils_readbuffer(&reference, buf.ptr)) < 0)
if ((error = git_repository_refdb(&refdb, (git_repository *) repo)) < 0 ||
(error = git_refdb_lookup(&ref, refdb, GIT_HEAD_REF)) < 0)
goto out;
git_str_rtrim(&reference);

if (git__strncmp(reference.ptr, GIT_SYMREF, strlen(GIT_SYMREF)))
if (git_reference_type(ref) != GIT_REFERENCE_SYMBOLIC) {
*matches = 0;
goto out;
git_str_consume(&reference, reference.ptr + strlen(GIT_SYMREF));
}

if ((error = git_str_sets(&reference, git_reference_symbolic_target(ref))) < 0)
goto out;
if (git__strncmp(reference.ptr, GIT_REFS_HEADS_DIR, strlen(GIT_REFS_HEADS_DIR)))
goto out;
git_str_consume(&reference, reference.ptr + strlen(GIT_REFS_HEADS_DIR));
Expand All @@ -701,9 +709,12 @@ static int conditional_match_onbranch(
goto out;

*matches = wildmatch(buf.ptr, reference.ptr, WM_PATHNAME) == WM_MATCH;

out:
git_str_dispose(&reference);
git_str_dispose(&buf);
git_reference_free(ref);
git_refdb_free(refdb);

return error;

Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ int git_describe_workdir(
git_describe_result *result = NULL;
git_object *commit;

if ((error = git_reference_name_to_id(&current_id, repo, GIT_HEAD_FILE)) < 0)
if ((error = git_reference_name_to_id(&current_id, repo, GIT_HEAD_REF)) < 0)
return error;

if ((error = git_object_lookup(&commit, repo, &current_id, GIT_OBJECT_COMMIT)) < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/fetchhead.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int fetchhead_ref_write(
GIT_REFS_TAGS_DIR) == 0) {
type = "tag ";
name = fetchhead_ref->ref_name + strlen(GIT_REFS_TAGS_DIR);
} else if (!git__strcmp(fetchhead_ref->ref_name, GIT_HEAD_FILE)) {
} else if (!git__strcmp(fetchhead_ref->ref_name, GIT_HEAD_REF)) {
head = 1;
} else {
type = "";
Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -3317,7 +3317,7 @@ int git_merge_analysis(
git_reference *head_ref = NULL;
int error = 0;

if ((error = git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE)) < 0) {
if ((error = git_reference_lookup(&head_ref, repo, GIT_HEAD_REF)) < 0) {
git_error_set(GIT_ERROR_MERGE, "failed to lookup HEAD reference");
return error;
}
Expand Down
8 changes: 4 additions & 4 deletions src/libgit2/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static int rebase_init_merge(
&onto_commit, repo, git_annotated_commit_id(onto))) < 0 ||
(error = git_checkout_tree(repo,
(git_object *)onto_commit, &rebase->options.checkout_options)) < 0 ||
(error = git_reference_create(&head_ref, repo, GIT_HEAD_FILE,
(error = git_reference_create(&head_ref, repo, GIT_HEAD_REF,
git_annotated_commit_id(onto), 1, reflog.ptr)) < 0)
goto done;

Expand Down Expand Up @@ -1191,10 +1191,10 @@ int git_rebase_abort(git_rebase *rebase)
return 0;

error = rebase->head_detached ?
git_reference_create(&orig_head_ref, rebase->repo, GIT_HEAD_FILE,
git_reference_create(&orig_head_ref, rebase->repo, GIT_HEAD_REF,
&rebase->orig_head_id, 1, "rebase: aborting") :
git_reference_symbolic_create(
&orig_head_ref, rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
&orig_head_ref, rebase->repo, GIT_HEAD_REF, rebase->orig_head_name, 1,
"rebase: aborting");

if (error < 0)
Expand Down Expand Up @@ -1379,7 +1379,7 @@ static int return_to_orig_head(git_rebase *rebase)
git_commit_id(terminal_commit), 1,
&rebase->orig_head_id, branch_msg.ptr)) == 0)
error = git_reference_symbolic_create(&head_ref,
rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
rebase->repo, GIT_HEAD_REF, rebase->orig_head_name, 1,
head_msg.ptr);

git_str_dispose(&head_msg);
Expand Down
4 changes: 2 additions & 2 deletions src/libgit2/refdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ int git_refdb_should_write_reflog(int *out, git_refdb *db, const git_reference *
*/
*out = git_refdb_has_log(db, ref->name) ||
!git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR) ||
!git__strcmp(ref->name, GIT_HEAD_FILE) ||
!git__strcmp(ref->name, GIT_HEAD_REF) ||
!git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR) ||
!git__prefixcmp(ref->name, GIT_REFS_NOTES_DIR);
break;
Expand All @@ -350,7 +350,7 @@ int git_refdb_should_write_head_reflog(int *out, git_refdb *db, const git_refere
goto out;
}

if ((error = git_refdb_lookup(&head, db, GIT_HEAD_FILE)) < 0)
if ((error = git_refdb_lookup(&head, db, GIT_HEAD_REF)) < 0)
goto out;

if (git_reference_type(head) == GIT_REFERENCE_DIRECT)
Expand Down
Loading
Loading