Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-08-27 22:53:59 +0400
committerRussell Belfer <rb@github.com>2012-08-27 22:53:59 +0400
commitd8057a5b0ed644b1f72a4eb80f82da7ce8977958 (patch)
tree43c962073e49ff204f92345a2d0713bb56a56ffd /src/reset.c
parent2b175ca972f2531e5ef46d24abeb831d90033a33 (diff)
Make git_object_peel a bit smarter
This expands the types of peeling that `git_object_peel` knows how to do to include TAG -> BLOB peeling, and makes the errors slightly more consistent depending on the situation. It also adds a new special behavior where peeling to ANY will peel until the object type changes (e.g. chases TAGs to a non-TAG). Using this expanded peeling, this replaces peeling code that was embedded in `git_tag_peel` and `git_reset`.
Diffstat (limited to 'src/reset.c')
-rw-r--r--src/reset.c30
1 files changed, 5 insertions, 25 deletions
diff --git a/src/reset.c b/src/reset.c
index 1379f6442..f9e16f7c6 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -20,10 +20,9 @@ static int reset_error_invalid(const char *msg)
int git_reset(
git_repository *repo,
- const git_object *target,
+ git_object *target,
git_reset_type reset_type)
{
- git_otype target_type = GIT_OBJ_BAD;
git_object *commit = NULL;
git_index *index = NULL;
git_tree *tree = NULL;
@@ -38,26 +37,9 @@ int git_reset(
if (reset_type == GIT_RESET_MIXED && git_repository_is_bare(repo))
return reset_error_invalid("Mixed reset is not allowed in a bare repository.");
- target_type = git_object_type(target);
-
- switch (target_type)
- {
- case GIT_OBJ_TAG:
- if (git_tag_peel(&commit, (git_tag *)target) < 0)
- goto cleanup;
-
- if (git_object_type(commit) != GIT_OBJ_COMMIT) {
- reset_error_invalid("The given target does not resolve to a commit.");
- goto cleanup;
- }
- break;
-
- case GIT_OBJ_COMMIT:
- commit = (git_object *)target;
- break;
-
- default:
- return reset_error_invalid("Only git_tag and git_commit objects are valid targets.");
+ if (git_object_peel(&commit, target, GIT_OBJ_COMMIT) < 0) {
+ reset_error_invalid("The given target does not resolve to a commit");
+ goto cleanup;
}
//TODO: Check for unmerged entries
@@ -93,9 +75,7 @@ int git_reset(
error = 0;
cleanup:
- if (target_type == GIT_OBJ_TAG)
- git_object_free(commit);
-
+ git_object_free(commit);
git_index_free(index);
git_tree_free(tree);