Commit 1aa21fe3 by Ben Straub

Deprecate git_revparse_single and _rangelike

parent 8480eef7
......@@ -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)) {
......
......@@ -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 "<commit>...<commit>" */
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;
......
......@@ -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
......
......@@ -221,7 +221,7 @@ GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
*
* The range should be of the form
* <commit>..<commit>
* where each <commit> is in the form accepted by 'git_revparse_single'.
* where each <commit> 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
......
......@@ -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);
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);
git_oid oid;
int error = git_revparse(&oid, NULL, NULL, push->repo, ref);
return -1;
} else
git_object_free(obj);
if (!error)
return 0;
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)
......
......@@ -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,
......
......@@ -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 "<commit>...<commit>" */
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;
}
......
......@@ -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();
}
......
......@@ -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;
......
......@@ -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");
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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)));
......
......@@ -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);
......
......@@ -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);
}
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment