summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-01-07 12:23:05 +0000
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-03 14:40:50 +0100
commit659cf2029f322ea876d663d85783b48945227e8f (patch)
tree435e9185c38d96656e21db83fc736b5294499b10 /src
parent99b68a2aecfaa24f252f265d61b230b8e2576dd2 (diff)
downloadlibgit2-659cf2029f322ea876d663d85783b48945227e8f.tar.gz
Remove the signature from ref-modifying functions
The signature for the reflog is not something which changes dynamically. Almost all uses will be NULL, since we want for the repository's default identity to be used, making it noise. In order to allow for changing the identity, we instead provide git_repository_set_ident() and git_repository_ident() which allow a user to override the choice of signature.
Diffstat (limited to 'src')
-rw-r--r--src/branch.c6
-rw-r--r--src/clone.c43
-rw-r--r--src/commit.c4
-rw-r--r--src/push.c3
-rw-r--r--src/push.h1
-rw-r--r--src/rebase.c23
-rw-r--r--src/refs.c153
-rw-r--r--src/refs.h3
-rw-r--r--src/remote.c27
-rw-r--r--src/repository.c46
-rw-r--r--src/repository.h3
-rw-r--r--src/reset.c3
-rw-r--r--src/stash.c5
-rw-r--r--src/submodule.c5
-rw-r--r--src/tag.c4
-rw-r--r--src/transports/local.c2
16 files changed, 183 insertions, 148 deletions
diff --git a/src/branch.c b/src/branch.c
index b39d74749..762a26211 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -55,7 +55,6 @@ int git_branch_create(
const char *branch_name,
const git_commit *commit,
int force,
- const git_signature *signature,
const char *log_message)
{
int is_head = 0;
@@ -92,7 +91,7 @@ int git_branch_create(
goto cleanup;
error = git_reference_create(&branch, repository,
- git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force, signature,
+ git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force,
git_buf_cstr(&log_message_buf));
if (!error)
@@ -223,7 +222,6 @@ int git_branch_move(
git_reference *branch,
const char *new_branch_name,
int force,
- const git_signature *signature,
const char *log_message)
{
git_buf new_reference_name = GIT_BUF_INIT,
@@ -253,7 +251,7 @@ int git_branch_move(
error = git_reference_rename(
out, branch, git_buf_cstr(&new_reference_name), force,
- signature, git_buf_cstr(&log_message_buf));
+ git_buf_cstr(&log_message_buf));
if (error < 0)
goto done;
diff --git a/src/clone.c b/src/clone.c
index f18f07611..f7ae17c57 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -24,14 +24,13 @@
#include "repository.h"
#include "odb.h"
-static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link, const git_signature *signature);
+static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link);
static int create_branch(
git_reference **branch,
git_repository *repo,
const git_oid *target,
const char *name,
- const git_signature *signature,
const char *log_message)
{
git_commit *head_obj = NULL;
@@ -43,7 +42,7 @@ static int create_branch(
return error;
/* Create the new branch */
- error = git_branch_create(&branch_ref, repo, name, head_obj, 0, signature, log_message);
+ error = git_branch_create(&branch_ref, repo, name, head_obj, 0, log_message);
git_commit_free(head_obj);
@@ -93,12 +92,11 @@ static int create_tracking_branch(
git_repository *repo,
const git_oid *target,
const char *branch_name,
- const git_signature *signature,
const char *log_message)
{
int error;
- if ((error = create_branch(branch, repo, target, branch_name, signature, log_message)) < 0)
+ if ((error = create_branch(branch, repo, target, branch_name, log_message)) < 0)
return error;
return setup_tracking_config(
@@ -112,7 +110,6 @@ static int update_head_to_new_branch(
git_repository *repo,
const git_oid *target,
const char *name,
- const git_signature *signature,
const char *reflog_message)
{
git_reference *tracking_branch = NULL;
@@ -122,12 +119,12 @@ static int update_head_to_new_branch(
name += strlen(GIT_REFS_HEADS_DIR);
error = create_tracking_branch(&tracking_branch, repo, target, name,
- signature, reflog_message);
+ reflog_message);
if (!error)
error = git_repository_set_head(
repo, git_reference_name(tracking_branch),
- signature, reflog_message);
+ reflog_message);
git_reference_free(tracking_branch);
@@ -141,7 +138,6 @@ static int update_head_to_new_branch(
static int update_head_to_remote(
git_repository *repo,
git_remote *remote,
- const git_signature *signature,
const char *reflog_message)
{
int error = 0;
@@ -169,7 +165,7 @@ static int update_head_to_remote(
error = git_remote_default_branch(&branch, remote);
if (error == GIT_ENOTFOUND) {
error = git_repository_set_head_detached(
- repo, remote_head_id, signature, reflog_message);
+ repo, remote_head_id, reflog_message);
goto cleanup;
}
@@ -192,7 +188,7 @@ static int update_head_to_remote(
repo,
remote_head_id,
git_buf_cstr(&branch),
- signature, reflog_message);
+ reflog_message);
cleanup:
git_buf_free(&remote_master_name);
@@ -205,7 +201,6 @@ static int update_head_to_branch(
git_repository *repo,
const char *remote_name,
const char *branch,
- const git_signature *signature,
const char *reflog_message)
{
int retcode;
@@ -222,7 +217,7 @@ static int update_head_to_branch(
goto cleanup;
retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
- signature, reflog_message);
+ reflog_message);
cleanup:
git_reference_free(remote_ref);
@@ -313,16 +308,16 @@ static bool should_checkout(
return !git_repository_head_unborn(repo);
}
-static int checkout_branch(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, const git_signature *signature, const char *reflog_message)
+static int checkout_branch(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, const char *reflog_message)
{
int error;
if (branch)
error = update_head_to_branch(repo, git_remote_name(remote), branch,
- signature, reflog_message);
+ reflog_message);
/* Point HEAD to the same ref as the remote's head */
else
- error = update_head_to_remote(repo, remote, signature, reflog_message);
+ error = update_head_to_remote(repo, remote, reflog_message);
if (!error && should_checkout(repo, git_repository_is_bare(repo), co_opts))
error = git_checkout_head(repo, co_opts);
@@ -330,7 +325,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
return error;
}
-static int clone_into(git_repository *repo, git_remote *_remote, const git_checkout_options *co_opts, const char *branch, const git_signature *signature)
+static int clone_into(git_repository *repo, git_remote *_remote, const git_checkout_options *co_opts, const char *branch)
{
int error;
git_buf reflog_message = GIT_BUF_INIT;
@@ -358,10 +353,10 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_check
git_remote_set_update_fetchhead(remote, 0);
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, signature, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, git_buf_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, signature, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
cleanup:
git_remote_free(remote);
@@ -442,11 +437,11 @@ int git_clone(
if (clone_local == 1)
error = clone_local_into(
repo, origin, &options.checkout_opts,
- options.checkout_branch, link, options.signature);
+ options.checkout_branch, link);
else if (clone_local == 0)
error = clone_into(
repo, origin, &options.checkout_opts,
- options.checkout_branch, options.signature);
+ options.checkout_branch);
else
error = -1;
@@ -508,7 +503,7 @@ static bool can_link(const char *src, const char *dst, int link)
#endif
}
-static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link, const git_signature *signature)
+static int clone_local_into(git_repository *repo, git_remote *remote, const git_checkout_options *co_opts, const char *branch, int link)
{
int error, flags;
git_repository *src;
@@ -553,10 +548,10 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
- if ((error = git_remote_fetch(remote, NULL, signature, git_buf_cstr(&reflog_message))) != 0)
+ if ((error = git_remote_fetch(remote, NULL, git_buf_cstr(&reflog_message))) != 0)
goto cleanup;
- error = checkout_branch(repo, remote, co_opts, branch, signature, git_buf_cstr(&reflog_message));
+ error = checkout_branch(repo, remote, co_opts, branch, git_buf_cstr(&reflog_message));
cleanup:
git_buf_free(&reflog_message);
diff --git a/src/commit.c b/src/commit.c
index beb2c64c3..84f24c6cf 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -104,7 +104,7 @@ int git_commit_create_from_callback(
if (update_ref != NULL) {
error = git_reference__update_for_commit(
- repo, ref, update_ref, id, committer, "commit");
+ repo, ref, update_ref, id, "commit");
git_reference_free(ref);
return error;
}
@@ -295,7 +295,7 @@ int git_commit_amend(
if (!error && update_ref) {
error = git_reference__update_for_commit(
- repo, ref, NULL, id, committer, "commit");
+ repo, ref, NULL, id, "commit");
git_reference_free(ref);
}
diff --git a/src/push.c b/src/push.c
index fb51383cb..8b3d38e70 100644
--- a/src/push.c
+++ b/src/push.c
@@ -169,7 +169,6 @@ int git_push_add_refspec(git_push *push, const char *refspec)
int git_push_update_tips(
git_push *push,
- const git_signature *signature,
const char *reflog_message)
{
git_buf remote_ref_name = GIT_BUF_INIT;
@@ -213,7 +212,7 @@ int git_push_update_tips(
}
} else {
error = git_reference_create(NULL, push->remote->repo,
- git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, signature,
+ git_buf_cstr(&remote_ref_name), &push_spec->loid, 1,
reflog_message ? reflog_message : "update by push");
}
}
diff --git a/src/push.h b/src/push.h
index 264ecad8c..16550a705 100644
--- a/src/push.h
+++ b/src/push.h
@@ -116,7 +116,6 @@ int git_push_add_refspec(git_push *push, const char *refspec);
*/
int git_push_update_tips(
git_push *push,
- const git_signature *signature,
const char *reflog_message);
/**
diff --git a/src/rebase.c b/src/rebase.c
index cf3558d16..2013f53a0 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -655,7 +655,6 @@ int git_rebase_init(
const git_annotated_commit *branch,
const git_annotated_commit *upstream,
const git_annotated_commit *onto,
- const git_signature *signature,
const git_rebase_options *given_opts)
{
git_rebase *rebase = NULL;
@@ -663,6 +662,7 @@ int git_rebase_init(
git_buf reflog = GIT_BUF_INIT;
git_commit *onto_commit = NULL;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_reference *head_ref = NULL;
int error;
assert(repo && (upstream || onto));
@@ -694,13 +694,14 @@ int git_rebase_init(
"rebase: checkout %s", rebase_onto_name(onto))) < 0 ||
(error = git_checkout_tree(
repo, (git_object *)onto_commit, &checkout_opts)) < 0 ||
- (error = git_repository_set_head_detached(
- repo, git_annotated_commit_id(onto), signature, reflog.ptr)) < 0)
+ (error = git_reference_create(&head_ref, repo, GIT_HEAD_FILE,
+ git_annotated_commit_id(onto), 1, reflog.ptr)) < 0)
goto done;
*out = rebase;
done:
+ git_reference_free(head_ref);
if (error < 0) {
rebase_cleanup(rebase);
git_rebase_free(rebase);
@@ -902,7 +903,7 @@ static int rebase_commit_merge(
(const git_commit **)&head_commit)) < 0 ||
(error = git_commit_lookup(&commit, rebase->repo, commit_id)) < 0 ||
(error = git_reference__update_for_commit(
- rebase->repo, NULL, "HEAD", commit_id, committer, "rebase")) < 0)
+ rebase->repo, NULL, "HEAD", commit_id, "rebase")) < 0)
goto done;
git_oid_fmt(old_idstr, git_commit_id(current_commit));
@@ -949,20 +950,20 @@ int git_rebase_commit(
return error;
}
-int git_rebase_abort(git_rebase *rebase, const git_signature *signature)
+int git_rebase_abort(git_rebase *rebase)
{
git_reference *orig_head_ref = NULL;
git_commit *orig_head_commit = NULL;
int error;
- assert(rebase && signature);
+ assert(rebase);
error = rebase->head_detached ?
git_reference_create(&orig_head_ref, rebase->repo, GIT_HEAD_FILE,
- &rebase->orig_head_id, 1, signature, "rebase: aborting") :
+ &rebase->orig_head_id, 1, "rebase: aborting") :
git_reference_symbolic_create(
&orig_head_ref, rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
- signature, "rebase: aborting");
+ "rebase: aborting");
if (error < 0)
goto done;
@@ -970,7 +971,7 @@ int git_rebase_abort(git_rebase *rebase, const git_signature *signature)
if ((error = git_commit_lookup(
&orig_head_commit, rebase->repo, &rebase->orig_head_id)) < 0 ||
(error = git_reset(rebase->repo, (git_object *)orig_head_commit,
- GIT_RESET_HARD, NULL, signature, NULL)) < 0)
+ GIT_RESET_HARD, NULL, NULL)) < 0)
goto done;
error = rebase_cleanup(rebase);
@@ -1115,10 +1116,10 @@ int git_rebase_finish(
terminal_ref, GIT_OBJ_COMMIT)) < 0 ||
(error = git_reference_create_matching(&branch_ref,
rebase->repo, rebase->orig_head_name, git_commit_id(terminal_commit), 1,
- &rebase->orig_head_id, signature, branch_msg.ptr)) < 0 ||
+ &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,
- signature, head_msg.ptr)) < 0 ||
+ head_msg.ptr)) < 0 ||
(error = rebase_copy_notes(rebase, signature, &opts)) < 0)
goto done;
diff --git a/src/refs.c b/src/refs.c
index e3157529b..415918600 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -416,12 +416,22 @@ static int reference__create(
return 0;
}
+int configured_ident(git_signature **out, const git_repository *repo)
+{
+ if (repo->ident_name && repo->ident_email)
+ return git_signature_now(out, repo->ident_name, repo->ident_email);
+
+ /* if not configured let us fall-through to the next method */
+ return -1;
+}
+
int git_reference__log_signature(git_signature **out, git_repository *repo)
{
int error;
git_signature *who;
- if(((error = git_signature_default(&who, repo)) < 0) &&
+ if(((error = configured_ident(&who, repo)) < 0) &&
+ ((error = git_signature_default(&who, repo)) < 0) &&
((error = git_signature_now(&who, "unknown", "unknown")) < 0))
return error;
@@ -436,7 +446,6 @@ int git_reference_create_matching(
const git_oid *id,
int force,
const git_oid *old_id,
- const git_signature *signature,
const char *log_message)
{
@@ -445,15 +454,11 @@ int git_reference_create_matching(
assert(id);
- if (!signature) {
- if ((error = git_reference__log_signature(&who, repo)) < 0)
- return error;
- else
- signature = who;
- }
+ if ((error = git_reference__log_signature(&who, repo)) < 0)
+ return error;
error = reference__create(
- ref_out, repo, name, id, NULL, force, signature, log_message, old_id, NULL);
+ ref_out, repo, name, id, NULL, force, who, log_message, old_id, NULL);
git_signature_free(who);
return error;
@@ -465,10 +470,9 @@ int git_reference_create(
const char *name,
const git_oid *id,
int force,
- const git_signature *signature,
const char *log_message)
{
- return git_reference_create_matching(ref_out, repo, name, id, force, NULL, signature, log_message);
+ return git_reference_create_matching(ref_out, repo, name, id, force, NULL, log_message);
}
int git_reference_symbolic_create_matching(
@@ -478,7 +482,6 @@ int git_reference_symbolic_create_matching(
const char *target,
int force,
const char *old_target,
- const git_signature *signature,
const char *log_message)
{
int error;
@@ -486,15 +489,11 @@ int git_reference_symbolic_create_matching(
assert(target);
- if (!signature) {
- if ((error = git_reference__log_signature(&who, repo)) < 0)
- return error;
- else
- signature = who;
- }
+ if ((error = git_reference__log_signature(&who, repo)) < 0)
+ return error;
error = reference__create(
- ref_out, repo, name, NULL, target, force, signature, log_message, NULL, old_target);
+ ref_out, repo, name, NULL, target, force, who, log_message, NULL, old_target);
git_signature_free(who);
return error;
@@ -506,10 +505,9 @@ int git_reference_symbolic_create(
const char *name,
const char *target,
int force,
- const git_signature *signature,
const char *log_message)
{
- return git_reference_symbolic_create_matching(ref_out, repo, name, target, force, NULL, signature, log_message);
+ return git_reference_symbolic_create_matching(ref_out, repo, name, target, force, NULL, log_message);
}
static int ensure_is_an_updatable_direct_reference(git_reference *ref)
@@ -525,7 +523,6 @@ int git_reference_set_target(
git_reference **out,
git_reference *ref,
const git_oid *id,
- const git_signature *signature,
const char *log_message)
{
int error;
@@ -538,7 +535,7 @@ int git_reference_set_target(
if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
return error;
- return git_reference_create_matching(out, repo, ref->name, id, 1, &ref->target.oid, signature, log_message);
+ return git_reference_create_matching(out, repo, ref->name, id, 1, &ref->target.oid, log_message);
}
static int ensure_is_an_updatable_symbolic_reference(git_reference *ref)
@@ -554,7 +551,6 @@ int git_reference_symbolic_set_target(
git_reference **out,
git_reference *ref,
const char *target,
- const git_signature *signature,
const char *log_message)
{
int error;
@@ -565,7 +561,7 @@ int git_reference_symbolic_set_target(
return error;
return git_reference_symbolic_create_matching(
- out, ref->db->repo, ref->name, target, 1, ref->target.symbolic, signature, log_message);
+ out, ref->db->repo, ref->name, target, 1, ref->target.symbolic, log_message);
}
static int reference__rename(git_reference **out, git_reference *ref, const char *new_name, int force,
@@ -593,7 +589,7 @@ static int reference__rename(git_reference **out, git_reference *ref, const char
/* Update HEAD it was pointing to the reference being renamed */
if (should_head_be_updated &&
- (error = git_repository_set_head(ref->db->repo, normalized, signature, message)) < 0) {
+ (error = git_repository_set_head(ref->db->repo, normalized, message)) < 0) {
giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
return error;
}
@@ -607,23 +603,16 @@ int git_reference_rename(
git_reference *ref,
const char *new_name,
int force,
- const git_signature *signature,
const char *log_message)
{
- git_signature *who = (git_signature*)signature;
+ git_signature *who;
int error;
- /* Should we return an error if there is no default? */
- if (!who &&
- ((error = git_signature_default(&who, ref->db->repo)) < 0) &&
- ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) {
+ if ((error = git_reference__log_signature(&who, ref->db->repo)) < 0)
return error;
- }
error = reference__rename(out, ref, new_name, force, who, log_message);
-
- if (!signature)
- git_signature_free(who);
+ git_signature_free(who);
return error;
}
@@ -1038,13 +1027,11 @@ int git_reference_cmp(
return git_oid__cmp(&ref1->target.oid, &ref2->target.oid);
}
-static int reference__update_terminal(
- git_repository *repo,
- const char *ref_name,
- const git_oid *oid,
- int nesting,
- const git_signature *signature,
- const char *log_message)
+/**
+ * Get the end of a chain of references. If the final one is not
+ * found, we return the reference just before that.
+ */
+static int get_terminal(git_reference **out, git_repository *repo, const char *ref_name, int nesting)
{
git_reference *ref;
int error = 0;
@@ -1054,27 +1041,23 @@ static int reference__update_terminal(
return GIT_ENOTFOUND;
}
- error = git_reference_lookup(&ref, repo, ref_name);
-
- /* If we haven't found the reference at all, create a new reference. */
- if (error == GIT_ENOTFOUND) {
- giterr_clear();
- return git_reference_create(NULL, repo, ref_name, oid, 0, signature, log_message);
- }
-
- if (error < 0)
+ /* set to NULL to let the caller know that they're at the end of the chain */
+ if ((error = git_reference_lookup(&ref, repo, ref_name)) < 0) {
+ *out = NULL;
return error;
+ }
- /* If the ref is a symbolic reference, follow its target. */
- if (git_reference_type(ref) == GIT_REF_SYMBOLIC) {
- error = reference__update_terminal(repo, git_reference_symbolic_target(ref), oid,
- nesting+1, signature, log_message);
- git_reference_free(ref);
+ if (git_reference_type(ref) == GIT_REF_OID) {
+ *out = ref;
+ error = 0;
} else {
- /* If we're not moving the target, don't recreate the ref */
- if (0 != git_oid_cmp(git_reference_target(ref), oid))
- error = git_reference_create(NULL, repo, ref_name, oid, 1, signature, log_message);
- git_reference_free(ref);
+ error = get_terminal(out, repo, git_reference_symbolic_target(ref), nesting + 1);
+ if (error == GIT_ENOTFOUND) {
+ if (!*out) /* set by the error case in lookup above */
+ *out = ref;
+ } else {
+ git_reference_free(ref);
+ }
}
return error;
@@ -1089,10 +1072,38 @@ int git_reference__update_terminal(
git_repository *repo,
const char *ref_name,
const git_oid *oid,
- const git_signature *signature,
+ const git_signature *sig,
const char *log_message)
{
- return reference__update_terminal(repo, ref_name, oid, 0, signature, log_message);
+ git_reference *ref = NULL;
+ git_signature *who = NULL;
+ const git_signature *to_use;
+ int error = 0;
+
+ if (!sig && (error = git_reference__log_signature(&who, repo)) < 0)
+ return error;
+
+ to_use = sig ? sig : who;
+ error = get_terminal(&ref, repo, ref_name, 0);
+
+ /* found a dangling symref */
+ if (error == GIT_ENOTFOUND && ref) {
+ assert(git_reference_type(ref) == GIT_REF_SYMBOLIC);
+ giterr_clear();
+ error = reference__create(&ref, repo, ref->target.symbolic, oid, NULL, 0, to_use,
+ log_message, NULL, NULL);
+ } else if (error == GIT_ENOTFOUND) {
+ giterr_clear();
+ error = reference__create(&ref, repo, ref_name, oid, NULL, 0, to_use,
+ log_message, NULL, NULL);
+ } else if (error == 0) {
+ assert(git_reference_type(ref) == GIT_REF_OID);
+ error = reference__create(&ref, repo, ref->name, oid, NULL, 1, to_use,
+ log_message, &ref->target.oid, NULL);
+ }
+
+ git_signature_free(who);
+ return error;
}
int git_reference__update_for_commit(
@@ -1100,12 +1111,12 @@ int git_reference__update_for_commit(
git_reference *ref,
const char *ref_name,
const git_oid *id,
- const git_signature *committer,
const char *operation)
{
git_reference *ref_new = NULL;
git_commit *commit = NULL;
git_buf reflog_msg = GIT_BUF_INIT;
+ const git_signature *who;
int error;
if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
@@ -1115,12 +1126,18 @@ int git_reference__update_for_commit(
git_commit_summary(commit))) < 0)
goto done;
- if (ref)
- error = git_reference_set_target(
- &ref_new, ref, id, committer, git_buf_cstr(&reflog_msg));
+ who = git_commit_committer(commit);
+
+ if (ref) {
+ if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
+ return error;
+
+ error = reference__create(&ref_new, repo, ref->name, id, NULL, 1, who,
+ git_buf_cstr(&reflog_msg), &ref->target.oid, NULL);
+ }
else
error = git_reference__update_terminal(
- repo, ref_name, id, committer, git_buf_cstr(&reflog_msg));
+ repo, ref_name, id, who, git_buf_cstr(&reflog_msg));
done:
git_reference_free(ref_new);
diff --git a/src/refs.h b/src/refs.h
index 5f48efc41..ace93e33b 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -69,7 +69,7 @@ struct git_reference {
git_reference *git_reference__set_name(git_reference *ref, const char *name);
int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags);
-int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *signature, const char *log_message);
+int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *sig, const char *log_message);
int git_reference__is_valid_name(const char *refname, unsigned int flags);
int git_reference__is_branch(const char *ref_name);
int git_reference__is_remote(const char *ref_name);
@@ -106,7 +106,6 @@ int git_reference__update_for_commit(
git_reference *ref,
const char *ref_name,
const git_oid *id,
- const git_signature *committer,
const char *operation);
#endif
diff --git a/src/remote.c b/src/remote.c
index d96274f1d..9d48638ca 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -924,7 +924,6 @@ on_error:
int git_remote_fetch(
git_remote *remote,
const git_strarray *refspecs,
- const git_signature *signature,
const char *reflog_message)
{
int error;
@@ -952,7 +951,7 @@ int git_remote_fetch(
}
/* Create "remote/foo" branches for all remote branches */
- error = git_remote_update_tips(remote, signature, git_buf_cstr(&reflog_msg_buf));
+ error = git_remote_update_tips(remote, git_buf_cstr(&reflog_msg_buf));
git_buf_free(&reflog_msg_buf);
if (error < 0)
return error;
@@ -1257,7 +1256,6 @@ static int update_tips_for_spec(
git_remote *remote,
git_refspec *spec,
git_vector *refs,
- const git_signature *signature,
const char *log_message)
{
int error = 0, autotag;
@@ -1332,7 +1330,7 @@ static int update_tips_for_spec(
/* In autotag mode, don't overwrite any locally-existing tags */
error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag,
- signature, log_message);
+ log_message);
if (error < 0 && error != GIT_EEXISTS)
goto on_error;
@@ -1418,7 +1416,7 @@ static int next_head(const git_remote *remote, git_vector *refs,
return GIT_ITEROVER;
}
-static int opportunistic_updates(const git_remote *remote, git_vector *refs, const git_signature *sig, const char *msg)
+static int opportunistic_updates(const git_remote *remote, git_vector *refs, const char *msg)
{
size_t i, j, k;
git_refspec *spec;
@@ -1441,7 +1439,7 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
if ((error = git_refspec_transform(&refname, spec, head->name)) < 0)
return error;
- error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, true, sig, msg);
+ error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, true, msg);
git_buf_free(&refname);
git_reference_free(ref);
@@ -1454,7 +1452,6 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
int git_remote_update_tips(
git_remote *remote,
- const git_signature *signature,
const char *reflog_message)
{
git_refspec *spec, tagspec;
@@ -1464,7 +1461,7 @@ int git_remote_update_tips(
/* push has its own logic hidden away in the push object */
if (remote->push) {
- return git_push_update_tips(remote->push, signature, reflog_message);
+ return git_push_update_tips(remote->push, reflog_message);
}
if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
@@ -1475,7 +1472,7 @@ int git_remote_update_tips(
goto out;
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
- if ((error = update_tips_for_spec(remote, &tagspec, &refs, signature, reflog_message)) < 0)
+ if ((error = update_tips_for_spec(remote, &tagspec, &refs, reflog_message)) < 0)
goto out;
}
@@ -1483,13 +1480,13 @@ int git_remote_update_tips(
if (spec->push)
continue;
- if ((error = update_tips_for_spec(remote, spec, &refs, signature, reflog_message)) < 0)
+ if ((error = update_tips_for_spec(remote, spec, &refs, reflog_message)) < 0)
goto out;
}
/* only try to do opportunisitic updates if the refpec lists differ */
if (remote->passed_refspecs)
- error = opportunistic_updates(remote, &refs, signature, reflog_message);
+ error = opportunistic_updates(remote, &refs, reflog_message);
out:
git_vector_free(&refs);
@@ -1755,7 +1752,7 @@ static int rename_one_remote_reference(
goto cleanup;
if ((error = git_reference_rename(&ref, reference_in, git_buf_cstr(&new_name), 1,
- NULL, git_buf_cstr(&log_message))) < 0)
+ git_buf_cstr(&log_message))) < 0)
goto cleanup;
if (git_reference_type(ref) != GIT_REF_SYMBOLIC)
@@ -1775,7 +1772,7 @@ static int rename_one_remote_reference(
goto cleanup;
error = git_reference_symbolic_set_target(&dummy, ref, git_buf_cstr(&new_name),
- NULL, git_buf_cstr(&log_message));
+ git_buf_cstr(&log_message));
git_reference_free(dummy);
@@ -2374,7 +2371,7 @@ cleanup:
}
int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts,
- const git_signature *signature, const char *reflog_message)
+ const char *reflog_message)
{
int error;
@@ -2386,7 +2383,7 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_
if ((error = git_remote_upload(remote, refspecs, opts)) < 0)
return error;
- error = git_remote_update_tips(remote, signature, reflog_message);
+ error = git_remote_update_tips(remote, reflog_message);
git_remote_disconnect(remote);
return error;
diff --git a/src/repository.c b/src/repository.c
index 23c99b0f0..f8a4d3e56 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -124,6 +124,8 @@ void git_repository_free(git_repository *repo)
git__free(repo->workdir);
git__free(repo->namespace);
git__free(repo->name_8dot3);
+ git__free(repo->ident_name);
+ git__free(repo->ident_email);
git__memzero(repo, sizeof(*repo));
git__free(repo);
@@ -1895,7 +1897,6 @@ static bool looks_like_a_branch(const char *refname)
int git_repository_set_head(
git_repository* repo,
const char* refname,
- const git_signature *signature,
const char *log_message)
{
git_reference *ref,
@@ -1911,14 +1912,14 @@ int git_repository_set_head(
if (!error) {
if (git_reference_is_branch(ref)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
- git_reference_name(ref), true, signature, log_message);
+ git_reference_name(ref), true, log_message);
} else {
error = git_repository_set_head_detached(repo, git_reference_target(ref),
- signature, log_message);
+ log_message);
}
} else if (looks_like_a_branch(refname)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
- true, signature, log_message);
+ true, log_message);
}
git_reference_free(ref);
@@ -1929,7 +1930,6 @@ int git_repository_set_head(
int git_repository_set_head_detached(
git_repository* repo,
const git_oid* commitish,
- const git_signature *signature,
const char *log_message)
{
int error;
@@ -1945,7 +1945,7 @@ int git_repository_set_head_detached(
if ((error = git_object_peel(&peeled, object, GIT_OBJ_COMMIT)) < 0)
goto cleanup;
- error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, signature, log_message);
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, log_message);
cleanup:
git_object_free(object);
@@ -1956,7 +1956,6 @@ cleanup:
int git_repository_detach_head(
git_repository* repo,
- const git_signature *signature,
const char *reflog_message)
{
git_reference *old_head = NULL,
@@ -1973,7 +1972,7 @@ int git_repository_detach_head(
goto cleanup;
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
- 1, signature, reflog_message);
+ 1, reflog_message);
cleanup:
git_object_free(object);
@@ -2096,3 +2095,34 @@ int git_repository_init_init_options(
GIT_REPOSITORY_INIT_OPTIONS_INIT);
return 0;
}
+
+int git_repository_ident(const char **name, const char **email, const git_repository *repo)
+{
+ *name = repo->ident_name;
+ *email = repo->ident_email;
+
+ return 0;
+}
+
+int git_repository_set_ident(git_repository *repo, const char *name, const char *email)
+{
+ char *tmp_name = NULL, *tmp_email = NULL;
+
+ if (name) {
+ tmp_name = git__strdup(name);
+ GITERR_CHECK_ALLOC(tmp_name);
+ }
+
+ if (email) {
+ tmp_email = git__strdup(email);
+ GITERR_CHECK_ALLOC(tmp_email);
+ }
+
+ tmp_name = git__swap(repo->ident_name, tmp_name);
+ tmp_email = git__swap(repo->ident_email, tmp_email);
+
+ git__free(tmp_name);
+ git__free(tmp_email);
+
+ return 0;
+}
diff --git a/src/repository.h b/src/repository.h
index dffa9a8ae..56d443d3c 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -128,6 +128,9 @@ struct git_repository {
char *namespace;
char *name_8dot3;
+ char *ident_name;
+ char *ident_email;
+
unsigned is_bare:1,
has_8dot3:1,
has_8dot3_default:1;
diff --git a/src/reset.c b/src/reset.c
index dc3aa4a66..bf8bbcccd 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -101,7 +101,6 @@ int git_reset(
git_object *target,
git_reset_t reset_type,
git_checkout_options *checkout_opts,
- const git_signature *signature,
const char *log_message)
{
git_object *commit = NULL;
@@ -148,7 +147,7 @@ int git_reset(
/* move HEAD to the new target */
if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE,
- git_object_id(commit), signature, git_buf_cstr(&log_message_buf))) < 0)
+ git_object_id(commit), NULL, git_buf_cstr(&log_message))) < 0)
goto cleanup;
if (reset_type == GIT_RESET_HARD) {
diff --git a/src/stash.c b/src/stash.c
index cad87d120..1cd64a6fe 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -411,7 +411,6 @@ cleanup:
static int update_reflog(
git_oid *w_commit_oid,
git_repository *repo,
- const git_signature *stasher,
const char *message)
{
git_reference *stash;
@@ -420,7 +419,7 @@ static int update_reflog(
if ((error = git_reference_ensure_log(repo, GIT_REFS_STASH_FILE)) < 0)
return error;
- error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, stasher, message);
+ error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, message);
git_reference_free(stash);
@@ -534,7 +533,7 @@ int git_stash_save(
git_buf_rtrim(&msg);
- if ((error = update_reflog(out, repo, stasher, git_buf_cstr(&msg))) < 0)
+ if ((error = update_reflog(out, repo, git_buf_cstr(&msg))) < 0)
goto cleanup;
if ((error = reset_index_and_workdir(
diff --git a/src/submodule.c b/src/submodule.c
index 80f1b3789..cba6c0f77 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -927,7 +927,6 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
/* Copy over the remote callbacks */
clone_options.remote_callbacks = update_options.remote_callbacks;
- clone_options.signature = update_options.signature;
/* Get the status of the submodule to determine if it is already initialized */
if ((error = git_submodule_status(&submodule_status, sm)) < 0)
@@ -985,7 +984,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
update_options.checkout_opts.checkout_strategy = update_options.clone_checkout_strategy;
if ((error = git_clone(&sub_repo, submodule_url, sm->path, &clone_options)) < 0 ||
- (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm), update_options.signature, NULL)) < 0 ||
+ (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm), NULL)) < 0 ||
(error = git_checkout_head(sub_repo, &update_options.checkout_opts)) != 0)
goto done;
} else {
@@ -997,7 +996,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
if ((error = git_submodule_open(&sub_repo, sm)) < 0 ||
(error = git_object_lookup(&target_commit, sub_repo, git_submodule_index_id(sm), GIT_OBJ_COMMIT)) < 0 ||
(error = git_checkout_tree(sub_repo, target_commit, &update_options.checkout_opts)) != 0 ||
- (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm), update_options.signature, NULL)) < 0)
+ (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm), NULL)) < 0)
goto done;
/* Invalidate the wd flags as the workdir has been updated. */
diff --git a/src/tag.c b/src/tag.c
index 3b8d684ed..6e69d760d 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -273,7 +273,7 @@ static int git_tag_create__internal(
} else
git_oid_cpy(oid, git_object_id(target));
- error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL, NULL);
+ error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL);
cleanup:
git_reference_free(new_ref);
@@ -380,7 +380,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
}
error = git_reference_create(
- &new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL, NULL);
+ &new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL);
git_reference_free(new_ref);
git_buf_free(&ref_name);
diff --git a/src/transports/local.c b/src/transports/local.c
index 89f2651cd..bedd2390b 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -348,7 +348,7 @@ static int local_push_update_remote_ref(
if (lref[0] != '\0') {
/* Create or update a ref */
error = git_reference_create(NULL, remote_repo, rref, loid,
- !git_oid_iszero(roid), NULL, NULL);
+ !git_oid_iszero(roid), NULL);
} else {
/* Delete a ref */
if ((error = git_reference_lookup(&remote_ref, remote_repo, rref)) < 0) {