summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-02-07 16:14:17 -0800
committerRussell Belfer <rb@github.com>2014-02-07 16:14:17 -0800
commit2d9291943c253e9e1520f87b13abb1e81cffdb29 (patch)
tree653489f8d29124bb0a6d32d14dfed9d9974bc267 /src
parent57c47af107b45b73a46a1d157f8f758edd536bc7 (diff)
parentdb55bb73ff4bccbaccbb4c3a7f6b1fcf09498df7 (diff)
downloadlibgit2-2d9291943c253e9e1520f87b13abb1e81cffdb29.tar.gz
Merge pull request #2099 from libgit2/bs/more-reflog-stuff
More reflogness
Diffstat (limited to 'src')
-rw-r--r--src/clone.c2
-rw-r--r--src/commit.c23
-rw-r--r--src/push.c9
-rw-r--r--src/refs.c4
-rw-r--r--src/remote.c37
-rw-r--r--src/repository.c7
-rw-r--r--src/reset.c12
7 files changed, 77 insertions, 17 deletions
diff --git a/src/clone.c b/src/clone.c
index 3443528f7..bcc38678f 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -360,7 +360,7 @@ int git_clone_into(git_repository *repo, git_remote *remote, const git_checkout_
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)) != 0)
+ if ((error = git_remote_fetch(remote, signature, git_buf_cstr(&reflog_message))) != 0)
goto cleanup;
if (branch)
diff --git a/src/commit.c b/src/commit.c
index 730fa6403..d66cf0c6a 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -111,8 +111,27 @@ int git_commit_create_from_ids(
git_buf_free(&commit);
- if (update_ref != NULL)
- return git_reference__update_terminal(repo, update_ref, oid, NULL, NULL);
+ if (update_ref != NULL) {
+ int error;
+ git_commit *c;
+ const char *shortmsg;
+ git_buf reflog_msg = GIT_BUF_INIT;
+
+ if (git_commit_lookup(&c, repo, oid) < 0)
+ goto on_error;
+
+ shortmsg = git_commit_summary(c);
+ git_buf_printf(&reflog_msg, "commit%s: %s",
+ git_commit_parentcount(c) == 0 ? " (initial)" : "",
+ shortmsg);
+ git_commit_free(c);
+
+ error = git_reference__update_terminal(repo, update_ref, oid,
+ committer, git_buf_cstr(&reflog_msg));
+
+ git_buf_free(&reflog_msg);
+ return error;
+ }
return 0;
diff --git a/src/push.c b/src/push.c
index d39a27182..c2947808e 100644
--- a/src/push.c
+++ b/src/push.c
@@ -194,7 +194,10 @@ int git_push_add_refspec(git_push *push, const char *refspec)
return 0;
}
-int git_push_update_tips(git_push *push)
+int git_push_update_tips(
+ git_push *push,
+ const git_signature *signature,
+ const char *reflog_message)
{
git_buf remote_ref_name = GIT_BUF_INIT;
size_t i, j;
@@ -241,7 +244,9 @@ int git_push_update_tips(git_push *push)
giterr_clear();
else
goto on_error;
- } else if ((error = git_reference_create(NULL, push->remote->repo, git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, NULL, NULL)) < 0)
+ } else if ((error = git_reference_create(NULL, push->remote->repo,
+ git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, signature,
+ reflog_message ? reflog_message : "update by push")) < 0)
goto on_error;
}
diff --git a/src/refs.c b/src/refs.c
index bdf2da37e..3ba4b0a84 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1082,8 +1082,10 @@ static int reference__update_terminal(
nesting+1, signature, log_message);
git_reference_free(ref);
} 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 = git_reference_create(NULL, repo, ref_name, oid, 1, signature, log_message);
}
return error;
diff --git a/src/remote.c b/src/remote.c
index f33f5ef3c..f320f4a52 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -845,9 +845,13 @@ int git_remote_download(git_remote *remote)
return git_fetch_download_pack(remote);
}
-int git_remote_fetch(git_remote *remote)
+int git_remote_fetch(
+ git_remote *remote,
+ const git_signature *signature,
+ const char *reflog_message)
{
int error;
+ git_buf reflog_msg_buf = GIT_BUF_INIT;
/* Connect and download everything */
if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH)) != 0)
@@ -859,8 +863,18 @@ int git_remote_fetch(git_remote *remote)
/* We don't need to be connected anymore */
git_remote_disconnect(remote);
+ /* Default reflog message */
+ if (reflog_message)
+ git_buf_sets(&reflog_msg_buf, reflog_message);
+ else {
+ git_buf_printf(&reflog_msg_buf, "fetch %s",
+ remote->name ? remote->name : remote->url);
+ }
+
/* Create "remote/foo" branches for all remote branches */
- return git_remote_update_tips(remote);
+ error = git_remote_update_tips(remote, signature, git_buf_cstr(&reflog_msg_buf));
+ git_buf_free(&reflog_msg_buf);
+ return error;
}
static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *update_heads, const char *fetchspec_src)
@@ -978,7 +992,12 @@ cleanup:
return error;
}
-static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vector *refs)
+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;
unsigned int i = 0;
@@ -1045,7 +1064,8 @@ static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vecto
continue;
/* In autotag mode, don't overwrite any locally-existing tags */
- error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag, NULL, NULL);
+ error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag,
+ signature, log_message);
if (error < 0 && error != GIT_EEXISTS)
goto on_error;
@@ -1074,7 +1094,10 @@ on_error:
}
-int git_remote_update_tips(git_remote *remote)
+int git_remote_update_tips(
+ git_remote *remote,
+ const git_signature *signature,
+ const char *reflog_message)
{
git_refspec *spec, tagspec;
git_vector refs;
@@ -1089,7 +1112,7 @@ int git_remote_update_tips(git_remote *remote)
goto out;
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
- error = update_tips_for_spec(remote, &tagspec, &refs);
+ error = update_tips_for_spec(remote, &tagspec, &refs, signature, reflog_message);
goto out;
}
@@ -1097,7 +1120,7 @@ int git_remote_update_tips(git_remote *remote)
if (spec->push)
continue;
- if ((error = update_tips_for_spec(remote, spec, &refs)) < 0)
+ if ((error = update_tips_for_spec(remote, spec, &refs, signature, reflog_message)) < 0)
goto out;
}
diff --git a/src/repository.c b/src/repository.c
index 44d0f0b7d..9f0c2f68f 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1891,7 +1891,9 @@ cleanup:
}
int git_repository_detach_head(
- git_repository* repo)
+ git_repository* repo,
+ const git_signature *signature,
+ const char *reflog_message)
{
git_reference *old_head = NULL,
*new_head = NULL;
@@ -1906,7 +1908,8 @@ int git_repository_detach_head(
if ((error = git_object_lookup(&object, repo, git_reference_target(old_head), GIT_OBJ_COMMIT)) < 0)
goto cleanup;
- error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head), 1, NULL, NULL);
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
+ 1, signature, reflog_message);
cleanup:
git_object_free(object);
diff --git a/src/reset.c b/src/reset.c
index 15f7fe13a..07fd08863 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -94,13 +94,16 @@ cleanup:
int git_reset(
git_repository *repo,
git_object *target,
- git_reset_t reset_type)
+ git_reset_t reset_type,
+ git_signature *signature,
+ const char *log_message)
{
git_object *commit = NULL;
git_index *index = NULL;
git_tree *tree = NULL;
int error = 0;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_buf log_message_buf = GIT_BUF_INIT;
assert(repo && target);
@@ -129,9 +132,14 @@ int git_reset(
goto cleanup;
}
+ if (log_message)
+ git_buf_sets(&log_message_buf, log_message);
+ else
+ git_buf_sets(&log_message_buf, "reset: moving");
+
/* move HEAD to the new target */
if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE,
- git_object_id(commit), NULL, NULL)) < 0)
+ git_object_id(commit), signature, git_buf_cstr(&log_message_buf))) < 0)
goto cleanup;
if (reset_type == GIT_RESET_HARD) {