Give object structures more descriptive names The 'git_obj' structure is now called 'git_rawobj', since it represents a raw object read from the ODB. The 'git_repository_object' structure is now called 'git_object', since it's the base object class for all objects. 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 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
diff --git a/src/commit.c b/src/commit.c
index ce3a418..ad89088 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -69,14 +69,14 @@ int git_commit__parse(git_commit *commit, unsigned int parse_flags, int close_db
{
int error = 0;
- if ((error = git_repository__dbo_open((git_repository_object *)commit)) < 0)
+ if ((error = git_object__source_open((git_object *)commit)) < 0)
return error;
error = git_commit__parse_buffer(commit,
- commit->object.dbo.data, commit->object.dbo.len, parse_flags);
+ commit->object.source.raw.data, commit->object.source.raw.len, parse_flags);
if (close_db_object)
- git_repository__dbo_close((git_repository_object *)commit);
+ git_object__source_close((git_object *)commit);
return error;
}
diff --git a/src/commit.h b/src/commit.h
index ae4f06d..4e883c0 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -22,7 +22,7 @@ typedef struct git_commit_parents {
} git_commit_parents;
struct git_commit {
- git_repository_object object;
+ git_object object;
time_t commit_time;
git_commit_parents *parents;
diff --git a/src/delta-apply.c b/src/delta-apply.c
index 4915947..769e973 100644
--- a/src/delta-apply.c
+++ b/src/delta-apply.c
@@ -31,7 +31,7 @@ static int hdr_sz(
}
int git__delta_apply(
- git_obj *out,
+ git_rawobj *out,
const unsigned char *base,
size_t base_len,
const unsigned char *delta,
diff --git a/src/delta-apply.h b/src/delta-apply.h
index 498bccd..642442d 100644
--- a/src/delta-apply.h
+++ b/src/delta-apply.h
@@ -16,7 +16,7 @@
* - GIT_ERROR if the delta is corrupt or doesn't match the base.
*/
extern int git__delta_apply(
- git_obj *out,
+ git_rawobj *out,
const unsigned char *base,
size_t base_len,
const unsigned char *delta,
diff --git a/src/git/common.h b/src/git/common.h
index b43f4ee..faf9702 100644
--- a/src/git/common.h
+++ b/src/git/common.h
@@ -92,7 +92,7 @@ GIT_BEGIN_DECL
typedef struct git_repository git_repository;
/* Representation of a generic object in a repository */
-typedef struct git_repository_object git_repository_object;
+typedef struct git_object git_object;
/** Parsed representation of a person */
typedef struct git_person {
diff --git a/src/git/odb.h b/src/git/odb.h
index 5d105ba..a132346 100644
--- a/src/git/odb.h
+++ b/src/git/odb.h
@@ -52,7 +52,7 @@ typedef struct {
void *data; /**< Raw, decompressed object data. */
size_t len; /**< Total number of bytes in data. */
git_otype type; /**< Type of this object. */
-} git_obj;
+} git_rawobj;
/**
* Read an object from the database.
@@ -66,7 +66,7 @@ typedef struct {
* - GIT_SUCCESS if the object was read;
* - GIT_ENOTFOUND if the object is not in the database.
*/
-GIT_EXTERN(int) git_odb_read(git_obj *out, git_odb *db, const git_oid *id);
+GIT_EXTERN(int) git_odb_read(git_rawobj *out, git_odb *db, const git_oid *id);
/**
* Read an object from the database using only pack files.
@@ -80,7 +80,7 @@ GIT_EXTERN(int) git_odb_read(git_obj *out, git_odb *db, const git_oid *id);
* - GIT_SUCCESS if the object was read.
* - GIT_ENOTFOUND if the object is not in the database.
*/
-GIT_EXTERN(int) git_odb__read_packed(git_obj *out, git_odb *db, const git_oid *id);
+GIT_EXTERN(int) git_odb__read_packed(git_rawobj *out, git_odb *db, const git_oid *id);
/**
* Read an object from the database using only loose object files.
@@ -94,7 +94,7 @@ GIT_EXTERN(int) git_odb__read_packed(git_obj *out, git_odb *db, const git_oid *i
* - GIT_SUCCESS if the object was read.
* - GIT_ENOTFOUND if the object is not in the database.
*/
-GIT_EXTERN(int) git_odb__read_loose(git_obj *out, git_odb *db, const git_oid *id);
+GIT_EXTERN(int) git_odb__read_loose(git_rawobj *out, git_odb *db, const git_oid *id);
/**
* Write an object to the database.
@@ -106,7 +106,7 @@ GIT_EXTERN(int) git_odb__read_loose(git_obj *out, git_odb *db, const git_oid *id
* - GIT_SUCCESS if the object was written;
* - GIT_ERROR otherwise.
*/
-GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_obj *obj);
+GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj);
/**
* Release all memory used by the obj structure.
@@ -117,7 +117,7 @@ GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_obj *obj);
*
* @param obj object descriptor to free.
*/
-GIT_INLINE(void) git_obj_close(git_obj *obj)
+GIT_INLINE(void) git_obj_close(git_rawobj *obj)
{
free(obj->data);
obj->data = NULL;
@@ -152,7 +152,7 @@ GIT_EXTERN(git_otype) git_obj_string_to_type(const char *str);
GIT_EXTERN(int) git_obj__loose_object_type(git_otype type);
/**
- * Determine the object-ID (sha1 hash) of the given git_obj.
+ * Determine the object-ID (sha1 hash) of the given git_rawobj.
*
* The input obj must be a valid loose object type and the data
* pointer must not be NULL, unless the len field is also zero.
@@ -163,7 +163,7 @@ GIT_EXTERN(int) git_obj__loose_object_type(git_otype type);
* - GIT_SUCCESS if the object-ID was correctly determined.
* - GIT_ERROR if the given object is malformed.
*/
-GIT_EXTERN(int) git_obj_hash(git_oid *id, git_obj *obj);
+GIT_EXTERN(int) git_obj_hash(git_oid *id, git_rawobj *obj);
/**
* Determine if the given object can be found in the object database.
diff --git a/src/git/repository.h b/src/git/repository.h
index a61e5b6..33bb2fc 100644
--- a/src/git/repository.h
+++ b/src/git/repository.h
@@ -47,7 +47,7 @@ GIT_EXTERN(git_repository *) git_repository_alloc(git_odb *odb);
* @param type the type of the object
* @return a reference to the object
*/
-GIT_EXTERN(git_repository_object *) git_repository_lookup(git_repository *repo, const git_oid *id, git_otype type);
+GIT_EXTERN(git_object *) git_repository_lookup(git_repository *repo, const git_oid *id, git_otype type);
/**
* Get the object database behind a Git repository
@@ -63,7 +63,7 @@ GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo);
* @param obj the repository object
* @return the SHA1 id
*/
-const git_oid *git_repository_object_id(git_repository_object *obj);
+const git_oid *git_object_id(git_object *obj);
/**
* Get the object type of an object
@@ -71,7 +71,7 @@ const git_oid *git_repository_object_id(git_repository_object *obj);
* @param obj the repository object
* @return the object's type
*/
-git_otype git_repository_object_type(git_repository_object *obj);
+git_otype git_object_type(git_object *obj);
/**
* Free a reference to one of the objects in the repostory.
@@ -85,7 +85,7 @@ git_otype git_repository_object_type(git_repository_object *obj);
*
* @param object the object to free
*/
-GIT_EXTERN(void) git_repository_object_free(git_repository_object *object);
+GIT_EXTERN(void) git_object_free(git_object *object);
/**
* Free a previously allocated repository
diff --git a/src/git/tag.h b/src/git/tag.h
index d94083b..a6efabb 100644
--- a/src/git/tag.h
+++ b/src/git/tag.h
@@ -41,7 +41,7 @@ GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag);
* @param tag a previously loaded tag.
* @return reference to a repository object
*/
-GIT_EXTERN(const git_repository_object *) git_tag_target(git_tag *t);
+GIT_EXTERN(const git_object *) git_tag_target(git_tag *t);
/**
* Get the type of a tag's tagged object
diff --git a/src/git/tree.h b/src/git/tree.h
index fcc38d5..646c085 100644
--- a/src/git/tree.h
+++ b/src/git/tree.h
@@ -85,11 +85,11 @@ GIT_EXTERN(const char *) git_tree_entry_name(const git_tree_entry *entry);
GIT_EXTERN(const git_oid *) git_tree_entry_id(const git_tree_entry *entry);
/**
- * Convert a tree entry to the git_repository_object it points too.
+ * Convert a tree entry to the git_object it points too.
* @param entry a tree entry
* @return a reference to the pointed object in the repository
*/
-GIT_EXTERN(git_repository_object *) git_tree_entry_2object(const git_tree_entry *entry);
+GIT_EXTERN(git_object *) git_tree_entry_2object(const git_tree_entry *entry);
/** @} */
GIT_END_DECL
diff --git a/src/odb.c b/src/odb.c
index be896cc..5c59a4f 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -187,7 +187,7 @@ int git_obj__loose_object_type(git_otype type)
return obj_type_table[type].loose;
}
-static int format_object_header(char *hdr, size_t n, git_obj *obj)
+static int format_object_header(char *hdr, size_t n, git_rawobj *obj)
{
const char *type_str = git_obj_type_to_string(obj->type);
int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj->len);
@@ -200,7 +200,7 @@ static int format_object_header(char *hdr, size_t n, git_obj *obj)
return len+1;
}
-static int hash_obj(git_oid *id, char *hdr, size_t n, int *len, git_obj *obj)
+static int hash_obj(git_oid *id, char *hdr, size_t n, int *len, git_rawobj *obj)
{
git_buf_vec vec[2];
int hdrlen;
@@ -228,7 +228,7 @@ static int hash_obj(git_oid *id, char *hdr, size_t n, int *len, git_obj *obj)
return GIT_SUCCESS;
}
-int git_obj_hash(git_oid *id, git_obj *obj)
+int git_obj_hash(git_oid *id, git_rawobj *obj)
{
char hdr[64];
int hdrlen;
@@ -456,7 +456,7 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen)
* of loose object data into packs. This format is no longer used, but
* we must still read it.
*/
-static int inflate_packlike_loose_disk_obj(git_obj *out, gitfo_buf *obj)
+static int inflate_packlike_loose_disk_obj(git_rawobj *out, gitfo_buf *obj)
{
unsigned char *in, *buf;
obj_hdr hdr;
@@ -494,7 +494,7 @@ static int inflate_packlike_loose_disk_obj(git_obj *out, gitfo_buf *obj)
return GIT_SUCCESS;
}
-static int inflate_disk_obj(git_obj *out, gitfo_buf *obj)
+static int inflate_disk_obj(git_rawobj *out, gitfo_buf *obj)
{
unsigned char head[64], *buf;
z_stream zs;
@@ -579,7 +579,7 @@ static int deflate_buf(z_stream *s, void *in, size_t len, int flush)
return status;
}
-static int deflate_obj(gitfo_buf *buf, char *hdr, int hdrlen, git_obj *obj, int level)
+static int deflate_obj(gitfo_buf *buf, char *hdr, int hdrlen, git_rawobj *obj, int level)
{
z_stream zs;
int status;
@@ -1441,7 +1441,7 @@ void git_odb_close(git_odb *db)
}
int git_odb_read(
- git_obj *out,
+ git_rawobj *out,
git_odb *db,
const git_oid *id)
{
@@ -1457,7 +1457,7 @@ attempt:
return GIT_ENOTFOUND;
}
-int git_odb__read_loose(git_obj *out, git_odb *db, const git_oid *id)
+int git_odb__read_loose(git_rawobj *out, git_odb *db, const git_oid *id)
{
char file[GIT_PATH_MAX];
gitfo_buf obj = GITFO_BUF_INIT;
@@ -1484,9 +1484,9 @@ int git_odb__read_loose(git_obj *out, git_odb *db, const git_oid *id)
return GIT_SUCCESS;
}
-static int unpack_object(git_obj *out, git_pack *p, index_entry *e);
+static int unpack_object(git_rawobj *out, git_pack *p, index_entry *e);
-static int unpack_object_delta(git_obj *out, git_pack *p,
+static int unpack_object_delta(git_rawobj *out, git_pack *p,
index_entry *base_entry,
uint8_t *delta_buffer,
size_t delta_deflated_size,
@@ -1494,7 +1494,7 @@ static int unpack_object_delta(git_obj *out, git_pack *p,
{
int res = 0;
uint8_t *delta = NULL;
- git_obj base_obj;
+ git_rawobj base_obj;
base_obj.data = NULL;
base_obj.type = GIT_OBJ_BAD;
@@ -1519,7 +1519,7 @@ cleanup:
return res;
}
-static int unpack_object(git_obj *out, git_pack *p, index_entry *e)
+static int unpack_object(git_rawobj *out, git_pack *p, index_entry *e)
{
git_otype object_type;
size_t inflated_size, deflated_size, shift;
@@ -1623,7 +1623,7 @@ static int unpack_object(git_obj *out, git_pack *p, index_entry *e)
return GIT_SUCCESS;
}
-static int read_packed(git_obj *out, git_pack *p, const git_oid *id)
+static int read_packed(git_rawobj *out, git_pack *p, const git_oid *id)
{
uint32_t n;
index_entry e;
@@ -1646,7 +1646,7 @@ static int read_packed(git_obj *out, git_pack *p, const git_oid *id)
return res;
}
-int git_odb__read_packed(git_obj *out, git_odb *db, const git_oid *id)
+int git_odb__read_packed(git_rawobj *out, git_odb *db, const git_oid *id)
{
git_packlist *pl = packlist_get(db);
size_t j;
@@ -1671,7 +1671,7 @@ int git_odb__read_packed(git_obj *out, git_odb *db, const git_oid *id)
return GIT_ENOTFOUND;
}
-int git_odb_write(git_oid *id, git_odb *db, git_obj *obj)
+int git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj)
{
char hdr[64];
int hdrlen;
diff --git a/src/repository.c b/src/repository.c
index 4436971..e921c34 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -31,7 +31,7 @@
static const int default_table_size = 32;
static const double max_load_factor = 0.65;
-uint32_t git_repository_object_hash(const void *key)
+uint32_t git_object_hash(const void *key)
{
uint32_t r;
git_oid *id;
@@ -41,12 +41,12 @@ uint32_t git_repository_object_hash(const void *key)
return r;
}
-int git_repository_object_haskey(void *object, const void *key)
+int git_object_haskey(void *object, const void *key)
{
- git_repository_object *obj;
+ git_object *obj;
git_oid *oid;
- obj = (git_repository_object *)object;
+ obj = (git_object *)object;
oid = (git_oid *)key;
return (git_oid_cmp(oid, &obj->id) == 0);
@@ -62,8 +62,8 @@ git_repository *git_repository_alloc(git_odb *odb)
repo->objects = git_hashtable_alloc(
default_table_size,
- git_repository_object_hash,
- git_repository_object_haskey);
+ git_object_hash,
+ git_object_haskey);
if (repo->objects == NULL) {
free(repo);
@@ -78,128 +78,126 @@ git_repository *git_repository_alloc(git_odb *odb)
void git_repository_free(git_repository *repo)
{
git_hashtable_iterator it;
- git_repository_object *object;
+ git_object *object;
git_hashtable_iterator_init(repo->objects, &it);
- while ((object = (git_repository_object *)
+ while ((object = (git_object *)
git_hashtable_iterator_next(&it)) != NULL)
- git_repository_object_free(object);
+ git_object_free(object);
git_hashtable_free(repo->objects);
/* TODO: free odb */
free(repo);
}
-void git_repository__dbo_prepare_write(git_repository_object *object)
+void git_object__source_prepare_write(git_object *object)
{
size_t base_size = 512;
- if (object->writeback.write_ptr != NULL || object->dbo_open)
- git_repository__dbo_close(object);
+ if (object->source.write_ptr != NULL || object->source.open)
+ git_object__source_close(object);
/* TODO: proper size calculation */
- object->dbo.data = git__malloc(base_size);
- object->dbo.len = 0;
+ object->source.raw.data = git__malloc(base_size);
+ object->source.raw.len = base_size;
- object->writeback.write_ptr = object->dbo.data;
- object->writeback.ptr_size = base_size;
- object->writeback.written_bytes = 0;
+ object->source.write_ptr = object->source.raw.data;
+ object->source.written_bytes = 0;
- object->dbo_open = 1;
- object->out_of_sync = 1;
+ object->source.open = 1;
+ object->source.out_of_sync = 1;
}
-int git_repository__dbo_write(git_repository_object *object, const void *bytes, size_t len)
+int git_object__source_write(git_object *object, const void *bytes, size_t len)
{
assert(object);
- if (!object->dbo_open || object->writeback.write_ptr == NULL)
+ if (!object->source.open || object->source.write_ptr == NULL)
return GIT_ERROR;
/* TODO: resize buffer on overflow */
- if (object->writeback.written_bytes + len >= object->writeback.ptr_size)
+ if (object->source.written_bytes + len >= object->source.raw.len)
return GIT_ENOMEM;
- memcpy(object->writeback.write_ptr, bytes, len);
- object->writeback.write_ptr += len;
- object->writeback.written_bytes += len;
+ memcpy(object->source.write_ptr, bytes, len);
+ object->source.write_ptr += len;
+ object->source.written_bytes += len;
return GIT_SUCCESS;
}
-int git_repository__dbo_writeback(git_repository_object *object)
+int git_object__source_writeback(git_object *object)
{
int error;
git_oid new_id;
assert(object);
- if (!object->dbo_open)
+ if (!object->source.open)
return GIT_ERROR;
- if (!object->out_of_sync)
+ if (!object->source.out_of_sync)
return GIT_SUCCESS;
- object->dbo.len = object->writeback.written_bytes;
+ object->source.raw.len = object->source.written_bytes;
- git_obj_hash(&new_id, &object->dbo);
+ git_obj_hash(&new_id, &object->source.raw);
- if ((error = git_odb_write(&new_id, object->repo->db, &object->dbo)) < 0)
+ if ((error = git_odb_write(&new_id, object->repo->db, &object->source.raw)) < 0)
return error;
git_hashtable_remove(object->repo->objects, &object->id);
git_oid_cpy(&object->id, &new_id);
git_hashtable_insert(object->repo->objects, &object->id, object);
- object->writeback.write_ptr = NULL;
- object->writeback.ptr_size = 0;
- object->writeback.written_bytes = 0;
+ object->source.write_ptr = NULL;
+ object->source.written_bytes = 0;
- git_repository__dbo_close(object);
+ git_object__source_close(object);
return GIT_SUCCESS;
}
-int git_repository__dbo_open(git_repository_object *object)
+int git_object__source_open(git_object *object)
{
int error;
assert(object);
- if (object->dbo_open && object->out_of_sync)
- git_repository__dbo_close(object);
+ if (object->source.open && object->source.out_of_sync)
+ git_object__source_close(object);
- if (object->dbo_open)
+ if (object->source.open)
return GIT_SUCCESS;
- error = git_odb_read(&object->dbo, object->repo->db, &object->id);
+ error = git_odb_read(&object->source.raw, object->repo->db, &object->id);
if (error < 0)
return error;
- object->dbo_open = 1;
- object->out_of_sync = 0;
+ object->source.open = 1;
+ object->source.out_of_sync = 0;
return GIT_SUCCESS;
}
-void git_repository__dbo_close(git_repository_object *object)
+void git_object__source_close(git_object *object)
{
assert(object);
- if (!object->dbo_open) {
- git_obj_close(&object->dbo);
- object->dbo_open = 0;
- object->out_of_sync = 0;
+ if (!object->source.open) {
+ git_obj_close(&object->source.raw);
+ object->source.open = 0;
+ object->source.out_of_sync = 0;
}
}
-void git_repository_object_free(git_repository_object *object)
+void git_object_free(git_object *object)
{
assert(object);
git_hashtable_remove(object->repo->objects, &object->id);
- git_obj_close(&object->dbo);
+ git_obj_close(&object->source.raw);
- switch (object->dbo.type) {
+ switch (object->source.raw.type) {
case GIT_OBJ_COMMIT:
git_commit__free((git_commit *)object);
break;
@@ -224,30 +222,30 @@ git_odb *git_repository_database(git_repository *repo)
return repo->db;
}
-const git_oid *git_repository_object_id(git_repository_object *obj)
+const git_oid *git_object_id(git_object *obj)
{
assert(obj);
return &obj->id;
}
-git_otype git_repository_object_type(git_repository_object *obj)
+git_otype git_object_type(git_object *obj)
{
assert(obj);
- return obj->dbo.type;
+ return obj->source.raw.type;
}
-git_repository_object *git_repository_lookup(git_repository *repo, const git_oid *id, git_otype type)
+git_object *git_repository_lookup(git_repository *repo, const git_oid *id, git_otype type)
{
static const size_t object_sizes[] = {
0,
sizeof(git_commit),
sizeof(git_tree),
- sizeof(git_repository_object), /* TODO: sizeof(git_blob) */
+ sizeof(git_object), /* TODO: sizeof(git_blob) */
sizeof(git_tag)
};
- git_repository_object *object = NULL;
- git_obj obj_file;
+ git_object *object = NULL;
+ git_rawobj obj_file;
assert(repo);
@@ -273,8 +271,8 @@ git_repository_object *git_repository_lookup(git_repository *repo, const git_oid
/* Initialize parent object */
git_oid_cpy(&object->id, id);
object->repo = repo;
- object->dbo_open = 1;
- memcpy(&object->dbo, &obj_file, sizeof(git_obj));
+ object->source.open = 1;
+ memcpy(&object->source.raw, &obj_file, sizeof(git_rawobj));
switch (type) {
@@ -307,8 +305,8 @@ git_repository_object *git_repository_lookup(git_repository *repo, const git_oid
break;
}
- git_obj_close(&object->dbo);
- object->dbo_open = 0;
+ git_obj_close(&object->source.raw);
+ object->source.open = 0;
git_hashtable_insert(repo->objects, &object->id, object);
return object;
diff --git a/src/repository.h b/src/repository.h
index 1b5e6a0..476ca54 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -8,18 +8,17 @@
#include "hashtable.h"
-struct git_repository_object {
+typedef struct {
+ git_rawobj raw;
+ void *write_ptr;
+ size_t written_bytes;
+ int open:1, out_of_sync:1;
+} git_odb_source;
+
+struct git_object {
git_oid id;
git_repository *repo;
- git_obj dbo;
-
- struct {
- void *write_ptr;
- size_t ptr_size;
- size_t written_bytes;
- } writeback;
-
- int dbo_open:1, out_of_sync:1;
+ git_odb_source source;
};
struct git_repository {
@@ -28,10 +27,10 @@ struct git_repository {
};
-int git_repository__dbo_open(git_repository_object *object);
-void git_repository__dbo_close(git_repository_object *object);
-void git_repository__dbo_prepare_write(git_repository_object *object);
-int git_repository__dbo_write(git_repository_object *object, const void *bytes, size_t len);
-int git_repository__dbo_writeback(git_repository_object *object);
+int git_object__source_open(git_object *object);
+void git_object__source_close(git_object *object);
+void git_object__source_prepare_write(git_object *object);
+int git_object__source_write(git_object *object, const void *bytes, size_t len);
+int git_object__source_writeback(git_object *object);
#endif
diff --git a/src/tag.c b/src/tag.c
index ec0531b..13679ec 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -43,7 +43,7 @@ const git_oid *git_tag_id(git_tag *t)
return &t->object.id;
}
-const git_repository_object *git_tag_target(git_tag *t)
+const git_object *git_tag_target(git_tag *t)
{
return t->target;
}
@@ -161,13 +161,13 @@ int git_tag__parse(git_tag *tag)
{
int error = 0;
- error = git_repository__dbo_open((git_repository_object *)tag);
+ error = git_object__source_open((git_object *)tag);
if (error < 0)
return error;
- error = parse_tag_buffer(tag, tag->object.dbo.data, tag->object.dbo.data + tag->object.dbo.len);
+ error = parse_tag_buffer(tag, tag->object.source.raw.data, tag->object.source.raw.data + tag->object.source.raw.len);
- git_repository__dbo_close((git_repository_object *)tag);
+ git_object__source_close((git_object *)tag);
return error;
}
diff --git a/src/tag.h b/src/tag.h
index df03e2a..6d9cd82 100644
--- a/src/tag.h
+++ b/src/tag.h
@@ -5,9 +5,9 @@
#include "repository.h"
struct git_tag {
- git_repository_object object;
+ git_object object;
- git_repository_object *target;
+ git_object *target;
git_otype type;
char *tag_name;
git_person *tagger;
diff --git a/src/tree.c b/src/tree.c
index 7599c3f..f1c191c 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -65,7 +65,7 @@ const git_oid *git_tree_entry_id(const git_tree_entry *entry)
return &entry->oid;
}
-git_repository_object *git_tree_entry_2object(const git_tree_entry *entry)
+git_object *git_tree_entry_2object(const git_tree_entry *entry)
{
return git_repository_lookup(entry->owner->object.repo, &entry->oid, GIT_OBJ_ANY);
}
@@ -107,15 +107,15 @@ int git_tree__parse(git_tree *tree)
if (tree->entries != NULL)
return GIT_SUCCESS;
- error = git_repository__dbo_open((git_repository_object *)tree);
+ error = git_object__source_open((git_object *)tree);
if (error < 0)
return error;
- buffer = tree->object.dbo.data;
- buffer_end = buffer + tree->object.dbo.len;
+ buffer = tree->object.source.raw.data;
+ buffer_end = buffer + tree->object.source.raw.len;
tree->entry_count = 0;
- entries_size = (tree->object.dbo.len / avg_entry_size) + 1;
+ entries_size = (tree->object.source.raw.len / avg_entry_size) + 1;
tree->entries = git__malloc(entries_size * sizeof(git_tree_entry));
while (buffer < buffer_end) {
@@ -155,6 +155,6 @@ int git_tree__parse(git_tree *tree)
buffer += GIT_OID_RAWSZ;
}
- git_repository__dbo_close((git_repository_object *)tree);
+ git_object__source_close((git_object *)tree);
return error;
}
diff --git a/src/tree.h b/src/tree.h
index 4c0be2a..dd15b9b 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -13,7 +13,7 @@ struct git_tree_entry {
};
struct git_tree {
- git_repository_object object;
+ git_object object;
git_tree_entry *entries;
size_t entry_count;
diff --git a/tests/t0103-objhash.c b/tests/t0103-objhash.c
index 83131fe..8d0ba90 100644
--- a/tests/t0103-objhash.c
+++ b/tests/t0103-objhash.c
@@ -52,7 +52,7 @@ static unsigned char commit_data[] = {
0x3e, 0x0a,
};
-static git_obj commit_obj = {
+static git_rawobj commit_obj = {
commit_data,
sizeof(commit_data),
GIT_OBJ_COMMIT
@@ -79,7 +79,7 @@ static unsigned char tree_data[] = {
0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91,
};
-static git_obj tree_obj = {
+static git_rawobj tree_obj = {
tree_data,
sizeof(tree_data),
GIT_OBJ_TREE
@@ -112,7 +112,7 @@ static unsigned char tag_data[] = {
0x2e, 0x30, 0x2e, 0x31, 0x0a,
};
-static git_obj tag_obj = {
+static git_rawobj tag_obj = {
tag_data,
sizeof(tag_data),
GIT_OBJ_TAG
@@ -124,7 +124,7 @@ static unsigned char zero_data[] = {
0x00 /* dummy data */
};
-static git_obj zero_obj = {
+static git_rawobj zero_obj = {
zero_data,
0,
GIT_OBJ_BLOB
@@ -136,7 +136,7 @@ static unsigned char one_data[] = {
0x0a,
};
-static git_obj one_obj = {
+static git_rawobj one_obj = {
one_data,
sizeof(one_data),
GIT_OBJ_BLOB
@@ -148,7 +148,7 @@ static unsigned char two_data[] = {
0x61, 0x0a,
};
-static git_obj two_obj = {
+static git_rawobj two_obj = {
two_data,
sizeof(two_data),
GIT_OBJ_BLOB
@@ -306,13 +306,13 @@ static unsigned char some_data[] = {
0x0a,
};
-static git_obj some_obj = {
+static git_rawobj some_obj = {
some_data,
sizeof(some_data),
GIT_OBJ_BLOB
};
-static git_obj junk_obj = {
+static git_rawobj junk_obj = {
NULL,
0,
GIT_OBJ_BAD
diff --git a/tests/t0202-readloose.c b/tests/t0202-readloose.c
index 6e9fb9d..3cb99e4 100644
--- a/tests/t0202-readloose.c
+++ b/tests/t0202-readloose.c
@@ -526,7 +526,7 @@ static object_data some = {
BEGIN_TEST(read_loose_commit)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &commit));
must_pass(git_odb_open(&db, odb_dir));
@@ -543,7 +543,7 @@ END_TEST
BEGIN_TEST(read_loose_tree)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &tree));
must_pass(git_odb_open(&db, odb_dir));
@@ -560,7 +560,7 @@ END_TEST
BEGIN_TEST(read_loose_tag)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &tag));
must_pass(git_odb_open(&db, odb_dir));
@@ -577,7 +577,7 @@ END_TEST
BEGIN_TEST(read_loose_zero)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &zero));
must_pass(git_odb_open(&db, odb_dir));
@@ -594,7 +594,7 @@ END_TEST
BEGIN_TEST(read_loose_one)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &one));
must_pass(git_odb_open(&db, odb_dir));
@@ -611,7 +611,7 @@ END_TEST
BEGIN_TEST(read_loose_two)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &two));
must_pass(git_odb_open(&db, odb_dir));
@@ -628,7 +628,7 @@ END_TEST
BEGIN_TEST(read_loose_some)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &some));
must_pass(git_odb_open(&db, odb_dir));
diff --git a/tests/t0203-readloose.c b/tests/t0203-readloose.c
index 77bad85..5952c2e 100644
--- a/tests/t0203-readloose.c
+++ b/tests/t0203-readloose.c
@@ -527,7 +527,7 @@ static object_data some = {
BEGIN_TEST(read_loose_commit)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &commit));
must_pass(git_odb_open(&db, odb_dir));
@@ -544,7 +544,7 @@ END_TEST
BEGIN_TEST(read_loose_tree)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &tree));
must_pass(git_odb_open(&db, odb_dir));
@@ -561,7 +561,7 @@ END_TEST
BEGIN_TEST(read_loose_tag)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &tag));
must_pass(git_odb_open(&db, odb_dir));
@@ -578,7 +578,7 @@ END_TEST
BEGIN_TEST(read_loose_zero)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &zero));
must_pass(git_odb_open(&db, odb_dir));
@@ -595,7 +595,7 @@ END_TEST
BEGIN_TEST(read_loose_one)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &one));
must_pass(git_odb_open(&db, odb_dir));
@@ -612,7 +612,7 @@ END_TEST
BEGIN_TEST(read_loose_two)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &two));
must_pass(git_odb_open(&db, odb_dir));
@@ -629,7 +629,7 @@ END_TEST
BEGIN_TEST(read_loose_some)
git_odb *db;
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(write_object_files(odb_dir, &some));
must_pass(git_odb_open(&db, odb_dir));
diff --git a/tests/t0204-readpack.c b/tests/t0204-readpack.c
index 49ae9af..8310ea3 100644
--- a/tests/t0204-readpack.c
+++ b/tests/t0204-readpack.c
@@ -141,7 +141,7 @@ BEGIN_TEST(readpacked_test)
for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) {
git_oid id;
- git_obj obj;
+ git_rawobj obj;
must_pass(git_oid_mkstr(&id, packed_objects[i]));
must_be_true(git_odb_exists(db, &id) == 1);
diff --git a/tests/t0301-write.c b/tests/t0301-write.c
index b4440c0..6c995bb 100644
--- a/tests/t0301-write.c
+++ b/tests/t0301-write.c
@@ -65,7 +65,7 @@ static unsigned char commit_data[] = {
0x3e, 0x0a,
};
-static git_obj commit_obj = {
+static git_rawobj commit_obj = {
commit_data,
sizeof(commit_data),
GIT_OBJ_COMMIT
@@ -96,7 +96,7 @@ static unsigned char tree_data[] = {
0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91,
};
-static git_obj tree_obj = {
+static git_rawobj tree_obj = {
tree_data,
sizeof(tree_data),
GIT_OBJ_TREE
@@ -133,7 +133,7 @@ static unsigned char tag_data[] = {
0x2e, 0x30, 0x2e, 0x31, 0x0a,
};
-static git_obj tag_obj = {
+static git_rawobj tag_obj = {
tag_data,
sizeof(tag_data),
GIT_OBJ_TAG
@@ -149,7 +149,7 @@ static unsigned char zero_data[] = {
0x00 /* dummy data */
};
-static git_obj zero_obj = {
+static git_rawobj zero_obj = {
zero_data,
0,
GIT_OBJ_BLOB
@@ -165,7 +165,7 @@ static unsigned char one_data[] = {
0x0a,
};
-static git_obj one_obj = {
+static git_rawobj one_obj = {
one_data,
sizeof(one_data),
GIT_OBJ_BLOB
@@ -181,7 +181,7 @@ static unsigned char two_data[] = {
0x61, 0x0a,
};
-static git_obj two_obj = {
+static git_rawobj two_obj = {
two_data,
sizeof(two_data),
GIT_OBJ_BLOB
@@ -343,7 +343,7 @@ static unsigned char some_data[] = {
0x0a,
};
-static git_obj some_obj = {
+static git_rawobj some_obj = {
some_data,
sizeof(some_data),
GIT_OBJ_BLOB
@@ -390,7 +390,7 @@ static int check_object_files(object_data *d)
return 0;
}
-static int cmp_objects(git_obj *o1, git_obj *o2)
+static int cmp_objects(git_rawobj *o1, git_rawobj *o2)
{
if (o1->type != o2->type)
return -1;
@@ -404,7 +404,7 @@ static int cmp_objects(git_obj *o1, git_obj *o2)
BEGIN_TEST(write_commit)
git_odb *db;
git_oid id1, id2;
- git_obj obj;
+ git_rawobj obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
@@ -425,7 +425,7 @@ END_TEST
BEGIN_TEST(write_tree)
git_odb *db;
git_oid id1, id2;
- git_obj obj;
+ git_rawobj obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
@@ -446,7 +446,7 @@ END_TEST
BEGIN_TEST(write_tag)
git_odb *db;
git_oid id1, id2;
- git_obj obj;
+ git_rawobj obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
@@ -467,7 +467,7 @@ END_TEST
BEGIN_TEST(write_zero)
git_odb *db;
git_oid id1, id2;
- git_obj obj;
+ git_rawobj obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
@@ -488,7 +488,7 @@ END_TEST
BEGIN_TEST(write_one)
git_odb *db;
git_oid id1, id2;
- git_obj obj;
+ git_rawobj obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
@@ -509,7 +509,7 @@ END_TEST
BEGIN_TEST(write_two)
git_odb *db;
git_oid id1, id2;
- git_obj obj;
+ git_rawobj obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
@@ -530,7 +530,7 @@ END_TEST
BEGIN_TEST(write_some)
git_odb *db;
git_oid id1, id2;
- git_obj obj;
+ git_rawobj obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
diff --git a/tests/test_helpers.c b/tests/test_helpers.c
index 46a29b4..e7c2692 100644
--- a/tests/test_helpers.c
+++ b/tests/test_helpers.c
@@ -82,7 +82,7 @@ int remove_object_files(const char *odb_dir, object_data *d)
return 0;
}
-int cmp_objects(git_obj *o, object_data *d)
+int cmp_objects(git_rawobj *o, object_data *d)
{
if (o->type != git_obj_string_to_type(d->type))
return -1;
diff --git a/tests/test_helpers.h b/tests/test_helpers.h
index 2c09181..342a852 100644
--- a/tests/test_helpers.h
+++ b/tests/test_helpers.h
@@ -47,7 +47,7 @@ extern int write_object_files(const char *odb_dir, object_data *d);
extern int remove_object_files(const char *odb_dir, object_data *d);
-extern int cmp_objects(git_obj *o, object_data *d);
+extern int cmp_objects(git_rawobj *o, object_data *d);
#endif
/* INCLUDE_test_helpers_h__ */