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)) {
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;
*/
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
*
* 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
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)
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;
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,
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;
}
/* 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();
}
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));
}
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/"));
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"));
/* 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"));
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/"));
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));
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(
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));
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(
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));
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));
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(
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 */
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;
{
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;
{
int i;
git_object *obj;
+ git_oid oid;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
notify_counts cts = {0};
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");
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);
#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(
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);
}
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)
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");
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);
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);
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)
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));
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);
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));
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));
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));
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);
}
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)));
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)));
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",
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));
{
git_index_entry *conflict_entry[3];
git_strarray after;
+ git_oid oid;
char *paths[] = { "conflicts-one.txt" };
char *after_shas[] = { "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81" };
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);
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);
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);
}
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);
} 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)
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);