Change the object creation/lookup API The methods previously known as git_repository_lookup git_repository_newobject git_repository_lookup_ref are now part of their respective namespaces: git_object_lookup git_object_new git_reference_lookup This makes the API more consistent with the new references API. Signed-off-by: Vicent Marti <tanoku@gmail.com>
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 931 932 933 934 935 936 937 938
diff --git a/src/commit.c b/src/commit.c
index 49e2354..44e1e94 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -121,7 +121,7 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
if ((error = git__parse_oid(&oid, &buffer, buffer_end, "tree ")) < GIT_SUCCESS)
return error;
- if ((error = git_repository_lookup((git_object **)&commit->tree, commit->object.repo, &oid, GIT_OBJ_TREE)) < GIT_SUCCESS)
+ if ((error = git_object_lookup((git_object **)&commit->tree, commit->object.repo, &oid, GIT_OBJ_TREE)) < GIT_SUCCESS)
return error;
/*
@@ -131,7 +131,7 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
while (git__parse_oid(&oid, &buffer, buffer_end, "parent ") == GIT_SUCCESS) {
git_commit *parent;
- if ((error = git_repository_lookup((git_object **)&parent, commit->object.repo, &oid, GIT_OBJ_COMMIT)) < GIT_SUCCESS)
+ if ((error = git_object_lookup((git_object **)&parent, commit->object.repo, &oid, GIT_OBJ_COMMIT)) < GIT_SUCCESS)
return error;
if (git_vector_insert(&commit->parents, parent) < GIT_SUCCESS)
diff --git a/src/git2/blob.h b/src/git2/blob.h
index b34b5bf..b527d61 100644
--- a/src/git2/blob.h
+++ b/src/git2/blob.h
@@ -28,7 +28,7 @@
#include "common.h"
#include "types.h"
#include "oid.h"
-#include "repository.h"
+#include "object.h"
/**
* @file git2/blob.h
@@ -51,7 +51,7 @@ GIT_BEGIN_DECL
*/
GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id)
{
- return git_repository_lookup((git_object **)blob, repo, id, GIT_OBJ_BLOB);
+ return git_object_lookup((git_object **)blob, repo, id, GIT_OBJ_BLOB);
}
/**
@@ -67,7 +67,7 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
*/
GIT_INLINE(int) git_blob_new(git_blob **blob, git_repository *repo)
{
- return git_repository_newobject((git_object **)blob, repo, GIT_OBJ_BLOB);
+ return git_object_new((git_object **)blob, repo, GIT_OBJ_BLOB);
}
/**
diff --git a/src/git2/commit.h b/src/git2/commit.h
index 4d0b2ab..21836db 100644
--- a/src/git2/commit.h
+++ b/src/git2/commit.h
@@ -28,7 +28,7 @@
#include "common.h"
#include "types.h"
#include "oid.h"
-#include "repository.h"
+#include "object.h"
/**
* @file git2/commit.h
@@ -52,7 +52,7 @@ GIT_BEGIN_DECL
*/
GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id)
{
- return git_repository_lookup((git_object **)commit, repo, id, GIT_OBJ_COMMIT);
+ return git_object_lookup((git_object **)commit, repo, id, GIT_OBJ_COMMIT);
}
/**
@@ -68,7 +68,7 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con
*/
GIT_INLINE(int) git_commit_new(git_commit **commit, git_repository *repo)
{
- return git_repository_newobject((git_object **)commit, repo, GIT_OBJ_COMMIT);
+ return git_object_new((git_object **)commit, repo, GIT_OBJ_COMMIT);
}
/**
diff --git a/src/git2/object.h b/src/git2/object.h
index 128c9fa..80477d4 100644
--- a/src/git2/object.h
+++ b/src/git2/object.h
@@ -39,6 +39,49 @@
GIT_BEGIN_DECL
/**
+ * Lookup a reference to one of the objects in a repostory.
+ *
+ * The generated reference is owned by the repository and
+ * should not be freed by the user.
+ *
+ * The 'type' parameter must match the type of the object
+ * in the odb; the method will fail otherwise.
+ * The special value 'GIT_OBJ_ANY' may be passed to let
+ * the method guess the object's type.
+ *
+ * @param object pointer to the looked-up object
+ * @param repo the repository to look up the object
+ * @param id the unique identifier for the object
+ * @param type the type of the object
+ * @return a reference to the object
+ */
+GIT_EXTERN(int) git_object_lookup(git_object **object, git_repository *repo, const git_oid *id, git_otype type);
+
+/**
+ * Create a new in-memory repository object with
+ * the given type.
+ *
+ * The object's attributes can be filled in using the
+ * corresponding setter methods.
+ *
+ * The object will be written back to given git_repository
+ * when the git_object_write() function is called; objects
+ * cannot be written to disk until all their main
+ * attributes have been properly filled.
+ *
+ * Objects are instantiated with no SHA1 id; their id
+ * will be automatically generated when writing to the
+ * repository.
+ *
+ * @param object pointer to the new object
+ * @parem repo Repository where the object belongs
+ * @param type Type of the object to be created
+ * @return the new object
+ */
+GIT_EXTERN(int) git_object_new(git_object **object, git_repository *repo, git_otype type);
+
+
+/**
* Write back an object to disk.
*
* The object will be written to its corresponding
diff --git a/src/git2/refs.h b/src/git2/refs.h
index 752d808..1702d7e 100644
--- a/src/git2/refs.h
+++ b/src/git2/refs.h
@@ -39,6 +39,19 @@
GIT_BEGIN_DECL
/**
+ * Lookup a reference by its name in a repository.
+ *
+ * The generated reference is owned by the repository and
+ * should not be freed by the user.
+ *
+ * @param reference_out pointer to the looked-up reference
+ * @param repo the repository to look up the reference
+ * @param name the long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...)
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name);
+
+/**
* Create a new symbolic reference.
*
* The reference will be created in the repository and written
diff --git a/src/git2/repository.h b/src/git2/repository.h
index ec74305..dbb9ddd 100644
--- a/src/git2/repository.h
+++ b/src/git2/repository.h
@@ -132,26 +132,6 @@ GIT_EXTERN(int) git_repository_open3(git_repository **repository,
const char *git_index_file,
const char *git_work_tree);
-
-/**
- * Lookup a reference to one of the objects in the repostory.
- *
- * The generated reference is owned by the repository and
- * should not be freed by the user.
- *
- * The 'type' parameter must match the type of the object
- * in the odb; the method will fail otherwise.
- * The special value 'GIT_OBJ_ANY' may be passed to let
- * the method guess the object's type.
- *
- * @param object pointer to the looked-up object
- * @param repo the repository to look up the object
- * @param id the unique identifier for the object
- * @param type the type of the object
- * @return a reference to the object
- */
-GIT_EXTERN(int) git_repository_lookup(git_object **object, git_repository *repo, const git_oid *id, git_otype type);
-
/**
* Get the object database behind a Git repository
*
@@ -173,29 +153,6 @@ GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo);
GIT_EXTERN(int) git_repository_index(git_index **index, git_repository *repo);
/**
- * Create a new in-memory repository object with
- * the given type.
- *
- * The object's attributes can be filled in using the
- * corresponding setter methods.
- *
- * The object will be written back to given git_repository
- * when the git_object_write() function is called; objects
- * cannot be written to disk until all their main
- * attributes have been properly filled.
- *
- * Objects are instantiated with no SHA1 id; their id
- * will be automatically generated when writing to the
- * repository.
- *
- * @param object pointer to the new object
- * @parem repo Repository where the object belongs
- * @param type Type of the object to be created
- * @return the new object
- */
-GIT_EXTERN(int) git_repository_newobject(git_object **object, git_repository *repo, git_otype type);
-
-/**
* Free a previously allocated repository
* @param repo repository handle to close. If NULL nothing occurs.
*/
@@ -218,22 +175,6 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo);
*/
GIT_EXTERN(int) git_repository_init(git_repository **repo_out, const char *path, unsigned is_bare);
-/**
- * Lookup a reference by its name in the repository.
- *
- * The generated reference is owned by the repository and
- * should not be freed by the user.
- *
- * TODO:
- * - Ensure the reference name is valid
- *
- * @param reference_out pointer to the looked-up reference
- * @param repo the repository to look up the reference
- * @param name the long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...)
- * @return a reference to the reference
- */
-GIT_EXTERN(int) git_repository_lookup_ref(git_reference **reference_out, git_repository *repo, const char *name);
-
/** @} */
GIT_END_DECL
#endif
diff --git a/src/git2/tag.h b/src/git2/tag.h
index 4fd6ea9..2ca25c8 100644
--- a/src/git2/tag.h
+++ b/src/git2/tag.h
@@ -28,7 +28,7 @@
#include "common.h"
#include "types.h"
#include "oid.h"
-#include "repository.h"
+#include "object.h"
/**
* @file git2/tag.h
@@ -51,7 +51,7 @@ GIT_BEGIN_DECL
*/
GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oid *id)
{
- return git_repository_lookup((git_object **)tag, repo, id, (git_otype)GIT_OBJ_TAG);
+ return git_object_lookup((git_object **)tag, repo, id, (git_otype)GIT_OBJ_TAG);
}
/**
@@ -67,7 +67,7 @@ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oi
*/
GIT_INLINE(int) git_tag_new(git_tag **tag, git_repository *repo)
{
- return git_repository_newobject((git_object **)tag, repo, (git_otype)GIT_OBJ_TAG);
+ return git_object_new((git_object **)tag, repo, (git_otype)GIT_OBJ_TAG);
}
/**
diff --git a/src/git2/tree.h b/src/git2/tree.h
index 20c3675..70040f0 100644
--- a/src/git2/tree.h
+++ b/src/git2/tree.h
@@ -28,7 +28,7 @@
#include "common.h"
#include "types.h"
#include "oid.h"
-#include "repository.h"
+#include "object.h"
/**
* @file git2/tree.h
@@ -51,7 +51,7 @@ GIT_BEGIN_DECL
*/
GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git_oid *id)
{
- return git_repository_lookup((git_object **)tree, repo, id, GIT_OBJ_TREE);
+ return git_object_lookup((git_object **)tree, repo, id, GIT_OBJ_TREE);
}
/**
@@ -67,7 +67,7 @@ GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git
*/
GIT_INLINE(int) git_tree_new(git_tree **tree, git_repository *repo)
{
- return git_repository_newobject((git_object **)tree, repo, GIT_OBJ_TREE);
+ return git_object_new((git_object **)tree, repo, GIT_OBJ_TREE);
}
/**
diff --git a/src/object.c b/src/object.c
index c53a3ac..c9809c5 100644
--- a/src/object.c
+++ b/src/object.c
@@ -209,6 +209,125 @@ void git_object__source_close(git_object *object)
}
}
+static int create_object(git_object **object_out, git_otype type)
+{
+ git_object *object = NULL;
+
+ assert(object_out);
+
+ *object_out = NULL;
+
+ switch (type) {
+ case GIT_OBJ_COMMIT:
+ case GIT_OBJ_TAG:
+ case GIT_OBJ_BLOB:
+ object = git__malloc(git_object__size(type));
+ if (object == NULL)
+ return GIT_ENOMEM;
+ memset(object, 0x0, git_object__size(type));
+ break;
+
+ case GIT_OBJ_TREE:
+ object = (git_object *)git_tree__new();
+ if (object == NULL)
+ return GIT_ENOMEM;
+ break;
+
+ default:
+ return GIT_EINVALIDTYPE;
+ }
+
+ *object_out = object;
+ return GIT_SUCCESS;
+}
+
+int git_object_new(git_object **object_out, git_repository *repo, git_otype type)
+{
+ git_object *object = NULL;
+ int error;
+
+ assert(object_out && repo);
+
+ if ((error = create_object(&object, type)) < GIT_SUCCESS)
+ return error;
+
+ object->repo = repo;
+ object->in_memory = 1;
+ object->modified = 1;
+
+ object->source.raw.type = type;
+
+ *object_out = object;
+ return GIT_SUCCESS;
+}
+
+int git_object_lookup(git_object **object_out, git_repository *repo, const git_oid *id, git_otype type)
+{
+ git_object *object = NULL;
+ git_rawobj obj_file;
+ int error = GIT_SUCCESS;
+
+ assert(repo && object_out && id);
+
+ object = git_hashtable_lookup(repo->objects, id);
+ if (object != NULL) {
+ *object_out = object;
+ return GIT_SUCCESS;
+ }
+
+ error = git_odb_read(&obj_file, repo->db, id);
+ if (error < GIT_SUCCESS)
+ return error;
+
+ if (type != GIT_OBJ_ANY && type != obj_file.type) {
+ git_rawobj_close(&obj_file);
+ return GIT_EINVALIDTYPE;
+ }
+
+ type = obj_file.type;
+
+ if ((error = create_object(&object, type)) < GIT_SUCCESS)
+ return error;
+
+ /* Initialize parent object */
+ git_oid_cpy(&object->id, id);
+ object->repo = repo;
+ memcpy(&object->source.raw, &obj_file, sizeof(git_rawobj));
+ object->source.open = 1;
+
+ switch (type) {
+ case GIT_OBJ_COMMIT:
+ error = git_commit__parse((git_commit *)object);
+ break;
+
+ case GIT_OBJ_TREE:
+ error = git_tree__parse((git_tree *)object);
+ break;
+
+ case GIT_OBJ_TAG:
+ error = git_tag__parse((git_tag *)object);
+ break;
+
+ case GIT_OBJ_BLOB:
+ error = git_blob__parse((git_blob *)object);
+ break;
+
+ default:
+ break;
+ }
+
+ if (error < GIT_SUCCESS) {
+ git_object_free(object);
+ return error;
+ }
+
+ git_object__source_close(object);
+ git_hashtable_insert(repo->objects, &object->id, object);
+
+ *object_out = object;
+ return GIT_SUCCESS;
+}
+
int git_object_write(git_object *object)
{
int error;
diff --git a/src/refs.c b/src/refs.c
index 90123f1..f8da561 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -818,7 +818,7 @@ cleanup:
/**
* Constructors
*/
-int git_repository_lookup_ref(git_reference **ref_out, git_repository *repo, const char *name)
+int git_reference_lookup(git_reference **ref_out, git_repository *repo, const char *name)
{
int error;
char normalized_name[GIT_PATH_MAX];
@@ -1118,7 +1118,7 @@ int git_reference_delete(git_reference *ref)
/* When deleting a loose reference, we have to ensure that an older
* packed version of it doesn't exist
*/
- if (!git_repository_lookup_ref(&reference, ref->owner, ref->name)) {
+ if (!git_reference_lookup(&reference, ref->owner, ref->name)) {
assert((reference->type & GIT_REF_PACKED) != 0);
error = git_reference_delete(reference);
}
@@ -1157,7 +1157,7 @@ int git_reference_rename(git_reference *ref, const char *new_name)
return error;
/* Ensure we're not going to overwrite an existing reference */
- error = git_repository_lookup_ref(&looked_up_ref, ref->owner, new_name);
+ error = git_reference_lookup(&looked_up_ref, ref->owner, new_name);
if (error == GIT_SUCCESS)
return GIT_EINVALIDREFNAME;
@@ -1269,7 +1269,7 @@ int git_reference_resolve(git_reference **resolved_ref, git_reference *ref)
}
ref_sym = (reference_symbolic *)ref;
- if ((error = git_repository_lookup_ref(&ref, repo, ref_sym->target)) < GIT_SUCCESS)
+ if ((error = git_reference_lookup(&ref, repo, ref_sym->target)) < GIT_SUCCESS)
return error;
}
diff --git a/src/repository.c b/src/repository.c
index 9d457b7..77ce0c0 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -379,125 +379,6 @@ git_odb *git_repository_database(git_repository *repo)
return repo->db;
}
-static int create_object(git_object **object_out, git_otype type)
-{
- git_object *object = NULL;
-
- assert(object_out);
-
- *object_out = NULL;
-
- switch (type) {
- case GIT_OBJ_COMMIT:
- case GIT_OBJ_TAG:
- case GIT_OBJ_BLOB:
- object = git__malloc(git_object__size(type));
- if (object == NULL)
- return GIT_ENOMEM;
- memset(object, 0x0, git_object__size(type));
- break;
-
- case GIT_OBJ_TREE:
- object = (git_object *)git_tree__new();
- if (object == NULL)
- return GIT_ENOMEM;
- break;
-
- default:
- return GIT_EINVALIDTYPE;
- }
-
- *object_out = object;
- return GIT_SUCCESS;
-}
-
-int git_repository_newobject(git_object **object_out, git_repository *repo, git_otype type)
-{
- git_object *object = NULL;
- int error;
-
- assert(object_out && repo);
-
- if ((error = create_object(&object, type)) < GIT_SUCCESS)
- return error;
-
- object->repo = repo;
- object->in_memory = 1;
- object->modified = 1;
-
- object->source.raw.type = type;
-
- *object_out = object;
- return GIT_SUCCESS;
-}
-
-int git_repository_lookup(git_object **object_out, git_repository *repo, const git_oid *id, git_otype type)
-{
- git_object *object = NULL;
- git_rawobj obj_file;
- int error = GIT_SUCCESS;
-
- assert(repo && object_out && id);
-
- object = git_hashtable_lookup(repo->objects, id);
- if (object != NULL) {
- *object_out = object;
- return GIT_SUCCESS;
- }
-
- error = git_odb_read(&obj_file, repo->db, id);
- if (error < GIT_SUCCESS)
- return error;
-
- if (type != GIT_OBJ_ANY && type != obj_file.type) {
- git_rawobj_close(&obj_file);
- return GIT_EINVALIDTYPE;
- }
-
- type = obj_file.type;
-
- if ((error = create_object(&object, type)) < GIT_SUCCESS)
- return error;
-
- /* Initialize parent object */
- git_oid_cpy(&object->id, id);
- object->repo = repo;
- memcpy(&object->source.raw, &obj_file, sizeof(git_rawobj));
- object->source.open = 1;
-
- switch (type) {
- case GIT_OBJ_COMMIT:
- error = git_commit__parse((git_commit *)object);
- break;
-
- case GIT_OBJ_TREE:
- error = git_tree__parse((git_tree *)object);
- break;
-
- case GIT_OBJ_TAG:
- error = git_tag__parse((git_tag *)object);
- break;
-
- case GIT_OBJ_BLOB:
- error = git_blob__parse((git_blob *)object);
- break;
-
- default:
- break;
- }
-
- if (error < GIT_SUCCESS) {
- git_object_free(object);
- return error;
- }
-
- git_object__source_close(object);
- git_hashtable_insert(repo->objects, &object->id, object);
-
- *object_out = object;
- return GIT_SUCCESS;
-}
-
static int repo_init_reinit(repo_init *results)
{
/* TODO: reinit the repository */
diff --git a/src/tag.c b/src/tag.c
index 4c6cabf..7d57ee0 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -164,7 +164,7 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
if (tag->type == GIT_OBJ_BAD)
return GIT_EOBJCORRUPTED;
- error = git_repository_lookup(&tag->target, tag->object.repo, &target_oid, tag->type);
+ error = git_object_lookup(&tag->target, tag->object.repo, &target_oid, tag->type);
if (error < 0)
return error;
diff --git a/src/tree.c b/src/tree.c
index a23be91..656798c 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -153,7 +153,7 @@ const git_oid *git_tree_entry_id(git_tree_entry *entry)
int git_tree_entry_2object(git_object **object_out, git_tree_entry *entry)
{
assert(entry && object_out);
- return git_repository_lookup(object_out, entry->owner->object.repo, &entry->oid, GIT_OBJ_ANY);
+ return git_object_lookup(object_out, entry->owner->object.repo, &entry->oid, GIT_OBJ_ANY);
}
static void sort_entries(git_tree *tree)
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index 225b4e0..abe3641 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -37,12 +37,12 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference")
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&reference, repo, loose_tag_ref_name));
+ must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name));
must_be_true(reference->type & GIT_REF_OID);
must_be_true((reference->type & GIT_REF_PACKED) == 0);
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
- must_pass(git_repository_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY));
+ must_pass(git_object_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_TAG);
@@ -54,7 +54,7 @@ BEGIN_TEST(readtag1, "lookup a loose tag reference that doesn't exist")
git_reference *reference;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_fail(git_repository_lookup_ref(&reference, repo, non_existing_tag_ref_name));
+ must_fail(git_reference_lookup(&reference, repo, non_existing_tag_ref_name));
git_repository_free(repo);
END_TEST
@@ -71,7 +71,7 @@ BEGIN_TEST(readsym0, "lookup a symbolic reference")
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&reference, repo, GIT_HEAD_FILE));
+ must_pass(git_reference_lookup(&reference, repo, GIT_HEAD_FILE));
must_be_true(reference->type & GIT_REF_SYMBOLIC);
must_be_true((reference->type & GIT_REF_PACKED) == 0);
must_be_true(strcmp(reference->name, GIT_HEAD_FILE) == 0);
@@ -79,7 +79,7 @@ BEGIN_TEST(readsym0, "lookup a symbolic reference")
must_pass(git_reference_resolve(&resolved_ref, reference));
must_be_true(resolved_ref->type == GIT_REF_OID);
- must_pass(git_repository_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY));
+ must_pass(git_object_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_COMMIT);
@@ -97,7 +97,7 @@ BEGIN_TEST(readsym1, "lookup a nested symbolic reference")
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&reference, repo, head_tracker_sym_ref_name));
+ must_pass(git_reference_lookup(&reference, repo, head_tracker_sym_ref_name));
must_be_true(reference->type & GIT_REF_SYMBOLIC);
must_be_true((reference->type & GIT_REF_PACKED) == 0);
must_be_true(strcmp(reference->name, head_tracker_sym_ref_name) == 0);
@@ -105,7 +105,7 @@ BEGIN_TEST(readsym1, "lookup a nested symbolic reference")
must_pass(git_reference_resolve(&resolved_ref, reference));
must_be_true(resolved_ref->type == GIT_REF_OID);
- must_pass(git_repository_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY));
+ must_pass(git_object_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_COMMIT);
@@ -121,15 +121,15 @@ BEGIN_TEST(readsym2, "lookup the HEAD and resolve the master branch")
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&reference, repo, head_tracker_sym_ref_name));
+ must_pass(git_reference_lookup(&reference, repo, head_tracker_sym_ref_name));
must_pass(git_reference_resolve(&resolved_ref, reference));
comp_base_ref = resolved_ref;
- must_pass(git_repository_lookup_ref(&reference, repo, GIT_HEAD_FILE));
+ must_pass(git_reference_lookup(&reference, repo, GIT_HEAD_FILE));
must_pass(git_reference_resolve(&resolved_ref, reference));
must_pass(git_oid_cmp(git_reference_oid(comp_base_ref), git_reference_oid(resolved_ref)));
- must_pass(git_repository_lookup_ref(&reference, repo, current_head_target));
+ must_pass(git_reference_lookup(&reference, repo, current_head_target));
must_pass(git_reference_resolve(&resolved_ref, reference));
must_pass(git_oid_cmp(git_reference_oid(comp_base_ref), git_reference_oid(resolved_ref)));
@@ -142,8 +142,8 @@ BEGIN_TEST(readsym3, "lookup the master branch and then the HEAD")
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&master_ref, repo, current_head_target));
- must_pass(git_repository_lookup_ref(&reference, repo, GIT_HEAD_FILE));
+ must_pass(git_reference_lookup(&master_ref, repo, current_head_target));
+ must_pass(git_reference_lookup(&reference, repo, GIT_HEAD_FILE));
must_pass(git_reference_resolve(&resolved_ref, reference));
must_pass(git_oid_cmp(git_reference_oid(master_ref), git_reference_oid(resolved_ref)));
@@ -161,12 +161,12 @@ BEGIN_TEST(readpacked0, "lookup a packed reference")
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&reference, repo, packed_head_name));
+ must_pass(git_reference_lookup(&reference, repo, packed_head_name));
must_be_true(reference->type & GIT_REF_OID);
must_be_true((reference->type & GIT_REF_PACKED) != 0);
must_be_true(strcmp(reference->name, packed_head_name) == 0);
- must_pass(git_repository_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY));
+ must_pass(git_object_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_COMMIT);
@@ -178,8 +178,8 @@ BEGIN_TEST(readpacked1, "assure that a loose reference is looked up before a pac
git_reference *reference;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&reference, repo, packed_head_name));
- must_pass(git_repository_lookup_ref(&reference, repo, packed_test_head_name));
+ must_pass(git_reference_lookup(&reference, repo, packed_head_name));
+ must_pass(git_reference_lookup(&reference, repo, packed_test_head_name));
must_be_true(reference->type & GIT_REF_OID);
must_be_true((reference->type & GIT_REF_PACKED) == 0);
must_be_true(strcmp(reference->name, packed_test_head_name) == 0);
@@ -206,7 +206,7 @@ BEGIN_TEST(create0, "create a new symbolic reference")
must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target));
/* Ensure the reference can be looked-up... */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, new_head_tracker));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker));
must_be_true(looked_up_ref->type & GIT_REF_SYMBOLIC);
must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0);
must_be_true(strcmp(looked_up_ref->name, new_head_tracker) == 0);
@@ -223,7 +223,7 @@ BEGIN_TEST(create0, "create a new symbolic reference")
/* Similar test with a fresh new repository */
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, new_head_tracker));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker));
must_pass(git_reference_resolve(&resolved_ref, looked_up_ref));
must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0);
@@ -246,7 +246,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference")
git__joinpath(ref_path, repo->path_repository, new_head_tracker);
must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target));
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, new_head_tracker));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker));
must_pass(git_reference_resolve(&resolved_ref, looked_up_ref));
must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0);
@@ -274,7 +274,7 @@ BEGIN_TEST(create2, "create a new OID reference")
must_pass(git_reference_create_oid(&new_reference, repo, new_head, &id));
/* Ensure the reference can be looked-up... */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, new_head));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head));
must_be_true(looked_up_ref->type & GIT_REF_OID);
must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0);
must_be_true(strcmp(looked_up_ref->name, new_head) == 0);
@@ -287,7 +287,7 @@ BEGIN_TEST(create2, "create a new OID reference")
/* Similar test with a fresh new repository */
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, new_head));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head));
must_be_true(git_oid_cmp(&id, git_reference_oid(looked_up_ref)) == 0);
git_repository_free(repo);
@@ -318,7 +318,7 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure a known loose ref can be looked up */
- must_pass(git_repository_lookup_ref(&reference, repo, loose_tag_ref_name));
+ must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name));
must_be_true((reference->type & GIT_REF_PACKED) == 0);
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
@@ -329,7 +329,7 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_pass(gitfo_exists(temp_path));
/* Ensure the known ref can still be looked up but is now packed */
- must_pass(git_repository_lookup_ref(&reference, repo, loose_tag_ref_name));
+ must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name));
must_be_true((reference->type & GIT_REF_PACKED) != 0);
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
@@ -353,7 +353,7 @@ BEGIN_TEST(rename0, "rename a loose reference")
must_pass(!gitfo_exists(temp_path));
/* Retrieval of the reference to rename */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, loose_tag_ref_name));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, loose_tag_ref_name));
/* ... which is indeed loose */
must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0);
@@ -363,10 +363,10 @@ BEGIN_TEST(rename0, "rename a loose reference")
must_be_true(!strcmp(looked_up_ref->name, new_name));
/* ...It can't be looked-up with the old name... */
- must_fail(git_repository_lookup_ref(&another_looked_up_ref, repo, loose_tag_ref_name));
+ must_fail(git_reference_lookup(&another_looked_up_ref, repo, loose_tag_ref_name));
/* ...but the new name works ok... */
- must_pass(git_repository_lookup_ref(&another_looked_up_ref, repo, new_name));
+ must_pass(git_reference_lookup(&another_looked_up_ref, repo, new_name));
must_be_true(!strcmp(another_looked_up_ref->name, new_name));
/* .. the ref is still loose... */
@@ -393,7 +393,7 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
must_pass(!gitfo_exists(temp_path));
/* The reference can however be looked-up... */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_head_name));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
/* .. and it's packed */
must_be_true((looked_up_ref->type & GIT_REF_PACKED) != 0);
@@ -403,10 +403,10 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
must_be_true(!strcmp(looked_up_ref->name, brand_new_name));
/* ...It can't be looked-up with the old name... */
- must_fail(git_repository_lookup_ref(&another_looked_up_ref, repo, packed_head_name));
+ must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_head_name));
/* ...but the new name works ok... */
- must_pass(git_repository_lookup_ref(&another_looked_up_ref, repo, brand_new_name));
+ must_pass(git_reference_lookup(&another_looked_up_ref, repo, brand_new_name));
must_be_true(!strcmp(another_looked_up_ref->name, brand_new_name));
/* .. the ref is no longer packed... */
@@ -433,13 +433,13 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference
must_pass(gitfo_exists(temp_path));
/* Lookup the other reference */
- must_pass(git_repository_lookup_ref(&another_looked_up_ref, repo, packed_test_head_name));
+ must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
/* Ensure it's loose */
must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0);
/* Lookup the reference to rename */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_head_name));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
/* Ensure it's packed */
must_be_true((looked_up_ref->type & GIT_REF_PACKED) != 0);
@@ -448,7 +448,7 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference
must_pass(git_reference_rename(looked_up_ref, brand_new_name));
/* Lookup the other reference */
- must_pass(git_repository_lookup_ref(&another_looked_up_ref, repo, packed_test_head_name));
+ must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
/* Ensure it's loose */
must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0);
@@ -466,13 +466,13 @@ BEGIN_TEST(rename3, "can not rename a reference with the name of an existing ref
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* An existing reference... */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_head_name));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
/* Can not be renamed to the name of another existing reference. */
must_fail(git_reference_rename(looked_up_ref, packed_test_head_name));
/* Failure to rename it hasn't corrupted its state */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_head_name));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
must_be_true(!strcmp(looked_up_ref->name, packed_head_name));
close_temp_repo(repo);
@@ -485,7 +485,7 @@ BEGIN_TEST(rename4, "can not rename a reference with an invalid name")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* An existing oid reference... */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_test_head_name));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));
/* Can not be renamed with an invalid name. */
must_fail(git_reference_rename(looked_up_ref, "Hello! I'm a very invalid name."));
@@ -494,7 +494,7 @@ BEGIN_TEST(rename4, "can not rename a reference with an invalid name")
must_fail(git_reference_rename(looked_up_ref, "i-will-sudo-you"));
/* Failure to rename it hasn't corrupted its state */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_test_head_name));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));
must_be_true(!strcmp(looked_up_ref->name, packed_test_head_name));
close_temp_repo(repo);
@@ -512,7 +512,7 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove
must_pass(gitfo_exists(temp_path));
/* Lookup the reference */
- must_pass(git_repository_lookup_ref(&looked_up_ref, repo, packed_test_head_name));
+ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));
/* Ensure it's the loose version that has been found */
must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0);
@@ -521,7 +521,7 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove
must_pass(git_reference_delete(looked_up_ref));
/* Looking up the reference once again should not retrieve it */
- must_fail(git_repository_lookup_ref(&another_looked_up_ref, repo, packed_test_head_name));
+ must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
/* Ensure the loose reference doesn't exist any longer on the file system */
must_pass(!gitfo_exists(temp_path));