From 4d13d07ab21d5041dc3b2e77c9447298d6b39eaa Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 11 Mar 2013 13:20:47 -0700 Subject: [PATCH 1/9] Propose unified rev-parse API --- include/git2/revparse.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/git2/revparse.h b/include/git2/revparse.h index edd8b3cce..71ff6d696 100644 --- a/include/git2/revparse.h +++ b/include/git2/revparse.h @@ -45,6 +45,43 @@ GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, cons */ GIT_EXTERN(int) git_revparse_rangelike(git_object **left, git_object **right, int *threedots, git_repository *repo, const char *rangelike); + +/** + * Revparse flags. These indicate the intended behavior of the spec passed to + * git_revparse. + */ +typedef enum { + /** The spec targeted a single object. */ + GIT_REVPARSE_SINGLE = 1 << 0, + /** The spec targeted a range of commits. */ + GIT_REVPARSE_RANGE = 1 << 1, + /** The spec used the '...' operator, which invokes special semantics. */ + GIT_REVPARSE_MERGE_BASE = 1 << 2, +} git_revparse_flag_t; + + +/** + * Find an object or range of commits as specified by a revision string. + * See `man gitrevisions` or http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions + * for information on the syntax accepted. + * + * @param left buffer that receives the target of the left side of a range operator. If + * there is no range operator, this buffer receives the single target. + * @param right buffer that receives the target of the right side of a range operator. + * This is only filled in if `spec` specifies a range of commits + * @param flags buffer that receives a bitwise combination of `git_revparse_flag_t` values + * @param repo the repository to search in + * @param spec the rev-parse spec to parse + * @return 0 on success, GIT_INVALIDSPEC, GIT_ENOTFOUND, GIT_EAMBIGUOUS or an error code + */ +GIT_EXTERN(int) git_revparse( + git_oid *left, + git_oid *right, + unsigned int *flags, + git_repository *repo, + const char *spec); + + /** @} */ GIT_END_DECL #endif From 8480eef7ee0c8e52a8bf3ea12e5626009a966164 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 11 Mar 2013 20:27:16 -0700 Subject: [PATCH 2/9] Implement unified git_revparse --- include/git2/revparse.h | 34 ++++++++++---------- src/revparse.c | 64 ++++++++++++++++++++++++++++++++++---- tests-clar/refs/revparse.c | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 22 deletions(-) diff --git a/include/git2/revparse.h b/include/git2/revparse.h index 71ff6d696..9315b66eb 100644 --- a/include/git2/revparse.h +++ b/include/git2/revparse.h @@ -51,35 +51,37 @@ GIT_EXTERN(int) git_revparse_rangelike(git_object **left, git_object **right, in * git_revparse. */ typedef enum { - /** The spec targeted a single object. */ - GIT_REVPARSE_SINGLE = 1 << 0, - /** The spec targeted a range of commits. */ - GIT_REVPARSE_RANGE = 1 << 1, - /** The spec used the '...' operator, which invokes special semantics. */ - GIT_REVPARSE_MERGE_BASE = 1 << 2, + /** The spec targeted a single object. */ + GIT_REVPARSE_SINGLE = 1 << 0, + /** The spec targeted a range of commits. */ + GIT_REVPARSE_RANGE = 1 << 1, + /** The spec used the '...' operator, which invokes special semantics. */ + GIT_REVPARSE_MERGE_BASE = 1 << 2, } git_revparse_flag_t; /** - * Find an object or range of commits as specified by a revision string. - * See `man gitrevisions` or http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions - * for information on the syntax accepted. + * Parse a revision string for left, right, and intent. See `man gitrevisions` or + * http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for information + * on the syntax accepted. * * @param left buffer that receives the target of the left side of a range operator. If * there is no range operator, this buffer receives the single target. * @param right buffer that receives the target of the right side of a range operator. - * This is only filled in if `spec` specifies a range of commits - * @param flags buffer that receives a bitwise combination of `git_revparse_flag_t` values + * This is only filled in if `spec` specifies a range of commits. May + * be NULL. + * @param flags buffer that receives a bitwise combination of `git_revparse_flag_t` values. + * May be NULL. * @param repo the repository to search in * @param spec the rev-parse spec to parse * @return 0 on success, GIT_INVALIDSPEC, GIT_ENOTFOUND, GIT_EAMBIGUOUS or an error code */ GIT_EXTERN(int) git_revparse( - git_oid *left, - git_oid *right, - unsigned int *flags, - git_repository *repo, - const char *spec); + git_oid *left, + git_oid *right, + unsigned int *flags, + git_repository *repo, + const char *spec); /** @} */ diff --git a/src/revparse.c b/src/revparse.c index 2ba29383e..2ba42d8e3 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -107,7 +107,7 @@ static int build_regex(regex_t *regex, const char *pattern) error = regcomp(regex, pattern, REG_EXTENDED); if (!error) return 0; - + error = giterr_set_regex(regex, error); regfree(regex); @@ -125,7 +125,7 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe if (substr == NULL) return GIT_ENOTFOUND; - + if (build_regex(®ex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0) return -1; @@ -358,7 +358,7 @@ static int retrieve_remote_tracking_reference(git_reference **base_ref, const ch if ((error = git_branch_tracking(&tracking, ref)) < 0) goto cleanup; - + *base_ref = tracking; cleanup: @@ -508,7 +508,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex) int error; git_oid oid; git_object *obj; - + while (!(error = git_revwalk_next(&oid, walk))) { error = git_object_lookup(&obj, git_revwalk_repository(walk), &oid, GIT_OBJ_COMMIT); @@ -537,7 +537,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_ if ((error = build_regex(&preg, pattern)) < 0) return error; - + if ((error = git_revwalk_new(&walk, repo)) < 0) goto cleanup; @@ -551,7 +551,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_ goto cleanup; error = walk_and_search(out, walk, &preg); - + cleanup: regfree(&preg); git_revwalk_free(walk); @@ -892,3 +892,55 @@ int git_revparse_rangelike(git_object **left, git_object **right, int *threedots git__free(revspec); return error; } + + +int git_revparse( + git_oid *left, + git_oid *right, + unsigned int *flags, + git_repository *repo, + const char *spec) +{ + unsigned int lflags = 0; + const char *dotdot; + int error = 0; + git_object *obj = NULL; + + assert(left && repo && spec); + + if ((dotdot = strstr(spec, "..")) != NULL) { + char *lstr; + const char *rstr; + lflags = GIT_REVPARSE_RANGE; + + lstr = git__substrdup(spec, dotdot-spec); + rstr = dotdot + 2; + if (dotdot[2] == '.') { + lflags |= GIT_REVPARSE_MERGE_BASE; + rstr++; + } + + if (!(error = git_revparse_single(&obj, repo, lstr))) { + git_oid_cpy(left, git_object_id(obj)); + git_object_free(obj); + } + if (right && !(error = git_revparse_single(&obj, repo, rstr))) { + git_oid_cpy(right, git_object_id(obj)); + git_object_free(obj); + } + + git__free((void*)lstr); + } else { + lflags = GIT_REVPARSE_SINGLE; + if (!(error = git_revparse_single(&obj, repo, spec))) { + git_oid_cpy(left, git_object_id(obj)); + git_object_free(obj); + } + } + + if (flags) + *flags = lflags; + + return error; +} + diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c index 66ee391a7..ab8839fda 100644 --- a/tests-clar/refs/revparse.c +++ b/tests-clar/refs/revparse.c @@ -27,6 +27,37 @@ static void test_object_inrepo(const char *spec, const char *expected_oid, git_r git_object_free(obj); } +static void test_id_inrepo( + const char *spec, + const char *expected_left, + const char *expected_right, + git_revparse_flag_t expected_flags, + git_repository *repo) +{ + git_oid l = {{0}}, r = {{0}}; + git_revparse_flag_t flags = 0; + + int error = git_revparse(&l, &r, &flags, repo, spec); + + if (expected_left) { + char str[64] = {0}; + cl_assert_equal_i(0, error); + git_oid_fmt(str, &l); + cl_assert_equal_s(str, expected_left); + } else { + cl_assert_equal_i(GIT_ENOTFOUND, error); + } + + if (expected_right) { + char str[64] = {0}; + git_oid_fmt(str, &r); + cl_assert_equal_s(str, expected_right); + } + + if (expected_flags) + cl_assert_equal_i(expected_flags, flags); +} + static void test_object(const char *spec, const char *expected_oid) { test_object_inrepo(spec, expected_oid, g_repo); @@ -59,6 +90,15 @@ static void test_rangelike(const char *rangelike, } +static void test_id( + const char *spec, + const char *expected_left, + const char *expected_right, + git_revparse_flag_t expected_flags) +{ + test_id_inrepo(spec, expected_left, expected_right, expected_flags, g_repo); +} + void test_refs_revparse__initialize(void) { cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git"))); @@ -639,3 +679,22 @@ void test_refs_revparse__range(void) test_rangelike("be3563a^1.be3563a", NULL, NULL, 0); } + +void test_refs_revparse__validates_args(void) +{ + git_oid l={{0}}, r={{0}}; + git_revparse_flag_t flags = 0; + + cl_git_pass(git_revparse(&l,&r,NULL, g_repo, "HEAD")); + cl_git_pass(git_revparse(&l,NULL,&flags, g_repo, "HEAD")); + cl_assert_equal_i(GIT_EINVALIDSPEC, git_revparse(&l,&r,&flags, g_repo, "^&*(")); +} + +void test_refs_revparse__parses_range_operator(void) +{ + test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVPARSE_SINGLE); + test_id("HEAD~3..HEAD", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_REVPARSE_RANGE); + test_id("HEAD~3...HEAD", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", + GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE); +} + From 1aa21fe3b87a1e601023f49c41fab3ce76c189ac Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 9 Apr 2013 05:03:51 +0400 Subject: [PATCH 3/9] Deprecate git_revparse_single and _rangelike --- examples/diff.c | 4 +- examples/rev-list.c | 28 ++++++------- include/git2/revparse.h | 25 ------------ include/git2/revwalk.h | 2 +- src/push.c | 23 +++++------ src/revparse.c | 27 +----------- src/revwalk.c | 14 +++---- src/transports/local.c | 7 ++-- tests-clar/checkout/tree.c | 50 +++++++++++++++++------ tests-clar/checkout/typechange.c | 8 +++- tests-clar/clone/nonetwork.c | 9 ++-- tests-clar/refs/revparse.c | 70 ++++++++++++++++++-------------- tests-clar/repo/head.c | 8 +++- tests-clar/reset/default.c | 12 ++++-- tests-clar/stash/drop.c | 19 ++++----- tests-clar/stash/save.c | 16 +++++--- 16 files changed, 156 insertions(+), 166 deletions(-) diff --git a/examples/diff.c b/examples/diff.c index a153b493b..6fa0fee52 100644 --- a/examples/diff.c +++ b/examples/diff.c @@ -15,9 +15,11 @@ static int resolve_to_tree( git_repository *repo, const char *identifier, git_tree **tree) { int err = 0; + git_oid oid; git_object *obj = NULL; - if (git_revparse_single(&obj, repo, identifier) < 0) + if (git_revparse(&oid, NULL, NULL, repo, identifier) < 0 || + git_object_lookup(&obj, repo, &oid, GIT_OBJ_ANY) < 0) return GIT_ENOTFOUND; switch (git_object_type(obj)) { diff --git a/examples/rev-list.c b/examples/rev-list.c index b7e466f9e..71a8180f7 100644 --- a/examples/rev-list.c +++ b/examples/rev-list.c @@ -14,48 +14,46 @@ static void check_error(int error_code, const char *action) exit(1); } -static int push_commit(git_revwalk *walk, git_object *obj, int hide) +static int push_commit(git_revwalk *walk, git_oid *oid, int hide) { if (hide) - return git_revwalk_hide(walk, git_object_id(obj)); + return git_revwalk_hide(walk, oid); else - return git_revwalk_push(walk, git_object_id(obj)); + return git_revwalk_push(walk, oid); } static int push_spec(git_repository *repo, git_revwalk *walk, const char *spec, int hide) { int error; - git_object *obj; + git_oid oid; - if ((error = git_revparse_single(&obj, repo, spec))) + if ((error = git_revparse(&oid, NULL, NULL, repo, spec))) return error; - return push_commit(walk, obj, hide); + return push_commit(walk, &oid, hide); } static int push_range(git_repository *repo, git_revwalk *walk, const char *range, int hide) { - git_object *left, *right; - int threedots; + git_oid left, right; + git_revparse_flag_t flags; int error = 0; - if ((error = git_revparse_rangelike(&left, &right, &threedots, repo, range))) + if ((error = git_revparse(&left, &right, &flags, repo, range))) return error; - if (threedots) { + if (flags & GIT_REVPARSE_MERGE_BASE) { /* TODO: support "..." */ return GIT_EINVALIDSPEC; } - if ((error = push_commit(walk, left, !hide))) + if ((error = push_commit(walk, &left, !hide))) goto out; - error = push_commit(walk, right, hide); + error = push_commit(walk, &right, hide); out: - git_object_free(left); - git_object_free(right); return error; } -static int revwalk_parseopts(git_repository *repo, git_revwalk *walk, int nopts, const char *const *opts) +static int revwalk_parseopts(git_repository *repo, git_revwalk *walk, int nopts, char **opts) { int hide, i, error; unsigned int sorting = GIT_SORT_NONE; diff --git a/include/git2/revparse.h b/include/git2/revparse.h index 9315b66eb..7fe910b45 100644 --- a/include/git2/revparse.h +++ b/include/git2/revparse.h @@ -20,31 +20,6 @@ */ GIT_BEGIN_DECL -/** - * Find an object, as specified by a revision string. See `man gitrevisions`, or the documentation - * for `git rev-parse` for information on the syntax accepted. - * - * @param out pointer to output object - * @param repo the repository to search in - * @param spec the textual specification for an object - * @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS, - * GIT_EINVALIDSPEC or an error code - */ -GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, const char *spec); - -/** - * Parse a string with the form of a revision range, as accepted by - * `git rev-list`, `git diff`, and others. - * - * @param left (output) the left-hand commit - * @param right (output) the right-hand commit - * @param threedots (output) 0 if the endpoints are separated by two dots, 1 if by three - * @param repo the repository to find the commits in - * @param rangelike the rangelike string to be parsed - * @return 0 on success, or any error `git_revparse_single` can return - */ -GIT_EXTERN(int) git_revparse_rangelike(git_object **left, git_object **right, int *threedots, git_repository *repo, const char *rangelike); - /** * Revparse flags. These indicate the intended behavior of the spec passed to diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h index 8bfe0b502..c9f7372e9 100644 --- a/include/git2/revwalk.h +++ b/include/git2/revwalk.h @@ -221,7 +221,7 @@ GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); * * The range should be of the form * .. - * where each is in the form accepted by 'git_revparse_single'. + * where each is in the form accepted by 'git_revparse'. * The left-hand commit will be hidden and the right-hand commit pushed. * * @param walk the walker being used for the traversal diff --git a/src/push.c b/src/push.c index 37f641812..dcd8122d1 100644 --- a/src/push.c +++ b/src/push.c @@ -96,21 +96,18 @@ static int check_rref(char *ref) static int check_lref(git_push *push, char *ref) { /* lref must be resolvable to an existing object */ - git_object *obj; - int error = git_revparse_single(&obj, push->repo, ref); + git_oid oid; + int error = git_revparse(&oid, NULL, NULL, push->repo, ref); - if (error) { - if (error == GIT_ENOTFOUND) - giterr_set(GITERR_REFERENCE, - "src refspec '%s' does not match any existing object", ref); - else - giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref); + if (!error) + return 0; - return -1; - } else - git_object_free(obj); - - return 0; + if (error == GIT_ENOTFOUND) + giterr_set(GITERR_REFERENCE, + "src refspec '%s' does not match any existing object", ref); + else + giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref); + return -1; } static int parse_refspec(git_push *push, push_spec **spec, const char *str) diff --git a/src/revparse.c b/src/revparse.c index 2ba42d8e3..7842c49b7 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -722,7 +722,7 @@ static int ensure_left_hand_identifier_is_not_known_yet(git_object *object, git_ return GIT_EINVALIDSPEC; } -int git_revparse_single(git_object **out, git_repository *repo, const char *spec) +static int git_revparse_single(git_object **out, git_repository *repo, const char *spec) { size_t pos = 0, identifier_len = 0; int error = -1, n; @@ -868,31 +868,6 @@ cleanup: return error; } -int git_revparse_rangelike(git_object **left, git_object **right, int *threedots, git_repository *repo, const char *rangelike) -{ - int error = 0; - const char *p, *q; - char *revspec; - - p = strstr(rangelike, ".."); - if (!p) { - giterr_set(GITERR_INVALID, "Malformed range (or rangelike syntax): %s", rangelike); - return GIT_EINVALIDSPEC; - } else if (p[2] == '.') { - *threedots = 1; - q = p + 3; - } else { - *threedots = 0; - q = p + 2; - } - - revspec = git__substrdup(rangelike, p - rangelike); - error = (git_revparse_single(left, repo, revspec) - || git_revparse_single(right, repo, q)); - git__free(revspec); - return error; -} - int git_revparse( git_oid *left, diff --git a/src/revwalk.c b/src/revwalk.c index c1071843b..b22fef07f 100644 --- a/src/revwalk.c +++ b/src/revwalk.c @@ -231,25 +231,23 @@ int git_revwalk_push_ref(git_revwalk *walk, const char *refname) int git_revwalk_push_range(git_revwalk *walk, const char *range) { - git_object *left, *right; - int threedots; + git_oid left, right; + git_revparse_flag_t revparseflags; int error = 0; - if ((error = git_revparse_rangelike(&left, &right, &threedots, walk->repo, range))) + if ((error = git_revparse(&left, &right, &revparseflags, walk->repo, range))) return error; - if (threedots) { + if (revparseflags & GIT_REVPARSE_MERGE_BASE) { /* TODO: support "..." */ giterr_set(GITERR_INVALID, "Symmetric differences not implemented in revwalk"); return GIT_EINVALIDSPEC; } - if ((error = push_commit(walk, git_object_id(left), 1))) + if ((error = push_commit(walk, &left, 1))) goto out; - error = push_commit(walk, git_object_id(right), 0); + error = push_commit(walk, &right, 0); out: - git_object_free(left); - git_object_free(right); return error; } diff --git a/src/transports/local.c b/src/transports/local.c index ce89bb213..1e27fc38c 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -236,14 +236,13 @@ static int local_negotiate_fetch( /* Fill in the loids */ git_vector_foreach(&t->refs, i, rhead) { - git_object *obj; + git_oid oid; - int error = git_revparse_single(&obj, repo, rhead->name); + int error = git_revparse(&oid, NULL, NULL, repo, rhead->name); if (!error) - git_oid_cpy(&rhead->loid, git_object_id(obj)); + git_oid_cpy(&rhead->loid, &oid); else if (error != GIT_ENOTFOUND) return error; - git_object_free(obj); giterr_clear(); } diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c index 5a2eacea1..ae4087f41 100644 --- a/tests-clar/checkout/tree.c +++ b/tests-clar/checkout/tree.c @@ -28,8 +28,11 @@ void test_checkout_tree__cleanup(void) void test_checkout_tree__cannot_checkout_a_non_treeish(void) { + git_oid oid; + /* blob */ - cl_git_pass(git_revparse_single(&g_object, g_repo, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_fail(git_checkout_tree(g_repo, g_object, NULL)); } @@ -37,11 +40,13 @@ void test_checkout_tree__cannot_checkout_a_non_treeish(void) void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void) { char *entries[] = { "ab/de/" }; + git_oid oid; g_opts.paths.strings = entries; g_opts.paths.count = 1; - cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees")); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "subtrees")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); @@ -53,12 +58,15 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void) void test_checkout_tree__can_checkout_and_remove_directory(void) { + git_oid oid; + cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); /* Checkout brach "subtrees" and update HEAD, so that HEAD matches the * current working tree */ - cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees")); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "subtrees")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); @@ -73,7 +81,8 @@ void test_checkout_tree__can_checkout_and_remove_directory(void) /* Checkout brach "master" and update HEAD, so that HEAD matches the * current working tree */ - cl_git_pass(git_revparse_single(&g_object, g_repo, "master")); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "master")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master")); @@ -85,11 +94,13 @@ void test_checkout_tree__can_checkout_and_remove_directory(void) void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void) { char *entries[] = { "de/" }; + git_oid oid; g_opts.paths.strings = entries; g_opts.paths.count = 1; - cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees:ab")); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "subtrees:ab")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_assert_equal_i(false, git_path_isdir("./testrepo/de/")); @@ -109,11 +120,13 @@ static void progress(const char *path, size_t cur, size_t tot, void *payload) void test_checkout_tree__calls_progress_callback(void) { bool was_called = 0; + git_oid oid; g_opts.progress_cb = progress; g_opts.progress_payload = &was_called; - cl_git_pass(git_revparse_single(&g_object, g_repo, "master")); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "master")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); @@ -277,14 +290,16 @@ void test_checkout_tree__can_update_only(void) void test_checkout_tree__can_checkout_with_pattern(void) { char *entries[] = { "[l-z]*.txt" }; + git_oid oid; /* reset to beginning of history (i.e. just a README file) */ g_opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED; - cl_git_pass(git_revparse_single(&g_object, g_repo, + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass( @@ -304,7 +319,8 @@ void test_checkout_tree__can_checkout_with_pattern(void) g_opts.paths.strings = entries; g_opts.paths.count = 1; - cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master")); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "refs/heads/master")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); @@ -317,14 +333,16 @@ void test_checkout_tree__can_checkout_with_pattern(void) void test_checkout_tree__can_disable_pattern_match(void) { char *entries[] = { "b*.txt" }; + git_oid oid; /* reset to beginning of history (i.e. just a README file) */ g_opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED; - cl_git_pass(git_revparse_single(&g_object, g_repo, + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass( @@ -342,7 +360,8 @@ void test_checkout_tree__can_disable_pattern_match(void) g_opts.paths.strings = entries; g_opts.paths.count = 1; - cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master")); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "refs/heads/master")); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); @@ -367,11 +386,13 @@ void assert_conflict( git_object *hack_tree; git_reference *branch, *head; git_buf file_path = GIT_BUF_INIT; + git_oid oid; cl_git_pass(git_repository_index(&index, g_repo)); /* Create a branch pointing at the parent */ - cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha)); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, parent_sha)); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_branch_create(&branch, g_repo, "potential_conflict", (git_commit *)g_object, 0)); @@ -400,7 +421,8 @@ void assert_conflict( git_buf_free(&file_path); /* Trying to checkout the original commit */ - cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha)); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, commit_sha)); + cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); g_opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_assert_equal_i( @@ -487,6 +509,7 @@ void test_checkout_tree__issue_1397(void) git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; const char *partial_oid = "8a7ef04"; git_object *tree = NULL; + git_oid oid; test_checkout_tree__cleanup(); /* cleanup default checkout */ @@ -494,7 +517,8 @@ void test_checkout_tree__issue_1397(void) cl_repo_set_bool(g_repo, "core.autocrlf", true); - cl_git_pass(git_revparse_single(&tree, g_repo, partial_oid)); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, partial_oid)); + cl_git_pass(git_object_lookup(&tree, g_repo, &oid, GIT_OBJ_ANY)); opts.checkout_strategy = GIT_CHECKOUT_FORCE; diff --git a/tests-clar/checkout/typechange.c b/tests-clar/checkout/typechange.c index b92cc23fa..74521312a 100644 --- a/tests-clar/checkout/typechange.c +++ b/tests-clar/checkout/typechange.c @@ -107,10 +107,12 @@ void test_checkout_typechange__checkout_typechanges_safe(void) { int i; git_object *obj; + git_oid oid; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; for (i = 0; g_typechange_oids[i] != NULL; ++i) { - cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i])); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, g_typechange_oids[i])); + cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); opts.checkout_strategy = GIT_CHECKOUT_FORCE; @@ -194,6 +196,7 @@ void test_checkout_typechange__checkout_with_conflicts(void) { int i; git_object *obj; + git_oid oid; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; notify_counts cts = {0}; @@ -203,7 +206,8 @@ void test_checkout_typechange__checkout_with_conflicts(void) opts.notify_payload = &cts; for (i = 0; g_typechange_oids[i] != NULL; ++i) { - cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i])); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, g_typechange_oids[i])); + cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); force_create_file("typechanges/a/blocker"); force_create_file("typechanges/b"); diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c index 2c4cba4eb..d86c1f4c9 100644 --- a/tests-clar/clone/nonetwork.c +++ b/tests-clar/clone/nonetwork.c @@ -214,23 +214,22 @@ void test_clone_nonetwork__can_checkout_given_branch(void) void test_clone_nonetwork__can_detached_head(void) { - git_object *commit; + git_oid oid; git_repository *cloned; git_reference *cloned_head; cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); - cl_git_pass(git_revparse_single(&commit, g_repo, "master~1")); - cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(commit))); + cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "master~1")); + cl_git_pass(git_repository_set_head_detached(g_repo, &oid)); cl_git_pass(git_clone(&cloned, "./foo", "./foo1", &g_options)); cl_assert(git_repository_head_detached(cloned)); cl_git_pass(git_repository_head(&cloned_head, cloned)); - cl_assert(!git_oid_cmp(git_object_id(commit), git_reference_target(cloned_head))); + cl_assert(!git_oid_cmp(&oid, git_reference_target(cloned_head))); - git_commit_free((git_commit*)commit); git_reference_free(cloned_head); git_repository_free(cloned); diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c index ab8839fda..39e77c8eb 100644 --- a/tests-clar/refs/revparse.c +++ b/tests-clar/refs/revparse.c @@ -6,25 +6,22 @@ #include "path.h" static git_repository *g_repo; -static git_object *g_obj; /* Helpers */ static void test_object_inrepo(const char *spec, const char *expected_oid, git_repository *repo) { char objstr[64] = {0}; - git_object *obj = NULL; + git_oid oid; int error; - error = git_revparse_single(&obj, repo, spec); + error = git_revparse(&oid, NULL, NULL, repo, spec); if (expected_oid != NULL) { cl_assert_equal_i(0, error); - git_oid_fmt(objstr, git_object_id(obj)); + git_oid_fmt(objstr, &oid); cl_assert_equal_s(objstr, expected_oid); } else cl_assert_equal_i(GIT_ENOTFOUND, error); - - git_object_free(obj); } static void test_id_inrepo( @@ -66,27 +63,24 @@ static void test_object(const char *spec, const char *expected_oid) static void test_rangelike(const char *rangelike, const char *expected_left, const char *expected_right, - int expected_threedots) + git_revparse_flag_t expected_revparseflags) { char objstr[64] = {0}; - git_object *left = NULL, *right = NULL; - int threedots; + git_oid left = {{0}}, right = {{0}}; + git_revparse_flag_t revparseflags; int error; - error = git_revparse_rangelike(&left, &right, &threedots, g_repo, rangelike); + error = git_revparse(&left, &right, &revparseflags, g_repo, rangelike); if (expected_left != NULL) { cl_assert_equal_i(0, error); - cl_assert_equal_i(threedots, expected_threedots); - git_oid_fmt(objstr, git_object_id(left)); + cl_assert_equal_i(revparseflags, expected_revparseflags); + git_oid_fmt(objstr, &left); cl_assert_equal_s(objstr, expected_left); - git_oid_fmt(objstr, git_object_id(right)); + git_oid_fmt(objstr, &right); cl_assert_equal_s(objstr, expected_right); } else cl_assert(error != 0); - - git_object_free(left); - git_object_free(right); } @@ -118,8 +112,9 @@ void test_refs_revparse__nonexistant_object(void) static void assert_invalid_spec(const char *invalid_spec) { + git_oid oid; cl_assert_equal_i( - GIT_EINVALIDSPEC, git_revparse_single(&g_obj, g_repo, invalid_spec)); + GIT_EINVALIDSPEC, git_revparse(&oid, NULL, NULL, g_repo, invalid_spec)); } void test_refs_revparse__invalid_reference_name(void) @@ -196,10 +191,12 @@ void test_refs_revparse__not_tag(void) void test_refs_revparse__to_type(void) { + git_oid oid; + assert_invalid_spec("wrapped_tag^{trip}"); test_object("point_to_blob^{commit}", NULL); cl_assert_equal_i( - GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}")); + GIT_EAMBIGUOUS, git_revparse(&oid, NULL, NULL, g_repo, "wrapped_tag^{blob}")); test_object("wrapped_tag^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("wrapped_tag^{tree}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"); @@ -263,7 +260,8 @@ void test_refs_revparse__ordinal(void) assert_invalid_spec("master@{-2}"); /* TODO: make the test below actually fail - * cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}")); + * git_oid oid; + * cl_git_fail(git_revparse(&oid, NULL, NULL, g_repo, "master@{1a}")); */ test_object("nope@{0}", NULL); @@ -425,9 +423,11 @@ void test_refs_revparse__date(void) void test_refs_revparse__colon(void) { + git_oid oid; + assert_invalid_spec(":/"); assert_invalid_spec("point_to_blob:readme.txt"); - cl_git_fail(git_revparse_single(&g_obj, g_repo, ":2:README")); /* Not implemented */ + cl_git_fail(git_revparse(&oid, NULL, NULL, g_repo, ":2:README")); /* Not implemented */ test_object(":/not found in any commit", NULL); test_object("subtrees:ab/42.txt", NULL); @@ -517,8 +517,9 @@ void test_refs_revparse__disambiguation(void) void test_refs_revparse__a_too_short_objectid_returns_EAMBIGUOUS(void) { + git_oid oid; cl_assert_equal_i( - GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "e90")); + GIT_EAMBIGUOUS, git_revparse(&oid, NULL, NULL, g_repo, "e90")); } void test_refs_revparse__issue_994(void) @@ -526,14 +527,15 @@ void test_refs_revparse__issue_994(void) git_repository *repo; git_reference *head, *with_at; git_object *target; + git_oid oid; repo = cl_git_sandbox_init("testrepo.git"); cl_assert_equal_i(GIT_ENOTFOUND, - git_revparse_single(&target, repo, "origin/bim_with_3d@11296")); + git_revparse(&oid, NULL, NULL, repo, "origin/bim_with_3d@11296")); cl_assert_equal_i(GIT_ENOTFOUND, - git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296")); + git_revparse(&oid, NULL, NULL, repo, "refs/remotes/origin/bim_with_3d@11296")); cl_git_pass(git_repository_head(&head, repo)); @@ -544,10 +546,12 @@ void test_refs_revparse__issue_994(void) git_reference_target(head), 0)); - cl_git_pass(git_revparse_single(&target, repo, "origin/bim_with_3d@11296")); + cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "origin/bim_with_3d@11296")); + cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); git_object_free(target); - cl_git_pass(git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296")); + cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "refs/remotes/origin/bim_with_3d@11296")); + cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); git_object_free(target); git_reference_free(with_at); @@ -573,12 +577,14 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void) git_reference *branch; git_object *target; char sha[GIT_OID_HEXSZ + 1]; + git_oid oid; repo = cl_git_sandbox_init("testrepo.git"); test_object_inrepo("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo); - cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); + cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "HEAD~3")); + cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0)); git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); @@ -611,12 +617,14 @@ void test_refs_revparse__try_to_retrieve_sha_before_branch(void) git_reference *branch; git_object *target; char sha[GIT_OID_HEXSZ + 1]; + git_oid oid; repo = cl_git_sandbox_init("testrepo.git"); test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo); - cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); + cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "HEAD~3")); + cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0)); git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); @@ -647,12 +655,14 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void) git_reference *branch; git_object *target; char sha[GIT_OID_HEXSZ + 1]; + git_oid oid; repo = cl_git_sandbox_init("testrepo.git"); test_object_inrepo("c47800", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo); - cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); + cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "HEAD~3")); + cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0)); git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); @@ -670,12 +680,12 @@ void test_refs_revparse__range(void) test_rangelike("be3563a^1..be3563a", "9fd738e8f7967c078dceed8190330fc8648ee56a", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", - 0); + GIT_REVPARSE_RANGE); test_rangelike("be3563a^1...be3563a", "9fd738e8f7967c078dceed8190330fc8648ee56a", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", - 1); + GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE); test_rangelike("be3563a^1.be3563a", NULL, NULL, 0); } diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c index a9f5cfc58..bb81bb087 100644 --- a/tests-clar/repo/head.c +++ b/tests-clar/repo/head.c @@ -120,9 +120,11 @@ void test_repo_head__set_head_detached_Return_ENOTFOUND_when_the_object_doesnt_e void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void) { + git_oid oid; git_object *blob; - cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob")); + cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "point_to_blob")); + cl_git_pass(git_object_lookup(&blob, repo, &oid, GIT_OBJ_ANY)); cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob))); @@ -131,9 +133,11 @@ void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(vo void test_repo_head__set_head_detached_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void) { + git_oid oid; git_object *tag; - cl_git_pass(git_revparse_single(&tag, repo, "tags/test")); + cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "tags/test")); + cl_git_pass(git_object_lookup(&tag, repo, &oid, GIT_OBJ_ANY)); cl_assert_equal_i(GIT_OBJ_TAG, git_object_type(tag)); cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag))); diff --git a/tests-clar/reset/default.c b/tests-clar/reset/default.c index 506d971ff..bc8da7392 100644 --- a/tests-clar/reset/default.c +++ b/tests-clar/reset/default.c @@ -95,6 +95,7 @@ void test_reset_default__resetting_filepaths_against_a_null_target_removes_them_ void test_reset_default__resetting_filepaths_replaces_their_corresponding_index_entries(void) { git_strarray before, after; + git_oid oid; char *paths[] = { "staged_changes", "staged_changes_file_deleted" }; char *before_shas[] = { "55d316c9ba708999f1918e9677d01dfcae69c6b9", @@ -109,7 +110,8 @@ void test_reset_default__resetting_filepaths_replaces_their_corresponding_index_ after.strings = after_shas; after.count = 2; - cl_git_pass(git_revparse_single(&_target, _repo, "0017bd4")); + cl_git_pass(git_revparse(&oid, NULL, NULL, _repo, "0017bd4")); + cl_git_pass(git_object_lookup(&_target, _repo, &oid, GIT_OBJ_ANY)); assert_content_in_index(&_pathspecs, true, &before); cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); @@ -135,6 +137,7 @@ void test_reset_default__resetting_filepaths_clears_previous_conflicts(void) { git_index_entry *conflict_entry[3]; git_strarray after; + git_oid oid; char *paths[] = { "conflicts-one.txt" }; char *after_shas[] = { "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81" }; @@ -150,7 +153,8 @@ void test_reset_default__resetting_filepaths_clears_previous_conflicts(void) cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], _index, "conflicts-one.txt")); - cl_git_pass(git_revparse_single(&_target, _repo, "9a05ccb")); + cl_git_pass(git_revparse(&oid, NULL, NULL, _repo, "9a05ccb")); + cl_git_pass(git_object_lookup(&_target, _repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); assert_content_in_index(&_pathspecs, true, &after); @@ -167,13 +171,15 @@ Unstaged changes after reset: void test_reset_default__resetting_unknown_filepaths_does_not_fail(void) { char *paths[] = { "I_am_not_there.txt", "me_neither.txt" }; + git_oid oid; _pathspecs.strings = paths; _pathspecs.count = 2; assert_content_in_index(&_pathspecs, false, NULL); - cl_git_pass(git_revparse_single(&_target, _repo, "HEAD")); + cl_git_pass(git_revparse(&oid, NULL, NULL, _repo, "HEAD")); + cl_git_pass(git_object_lookup(&_target, _repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); assert_content_in_index(&_pathspecs, false, NULL); diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c index d171390da..da9e676a9 100644 --- a/tests-clar/stash/drop.c +++ b/tests-clar/stash/drop.c @@ -140,35 +140,30 @@ void test_stash_drop__dropping_the_last_entry_removes_the_stash(void) void retrieve_top_stash_id(git_oid *out) { - git_object *top_stash; + git_oid top_stash_id; - cl_git_pass(git_revparse_single(&top_stash, repo, "stash@{0}")); + cl_git_pass(git_revparse(&top_stash_id, NULL, NULL, repo, "stash@{0}")); cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE)); - cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0); - - git_object_free(top_stash); + cl_assert_equal_i(true, git_oid_cmp(out, &top_stash_id) == 0); } void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void) { - git_object *next_top_stash; + git_oid next_top_stash_id; git_oid oid; push_three_states(); retrieve_top_stash_id(&oid); - cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}")); - cl_assert_equal_i( - false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0); + cl_git_pass(git_revparse(&next_top_stash_id, NULL, NULL, repo, "stash@{1}")); + cl_assert_equal_i(false, git_oid_cmp(&oid, &next_top_stash_id) == 0); cl_git_pass(git_stash_drop(repo, 0)); retrieve_top_stash_id(&oid); cl_assert_equal_i( - true, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0); - - git_object_free(next_top_stash); + true, git_oid_cmp(&oid, &next_top_stash_id) == 0); } diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c index 588dfc3ea..4185e549c 100644 --- a/tests-clar/stash/save.c +++ b/tests-clar/stash/save.c @@ -37,10 +37,11 @@ void test_stash_save__cleanup(void) static void assert_object_oid(const char* revision, const char* expected_oid, git_otype type) { - git_object *object; + git_oid oid; int result; + git_object *obj; - result = git_revparse_single(&object, repo, revision); + result = git_revparse(&oid, NULL, NULL, repo, revision); if (!expected_oid) { cl_assert_equal_i(GIT_ENOTFOUND, result); @@ -48,10 +49,11 @@ static void assert_object_oid(const char* revision, const char* expected_oid, gi } else cl_assert_equal_i(0, result); - cl_assert_equal_i(type, git_object_type(object)); - cl_git_pass(git_oid_streq(git_object_id(object), expected_oid)); + cl_git_pass(git_oid_streq(&oid, expected_oid)); - git_object_free(object); + cl_git_pass(git_object_lookup(&obj, repo, &oid, GIT_OBJ_ANY)); + cl_assert_equal_i(type, git_object_type(obj)); + git_object_free(obj); } static void assert_blob_oid(const char* revision, const char* expected_oid) @@ -145,9 +147,11 @@ void test_stash_save__can_keep_index(void) static void assert_commit_message_contains(const char *revision, const char *fragment) { + git_oid oid; git_commit *commit; - cl_git_pass(git_revparse_single(((git_object **)&commit), repo, revision)); + cl_git_pass(git_revparse(&oid, NULL, NULL, repo, revision)); + cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_assert(strstr(git_commit_message(commit), fragment) != NULL); From ec7e240ba4a3277a94def51005d2558d02cb8c3c Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 9 Apr 2013 05:07:12 +0400 Subject: [PATCH 4/9] Add rev-list example to makefiles --- CMakeLists.txt | 3 +++ examples/Makefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfca73630..6bd25aacc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -388,4 +388,7 @@ IF (BUILD_EXAMPLES) ADD_EXECUTABLE(git-showindex examples/showindex.c) TARGET_LINK_LIBRARIES(git-showindex git2) + + ADD_EXECUTABLE(git-rev-list examples/rev-list.c) + TARGET_LINK_LIBRARIES(git-rev-list git2) ENDIF () diff --git a/examples/Makefile b/examples/Makefile index b306d4800..2c18731fd 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -3,7 +3,7 @@ CC = gcc CFLAGS = -g -I../include -I../src -Wall -Wextra -Wmissing-prototypes -Wno-missing-field-initializers LFLAGS = -L../build -lgit2 -lz -APPS = general showindex diff +APPS = general showindex diff rev-list all: $(APPS) From 4291ad078128003ad6d4ac6fb58244f3343ad87a Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 15 Apr 2013 11:42:34 -0700 Subject: [PATCH 5/9] Reintroduce git_revparse_single. --- include/git2/revparse.h | 14 ++++++++++++++ src/revparse.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/git2/revparse.h b/include/git2/revparse.h index 7fe910b45..2bbbaa5e1 100644 --- a/include/git2/revparse.h +++ b/include/git2/revparse.h @@ -20,6 +20,20 @@ */ GIT_BEGIN_DECL +/** + * + * Find a single object, as specified by a revision string. See `man gitrevisions`, + * or http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for + * information on the syntax accepted. + * + * @param out pointer to output object + * @param repo the repository to search in + * @param spec the textual specification for an object + * @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS, GIT_EINVALIDSPEC or an error code + */ +GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, + const char *spec); + /** * Revparse flags. These indicate the intended behavior of the spec passed to diff --git a/src/revparse.c b/src/revparse.c index 7842c49b7..5f591406e 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -722,7 +722,7 @@ static int ensure_left_hand_identifier_is_not_known_yet(git_object *object, git_ return GIT_EINVALIDSPEC; } -static int git_revparse_single(git_object **out, git_repository *repo, const char *spec) +int git_revparse_single(git_object **out, git_repository *repo, const char *spec) { size_t pos = 0, identifier_len = 0; int error = -1, n; From 2ebc3c66c292539786b6ec1538f740c5e444fe16 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 15 Apr 2013 11:57:24 -0700 Subject: [PATCH 6/9] Redeploy git_revparse_single. --- src/push.c | 5 +- src/transports/local.c | 7 +- tests-clar/checkout/tree.c | 53 ++++----------- tests-clar/checkout/typechange.c | 8 +-- tests-clar/clone/nonetwork.c | 9 +-- tests-clar/refs/revparse.c | 111 ++++++++++++++----------------- 6 files changed, 77 insertions(+), 116 deletions(-) diff --git a/src/push.c b/src/push.c index dcd8122d1..ce7af3598 100644 --- a/src/push.c +++ b/src/push.c @@ -96,8 +96,9 @@ static int check_rref(char *ref) static int check_lref(git_push *push, char *ref) { /* lref must be resolvable to an existing object */ - git_oid oid; - int error = git_revparse(&oid, NULL, NULL, push->repo, ref); + git_object *obj; + int error = git_revparse_single(&obj, push->repo, ref); + git_object_free(obj); if (!error) return 0; diff --git a/src/transports/local.c b/src/transports/local.c index 1e27fc38c..ce89bb213 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -236,13 +236,14 @@ static int local_negotiate_fetch( /* Fill in the loids */ git_vector_foreach(&t->refs, i, rhead) { - git_oid oid; + git_object *obj; - int error = git_revparse(&oid, NULL, NULL, repo, rhead->name); + int error = git_revparse_single(&obj, repo, rhead->name); if (!error) - git_oid_cpy(&rhead->loid, &oid); + git_oid_cpy(&rhead->loid, git_object_id(obj)); else if (error != GIT_ENOTFOUND) return error; + git_object_free(obj); giterr_clear(); } diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c index ae4087f41..0748b22e0 100644 --- a/tests-clar/checkout/tree.c +++ b/tests-clar/checkout/tree.c @@ -28,25 +28,19 @@ void test_checkout_tree__cleanup(void) void test_checkout_tree__cannot_checkout_a_non_treeish(void) { - git_oid oid; - /* blob */ - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); - + cl_git_pass(git_revparse_single(&g_object, g_repo, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); cl_git_fail(git_checkout_tree(g_repo, g_object, NULL)); } void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void) { char *entries[] = { "ab/de/" }; - git_oid oid; g_opts.paths.strings = entries; g_opts.paths.count = 1; - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "subtrees")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees")); cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); @@ -58,15 +52,12 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void) void test_checkout_tree__can_checkout_and_remove_directory(void) { - git_oid oid; - cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); /* Checkout brach "subtrees" and update HEAD, so that HEAD matches the * current working tree */ - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "subtrees")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); @@ -81,8 +72,7 @@ void test_checkout_tree__can_checkout_and_remove_directory(void) /* Checkout brach "master" and update HEAD, so that HEAD matches the * current working tree */ - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "master")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "master")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master")); @@ -94,13 +84,11 @@ void test_checkout_tree__can_checkout_and_remove_directory(void) void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void) { char *entries[] = { "de/" }; - git_oid oid; g_opts.paths.strings = entries; g_opts.paths.count = 1; - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "subtrees:ab")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees:ab")); cl_assert_equal_i(false, git_path_isdir("./testrepo/de/")); @@ -120,13 +108,11 @@ static void progress(const char *path, size_t cur, size_t tot, void *payload) void test_checkout_tree__calls_progress_callback(void) { bool was_called = 0; - git_oid oid; g_opts.progress_cb = progress; g_opts.progress_payload = &was_called; - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "master")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "master")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); @@ -290,16 +276,13 @@ void test_checkout_tree__can_update_only(void) void test_checkout_tree__can_checkout_with_pattern(void) { char *entries[] = { "[l-z]*.txt" }; - git_oid oid; /* reset to beginning of history (i.e. just a README file) */ g_opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED; - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, - "8496071c1b46c854b31185ea97743be6a8774479")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass( @@ -319,8 +302,7 @@ void test_checkout_tree__can_checkout_with_pattern(void) g_opts.paths.strings = entries; g_opts.paths.count = 1; - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "refs/heads/master")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); @@ -333,16 +315,13 @@ void test_checkout_tree__can_checkout_with_pattern(void) void test_checkout_tree__can_disable_pattern_match(void) { char *entries[] = { "b*.txt" }; - git_oid oid; /* reset to beginning of history (i.e. just a README file) */ g_opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED; - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, - "8496071c1b46c854b31185ea97743be6a8774479")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass( @@ -360,8 +339,7 @@ void test_checkout_tree__can_disable_pattern_match(void) g_opts.paths.strings = entries; g_opts.paths.count = 1; - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "refs/heads/master")); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); @@ -386,13 +364,11 @@ void assert_conflict( git_object *hack_tree; git_reference *branch, *head; git_buf file_path = GIT_BUF_INIT; - git_oid oid; cl_git_pass(git_repository_index(&index, g_repo)); /* Create a branch pointing at the parent */ - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, parent_sha)); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha)); cl_git_pass(git_branch_create(&branch, g_repo, "potential_conflict", (git_commit *)g_object, 0)); @@ -421,8 +397,7 @@ void assert_conflict( git_buf_free(&file_path); /* Trying to checkout the original commit */ - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, commit_sha)); - cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha)); g_opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_assert_equal_i( @@ -509,7 +484,6 @@ void test_checkout_tree__issue_1397(void) git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; const char *partial_oid = "8a7ef04"; git_object *tree = NULL; - git_oid oid; test_checkout_tree__cleanup(); /* cleanup default checkout */ @@ -517,8 +491,7 @@ void test_checkout_tree__issue_1397(void) cl_repo_set_bool(g_repo, "core.autocrlf", true); - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, partial_oid)); - cl_git_pass(git_object_lookup(&tree, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&tree, g_repo, partial_oid)); opts.checkout_strategy = GIT_CHECKOUT_FORCE; diff --git a/tests-clar/checkout/typechange.c b/tests-clar/checkout/typechange.c index 74521312a..b92cc23fa 100644 --- a/tests-clar/checkout/typechange.c +++ b/tests-clar/checkout/typechange.c @@ -107,12 +107,10 @@ void test_checkout_typechange__checkout_typechanges_safe(void) { int i; git_object *obj; - git_oid oid; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; for (i = 0; g_typechange_oids[i] != NULL; ++i) { - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, g_typechange_oids[i])); - cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i])); opts.checkout_strategy = GIT_CHECKOUT_FORCE; @@ -196,7 +194,6 @@ void test_checkout_typechange__checkout_with_conflicts(void) { int i; git_object *obj; - git_oid oid; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; notify_counts cts = {0}; @@ -206,8 +203,7 @@ void test_checkout_typechange__checkout_with_conflicts(void) opts.notify_payload = &cts; for (i = 0; g_typechange_oids[i] != NULL; ++i) { - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, g_typechange_oids[i])); - cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i])); force_create_file("typechanges/a/blocker"); force_create_file("typechanges/b"); diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c index d86c1f4c9..c4b482234 100644 --- a/tests-clar/clone/nonetwork.c +++ b/tests-clar/clone/nonetwork.c @@ -214,22 +214,23 @@ void test_clone_nonetwork__can_checkout_given_branch(void) void test_clone_nonetwork__can_detached_head(void) { - git_oid oid; + git_object *obj; git_repository *cloned; git_reference *cloned_head; cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); - cl_git_pass(git_revparse(&oid, NULL, NULL, g_repo, "master~1")); - cl_git_pass(git_repository_set_head_detached(g_repo, &oid)); + cl_git_pass(git_revparse_single(&obj, g_repo, "master~1")); + cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(obj))); cl_git_pass(git_clone(&cloned, "./foo", "./foo1", &g_options)); cl_assert(git_repository_head_detached(cloned)); cl_git_pass(git_repository_head(&cloned_head, cloned)); - cl_assert(!git_oid_cmp(&oid, git_reference_target(cloned_head))); + cl_assert(!git_oid_cmp(git_object_id(obj), git_reference_target(cloned_head))); + git_object_free(obj); git_reference_free(cloned_head); git_repository_free(cloned); diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c index 39e77c8eb..8c3e5e43a 100644 --- a/tests-clar/refs/revparse.c +++ b/tests-clar/refs/revparse.c @@ -6,22 +6,25 @@ #include "path.h" static git_repository *g_repo; +static git_object *g_obj; /* Helpers */ static void test_object_inrepo(const char *spec, const char *expected_oid, git_repository *repo) { char objstr[64] = {0}; - git_oid oid; + git_object *obj = NULL; int error; - error = git_revparse(&oid, NULL, NULL, repo, spec); + error = git_revparse_single(&obj, repo, spec); if (expected_oid != NULL) { cl_assert_equal_i(0, error); - git_oid_fmt(objstr, &oid); + git_oid_fmt(objstr, git_object_id(obj)); cl_assert_equal_s(objstr, expected_oid); } else cl_assert_equal_i(GIT_ENOTFOUND, error); + + git_object_free(obj); } static void test_id_inrepo( @@ -110,18 +113,17 @@ void test_refs_revparse__nonexistant_object(void) test_object("this-does-not-exist~2", NULL); } -static void assert_invalid_spec(const char *invalid_spec) +static void assert_invalid_single_spec(const char *invalid_spec) { - git_oid oid; cl_assert_equal_i( - GIT_EINVALIDSPEC, git_revparse(&oid, NULL, NULL, g_repo, invalid_spec)); + GIT_EINVALIDSPEC, git_revparse_single(&g_obj, g_repo, invalid_spec)); } void test_refs_revparse__invalid_reference_name(void) { - assert_invalid_spec("this doesn't make sense"); - assert_invalid_spec("Inv@{id"); - assert_invalid_spec(""); + assert_invalid_single_spec("this doesn't make sense"); + assert_invalid_single_spec("Inv@{id"); + assert_invalid_single_spec(""); } void test_refs_revparse__shas(void) @@ -160,11 +162,11 @@ void test_refs_revparse__describe_output(void) void test_refs_revparse__nth_parent(void) { - assert_invalid_spec("be3563a^-1"); - assert_invalid_spec("^"); - assert_invalid_spec("be3563a^{tree}^"); - assert_invalid_spec("point_to_blob^{blob}^"); - assert_invalid_spec("this doesn't make sense^1"); + assert_invalid_single_spec("be3563a^-1"); + assert_invalid_single_spec("^"); + assert_invalid_single_spec("be3563a^{tree}^"); + assert_invalid_single_spec("point_to_blob^{blob}^"); + assert_invalid_single_spec("this doesn't make sense^1"); test_object("be3563a^1", "9fd738e8f7967c078dceed8190330fc8648ee56a"); test_object("be3563a^", "9fd738e8f7967c078dceed8190330fc8648ee56a"); @@ -191,12 +193,10 @@ void test_refs_revparse__not_tag(void) void test_refs_revparse__to_type(void) { - git_oid oid; - - assert_invalid_spec("wrapped_tag^{trip}"); + assert_invalid_single_spec("wrapped_tag^{trip}"); test_object("point_to_blob^{commit}", NULL); cl_assert_equal_i( - GIT_EAMBIGUOUS, git_revparse(&oid, NULL, NULL, g_repo, "wrapped_tag^{blob}")); + GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}")); test_object("wrapped_tag^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("wrapped_tag^{tree}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"); @@ -206,15 +206,15 @@ void test_refs_revparse__to_type(void) void test_refs_revparse__linear_history(void) { - assert_invalid_spec("~"); + assert_invalid_single_spec("~"); test_object("foo~bar", NULL); - assert_invalid_spec("master~bar"); - assert_invalid_spec("master~-1"); - assert_invalid_spec("master~0bar"); - assert_invalid_spec("this doesn't make sense~2"); - assert_invalid_spec("be3563a^{tree}~"); - assert_invalid_spec("point_to_blob^{blob}~"); + assert_invalid_single_spec("master~bar"); + assert_invalid_single_spec("master~-1"); + assert_invalid_single_spec("master~0bar"); + assert_invalid_single_spec("this doesn't make sense~2"); + assert_invalid_single_spec("be3563a^{tree}~"); + assert_invalid_single_spec("point_to_blob^{blob}~"); test_object("master~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("master~1", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); @@ -225,10 +225,10 @@ void test_refs_revparse__linear_history(void) void test_refs_revparse__chaining(void) { - assert_invalid_spec("master@{0}@{0}"); - assert_invalid_spec("@{u}@{-1}"); - assert_invalid_spec("@{-1}@{-1}"); - assert_invalid_spec("@{-3}@{0}"); + assert_invalid_single_spec("master@{0}@{0}"); + assert_invalid_single_spec("@{u}@{-1}"); + assert_invalid_single_spec("@{-1}@{-1}"); + assert_invalid_single_spec("@{-3}@{0}"); test_object("master@{0}~1^1", "9fd738e8f7967c078dceed8190330fc8648ee56a"); test_object("@{u}@{0}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); @@ -244,8 +244,8 @@ void test_refs_revparse__chaining(void) void test_refs_revparse__upstream(void) { - assert_invalid_spec("e90810b@{u}"); - assert_invalid_spec("refs/tags/e90810b@{u}"); + assert_invalid_single_spec("e90810b@{u}"); + assert_invalid_single_spec("refs/tags/e90810b@{u}"); test_object("refs/heads/e90810b@{u}", NULL); test_object("master@{upstream}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); @@ -257,11 +257,10 @@ void test_refs_revparse__upstream(void) void test_refs_revparse__ordinal(void) { - assert_invalid_spec("master@{-2}"); + assert_invalid_single_spec("master@{-2}"); /* TODO: make the test below actually fail - * git_oid oid; - * cl_git_fail(git_revparse(&oid, NULL, NULL, g_repo, "master@{1a}")); + * cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}")); */ test_object("nope@{0}", NULL); @@ -280,9 +279,9 @@ void test_refs_revparse__ordinal(void) void test_refs_revparse__previous_head(void) { - assert_invalid_spec("@{-xyz}"); - assert_invalid_spec("@{-0}"); - assert_invalid_spec("@{-1b}"); + assert_invalid_single_spec("@{-xyz}"); + assert_invalid_single_spec("@{-0}"); + assert_invalid_single_spec("@{-1b}"); test_object("@{-42}", NULL); @@ -342,7 +341,7 @@ void test_refs_revparse__revwalk(void) { test_object("master^{/not found in any commit}", NULL); test_object("master^{/merge}", NULL); - assert_invalid_spec("master^{/((}"); + assert_invalid_single_spec("master^{/((}"); test_object("master^{/anoth}", "5b5b025afb0b4c913b4c338a42934a3863bf3644"); test_object("master^{/Merge}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); @@ -423,11 +422,9 @@ void test_refs_revparse__date(void) void test_refs_revparse__colon(void) { - git_oid oid; - - assert_invalid_spec(":/"); - assert_invalid_spec("point_to_blob:readme.txt"); - cl_git_fail(git_revparse(&oid, NULL, NULL, g_repo, ":2:README")); /* Not implemented */ + assert_invalid_single_spec(":/"); + assert_invalid_single_spec("point_to_blob:readme.txt"); + cl_git_fail(git_revparse_single(&g_obj, g_repo, ":2:README")); /* Not implemented */ test_object(":/not found in any commit", NULL); test_object("subtrees:ab/42.txt", NULL); @@ -517,9 +514,8 @@ void test_refs_revparse__disambiguation(void) void test_refs_revparse__a_too_short_objectid_returns_EAMBIGUOUS(void) { - git_oid oid; cl_assert_equal_i( - GIT_EAMBIGUOUS, git_revparse(&oid, NULL, NULL, g_repo, "e90")); + GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "e90")); } void test_refs_revparse__issue_994(void) @@ -527,15 +523,14 @@ void test_refs_revparse__issue_994(void) git_repository *repo; git_reference *head, *with_at; git_object *target; - git_oid oid; repo = cl_git_sandbox_init("testrepo.git"); cl_assert_equal_i(GIT_ENOTFOUND, - git_revparse(&oid, NULL, NULL, repo, "origin/bim_with_3d@11296")); + git_revparse_single(&target, repo, "origin/bim_with_3d@11296")); cl_assert_equal_i(GIT_ENOTFOUND, - git_revparse(&oid, NULL, NULL, repo, "refs/remotes/origin/bim_with_3d@11296")); + git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296")); cl_git_pass(git_repository_head(&head, repo)); @@ -546,12 +541,10 @@ void test_refs_revparse__issue_994(void) git_reference_target(head), 0)); - cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "origin/bim_with_3d@11296")); - cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); + cl_git_pass(git_revparse_single(&target, repo, "origin/bim_with_3d@11296")); git_object_free(target); - cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "refs/remotes/origin/bim_with_3d@11296")); - cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); + cl_git_pass(git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296")); git_object_free(target); git_reference_free(with_at); @@ -577,14 +570,12 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void) git_reference *branch; git_object *target; char sha[GIT_OID_HEXSZ + 1]; - git_oid oid; repo = cl_git_sandbox_init("testrepo.git"); test_object_inrepo("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo); - cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "HEAD~3")); - cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); + cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0)); git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); @@ -617,14 +608,12 @@ void test_refs_revparse__try_to_retrieve_sha_before_branch(void) git_reference *branch; git_object *target; char sha[GIT_OID_HEXSZ + 1]; - git_oid oid; repo = cl_git_sandbox_init("testrepo.git"); test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo); - cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "HEAD~3")); - cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); + cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0)); git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); @@ -655,14 +644,12 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void) git_reference *branch; git_object *target; char sha[GIT_OID_HEXSZ + 1]; - git_oid oid; repo = cl_git_sandbox_init("testrepo.git"); test_object_inrepo("c47800", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo); - cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "HEAD~3")); - cl_git_pass(git_object_lookup(&target, repo, &oid, GIT_OBJ_COMMIT)); + cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0)); git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); @@ -677,6 +664,8 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void) void test_refs_revparse__range(void) { + assert_invalid_single_spec("be3563a^1..be3563a"); + test_rangelike("be3563a^1..be3563a", "9fd738e8f7967c078dceed8190330fc8648ee56a", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", From 299a224be16368dc36bef4dc3f5e711ce35300cd Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 15 Apr 2013 12:00:04 -0700 Subject: [PATCH 7/9] Change git_revparse to output git_object pointers This will probably prevent many lookup/free operations in calling code. --- examples/diff.c | 6 ++---- examples/rev-list.c | 16 ++++++++++------ include/git2/revparse.h | 4 ++-- src/revparse.c | 21 ++++++++------------- src/revwalk.c | 8 +++++--- tests-clar/refs/revparse.c | 19 ++++++++++++------- tests-clar/repo/head.c | 8 ++------ tests-clar/reset/default.c | 12 +++--------- tests-clar/stash/drop.c | 15 +++++++-------- tests-clar/stash/save.c | 11 +++-------- 10 files changed, 54 insertions(+), 66 deletions(-) diff --git a/examples/diff.c b/examples/diff.c index 6fa0fee52..a977abd3f 100644 --- a/examples/diff.c +++ b/examples/diff.c @@ -15,12 +15,10 @@ static int resolve_to_tree( git_repository *repo, const char *identifier, git_tree **tree) { int err = 0; - git_oid oid; git_object *obj = NULL; - if (git_revparse(&oid, NULL, NULL, repo, identifier) < 0 || - git_object_lookup(&obj, repo, &oid, GIT_OBJ_ANY) < 0) - return GIT_ENOTFOUND; + if ((err =git_revparse(&obj, NULL, NULL, repo, identifier)) < 0) + return err; switch (git_object_type(obj)) { case GIT_OBJ_TREE: diff --git a/examples/rev-list.c b/examples/rev-list.c index 71a8180f7..1747f2041 100644 --- a/examples/rev-list.c +++ b/examples/rev-list.c @@ -25,16 +25,18 @@ static int push_commit(git_revwalk *walk, git_oid *oid, int hide) static int push_spec(git_repository *repo, git_revwalk *walk, const char *spec, int hide) { int error; - git_oid oid; + git_object *obj; - if ((error = git_revparse(&oid, NULL, NULL, repo, spec))) + if ((error = git_revparse(&obj, NULL, NULL, repo, spec)) < 0) return error; - return push_commit(walk, &oid, hide); + error = push_commit(walk, git_object_id(obj), hide); + git_object_free(obj); + return error; } static int push_range(git_repository *repo, git_revwalk *walk, const char *range, int hide) { - git_oid left, right; + git_object left, right; git_revparse_flag_t flags; int error = 0; @@ -45,11 +47,13 @@ static int push_range(git_repository *repo, git_revwalk *walk, const char *range return GIT_EINVALIDSPEC; } - if ((error = push_commit(walk, &left, !hide))) + if ((error = push_commit(walk, git_object_id(left), !hide))) goto out; - error = push_commit(walk, &right, hide); + error = push_commit(walk, git_object_id(right), hide); out: + git_object_free(left); + git_object_free(right); return error; } diff --git a/include/git2/revparse.h b/include/git2/revparse.h index 2bbbaa5e1..4f8c274a4 100644 --- a/include/git2/revparse.h +++ b/include/git2/revparse.h @@ -66,8 +66,8 @@ typedef enum { * @return 0 on success, GIT_INVALIDSPEC, GIT_ENOTFOUND, GIT_EAMBIGUOUS or an error code */ GIT_EXTERN(int) git_revparse( - git_oid *left, - git_oid *right, + git_object **left, + git_object **right, unsigned int *flags, git_repository *repo, const char *spec); diff --git a/src/revparse.c b/src/revparse.c index 5f591406e..62be3128a 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -870,8 +870,8 @@ cleanup: int git_revparse( - git_oid *left, - git_oid *right, + git_object **left, + git_object **right, unsigned int *flags, git_repository *repo, const char *spec) @@ -879,7 +879,6 @@ int git_revparse( unsigned int lflags = 0; const char *dotdot; int error = 0; - git_object *obj = NULL; assert(left && repo && spec); @@ -895,22 +894,18 @@ int git_revparse( rstr++; } - if (!(error = git_revparse_single(&obj, repo, lstr))) { - git_oid_cpy(left, git_object_id(obj)); - git_object_free(obj); + if ((error = git_revparse_single(left, repo, lstr)) < 0) { + return error; } - if (right && !(error = git_revparse_single(&obj, repo, rstr))) { - git_oid_cpy(right, git_object_id(obj)); - git_object_free(obj); + if (right && + (error = git_revparse_single(right, repo, rstr)) < 0) { + return error; } git__free((void*)lstr); } else { lflags = GIT_REVPARSE_SINGLE; - if (!(error = git_revparse_single(&obj, repo, spec))) { - git_oid_cpy(left, git_object_id(obj)); - git_object_free(obj); - } + error = git_revparse_single(left, repo, spec); } if (flags) diff --git a/src/revwalk.c b/src/revwalk.c index b22fef07f..05e99c0b6 100644 --- a/src/revwalk.c +++ b/src/revwalk.c @@ -231,7 +231,7 @@ int git_revwalk_push_ref(git_revwalk *walk, const char *refname) int git_revwalk_push_range(git_revwalk *walk, const char *range) { - git_oid left, right; + git_object *left, *right; git_revparse_flag_t revparseflags; int error = 0; @@ -243,11 +243,13 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range) return GIT_EINVALIDSPEC; } - if ((error = push_commit(walk, &left, 1))) + if ((error = push_commit(walk, git_object_id(left), 1))) goto out; - error = push_commit(walk, &right, 0); + error = push_commit(walk, git_object_id(right), 0); out: + git_object_free(left); + git_object_free(right); return error; } diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c index 8c3e5e43a..c1cfc58af 100644 --- a/tests-clar/refs/revparse.c +++ b/tests-clar/refs/revparse.c @@ -34,7 +34,7 @@ static void test_id_inrepo( git_revparse_flag_t expected_flags, git_repository *repo) { - git_oid l = {{0}}, r = {{0}}; + git_object *l, *r; git_revparse_flag_t flags = 0; int error = git_revparse(&l, &r, &flags, repo, spec); @@ -42,16 +42,18 @@ static void test_id_inrepo( if (expected_left) { char str[64] = {0}; cl_assert_equal_i(0, error); - git_oid_fmt(str, &l); + git_oid_fmt(str, git_object_id(l)); cl_assert_equal_s(str, expected_left); + git_object_free(l); } else { cl_assert_equal_i(GIT_ENOTFOUND, error); } if (expected_right) { char str[64] = {0}; - git_oid_fmt(str, &r); + git_oid_fmt(str, git_object_id(r)); cl_assert_equal_s(str, expected_right); + git_object_free(r); } if (expected_flags) @@ -69,7 +71,7 @@ static void test_rangelike(const char *rangelike, git_revparse_flag_t expected_revparseflags) { char objstr[64] = {0}; - git_oid left = {{0}}, right = {{0}}; + git_object *left = NULL, *right = NULL; git_revparse_flag_t revparseflags; int error; @@ -78,12 +80,15 @@ static void test_rangelike(const char *rangelike, if (expected_left != NULL) { cl_assert_equal_i(0, error); cl_assert_equal_i(revparseflags, expected_revparseflags); - git_oid_fmt(objstr, &left); + git_oid_fmt(objstr, git_object_id(left)); cl_assert_equal_s(objstr, expected_left); - git_oid_fmt(objstr, &right); + git_oid_fmt(objstr, git_object_id(right)); cl_assert_equal_s(objstr, expected_right); } else cl_assert(error != 0); + + git_object_free(left); + git_object_free(right); } @@ -681,7 +686,7 @@ void test_refs_revparse__range(void) void test_refs_revparse__validates_args(void) { - git_oid l={{0}}, r={{0}}; + git_object *l, *r; git_revparse_flag_t flags = 0; cl_git_pass(git_revparse(&l,&r,NULL, g_repo, "HEAD")); diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c index bb81bb087..a9f5cfc58 100644 --- a/tests-clar/repo/head.c +++ b/tests-clar/repo/head.c @@ -120,11 +120,9 @@ void test_repo_head__set_head_detached_Return_ENOTFOUND_when_the_object_doesnt_e void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void) { - git_oid oid; git_object *blob; - cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "point_to_blob")); - cl_git_pass(git_object_lookup(&blob, repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob")); cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob))); @@ -133,11 +131,9 @@ void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(vo void test_repo_head__set_head_detached_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void) { - git_oid oid; git_object *tag; - cl_git_pass(git_revparse(&oid, NULL, NULL, repo, "tags/test")); - cl_git_pass(git_object_lookup(&tag, repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&tag, repo, "tags/test")); cl_assert_equal_i(GIT_OBJ_TAG, git_object_type(tag)); cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag))); diff --git a/tests-clar/reset/default.c b/tests-clar/reset/default.c index bc8da7392..506d971ff 100644 --- a/tests-clar/reset/default.c +++ b/tests-clar/reset/default.c @@ -95,7 +95,6 @@ void test_reset_default__resetting_filepaths_against_a_null_target_removes_them_ void test_reset_default__resetting_filepaths_replaces_their_corresponding_index_entries(void) { git_strarray before, after; - git_oid oid; char *paths[] = { "staged_changes", "staged_changes_file_deleted" }; char *before_shas[] = { "55d316c9ba708999f1918e9677d01dfcae69c6b9", @@ -110,8 +109,7 @@ void test_reset_default__resetting_filepaths_replaces_their_corresponding_index_ after.strings = after_shas; after.count = 2; - cl_git_pass(git_revparse(&oid, NULL, NULL, _repo, "0017bd4")); - cl_git_pass(git_object_lookup(&_target, _repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&_target, _repo, "0017bd4")); assert_content_in_index(&_pathspecs, true, &before); cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); @@ -137,7 +135,6 @@ void test_reset_default__resetting_filepaths_clears_previous_conflicts(void) { git_index_entry *conflict_entry[3]; git_strarray after; - git_oid oid; char *paths[] = { "conflicts-one.txt" }; char *after_shas[] = { "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81" }; @@ -153,8 +150,7 @@ void test_reset_default__resetting_filepaths_clears_previous_conflicts(void) cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], _index, "conflicts-one.txt")); - cl_git_pass(git_revparse(&oid, NULL, NULL, _repo, "9a05ccb")); - cl_git_pass(git_object_lookup(&_target, _repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&_target, _repo, "9a05ccb")); cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); assert_content_in_index(&_pathspecs, true, &after); @@ -171,15 +167,13 @@ Unstaged changes after reset: void test_reset_default__resetting_unknown_filepaths_does_not_fail(void) { char *paths[] = { "I_am_not_there.txt", "me_neither.txt" }; - git_oid oid; _pathspecs.strings = paths; _pathspecs.count = 2; assert_content_in_index(&_pathspecs, false, NULL); - cl_git_pass(git_revparse(&oid, NULL, NULL, _repo, "HEAD")); - cl_git_pass(git_object_lookup(&_target, _repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_revparse_single(&_target, _repo, "HEAD")); cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); assert_content_in_index(&_pathspecs, false, NULL); diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c index da9e676a9..12f922630 100644 --- a/tests-clar/stash/drop.c +++ b/tests-clar/stash/drop.c @@ -140,30 +140,29 @@ void test_stash_drop__dropping_the_last_entry_removes_the_stash(void) void retrieve_top_stash_id(git_oid *out) { - git_oid top_stash_id; + git_object *top_stash; - cl_git_pass(git_revparse(&top_stash_id, NULL, NULL, repo, "stash@{0}")); + cl_git_pass(git_revparse_single(&top_stash, repo, "stash@{0}")); cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE)); - cl_assert_equal_i(true, git_oid_cmp(out, &top_stash_id) == 0); + cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0); } void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void) { - git_oid next_top_stash_id; + git_object *next_top_stash; git_oid oid; push_three_states(); retrieve_top_stash_id(&oid); - cl_git_pass(git_revparse(&next_top_stash_id, NULL, NULL, repo, "stash@{1}")); - cl_assert_equal_i(false, git_oid_cmp(&oid, &next_top_stash_id) == 0); + cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}")); + cl_assert_equal_i(false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0); cl_git_pass(git_stash_drop(repo, 0)); retrieve_top_stash_id(&oid); - cl_assert_equal_i( - true, git_oid_cmp(&oid, &next_top_stash_id) == 0); + cl_git_pass(git_oid_cmp(&oid, git_object_id(next_top_stash))); } diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c index 4185e549c..eae116ac5 100644 --- a/tests-clar/stash/save.c +++ b/tests-clar/stash/save.c @@ -37,11 +37,10 @@ void test_stash_save__cleanup(void) static void assert_object_oid(const char* revision, const char* expected_oid, git_otype type) { - git_oid oid; int result; git_object *obj; - result = git_revparse(&oid, NULL, NULL, repo, revision); + result = git_revparse_single(&obj, repo, revision); if (!expected_oid) { cl_assert_equal_i(GIT_ENOTFOUND, result); @@ -49,9 +48,7 @@ static void assert_object_oid(const char* revision, const char* expected_oid, gi } else cl_assert_equal_i(0, result); - cl_git_pass(git_oid_streq(&oid, expected_oid)); - - cl_git_pass(git_object_lookup(&obj, repo, &oid, GIT_OBJ_ANY)); + cl_git_pass(git_oid_streq(git_object_id(obj), expected_oid)); cl_assert_equal_i(type, git_object_type(obj)); git_object_free(obj); } @@ -147,11 +144,9 @@ void test_stash_save__can_keep_index(void) static void assert_commit_message_contains(const char *revision, const char *fragment) { - git_oid oid; git_commit *commit; - cl_git_pass(git_revparse(&oid, NULL, NULL, repo, revision)); - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); + cl_git_pass(git_revparse_single((git_object**)&commit, repo, revision)); cl_assert(strstr(git_commit_message(commit), fragment) != NULL); From 5961d5ea7f77cc442ec7d7c9f698f8c96c050298 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 15 Apr 2013 12:10:18 -0700 Subject: [PATCH 8/9] Clean up example code. --- examples/rev-list.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/rev-list.c b/examples/rev-list.c index 1747f2041..f309207b0 100644 --- a/examples/rev-list.c +++ b/examples/rev-list.c @@ -14,7 +14,7 @@ static void check_error(int error_code, const char *action) exit(1); } -static int push_commit(git_revwalk *walk, git_oid *oid, int hide) +static int push_commit(git_revwalk *walk, const git_oid *oid, int hide) { if (hide) return git_revwalk_hide(walk, oid); @@ -27,7 +27,7 @@ static int push_spec(git_repository *repo, git_revwalk *walk, const char *spec, int error; git_object *obj; - if ((error = git_revparse(&obj, NULL, NULL, repo, spec)) < 0) + if ((error = git_revparse_single(&obj, repo, spec)) < 0) return error; error = push_commit(walk, git_object_id(obj), hide); git_object_free(obj); @@ -36,7 +36,7 @@ static int push_spec(git_repository *repo, git_revwalk *walk, const char *spec, static int push_range(git_repository *repo, git_revwalk *walk, const char *range, int hide) { - git_object left, right; + git_object *left, *right; git_revparse_flag_t flags; int error = 0; From 201566539f38874b4e93c6a36593bd0d10e6352c Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 15 Apr 2013 13:29:40 -0700 Subject: [PATCH 9/9] Clean up minor details --- examples/diff.c | 2 +- include/git2/revparse.h | 4 +--- include/git2/revwalk.h | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/diff.c b/examples/diff.c index a977abd3f..2ef405665 100644 --- a/examples/diff.c +++ b/examples/diff.c @@ -17,7 +17,7 @@ static int resolve_to_tree( int err = 0; git_object *obj = NULL; - if ((err =git_revparse(&obj, NULL, NULL, repo, identifier)) < 0) + if ((err = git_revparse_single(&obj, repo, identifier)) < 0) return err; switch (git_object_type(obj)) { diff --git a/include/git2/revparse.h b/include/git2/revparse.h index 4f8c274a4..a992d2c48 100644 --- a/include/git2/revparse.h +++ b/include/git2/revparse.h @@ -21,7 +21,6 @@ GIT_BEGIN_DECL /** - * * Find a single object, as specified by a revision string. See `man gitrevisions`, * or http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for * information on the syntax accepted. @@ -31,8 +30,7 @@ GIT_BEGIN_DECL * @param spec the textual specification for an object * @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS, GIT_EINVALIDSPEC or an error code */ -GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, - const char *spec); +GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, const char *spec); /** diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h index c9f7372e9..8bfe0b502 100644 --- a/include/git2/revwalk.h +++ b/include/git2/revwalk.h @@ -221,7 +221,7 @@ GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); * * The range should be of the form * .. - * where each is in the form accepted by 'git_revparse'. + * where each is in the form accepted by 'git_revparse_single'. * The left-hand commit will be hidden and the right-hand commit pushed. * * @param walk the walker being used for the traversal