summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2012-08-27 14:54:52 -0700
committerVicent Marti <tanoku@gmail.com>2012-08-27 14:54:52 -0700
commit62eafd0620eff3d7ca3659a3f4a4808488f0b2c3 (patch)
treec0f29b20a9e8194ccfb0ea59ad55b56bed803206 /src
parentbd2887a5e5d823b2fc9debef245bcd865ba3dd83 (diff)
parent1c947daa80dfa442acbf8119530a3dcbf5af00c5 (diff)
downloadlibgit2-62eafd0620eff3d7ca3659a3f4a4808488f0b2c3.tar.gz
Merge branch 'branch-delete-ref' into development
Conflicts: include/git2/refs.h
Diffstat (limited to 'src')
-rw-r--r--src/branch.c31
-rw-r--r--src/refs.c7
-rw-r--r--src/unix/map.c2
3 files changed, 23 insertions, 17 deletions
diff --git a/src/branch.c b/src/branch.c
index f6f314035..cd5c10ede 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -50,6 +50,12 @@ static int create_error_invalid(const char *msg)
return -1;
}
+static int not_a_local_branch(git_reference *ref)
+{
+ giterr_set(GITERR_INVALID, "Reference '%s' is not a local branch.", git_reference_name(ref));
+ return -1;
+}
+
int git_branch_create(
git_reference **ref_out,
git_repository *repository,
@@ -84,19 +90,19 @@ cleanup:
return error;
}
-int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_t branch_type)
+int git_branch_delete(git_reference *branch)
{
- git_reference *branch = NULL;
git_reference *head = NULL;
- int error;
- assert(repo && branch_name);
- assert((branch_type == GIT_BRANCH_LOCAL) || (branch_type == GIT_BRANCH_REMOTE));
+ assert(branch);
- if ((error = retrieve_branch_reference(&branch, repo, branch_name, branch_type == GIT_BRANCH_REMOTE)) < 0)
- return error;
+ if (!git_reference_is_branch(branch) &&
+ !git_reference_is_remote(branch)) {
+ giterr_set(GITERR_INVALID, "Reference '%s' is not a valid branch.", git_reference_name(branch));
+ return -1;
+ }
- if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0) {
+ if (git_reference_lookup(&head, git_reference_owner(branch), GIT_HEAD_FILE) < 0) {
giterr_set(GITERR_REFERENCE, "Cannot locate HEAD.");
goto on_error;
}
@@ -104,7 +110,7 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_
if ((git_reference_type(head) == GIT_REF_SYMBOLIC)
&& (strcmp(git_reference_target(head), git_reference_name(branch)) == 0)) {
giterr_set(GITERR_REFERENCE,
- "Cannot delete branch '%s' as it is the current HEAD of the repository.", branch_name);
+ "Cannot delete branch '%s' as it is the current HEAD of the repository.", git_reference_name(branch));
goto on_error;
}
@@ -116,7 +122,6 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_
on_error:
git_reference_free(head);
- git_reference_free(branch);
return -1;
}
@@ -163,12 +168,6 @@ int git_branch_foreach(
return git_reference_foreach(repo, GIT_REF_LISTALL, &branch_foreach_cb, (void *)&filter);
}
-static int not_a_local_branch(git_reference *ref)
-{
- giterr_set(GITERR_INVALID, "Reference '%s' is not a local branch.", git_reference_name(ref));
- return -1;
-}
-
int git_branch_move(
git_reference *branch,
const char *new_branch_name,
diff --git a/src/refs.c b/src/refs.c
index 9fc194cb6..eb8af5863 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1836,6 +1836,11 @@ int git_reference_has_log(
int git_reference_is_branch(git_reference *ref)
{
assert(ref);
-
return git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR) == 0;
}
+
+int git_reference_is_remote(git_reference *ref)
+{
+ assert(ref);
+ return git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR) == 0;
+}
diff --git a/src/unix/map.c b/src/unix/map.c
index 9dcae5845..ee7888c17 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -31,6 +31,8 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
mflag = MAP_SHARED;
else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE)
mflag = MAP_PRIVATE;
+ else
+ mflag = MAP_SHARED;
out->data = mmap(NULL, len, mprot, mflag, fd, offset);