inline struct got_object_id in struct got_object_qid Saves us from doing a malloc/free call for every item on the list. ok op@
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
diff --git a/got/got.c b/got/got.c
index 0e1d784..b9754c1 100644
--- a/got/got.c
+++ b/got/got.c
@@ -27,6 +27,7 @@
#include <limits.h>
#include <locale.h>
#include <ctype.h>
+#include <sha1.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -3552,7 +3553,7 @@ get_changed_paths(struct got_pathlist_head *paths,
if (qid != NULL) {
struct got_commit_object *pcommit;
err = got_object_open_as_commit(&pcommit, repo,
- qid->id);
+ &qid->id);
if (err)
return err;
@@ -3601,7 +3602,7 @@ print_patch(struct got_commit_object *commit, struct got_object_id *id,
qid = STAILQ_FIRST(got_object_commit_get_parent_ids(commit));
if (qid != NULL) {
err = got_object_open_as_commit(&pcommit, repo,
- qid->id);
+ &qid->id);
if (err)
return err;
}
@@ -3860,7 +3861,7 @@ print_commit(struct got_commit_object *commit, struct got_object_id *id,
int n = 1;
parent_ids = got_object_commit_get_parent_ids(commit);
STAILQ_FOREACH(qid, parent_ids, entry) {
- err = got_object_id_str(&id_str, qid->id);
+ err = got_object_id_str(&id_str, &qid->id);
if (err)
goto done;
printf("parent %d: %s\n", n++, id_str);
@@ -4006,7 +4007,8 @@ print_commits(struct got_object_id *root_id, struct got_object_id *end_id,
}
if (reverse_display_order) {
STAILQ_FOREACH(qid, &reversed_commits, entry) {
- err = got_object_open_as_commit(&commit, repo, qid->id);
+ err = got_object_open_as_commit(&commit, repo,
+ &qid->id);
if (err)
break;
if (show_changed_paths) {
@@ -4015,7 +4017,7 @@ print_commits(struct got_object_id *root_id, struct got_object_id *end_id,
if (err)
break;
}
- err = print_commit(commit, qid->id, repo, path,
+ err = print_commit(commit, &qid->id, repo, path,
show_changed_paths ? &changed_paths : NULL,
show_patch, diff_context, refs_idmap, NULL);
got_object_commit_close(commit);
@@ -4708,7 +4710,7 @@ cmd_diff(int argc, char *argv[])
struct got_object_qid *pid;
pids = got_object_commit_get_parent_ids(commit);
pid = STAILQ_FIRST(pids);
- ids[0] = got_object_id_dup(pid->id);
+ ids[0] = got_object_id_dup(&pid->id);
if (ids[0] == NULL) {
error = got_error_from_errno(
"got_object_id_dup");
@@ -8530,7 +8532,7 @@ cmd_cherrypick(int argc, char *argv[])
goto done;
pid = STAILQ_FIRST(got_object_commit_get_parent_ids(commit));
memset(&upa, 0, sizeof(upa));
- error = got_worktree_merge_files(worktree, pid ? pid->id : NULL,
+ error = got_worktree_merge_files(worktree, pid ? &pid->id : NULL,
commit_id, repo, update_progress, &upa, check_cancelled,
NULL);
if (error != NULL)
@@ -8632,7 +8634,7 @@ cmd_backout(int argc, char *argv[])
}
memset(&upa, 0, sizeof(upa));
- error = got_worktree_merge_files(worktree, commit_id, pid->id,
+ error = got_worktree_merge_files(worktree, commit_id, &pid->id,
repo, update_progress, &upa, check_cancelled, NULL);
if (error != NULL)
goto done;
@@ -9476,7 +9478,7 @@ cmd_rebase(int argc, char *argv[])
error = got_error(GOT_ERR_EMPTY_REBASE);
goto done;
}
- error = collect_commits(&commits, commit_id, pid->id,
+ error = collect_commits(&commits, commit_id, &pid->id,
yca_id, got_worktree_get_path_prefix(worktree),
GOT_ERR_REBASE_PATH, repo);
got_object_commit_close(commit);
@@ -9521,8 +9523,8 @@ cmd_rebase(int argc, char *argv[])
pid = NULL;
STAILQ_FOREACH(qid, &commits, entry) {
- commit_id = qid->id;
- parent_id = pid ? pid->id : yca_id;
+ commit_id = &qid->id;
+ parent_id = pid ? &pid->id : yca_id;
pid = qid;
memset(&upa, 0, sizeof(upa));
@@ -9536,7 +9538,7 @@ cmd_rebase(int argc, char *argv[])
if (upa.conflicts > 0 || upa.missing > 0 ||
upa.not_deleted > 0 || upa.unversioned > 0) {
if (upa.conflicts > 0) {
- error = show_rebase_merge_conflict(qid->id,
+ error = show_rebase_merge_conflict(&qid->id,
repo);
if (error)
goto done;
@@ -9689,7 +9691,7 @@ histedit_write_commit_list(struct got_object_id_queue *commits,
histedit_cmd = "edit";
else if (fold_only && STAILQ_NEXT(qid, entry) != NULL)
histedit_cmd = "fold";
- err = histedit_write_commit(qid->id, histedit_cmd, f, repo);
+ err = histedit_write_commit(&qid->id, histedit_cmd, f, repo);
if (err)
break;
if (edit_logmsg_only) {
@@ -9715,7 +9717,7 @@ write_cmd_list(FILE *f, const char *branch_name,
struct got_object_qid *qid;
qid = STAILQ_FIRST(commits);
- err = got_object_id_str(&id_str, qid->id);
+ err = got_object_id_str(&id_str, &qid->id);
if (err)
return err;
@@ -10036,11 +10038,11 @@ histedit_check_script(struct got_histedit_list *histedit_cmds,
STAILQ_FOREACH(qid, commits, entry) {
TAILQ_FOREACH(hle, histedit_cmds, entry) {
- if (got_object_id_cmp(qid->id, hle->commit_id) == 0)
+ if (got_object_id_cmp(&qid->id, hle->commit_id) == 0)
break;
}
if (hle == NULL) {
- err = got_object_id_str(&id_str, qid->id);
+ err = got_object_id_str(&id_str, &qid->id);
if (err)
return err;
snprintf(msg, sizeof(msg),
@@ -10709,7 +10711,7 @@ cmd_histedit(int argc, char *argv[])
error = got_error(GOT_ERR_EMPTY_HISTEDIT);
goto done;
}
- error = collect_commits(&commits, head_commit_id, pid->id,
+ error = collect_commits(&commits, head_commit_id, &pid->id,
base_commit_id, got_worktree_get_path_prefix(worktree),
GOT_ERR_HISTEDIT_PATH, repo);
got_object_commit_close(commit);
@@ -10750,7 +10752,7 @@ cmd_histedit(int argc, char *argv[])
error = got_error(GOT_ERR_EMPTY_HISTEDIT);
goto done;
}
- error = collect_commits(&commits, head_commit_id, pid->id,
+ error = collect_commits(&commits, head_commit_id, &pid->id,
got_worktree_get_base_commit_id(worktree),
got_worktree_get_path_prefix(worktree),
GOT_ERR_HISTEDIT_PATH, repo);
@@ -10880,7 +10882,7 @@ cmd_histedit(int argc, char *argv[])
pid = STAILQ_FIRST(parent_ids);
error = got_worktree_histedit_merge_files(&merged_paths,
- worktree, fileindex, pid->id, hle->commit_id, repo,
+ worktree, fileindex, &pid->id, hle->commit_id, repo,
update_progress, &upa, check_cancelled, NULL);
if (error)
goto done;
@@ -11750,7 +11752,7 @@ cat_commit(struct got_object_id *id, struct got_repository *repo, FILE *outfile)
got_object_commit_get_nparents(commit));
STAILQ_FOREACH(pid, parent_ids, entry) {
char *pid_str;
- err = got_object_id_str(&pid_str, pid->id);
+ err = got_object_id_str(&pid_str, &pid->id);
if (err)
goto done;
fprintf(outfile, "%s%s\n", GOT_COMMIT_LABEL_PARENT, pid_str);
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index d1549fb..3d8c001 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -24,6 +24,7 @@
#include <err.h>
#include <errno.h>
#include <regex.h>
+#include <sha1.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
@@ -3703,7 +3704,7 @@ gw_get_commit(struct gw_trans *gw_trans, struct gw_header *header,
parent_id = STAILQ_FIRST(
got_object_commit_get_parent_ids(commit));
if (parent_id != NULL) {
- id2 = got_object_id_dup(parent_id->id);
+ id2 = got_object_id_dup(&parent_id->id);
free (parent_id);
error = got_object_id_str(&header->parent_id, id2);
if (error)
diff --git a/include/got_object.h b/include/got_object.h
index 9d6f362..0a162cb 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -14,7 +14,9 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-struct got_object_id;
+struct got_object_id {
+ u_int8_t sha1[SHA1_DIGEST_LENGTH];
+};
struct got_blob_object;
struct got_tree_object;
@@ -24,7 +26,7 @@ struct got_commit_object;
struct got_object_qid {
STAILQ_ENTRY(got_object_qid) entry;
- struct got_object_id *id;
+ struct got_object_id id;
void *data; /* managed by API user */
};
diff --git a/lib/blame.c b/lib/blame.c
index 19208f0..5e6b967 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -215,7 +215,7 @@ blame_commit(struct got_blame *blame, struct got_object_id *id,
return NULL;
}
- err = got_object_open_as_commit(&pcommit, repo, pid->id);
+ err = got_object_open_as_commit(&pcommit, repo, &pid->id);
if (err)
goto done;
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 644fd4c..01dc826 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -126,7 +126,7 @@ detect_changed_path(int *changed, struct got_commit_object *commit,
if (err)
return err;
- err = got_object_open_as_commit(&pcommit, repo, pid->id);
+ err = got_object_open_as_commit(&pcommit, repo, &pid->id);
if (err)
goto done;
@@ -215,9 +215,9 @@ packed_first_parent_traversal(int *ncommits_traversed,
STAILQ_FOREACH(qid, &traversed_commits, entry) {
struct got_commit_graph_node *node;
- if (got_object_idset_contains(graph->open_branches, qid->id))
+ if (got_object_idset_contains(graph->open_branches, &qid->id))
continue;
- if (got_object_idset_contains(graph->node_ids, qid->id))
+ if (got_object_idset_contains(graph->node_ids, &qid->id))
continue;
(*ncommits_traversed)++;
@@ -225,11 +225,11 @@ packed_first_parent_traversal(int *ncommits_traversed,
/* ... except the last commit is the new branch tip. */
if (STAILQ_NEXT(qid, entry) == NULL) {
err = got_object_idset_add(graph->open_branches,
- qid->id, NULL);
+ &qid->id, NULL);
break;
}
- err = add_node(&node, graph, qid->id, repo);
+ err = add_node(&node, graph, &qid->id, repo);
if (err)
break;
}
@@ -263,7 +263,7 @@ advance_branch(struct got_commit_graph *graph, struct got_object_id *commit_id,
if (graph->flags & GOT_COMMIT_GRAPH_FIRST_PARENT_TRAVERSAL) {
qid = STAILQ_FIRST(&commit->parent_ids);
if (qid == NULL ||
- got_object_idset_contains(graph->open_branches, qid->id))
+ got_object_idset_contains(graph->open_branches, &qid->id))
return NULL;
/*
* The root directory always changes by definition, and when
@@ -277,12 +277,12 @@ advance_branch(struct got_commit_graph *graph, struct got_object_id *commit_id,
(commit->flags & GOT_COMMIT_FLAG_PACKED)) {
int ncommits = 0;
err = packed_first_parent_traversal(&ncommits,
- graph, qid->id, repo);
+ graph, &qid->id, repo);
if (err || ncommits > 0)
return err;
}
return got_object_idset_add(graph->open_branches,
- qid->id, NULL);
+ &qid->id, NULL);
}
/*
@@ -303,11 +303,11 @@ advance_branch(struct got_commit_graph *graph, struct got_object_id *commit_id,
struct got_commit_object *pcommit = NULL;
if (got_object_idset_contains(graph->open_branches,
- qid->id))
+ &qid->id))
continue;
err = got_object_open_as_commit(&pcommit, repo,
- qid->id);
+ &qid->id);
if (err) {
free(merged_id);
free(prev_id);
@@ -341,7 +341,7 @@ advance_branch(struct got_commit_graph *graph, struct got_object_id *commit_id,
*/
if (got_object_id_cmp(merged_id, id) == 0) {
err = got_object_idset_add(graph->open_branches,
- qid->id, NULL);
+ &qid->id, NULL);
free(merged_id);
free(id);
return err;
@@ -362,22 +362,23 @@ advance_branch(struct got_commit_graph *graph, struct got_object_id *commit_id,
if (qid == NULL)
return NULL;
if (got_object_idset_contains(graph->open_branches,
- qid->id))
+ &qid->id))
return NULL;
if (got_object_idset_contains(graph->node_ids,
- qid->id))
+ &qid->id))
return NULL; /* parent already traversed */
return got_object_idset_add(graph->open_branches,
- qid->id, NULL);
+ &qid->id, NULL);
}
}
STAILQ_FOREACH(qid, &commit->parent_ids, entry) {
- if (got_object_idset_contains(graph->open_branches, qid->id))
+ if (got_object_idset_contains(graph->open_branches, &qid->id))
continue;
- if (got_object_idset_contains(graph->node_ids, qid->id))
+ if (got_object_idset_contains(graph->node_ids, &qid->id))
continue; /* parent already traversed */
- err = got_object_idset_add(graph->open_branches, qid->id, NULL);
+ err = got_object_idset_add(graph->open_branches, &qid->id,
+ NULL);
if (err)
return err;
}
diff --git a/lib/diff3.c b/lib/diff3.c
index aa2b7c6..f28b50b 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -69,6 +69,7 @@
#include <ctype.h>
#include <limits.h>
+#include <sha1.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
diff --git a/lib/diffreg.c b/lib/diffreg.c
index 7bfd862..8121609 100644
--- a/lib/diffreg.c
+++ b/lib/diffreg.c
@@ -20,6 +20,7 @@
#include <sys/queue.h>
#include <errno.h>
+#include <sha1.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/lib/got_lib_object.h b/lib/got_lib_object.h
index 7a4aaaa..6af8d57 100644
--- a/lib/got_lib_object.h
+++ b/lib/got_lib_object.h
@@ -14,10 +14,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-struct got_object_id {
- u_int8_t sha1[SHA1_DIGEST_LENGTH];
-};
-
struct got_object {
int type;
diff --git a/lib/object.c b/lib/object.c
index f6a83e1..b87e6ee 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -930,20 +930,11 @@ got_object_commit_open(struct got_commit_object **commit,
const struct got_error *
got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id)
{
- const struct got_error *err = NULL;
-
*qid = calloc(1, sizeof(**qid));
if (*qid == NULL)
return got_error_from_errno("calloc");
- (*qid)->id = got_object_id_dup(id);
- if ((*qid)->id == NULL) {
- err = got_error_from_errno("got_object_id_dup");
- got_object_qid_free(*qid);
- *qid = NULL;
- return err;
- }
-
+ memcpy(&(*qid)->id, id, sizeof((*qid)->id));
return NULL;
}
@@ -960,7 +951,7 @@ got_object_id_queue_copy(const struct got_object_id_queue *src,
* Deep-copy the object ID only. Let the caller deal
* with setting up the new->data pointer if needed.
*/
- err = got_object_qid_alloc(&new, qid->id);
+ err = got_object_qid_alloc(&new, &qid->id);
if (err) {
got_object_id_queue_free(dest);
return err;
diff --git a/lib/object_cache.c b/lib/object_cache.c
index c684ffd..644fb1a 100644
--- a/lib/object_cache.c
+++ b/lib/object_cache.c
@@ -122,7 +122,7 @@ get_size_commit(struct got_commit_object *commit)
size += strlen(commit->logmsg);
STAILQ_FOREACH(qid, &commit->parent_ids, entry)
- size += sizeof(*qid) + sizeof(*qid->id);
+ size += sizeof(*qid) + sizeof(qid->id);
return size;
}
diff --git a/lib/object_create.c b/lib/object_create.c
index 3102c04..a3ad673 100644
--- a/lib/object_create.c
+++ b/lib/object_create.c
@@ -507,7 +507,7 @@ got_object_commit_create(struct got_object_id **id,
STAILQ_FOREACH(qid, parent_ids, entry) {
char *parent_str = NULL;
- err = got_object_id_str(&id_str, qid->id);
+ err = got_object_id_str(&id_str, &qid->id);
if (err)
goto done;
if (asprintf(&parent_str, "%s%s\n",
diff --git a/lib/object_idset.c b/lib/object_idset.c
index e27d30c..a6f2789 100644
--- a/lib/object_idset.c
+++ b/lib/object_idset.c
@@ -123,7 +123,7 @@ idset_resize(struct got_object_idset *set, size_t nbuckets)
uint64_t idx;
qid = STAILQ_FIRST(&set->ids[i]);
STAILQ_REMOVE(&set->ids[i], qid, got_object_qid, entry);
- idx = idset_hash(set, qid->id) % nbuckets;
+ idx = idset_hash(set, &qid->id) % nbuckets;
STAILQ_INSERT_HEAD(&ids[idx], qid, entry);
}
}
@@ -170,7 +170,7 @@ got_object_idset_add(struct got_object_idset *set, struct got_object_id *id,
err = got_object_qid_alloc_partial(&qid);
if (err)
return err;
- memcpy(qid->id, id, sizeof(*qid->id));
+ memcpy(&qid->id, id, sizeof(qid->id));
qid->data = data;
idx = idset_hash(set, id) % set->nbuckets;
@@ -192,7 +192,7 @@ find_element(struct got_object_idset *set, struct got_object_id *id)
struct got_object_qid *qid;
STAILQ_FOREACH(qid, head, entry) {
- if (got_object_id_cmp(qid->id, id) == 0)
+ if (got_object_id_cmp(&qid->id, id) == 0)
return qid;
}
@@ -232,7 +232,7 @@ got_object_idset_remove(void **data, struct got_object_idset *set,
idx = idset_hash(set, id) % set->nbuckets;
head = &set->ids[idx];
STAILQ_FOREACH(qid, head, entry) {
- if (got_object_id_cmp(qid->id, id) == 0)
+ if (got_object_id_cmp(&qid->id, id) == 0)
break;
}
if (qid == NULL)
@@ -270,7 +270,7 @@ got_object_idset_for_each(struct got_object_idset *set,
for (i = 0; i < set->nbuckets; i++) {
head = &set->ids[i];
STAILQ_FOREACH_SAFE(qid, head, entry, tmp) {
- err = (*cb)(qid->id, qid->data, arg);
+ err = (*cb)(&qid->id, qid->data, arg);
if (err)
goto done;
}
diff --git a/lib/object_parse.c b/lib/object_parse.c
index 3b225ca..5110532 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -78,21 +78,11 @@ got_object_id_cmp(const struct got_object_id *id1,
const struct got_error *
got_object_qid_alloc_partial(struct got_object_qid **qid)
{
- const struct got_error *err = NULL;
-
*qid = malloc(sizeof(**qid));
if (*qid == NULL)
return got_error_from_errno("malloc");
- (*qid)->id = malloc(sizeof(*((*qid)->id)));
- if ((*qid)->id == NULL) {
- err = got_error_from_errno("malloc");
- got_object_qid_free(*qid);
- *qid = NULL;
- return err;
- }
(*qid)->data = NULL;
-
return NULL;
}
@@ -164,7 +154,6 @@ got_object_raw_close(struct got_raw_object *obj)
void
got_object_qid_free(struct got_object_qid *qid)
{
- free(qid->id);
free(qid);
}
@@ -314,7 +303,7 @@ got_object_commit_add_parent(struct got_commit_object *commit,
if (err)
return err;
- if (!got_parse_sha1_digest(qid->id->sha1, id_str)) {
+ if (!got_parse_sha1_digest(qid->id.sha1, id_str)) {
err = got_error(GOT_ERR_BAD_OBJ_DATA);
got_object_qid_free(qid);
return err;
diff --git a/lib/pack.c b/lib/pack.c
index 4aa9467..d875046 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -701,7 +701,7 @@ got_packidx_match_id_str_prefix(struct got_object_id_queue *matched_ids,
err = got_object_qid_alloc_partial(&qid);
if (err)
break;
- memcpy(qid->id->sha1, oid->sha1, SHA1_DIGEST_LENGTH);
+ memcpy(qid->id.sha1, oid->sha1, SHA1_DIGEST_LENGTH);
STAILQ_INSERT_TAIL(matched_ids, qid, entry);
oid = &packidx->hdr.sorted_ids[++i];
diff --git a/lib/pack_create.c b/lib/pack_create.c
index 81518d5..14aa435 100644
--- a/lib/pack_create.c
+++ b/lib/pack_create.c
@@ -985,12 +985,12 @@ load_tree(int want_meta, struct got_object_idset *idset,
qid = STAILQ_FIRST(&tree_ids);
STAILQ_REMOVE_HEAD(&tree_ids, entry);
- if (got_object_idset_contains(idset, qid->id)) {
+ if (got_object_idset_contains(idset, &qid->id)) {
got_object_qid_free(qid);
continue;
}
- err = add_object(want_meta, idset, qid->id, dpath,
+ err = add_object(want_meta, idset, &qid->id, dpath,
GOT_OBJ_TYPE_TREE, mtime, loose_obj_only, repo,
ncolored, nfound, ntrees, progress_cb, progress_arg, rl);
if (err) {
@@ -998,7 +998,7 @@ load_tree(int want_meta, struct got_object_idset *idset,
break;
}
- err = load_tree_entries(&tree_ids, want_meta, idset, qid->id,
+ err = load_tree_entries(&tree_ids, want_meta, idset, &qid->id,
dpath, mtime, repo, loose_obj_only, ncolored, nfound,
ntrees, progress_cb, progress_arg, rl,
cancel_cb, cancel_arg);
@@ -1230,47 +1230,48 @@ paint_commits(int *ncolored, struct got_object_id_queue *ids, int nids,
if (color == COLOR_SKIP)
nskip--;
- if (got_object_idset_contains(skip, qid->id)) {
+ if (got_object_idset_contains(skip, &qid->id)) {
got_object_qid_free(qid);
continue;
}
switch (color) {
case COLOR_KEEP:
- if (got_object_idset_contains(keep, qid->id)) {
+ if (got_object_idset_contains(keep, &qid->id)) {
got_object_qid_free(qid);
continue;
}
- if (got_object_idset_contains(drop, qid->id)) {
+ if (got_object_idset_contains(drop, &qid->id)) {
err = paint_commit(qid, COLOR_SKIP);
if (err)
goto done;
nskip++;
} else
(*ncolored)++;
- err = got_object_idset_add(keep, qid->id, NULL);
+ err = got_object_idset_add(keep, &qid->id, NULL);
if (err)
goto done;
break;
case COLOR_DROP:
- if (got_object_idset_contains(drop, qid->id)) {
+ if (got_object_idset_contains(drop, &qid->id)) {
got_object_qid_free(qid);
continue;
}
- if (got_object_idset_contains(keep, qid->id)) {
+ if (got_object_idset_contains(keep, &qid->id)) {
err = paint_commit(qid, COLOR_SKIP);
if (err)
goto done;
nskip++;
} else
(*ncolored)++;
- err = got_object_idset_add(drop, qid->id, NULL);
+ err = got_object_idset_add(drop, &qid->id, NULL);
if (err)
goto done;
break;
case COLOR_SKIP:
- if (!got_object_idset_contains(skip, qid->id)) {
- err = got_object_idset_add(skip, qid->id, NULL);
+ if (!got_object_idset_contains(skip, &qid->id)) {
+ err = got_object_idset_add(skip, &qid->id,
+ NULL);
if (err)
goto done;
}
@@ -1288,7 +1289,7 @@ paint_commits(int *ncolored, struct got_object_id_queue *ids, int nids,
break;
- err = got_object_open_as_commit(&commit, repo, qid->id);
+ err = got_object_open_as_commit(&commit, repo, &qid->id);
if (err)
break;
@@ -1297,7 +1298,7 @@ paint_commits(int *ncolored, struct got_object_id_queue *ids, int nids,
struct got_object_qid *pid;
color = *((int *)qid->data);
STAILQ_FOREACH(pid, parents, entry) {
- err = queue_commit_id(ids, pid->id, color,
+ err = queue_commit_id(ids, &pid->id, color,
repo);
if (err)
break;
diff --git a/lib/privsep.c b/lib/privsep.c
index 67b0e54..de7f8e9 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -1308,7 +1308,7 @@ got_privsep_send_commit(struct imsgbuf *ibuf, struct got_commit_object *commit)
memcpy(buf + len, commit->committer, committer_len);
len += committer_len;
STAILQ_FOREACH(qid, &commit->parent_ids, entry) {
- memcpy(buf + len, qid->id, SHA1_DIGEST_LENGTH);
+ memcpy(buf + len, &qid->id, SHA1_DIGEST_LENGTH);
len += SHA1_DIGEST_LENGTH;
}
@@ -1444,8 +1444,8 @@ get_commit_from_imsg(struct got_commit_object **commit,
err = got_object_qid_alloc_partial(&qid);
if (err)
break;
- memcpy(qid->id, imsg->data + len +
- i * SHA1_DIGEST_LENGTH, sizeof(*qid->id));
+ memcpy(&qid->id, imsg->data + len +
+ i * SHA1_DIGEST_LENGTH, sizeof(qid->id));
STAILQ_INSERT_TAIL(&(*commit)->parent_ids, qid, entry);
(*commit)->nparents++;
}
@@ -2688,13 +2688,13 @@ got_privsep_recv_traversed_commits(struct got_commit_object **changed_commit,
err = got_object_qid_alloc_partial(&qid);
if (err)
break;
- memcpy(qid->id->sha1, sha1, SHA1_DIGEST_LENGTH);
+ memcpy(qid->id.sha1, sha1, SHA1_DIGEST_LENGTH);
STAILQ_INSERT_TAIL(commit_ids, qid, entry);
/* The last commit may contain a change. */
if (i == icommits->ncommits - 1) {
*changed_commit_id =
- got_object_id_dup(qid->id);
+ got_object_id_dup(&qid->id);
if (*changed_commit_id == NULL) {
err = got_error_from_errno(
"got_object_id_dup");
diff --git a/lib/repository.c b/lib/repository.c
index 634a1c3..7896e91 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -1480,20 +1480,21 @@ match_packed_object(struct got_object_id **unique_id,
if (obj_type != GOT_OBJ_TYPE_ANY) {
int matched_type;
err = got_object_get_type(&matched_type, repo,
- qid->id);
+ &qid->id);
if (err)
goto done;
if (matched_type != obj_type)
continue;
}
if (*unique_id == NULL) {
- *unique_id = got_object_id_dup(qid->id);
+ *unique_id = got_object_id_dup(&qid->id);
if (*unique_id == NULL) {
err = got_error_from_errno("malloc");
goto done;
}
} else {
- if (got_object_id_cmp(*unique_id, qid->id) == 0)
+ if (got_object_id_cmp(*unique_id,
+ &qid->id) == 0)
continue; /* packed multiple times */
err = got_error(GOT_ERR_AMBIGUOUS_ID);
goto done;
diff --git a/lib/repository_admin.c b/lib/repository_admin.c
index a2cd689..badde30 100644
--- a/lib/repository_admin.c
+++ b/lib/repository_admin.c
@@ -869,24 +869,24 @@ load_tree(struct got_object_idset *loose_ids,
qid = STAILQ_FIRST(&tree_ids);
STAILQ_REMOVE_HEAD(&tree_ids, entry);
- if (got_object_idset_contains(traversed_ids, qid->id)) {
+ if (got_object_idset_contains(traversed_ids, &qid->id)) {
got_object_qid_free(qid);
continue;
}
- err = got_object_idset_add(traversed_ids, qid->id, NULL);
+ err = got_object_idset_add(traversed_ids, &qid->id, NULL);
if (err) {
got_object_qid_free(qid);
break;
}
/* This tree is referenced. */
- err = preserve_loose_object(loose_ids, qid->id, repo, npacked);
+ err = preserve_loose_object(loose_ids, &qid->id, repo, npacked);
if (err)
break;
err = load_tree_entries(&tree_ids, loose_ids, traversed_ids,
- qid->id, dpath, repo, npacked, cancel_cb, cancel_arg);
+ &qid->id, dpath, repo, npacked, cancel_cb, cancel_arg);
got_object_qid_free(qid);
if (err)
break;
@@ -929,32 +929,33 @@ load_commit_or_tag(struct got_object_idset *loose_ids, int *ncommits,
qid = STAILQ_FIRST(&ids);
STAILQ_REMOVE_HEAD(&ids, entry);
- if (got_object_idset_contains(traversed_ids, qid->id)) {
+ if (got_object_idset_contains(traversed_ids, &qid->id)) {
got_object_qid_free(qid);
qid = NULL;
continue;
}
- err = got_object_idset_add(traversed_ids, qid->id, NULL);
+ err = got_object_idset_add(traversed_ids, &qid->id, NULL);
if (err)
break;
/* This commit or tag is referenced. */
- err = preserve_loose_object(loose_ids, qid->id, repo, npacked);
+ err = preserve_loose_object(loose_ids, &qid->id, repo, npacked);
if (err)
break;
- err = got_object_get_type(&obj_type, repo, qid->id);
+ err = got_object_get_type(&obj_type, repo, &qid->id);
if (err)
break;
switch (obj_type) {
case GOT_OBJ_TYPE_COMMIT:
- err = got_object_open_as_commit(&commit, repo, qid->id);
+ err = got_object_open_as_commit(&commit, repo,
+ &qid->id);
if (err)
goto done;
break;
case GOT_OBJ_TYPE_TAG:
- err = got_object_open_as_tag(&tag, repo, qid->id);
+ err = got_object_open_as_tag(&tag, repo, &qid->id);
if (err)
goto done;
break;
@@ -987,7 +988,7 @@ load_commit_or_tag(struct got_object_idset *loose_ids, int *ncommits,
* and the object it points to on disk.
*/
err = got_object_idset_remove(NULL, loose_ids,
- qid->id);
+ &qid->id);
if (err && err->code != GOT_ERR_NO_OBJ)
goto done;
err = got_object_idset_remove(NULL, loose_ids,
diff --git a/lib/worktree_open.c b/lib/worktree_open.c
index 965700c..673cbeb 100644
--- a/lib/worktree_open.c
+++ b/lib/worktree_open.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <sha1.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/libexec/got-read-pack/got-read-pack.c b/libexec/got-read-pack/got-read-pack.c
index a14d051..b014128 100644
--- a/libexec/got-read-pack/got-read-pack.c
+++ b/libexec/got-read-pack/got-read-pack.c
@@ -683,11 +683,11 @@ commit_traversal_request(struct imsg *imsg, struct imsgbuf *ibuf,
if (pid == NULL)
break;
- idx = got_packidx_get_object_idx(packidx, pid->id);
+ idx = got_packidx_get_object_idx(packidx, &pid->id);
if (idx == -1)
break;
- err = open_commit(&pcommit, pack, packidx, idx, pid->id,
+ err = open_commit(&pcommit, pack, packidx, idx, &pid->id,
objcache);
if (err) {
if (err->code != GOT_ERR_NO_OBJ)
@@ -745,7 +745,7 @@ commit_traversal_request(struct imsg *imsg, struct imsgbuf *ibuf,
}
if (!changed) {
- memcpy(id.sha1, pid->id->sha1, SHA1_DIGEST_LENGTH);
+ memcpy(id.sha1, pid->id.sha1, SHA1_DIGEST_LENGTH);
got_object_commit_close(commit);
commit = pcommit;
pcommit = NULL;
diff --git a/tog/tog.c b/tog/tog.c
index 1235f3d..a4221a9 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -24,6 +24,7 @@
#include <curses.h>
#include <panel.h>
#include <locale.h>
+#include <sha1.h>
#include <signal.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -1880,7 +1881,7 @@ open_diff_view_for_commit(struct tog_view **new_view, int begin_x,
return got_error_from_errno("view_open");
parent_id = STAILQ_FIRST(got_object_commit_get_parent_ids(commit));
- err = open_diff_view(diff_view, parent_id ? parent_id->id : NULL,
+ err = open_diff_view(diff_view, parent_id ? &parent_id->id : NULL,
commit_id, NULL, NULL, 3, 0, 0, log_view, repo);
if (err == NULL)
*new_view = diff_view;
@@ -3118,7 +3119,7 @@ get_changed_paths(struct got_pathlist_head *paths,
if (qid != NULL) {
struct got_commit_object *pcommit;
err = got_object_open_as_commit(&pcommit, repo,
- qid->id);
+ &qid->id);
if (err)
return err;
@@ -3261,7 +3262,7 @@ write_commit_info(off_t **line_offsets, size_t *nlines,
int pn = 1;
parent_ids = got_object_commit_get_parent_ids(commit);
STAILQ_FOREACH(qid, parent_ids, entry) {
- err = got_object_id_str(&id_str, qid->id);
+ err = got_object_id_str(&id_str, &qid->id);
if (err)
goto done;
n = fprintf(outfile, "parent %d: %s\n", pn++, id_str);
@@ -3390,7 +3391,7 @@ create_diff(struct tog_diff_view_state *s)
} else {
parent_ids = got_object_commit_get_parent_ids(commit2);
STAILQ_FOREACH(pid, parent_ids, entry) {
- if (got_object_id_cmp(s->id1, pid->id) == 0) {
+ if (got_object_id_cmp(s->id1, &pid->id) == 0) {
err = write_commit_info(
&s->line_offsets, &s->nlines,
s->id2, refs, s->repo, s->f);
@@ -3699,7 +3700,7 @@ set_selected_commit(struct tog_diff_view_state *s,
parent_ids = got_object_commit_get_parent_ids(selected_commit);
free(s->id1);
pid = STAILQ_FIRST(parent_ids);
- s->id1 = pid ? got_object_id_dup(pid->id) : NULL;
+ s->id1 = pid ? got_object_id_dup(&pid->id) : NULL;
got_object_commit_close(selected_commit);
return NULL;
}
@@ -4014,7 +4015,7 @@ draw_blame(struct tog_view *view)
char *id_str;
struct tog_color *tc;
- err = got_object_id_str(&id_str, s->blamed_commit->id);
+ err = got_object_id_str(&id_str, &s->blamed_commit->id);
if (err)
return err;
@@ -4337,7 +4338,7 @@ run_blame(struct tog_view *view)
int obj_type;
err = got_object_open_as_commit(&commit, s->repo,
- s->blamed_commit->id);
+ &s->blamed_commit->id);
if (err)
return err;
@@ -4388,7 +4389,7 @@ run_blame(struct tog_view *view)
blame->cb_args.view = view;
blame->cb_args.lines = blame->lines;
blame->cb_args.nlines = blame->nlines;
- blame->cb_args.commit_id = got_object_id_dup(s->blamed_commit->id);
+ blame->cb_args.commit_id = got_object_id_dup(&s->blamed_commit->id);
if (blame->cb_args.commit_id == NULL) {
err = got_error_from_errno("got_object_id_dup");
goto done;
@@ -4670,7 +4671,7 @@ input_blame_view(struct tog_view **new_view, struct tog_view *view, int ch)
}
/* Check if path history ends here. */
err = got_object_open_as_commit(&pcommit,
- s->repo, pid->id);
+ s->repo, &pid->id);
if (err)
break;
err = got_object_id_by_path(&blob_id, s->repo,
@@ -4691,11 +4692,11 @@ input_blame_view(struct tog_view **new_view, struct tog_view *view, int ch)
break;
}
err = got_object_qid_alloc(&s->blamed_commit,
- pid->id);
+ &pid->id);
got_object_commit_close(commit);
} else {
if (got_object_id_cmp(id,
- s->blamed_commit->id) == 0)
+ &s->blamed_commit->id) == 0)
break;
err = got_object_qid_alloc(&s->blamed_commit,
id);
@@ -4717,7 +4718,7 @@ input_blame_view(struct tog_view **new_view, struct tog_view *view, int ch)
case 'B': {
struct got_object_qid *first;
first = STAILQ_FIRST(&s->blamed_commits);
- if (!got_object_id_cmp(first->id, s->commit_id))
+ if (!got_object_id_cmp(&first->id, s->commit_id))
break;
s->done = 1;
thread_err = stop_blame(&s->blame);
@@ -4755,7 +4756,7 @@ input_blame_view(struct tog_view **new_view, struct tog_view *view, int ch)
err = got_error_from_errno("view_open");
break;
}
- err = open_diff_view(diff_view, pid ? pid->id : NULL,
+ err = open_diff_view(diff_view, pid ? &pid->id : NULL,
id, NULL, NULL, 3, 0, 0, NULL, s->repo);
got_object_commit_close(commit);
if (err) {