Deprecate git_revparse_single and _rangelike
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
diff --git a/examples/diff.c b/examples/diff.c
index a153b49..6fa0fee 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 b7e466f..71a8180 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 "<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;
diff --git a/include/git2/revparse.h b/include/git2/revparse.h
index 9315b66..7fe910b 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 8bfe0b5..c9f7372 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
* <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
diff --git a/src/push.c b/src/push.c
index 37f6418..dcd8122 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);
-
- 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)
diff --git a/src/revparse.c b/src/revparse.c
index 2ba42d8..7842c49 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 c107184..b22fef0 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 "<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;
}
diff --git a/src/transports/local.c b/src/transports/local.c
index ce89bb2..1e27fc3 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 5a2eace..ae4087f 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 b92cc23..7452131 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 2c4cba4..d86c1f4 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 ab8839f..39e77c8 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 a9f5cfc..bb81bb0 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 506d971..bc8da73 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 d171390..da9e676 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 588dfc3..4185e54 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);