Merge pull request #1518 from arrbee/export-oid-comparison Remove most inlines from the public API
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
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 0a2aa9d..8fca489 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -29,10 +29,7 @@ GIT_BEGIN_DECL
* @param id identity of the blob to locate.
* @return 0 or an error code
*/
-GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id)
-{
- return git_object_lookup((git_object **)blob, repo, id, GIT_OBJ_BLOB);
-}
+GIT_EXTERN(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id);
/**
* Lookup a blob object from a repository,
@@ -46,10 +43,7 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
* @param len the length of the short identifier
* @return 0 or an error code
*/
-GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len)
-{
- return git_object_lookup_prefix((git_object **)blob, repo, id, len, GIT_OBJ_BLOB);
-}
+GIT_EXTERN(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len);
/**
* Close an open blob
@@ -62,11 +56,7 @@ GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, co
*
* @param blob the blob to close
*/
-
-GIT_INLINE(void) git_blob_free(git_blob *blob)
-{
- git_object_free((git_object *) blob);
-}
+GIT_EXTERN(void) git_blob_free(git_blob *blob);
/**
* Get the id of a blob.
@@ -74,11 +64,15 @@ GIT_INLINE(void) git_blob_free(git_blob *blob)
* @param blob a previously loaded blob.
* @return SHA1 hash for this blob.
*/
-GIT_INLINE(const git_oid *) git_blob_id(const git_blob *blob)
-{
- return git_object_id((const git_object *)blob);
-}
+GIT_EXTERN(const git_oid *) git_blob_id(const git_blob *blob);
+/**
+ * Get the repository that contains the blob.
+ *
+ * @param blob A previously loaded blob.
+ * @return Repository that contains this blob.
+ */
+GIT_EXTERN(git_repository *) git_blob_owner(const git_blob *blob);
/**
* Get a read-only buffer with the raw content of a blob.
diff --git a/include/git2/oid.h b/include/git2/oid.h
index 862f4b2..b20bb22 100644
--- a/include/git2/oid.h
+++ b/include/git2/oid.h
@@ -145,19 +145,7 @@ GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src);
* @param b second oid structure.
* @return <0, 0, >0 if a < b, a == b, a > b.
*/
-GIT_INLINE(int) git_oid_cmp(const git_oid *a, const git_oid *b)
-{
- const unsigned char *sha1 = a->id;
- const unsigned char *sha2 = b->id;
- int i;
-
- for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
- if (*sha1 != *sha2)
- return *sha1 - *sha2;
- }
-
- return 0;
-}
+GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
/**
* Compare two oid structures for equality
@@ -193,6 +181,16 @@ GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, size_t len);
GIT_EXTERN(int) git_oid_streq(const git_oid *id, const char *str);
/**
+ * Compare an oid to an hex formatted object id.
+ *
+ * @param id oid structure.
+ * @param str input hex string of an object id.
+ * @return -1 if str is not valid, <0 if id sorts before str,
+ * 0 if id matches str, >0 if id sorts after str.
+ */
+GIT_EXTERN(int) git_oid_strcmp(const git_oid *id, const char *str);
+
+/**
* Check is an oid is all zeros.
*
* @return 1 if all zeros, 0 otherwise.
diff --git a/include/git2/tag.h b/include/git2/tag.h
index 84c954c..469b1d7 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -30,12 +30,8 @@ GIT_BEGIN_DECL
* @param id identity of the tag to locate.
* @return 0 or an error code
*/
-GIT_INLINE(int) git_tag_lookup(
- git_tag **out, git_repository *repo, const git_oid *id)
-{
- return git_object_lookup(
- (git_object **)out, repo, id, (git_otype)GIT_OBJ_TAG);
-}
+GIT_EXTERN(int) git_tag_lookup(
+ git_tag **out, git_repository *repo, const git_oid *id);
/**
* Lookup a tag object from the repository,
@@ -49,12 +45,8 @@ GIT_INLINE(int) git_tag_lookup(
* @param len the length of the short identifier
* @return 0 or an error code
*/
-GIT_INLINE(int) git_tag_lookup_prefix(
- git_tag **out, git_repository *repo, const git_oid *id, size_t len)
-{
- return git_object_lookup_prefix(
- (git_object **)out, repo, id, len, (git_otype)GIT_OBJ_TAG);
-}
+GIT_EXTERN(int) git_tag_lookup_prefix(
+ git_tag **out, git_repository *repo, const git_oid *id, size_t len);
/**
* Close an open tag
@@ -66,12 +58,7 @@ GIT_INLINE(int) git_tag_lookup_prefix(
*
* @param tag the tag to close
*/
-
-GIT_INLINE(void) git_tag_free(git_tag *tag)
-{
- git_object_free((git_object *)tag);
-}
-
+GIT_EXTERN(void) git_tag_free(git_tag *tag);
/**
* Get the id of a tag.
@@ -82,6 +69,14 @@ GIT_INLINE(void) git_tag_free(git_tag *tag)
GIT_EXTERN(const git_oid *) git_tag_id(const git_tag *tag);
/**
+ * Get the repository that contains the tag.
+ *
+ * @param tag A previously loaded tag.
+ * @return Repository that contains this tag.
+ */
+GIT_EXTERN(git_repository *) git_tag_owner(const git_tag *tag);
+
+/**
* Get the tagged object of a tag
*
* This method performs a repository lookup for the
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 73bfc86..6ad7220 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -29,11 +29,8 @@ GIT_BEGIN_DECL
* @param id Identity of the tree to locate.
* @return 0 or an error code
*/
-GIT_INLINE(int) git_tree_lookup(
- git_tree **out, git_repository *repo, const git_oid *id)
-{
- return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_TREE);
-}
+GIT_EXTERN(int) git_tree_lookup(
+ git_tree **out, git_repository *repo, const git_oid *id);
/**
* Lookup a tree object from the repository,
@@ -47,15 +44,11 @@ GIT_INLINE(int) git_tree_lookup(
* @param len the length of the short identifier
* @return 0 or an error code
*/
-GIT_INLINE(int) git_tree_lookup_prefix(
+GIT_EXTERN(int) git_tree_lookup_prefix(
git_tree **out,
git_repository *repo,
const git_oid *id,
- size_t len)
-{
- return git_object_lookup_prefix(
- (git_object **)out, repo, id, len, GIT_OBJ_TREE);
-}
+ size_t len);
/**
* Close an open tree
@@ -67,10 +60,7 @@ GIT_INLINE(int) git_tree_lookup_prefix(
*
* @param tree The tree to close
*/
-GIT_INLINE(void) git_tree_free(git_tree *tree)
-{
- git_object_free((git_object *)tree);
-}
+GIT_EXTERN(void) git_tree_free(git_tree *tree);
/**
* Get the id of a tree.
diff --git a/src/attr.c b/src/attr.c
index 979fecc..6dd2c7e 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -312,7 +312,7 @@ static int load_attr_blob_from_index(
entry = git_index_get_byindex(index, pos);
- if (old_oid && git_oid_cmp(old_oid, &entry->oid) == 0)
+ if (old_oid && git_oid__cmp(old_oid, &entry->oid) == 0)
return GIT_ENOTFOUND;
if ((error = git_blob_lookup(blob, repo, &entry->oid)) < 0)
diff --git a/src/blob.c b/src/blob.c
index a68c4cc..25ea0df 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -15,6 +15,8 @@
#include "filter.h"
#include "buf_text.h"
+GIT_OBJECT__TYPED_FUNCTIONS(git_blob, GIT_OBJ_BLOB)
+
const void *git_blob_rawcontent(const git_blob *blob)
{
assert(blob);
diff --git a/src/checkout.c b/src/checkout.c
index e29fccd..96e1509 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -138,7 +138,7 @@ static bool checkout_is_workdir_modified(
if (!sm_oid)
return false;
- return (git_oid_cmp(&baseitem->oid, sm_oid) != 0);
+ return (git_oid__cmp(&baseitem->oid, sm_oid) != 0);
}
/* Look at the cache to decide if the workdir is modified. If not,
@@ -149,7 +149,7 @@ static bool checkout_is_workdir_modified(
if (wditem->mtime.seconds == ie->mtime.seconds &&
wditem->mtime.nanoseconds == ie->mtime.nanoseconds &&
wditem->file_size == ie->file_size)
- return (git_oid_cmp(&baseitem->oid, &ie->oid) != 0);
+ return (git_oid__cmp(&baseitem->oid, &ie->oid) != 0);
}
/* depending on where base is coming from, we may or may not know
@@ -163,7 +163,7 @@ static bool checkout_is_workdir_modified(
wditem->file_size, &oid) < 0)
return false;
- return (git_oid_cmp(&baseitem->oid, &oid) != 0);
+ return (git_oid__cmp(&baseitem->oid, &oid) != 0);
}
#define CHECKOUT_ACTION_IF(FLAG,YES,NO) \
diff --git a/src/clone.c b/src/clone.c
index 0665576..aeb7bbf 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -132,14 +132,14 @@ static int reference_matches_remote_head(
return 0;
}
- if (git_oid_cmp(&head_info->remote_head_oid, &oid) == 0) {
+ if (git_oid__cmp(&head_info->remote_head_oid, &oid) == 0) {
/* Determine the local reference name from the remote tracking one */
if (git_refspec_transform_l(
- &head_info->branchname,
+ &head_info->branchname,
head_info->refspec,
reference_name) < 0)
return -1;
-
+
if (git_buf_len(&head_info->branchname) > 0) {
if (git_buf_sets(
&head_info->branchname,
diff --git a/src/diff.c b/src/diff.c
index 881173c..6612abf 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -196,21 +196,21 @@ static git_diff_delta *diff_delta__last_for_item(
switch (delta->status) {
case GIT_DELTA_UNMODIFIED:
case GIT_DELTA_DELETED:
- if (git_oid_cmp(&delta->old_file.oid, &item->oid) == 0)
+ if (git_oid__cmp(&delta->old_file.oid, &item->oid) == 0)
return delta;
break;
case GIT_DELTA_ADDED:
- if (git_oid_cmp(&delta->new_file.oid, &item->oid) == 0)
+ if (git_oid__cmp(&delta->new_file.oid, &item->oid) == 0)
return delta;
break;
case GIT_DELTA_UNTRACKED:
if (diff->strcomp(delta->new_file.path, item->path) == 0 &&
- git_oid_cmp(&delta->new_file.oid, &item->oid) == 0)
+ git_oid__cmp(&delta->new_file.oid, &item->oid) == 0)
return delta;
break;
case GIT_DELTA_MODIFIED:
- if (git_oid_cmp(&delta->old_file.oid, &item->oid) == 0 ||
- git_oid_cmp(&delta->new_file.oid, &item->oid) == 0)
+ if (git_oid__cmp(&delta->old_file.oid, &item->oid) == 0 ||
+ git_oid__cmp(&delta->new_file.oid, &item->oid) == 0)
return delta;
break;
default:
diff --git a/src/diff_output.c b/src/diff_output.c
index b8bb73b..4ce01bc 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -660,7 +660,7 @@ static int diff_patch_load(
*/
if (check_if_unmodified &&
delta->old_file.mode == delta->new_file.mode &&
- !git_oid_cmp(&delta->old_file.oid, &delta->new_file.oid))
+ !git_oid__cmp(&delta->old_file.oid, &delta->new_file.oid))
{
delta->status = GIT_DELTA_UNMODIFIED;
@@ -1388,7 +1388,7 @@ static int diff_single_apply(diff_single_data *data)
(has_old ? GIT_DELTA_MODIFIED : GIT_DELTA_ADDED) :
(has_old ? GIT_DELTA_DELETED : GIT_DELTA_UNTRACKED);
- if (git_oid_cmp(&delta->new_file.oid, &delta->old_file.oid) == 0)
+ if (git_oid__cmp(&delta->new_file.oid, &delta->old_file.oid) == 0)
delta->status = GIT_DELTA_UNMODIFIED;
if ((error = diff_delta_is_binary_by_content(
diff --git a/src/diff_tform.c b/src/diff_tform.c
index efcb19d..5c1a86c 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -429,7 +429,7 @@ static int similarity_measure(
if (GIT_MODE_TYPE(a_file->mode) != GIT_MODE_TYPE(b_file->mode))
return 0;
- if (git_oid_cmp(&a_file->oid, &b_file->oid) == 0)
+ if (git_oid__cmp(&a_file->oid, &b_file->oid) == 0)
return 100;
/* update signature cache if needed */
diff --git a/src/index.c b/src/index.c
index d8ca78e..2e2d373 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1411,7 +1411,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
/* 160-bit SHA-1 over the content of the index file before this checksum. */
git_oid_fromraw(&checksum_expected, (const unsigned char *)buffer);
- if (git_oid_cmp(&checksum_calculated, &checksum_expected) != 0)
+ if (git_oid__cmp(&checksum_calculated, &checksum_expected) != 0)
return index_error_invalid("calculated checksum does not match expected");
#undef seek_forward
diff --git a/src/indexer.c b/src/indexer.c
index 6067719..91b7ba5 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -9,7 +9,6 @@
#include "git2/indexer.h"
#include "git2/object.h"
-#include "git2/oid.h"
#include "common.h"
#include "pack.h"
@@ -17,6 +16,7 @@
#include "posix.h"
#include "pack.h"
#include "filebuf.h"
+#include "oid.h"
#include "oidmap.h"
#define UINT31_MAX (0x7FFFFFFF)
@@ -103,7 +103,7 @@ static int objects_cmp(const void *a, const void *b)
const struct entry *entrya = a;
const struct entry *entryb = b;
- return git_oid_cmp(&entrya->oid, &entryb->oid);
+ return git_oid__cmp(&entrya->oid, &entryb->oid);
}
int git_indexer_stream_new(
diff --git a/src/object.h b/src/object.h
index d187c55..7b25fc3 100644
--- a/src/object.h
+++ b/src/object.h
@@ -28,4 +28,16 @@ int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end
void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid);
+#define GIT_OBJECT__TYPED_FUNCTIONS(TYPE,OBJTYPE) \
+ int TYPE##_lookup(TYPE **out, git_repository *repo, const git_oid *id) { \
+ return git_object_lookup((git_object **)out, repo, id, OBJTYPE); } \
+ int TYPE##_lookup_prefix(TYPE **out, git_repository *repo, const git_oid *id, size_t len) { \
+ return git_object_lookup_prefix((git_object **)out, repo, id, len, OBJTYPE); } \
+ void TYPE##_free(TYPE *obj) { \
+ git_object_free((git_object *)obj); } \
+ const git_oid *TYPE##_id(const TYPE *obj) { \
+ return git_object_id((const git_object *)obj); } \
+ git_repository *TYPE##_owner(const TYPE *obj) { \
+ return git_object_owner((const git_object *)obj); }
+
#endif
diff --git a/src/odb.c b/src/odb.c
index 64e1232..07e1ea6 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -772,7 +772,7 @@ attempt_lookup:
git__free(data);
data = raw.data;
- if (found && git_oid_cmp(&full_oid, &found_full_oid))
+ if (found && git_oid__cmp(&full_oid, &found_full_oid))
return git_odb__error_ambiguous("multiple matches for prefix");
found_full_oid = full_oid;
diff --git a/src/oid.c b/src/oid.c
index ab69eeb..e74640c 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -166,18 +166,26 @@ void git_oid_cpy(git_oid *out, const git_oid *src)
memcpy(out->id, src->id, sizeof(out->id));
}
+int git_oid_cmp(const git_oid *a, const git_oid *b)
+{
+ return git_oid__cmp(a, b);
+}
+
int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
{
const unsigned char *a = oid_a->id;
const unsigned char *b = oid_b->id;
- do {
+ if (len > GIT_OID_HEXSZ)
+ len = GIT_OID_HEXSZ;
+
+ while (len > 1) {
if (*a != *b)
return 1;
a++;
b++;
len -= 2;
- } while (len > 1);
+ };
if (len)
if ((*a ^ *b) & 0xf0)
@@ -186,14 +194,31 @@ int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
return 0;
}
-int git_oid_streq(const git_oid *a, const char *str)
+int git_oid_strcmp(const git_oid *oid_a, const char *str)
{
- git_oid id;
+ const unsigned char *a = oid_a->id;
+ unsigned char strval;
+ int hexval;
- if (git_oid_fromstr(&id, str) < 0)
- return -1;
+ for (a = oid_a->id; *str && (a - oid_a->id) < GIT_OID_RAWSZ; ++a) {
+ if ((hexval = git__fromhex(*str++)) < 0)
+ return -1;
+ strval = hexval << 4;
+ if (*str) {
+ if ((hexval = git__fromhex(*str++)) < 0)
+ return -1;
+ strval |= hexval;
+ }
+ if (*a != strval)
+ return (*a - strval);
+ }
- return git_oid_cmp(a, &id) == 0 ? 0 : -1;
+ return 0;
+}
+
+int git_oid_streq(const git_oid *oid_a, const char *str)
+{
+ return git_oid_strcmp(oid_a, str) == 0 ? 0 : -1;
}
int git_oid_iszero(const git_oid *oid_a)
diff --git a/src/oid.h b/src/oid.h
new file mode 100644
index 0000000..077d0a4
--- /dev/null
+++ b/src/oid.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_oid_h__
+#define INCLUDE_oid_h__
+
+#include "git2/oid.h"
+
+/*
+ * Compare two oid structures.
+ *
+ * @param a first oid structure.
+ * @param b second oid structure.
+ * @return <0, 0, >0 if a < b, a == b, a > b.
+ */
+GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
+{
+ const unsigned char *sha1 = a->id;
+ const unsigned char *sha2 = b->id;
+ int i;
+
+ for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
+ if (*sha1 != *sha2)
+ return *sha1 - *sha2;
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/src/pack.c b/src/pack.c
index 33cdf76..f8b621e 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -12,8 +12,8 @@
#include "sha1_lookup.h"
#include "mwindow.h"
#include "fileops.h"
+#include "oid.h"
-#include "git2/oid.h"
#include <zlib.h>
static int packfile_open(struct git_pack_file *p);
@@ -875,7 +875,7 @@ static int packfile_open(struct git_pack_file *p)
idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;
- if (git_oid_cmp(&sha1, (git_oid *)idx_sha1) == 0)
+ if (git_oid__cmp(&sha1, (git_oid *)idx_sha1) == 0)
return 0;
cleanup:
@@ -1139,7 +1139,7 @@ int git_pack_entry_find(
if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
unsigned i;
for (i = 0; i < p->num_bad_objects; i++)
- if (git_oid_cmp(short_oid, &p->bad_object_sha1[i]) == 0)
+ if (git_oid__cmp(short_oid, &p->bad_object_sha1[i]) == 0)
return packfile_error("bad object found in packfile");
}
diff --git a/src/push.c b/src/push.c
index b6be1a4..9b1e78c 100644
--- a/src/push.c
+++ b/src/push.c
@@ -376,7 +376,7 @@ static int queue_differences(
const git_tree_entry *d_entry = git_tree_entry_byindex(delta, j);
int cmp = 0;
- if (!git_oid_cmp(&b_entry->oid, &d_entry->oid))
+ if (!git_oid__cmp(&b_entry->oid, &d_entry->oid))
goto loop;
cmp = strcmp(b_entry->filename, d_entry->filename);
diff --git a/src/refs.c b/src/refs.c
index 2faa4cb..b85a2e8 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -832,7 +832,7 @@ int git_reference_cmp(git_reference *ref1, git_reference *ref2)
if (type1 == GIT_REF_SYMBOLIC)
return strcmp(ref1->target.symbolic, ref2->target.symbolic);
- return git_oid_cmp(&ref1->target.oid, &ref2->target.oid);
+ return git_oid__cmp(&ref1->target.oid, &ref2->target.oid);
}
static int reference__update_terminal(
diff --git a/src/refs.h b/src/refs.h
index 97d4d2e..908e86f 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -13,6 +13,7 @@
#include "git2/refdb.h"
#include "strmap.h"
#include "buffer.h"
+#include "oid.h"
#define GIT_REFS_DIR "refs/"
#define GIT_REFS_HEADS_DIR GIT_REFS_DIR "heads/"
diff --git a/src/remote.c b/src/remote.c
index 08f56cd..6eaaf8b 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -923,7 +923,7 @@ static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vecto
if (error == GIT_ENOTFOUND)
memset(&old, 0, GIT_OID_RAWSZ);
- if (!git_oid_cmp(&old, &head->oid))
+ if (!git_oid__cmp(&old, &head->oid))
continue;
/* In autotag mode, don't overwrite any locally-existing tags */
diff --git a/src/tag.c b/src/tag.c
index b9a806c..a0ecce1 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -15,6 +15,8 @@
#include "git2/signature.h"
#include "git2/odb_backend.h"
+GIT_OBJECT__TYPED_FUNCTIONS(git_tag, GIT_OBJ_TAG)
+
void git_tag__free(void *_tag)
{
git_tag *tag = _tag;
@@ -24,11 +26,6 @@ void git_tag__free(void *_tag)
git__free(tag);
}
-const git_oid *git_tag_id(const git_tag *c)
-{
- return git_object_id((const git_object *)c);
-}
-
int git_tag_target(git_object **target, const git_tag *t)
{
assert(t);
diff --git a/src/transports/local.c b/src/transports/local.c
index 8af970e..8b4d50c 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -282,7 +282,7 @@ static int local_push_copy_object(
odb_obj_size) < 0 ||
odb_stream->finalize_write(&remote_odb_obj_oid, odb_stream) < 0) {
error = -1;
- } else if (git_oid_cmp(&obj->id, &remote_odb_obj_oid) != 0) {
+ } else if (git_oid__cmp(&obj->id, &remote_odb_obj_oid) != 0) {
giterr_set(GITERR_ODB, "Error when writing object to remote odb "
"during local push operation. Remote odb object oid does not "
"match local oid.");
diff --git a/src/tree.c b/src/tree.c
index 58eb92f..0a94aec 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -11,6 +11,8 @@
#include "git2/repository.h"
#include "git2/object.h"
+GIT_OBJECT__TYPED_FUNCTIONS(git_tree, GIT_OBJ_TREE)
+
#define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE_BYTES 6
@@ -232,16 +234,6 @@ void git_tree__free(void *_tree)
git__free(tree);
}
-const git_oid *git_tree_id(const git_tree *t)
-{
- return git_object_id((const git_object *)t);
-}
-
-git_repository *git_tree_owner(const git_tree *t)
-{
- return git_object_owner((const git_object *)t);
-}
-
git_filemode_t git_tree_entry_filemode(const git_tree_entry *entry)
{
return (git_filemode_t)entry->attr;
diff --git a/tests-clar/core/oid.c b/tests-clar/core/oid.c
index 08791cc..7ee6fb6 100644
--- a/tests-clar/core/oid.c
+++ b/tests-clar/core/oid.c
@@ -16,15 +16,55 @@ void test_core_oid__initialize(void)
void test_core_oid__streq(void)
{
- cl_assert(git_oid_streq(&id, str_oid) == 0);
- cl_assert(git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == -1);
+ cl_assert_equal_i(0, git_oid_streq(&id, str_oid));
+ cl_assert_equal_i(-1, git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
- cl_assert(git_oid_streq(&id, "deadbeef") == -1);
- cl_assert(git_oid_streq(&id, "I'm not an oid.... :)") == -1);
-
- cl_assert(git_oid_streq(&idp, "ae90f12eea699729ed0000000000000000000000") == 0);
- cl_assert(git_oid_streq(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == -1);
+ cl_assert_equal_i(-1, git_oid_streq(&id, "deadbeef"));
+ cl_assert_equal_i(-1, git_oid_streq(&id, "I'm not an oid.... :)"));
- cl_assert(git_oid_streq(&idp, "deadbeef") == -1);
- cl_assert(git_oid_streq(&idp, "I'm not an oid.... :)") == -1);
+ cl_assert_equal_i(0, git_oid_streq(&idp, "ae90f12eea699729ed0000000000000000000000"));
+ cl_assert_equal_i(0, git_oid_streq(&idp, "ae90f12eea699729ed"));
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "ae90f12eea699729ed1"));
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "ae90f12eea699729ec"));
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
+
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "deadbeef"));
+ cl_assert_equal_i(-1, git_oid_streq(&idp, "I'm not an oid.... :)"));
+}
+
+void test_core_oid__strcmp(void)
+{
+ cl_assert_equal_i(0, git_oid_strcmp(&id, str_oid));
+ cl_assert(git_oid_strcmp(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0);
+
+ cl_assert(git_oid_strcmp(&id, "deadbeef") < 0);
+ cl_assert_equal_i(-1, git_oid_strcmp(&id, "I'm not an oid.... :)"));
+
+ cl_assert_equal_i(0, git_oid_strcmp(&idp, "ae90f12eea699729ed0000000000000000000000"));
+ cl_assert_equal_i(0, git_oid_strcmp(&idp, "ae90f12eea699729ed"));
+ cl_assert(git_oid_strcmp(&idp, "ae90f12eea699729ed1") < 0);
+ cl_assert(git_oid_strcmp(&idp, "ae90f12eea699729ec") > 0);
+ cl_assert(git_oid_strcmp(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0);
+
+ cl_assert(git_oid_strcmp(&idp, "deadbeef") < 0);
+ cl_assert_equal_i(-1, git_oid_strcmp(&idp, "I'm not an oid.... :)"));
+}
+
+void test_core_oid__ncmp(void)
+{
+ cl_assert(!git_oid_ncmp(&id, &idp, 0));
+ cl_assert(!git_oid_ncmp(&id, &idp, 1));
+ cl_assert(!git_oid_ncmp(&id, &idp, 2));
+ cl_assert(!git_oid_ncmp(&id, &idp, 17));
+ cl_assert(!git_oid_ncmp(&id, &idp, 18));
+ cl_assert(git_oid_ncmp(&id, &idp, 19));
+ cl_assert(git_oid_ncmp(&id, &idp, 40));
+ cl_assert(git_oid_ncmp(&id, &idp, 41));
+ cl_assert(git_oid_ncmp(&id, &idp, 42));
+
+ cl_assert(!git_oid_ncmp(&id, &id, 0));
+ cl_assert(!git_oid_ncmp(&id, &id, 1));
+ cl_assert(!git_oid_ncmp(&id, &id, 39));
+ cl_assert(!git_oid_ncmp(&id, &id, 40));
+ cl_assert(!git_oid_ncmp(&id, &id, 41));
}