summaryrefslogtreecommitdiff
path: root/src/branch.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-03-06 23:51:40 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-16 16:57:30 +0100
commit62d38a1ddb8081f8b46e7ff6e21ebeb0014162d6 (patch)
tree9db11e71533062a0ec6b55e1e767235469390ec0 /src/branch.c
parentd675982a15388d8c413acda139b4662062cf3286 (diff)
downloadlibgit2-62d38a1ddb8081f8b46e7ff6e21ebeb0014162d6.tar.gz
Add annotated commit versions of reflog-modifying functions
We do not always want to put the id directly into the reflog, but we want to speicfy what a user typed. For this use-case we provide annotated version of a few functions which let the caller specify what user-friendly name was used when asking for the operation.
Diffstat (limited to 'src/branch.c')
-rw-r--r--src/branch.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/branch.c b/src/branch.c
index a16d3a3f9..10be6f70c 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -12,6 +12,7 @@
#include "refspec.h"
#include "refs.h"
#include "remote.h"
+#include "annotated_commit.h"
#include "git2/branch.h"
@@ -49,11 +50,12 @@ static int not_a_local_branch(const char *reference_name)
return -1;
}
-int git_branch_create(
+static int create_branch(
git_reference **ref_out,
git_repository *repository,
const char *branch_name,
const git_commit *commit,
+ const char *from,
int force)
{
int is_head = 0;
@@ -86,7 +88,7 @@ int git_branch_create(
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup;
- if (git_buf_printf(&log_message, "branch: Created from %s", git_oid_tostr_s(git_commit_id(commit))) < 0)
+ if (git_buf_printf(&log_message, "branch: Created from %s", from) < 0)
goto cleanup;
error = git_reference_create(&branch, repository,
@@ -102,6 +104,26 @@ cleanup:
return error;
}
+int git_branch_create(
+ git_reference **ref_out,
+ git_repository *repository,
+ const char *branch_name,
+ const git_commit *commit,
+ int force)
+{
+ return create_branch(ref_out, repository, branch_name, commit, git_oid_tostr_s(git_commit_id(commit)), force);
+}
+
+int git_branch_create_from_annotated(
+ git_reference **ref_out,
+ git_repository *repository,
+ const char *branch_name,
+ const git_annotated_commit *commit,
+ int force)
+{
+ return create_branch(ref_out, repository, branch_name, commit->commit, commit->ref_name, force);
+}
+
int git_branch_delete(git_reference *branch)
{
int is_head;