summaryrefslogtreecommitdiff
path: root/src/branch.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2013-03-01 15:37:33 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2013-03-07 11:01:52 -0600
commitd00d54645d931c77a9b401518c0d73e3f640454b (patch)
treee1932dcc97172a53524e9db1ba4923cf137a4f9c /src/branch.c
parent6a9ef012376e8a21dcfd0499ab16048eb6e954c3 (diff)
downloadlibgit2-d00d54645d931c77a9b401518c0d73e3f640454b.tar.gz
immutable references and a pluggable ref database
Diffstat (limited to 'src/branch.c')
-rw-r--r--src/branch.c64
1 files changed, 25 insertions, 39 deletions
diff --git a/src/branch.c b/src/branch.c
index a50387541..6b289b12e 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -54,11 +54,11 @@ static int not_a_local_branch(const char *reference_name)
}
int git_branch_create(
- git_reference **ref_out,
- git_repository *repository,
- const char *branch_name,
- const git_commit *commit,
- int force)
+ git_reference **ref_out,
+ git_repository *repository,
+ const char *branch_name,
+ const git_commit *commit,
+ int force)
{
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT;
@@ -124,10 +124,7 @@ on_error:
}
typedef struct {
- int (*branch_cb)(
- const char *branch_name,
- git_branch_t branch_type,
- void *payload);
+ git_branch_foreach_cb branch_cb;
void *callback_payload;
unsigned int branch_type;
} branch_foreach_filter;
@@ -148,14 +145,10 @@ static int branch_foreach_cb(const char *branch_name, void *payload)
}
int git_branch_foreach(
- git_repository *repo,
- unsigned int list_flags,
- int (*branch_cb)(
- const char *branch_name,
- git_branch_t branch_type,
- void *payload),
- void *payload
-)
+ git_repository *repo,
+ unsigned int list_flags,
+ git_branch_foreach_cb branch_cb,
+ void *payload)
{
branch_foreach_filter filter;
@@ -167,6 +160,7 @@ int git_branch_foreach(
}
int git_branch_move(
+ git_reference **out,
git_reference *branch,
const char *new_branch_name,
int force)
@@ -181,28 +175,20 @@ int git_branch_move(
if (!git_reference_is_branch(branch))
return not_a_local_branch(git_reference_name(branch));
- if ((error = git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0)
- goto cleanup;
-
- if (git_buf_printf(
- &old_config_section,
- "branch.%s",
- git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)) < 0)
- goto cleanup;
-
- if ((error = git_reference_rename(branch, git_buf_cstr(&new_reference_name), force)) < 0)
- goto cleanup;
+ if ((error = git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0 ||
+ (error = git_buf_printf(&old_config_section, "branch.%s", git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)) < 0) ||
+ (error = git_buf_printf(&new_config_section, "branch.%s", new_branch_name)) < 0)
+ goto done;
- if (git_buf_printf(&new_config_section, "branch.%s", new_branch_name) < 0)
- goto cleanup;
-
- if ((error = git_config_rename_section(
- git_reference_owner(branch),
+ if ((error = git_config_rename_section(git_reference_owner(branch),
git_buf_cstr(&old_config_section),
git_buf_cstr(&new_config_section))) < 0)
- goto cleanup;
+ goto done;
+
+ if ((error = git_reference_rename(out, branch, git_buf_cstr(&new_reference_name), force)) < 0)
+ goto done;
-cleanup:
+done:
git_buf_free(&new_reference_name);
git_buf_free(&old_config_section);
git_buf_free(&new_config_section);
@@ -211,10 +197,10 @@ cleanup:
}
int git_branch_lookup(
- git_reference **ref_out,
- git_repository *repo,
- const char *branch_name,
- git_branch_t branch_type)
+ git_reference **ref_out,
+ git_repository *repo,
+ const char *branch_name,
+ git_branch_t branch_type)
{
assert(ref_out && repo && branch_name);