stop relying on commit cache for good performance of got_object_id_by_path() Instead of internally opening and closing the same commit object over and over again, require callers to pass an open commit object in. Avoids an inherent dependency on the commit object cache for reasonable performance. 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
diff --git a/got/got.c b/got/got.c
index 36bd7fe..5cb9d72 100644
--- a/got/got.c
+++ b/got/got.c
@@ -3609,7 +3609,7 @@ print_patch(struct got_commit_object *commit, struct got_object_id *id,
if (path && path[0] != '\0') {
int obj_type;
- err = got_object_id_by_path(&obj_id2, repo, id, path);
+ err = got_object_id_by_path(&obj_id2, repo, commit, path);
if (err)
goto done;
err = got_object_id_str(&id_str2, obj_id2);
@@ -3619,7 +3619,7 @@ print_patch(struct got_commit_object *commit, struct got_object_id *id,
}
if (pcommit) {
err = got_object_id_by_path(&obj_id1, repo,
- qid->id, path);
+ pcommit, path);
if (err) {
if (err->code != GOT_ERR_NO_TREE_ENTRY) {
free(obj_id2);
@@ -4984,6 +4984,7 @@ cmd_blame(int argc, char *argv[])
char *link_target = NULL;
struct got_object_id *obj_id = NULL;
struct got_object_id *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
struct got_blob_object *blob = NULL;
char *commit_id_str = NULL;
struct blame_cb_args bca;
@@ -5111,12 +5112,16 @@ cmd_blame(int argc, char *argv[])
worktree = NULL;
}
+ error = got_object_open_as_commit(&commit, repo, commit_id);
+ if (error)
+ goto done;
+
error = got_object_resolve_symlinks(&link_target, in_repo_path,
- commit_id, repo);
+ commit, repo);
if (error)
goto done;
- error = got_object_id_by_path(&obj_id, repo, commit_id,
+ error = got_object_id_by_path(&obj_id, repo, commit,
link_target ? link_target : in_repo_path);
if (error)
goto done;
@@ -5171,6 +5176,8 @@ done:
free(cwd);
free(commit_id);
free(obj_id);
+ if (commit)
+ got_object_commit_close(commit);
if (blob)
got_object_blob_close(blob);
if (worktree)
@@ -5246,7 +5253,7 @@ print_entry(struct got_tree_entry *te, const char *id, const char *path,
}
static const struct got_error *
-print_tree(const char *path, struct got_object_id *commit_id,
+print_tree(const char *path, struct got_commit_object *commit,
int show_ids, int recurse, const char *root_path,
struct got_repository *repo)
{
@@ -5255,7 +5262,7 @@ print_tree(const char *path, struct got_object_id *commit_id,
struct got_tree_object *tree = NULL;
int nentries, i;
- err = got_object_id_by_path(&tree_id, repo, commit_id, path);
+ err = got_object_id_by_path(&tree_id, repo, commit, path);
if (err)
goto done;
@@ -5297,7 +5304,7 @@ print_tree(const char *path, struct got_object_id *commit_id,
err = got_error_from_errno("asprintf");
goto done;
}
- err = print_tree(child_path, commit_id, show_ids, 1,
+ err = print_tree(child_path, commit, show_ids, 1,
root_path, repo);
free(child_path);
if (err)
@@ -5320,6 +5327,7 @@ cmd_tree(int argc, char *argv[])
const char *path, *refname = NULL;
char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
struct got_object_id *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
char *commit_id_str = NULL;
int show_ids = 0, recurse = 0;
int ch;
@@ -5459,13 +5467,19 @@ cmd_tree(int argc, char *argv[])
worktree = NULL;
}
- error = print_tree(in_repo_path, commit_id, show_ids, recurse,
+ error = got_object_open_as_commit(&commit, repo, commit_id);
+ if (error)
+ goto done;
+
+ error = print_tree(in_repo_path, commit, show_ids, recurse,
in_repo_path, repo);
done:
free(in_repo_path);
free(repo_path);
free(cwd);
free(commit_id);
+ if (commit)
+ got_object_commit_close(commit);
if (worktree)
got_worktree_close(worktree);
if (repo) {
@@ -11837,6 +11851,7 @@ cmd_cat(int argc, char *argv[])
char *cwd = NULL, *repo_path = NULL, *label = NULL;
const char *commit_id_str = NULL;
struct got_object_id *id = NULL, *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
int ch, obj_type, i, force_path = 0;
struct got_reflist_head refs;
@@ -11921,9 +11936,13 @@ cmd_cat(int argc, char *argv[])
if (error)
goto done;
+ error = got_object_open_as_commit(&commit, repo, commit_id);
+ if (error)
+ goto done;
+
for (i = 0; i < argc; i++) {
if (force_path) {
- error = got_object_id_by_path(&id, repo, commit_id,
+ error = got_object_id_by_path(&id, repo, commit,
argv[i]);
if (error)
break;
@@ -11936,7 +11955,7 @@ cmd_cat(int argc, char *argv[])
error->code != GOT_ERR_NOT_REF)
break;
error = got_object_id_by_path(&id, repo,
- commit_id, argv[i]);
+ commit, argv[i]);
if (error)
break;
}
@@ -11974,6 +11993,8 @@ done:
free(label);
free(id);
free(commit_id);
+ if (commit)
+ got_object_commit_close(commit);
if (worktree)
got_worktree_close(worktree);
if (repo) {
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index a0286f1..70b31ef 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -4044,6 +4044,7 @@ gw_output_file_blame(struct gw_trans *gw_trans, struct gw_header *header)
const struct got_error *error = NULL;
struct got_object_id *obj_id = NULL;
struct got_object_id *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
struct got_blob_object *blob = NULL;
char *path = NULL, *in_repo_path = NULL;
struct gw_blame_cb_args bca;
@@ -4069,7 +4070,11 @@ gw_output_file_blame(struct gw_trans *gw_trans, struct gw_header *header)
if (error)
goto done;
- error = got_object_id_by_path(&obj_id, gw_trans->repo, commit_id,
+ error = got_object_open_as_commit(&commit, gw_trans->repo, commit_id);
+ if (error)
+ goto done;
+
+ error = got_object_id_by_path(&obj_id, gw_trans->repo, commit,
in_repo_path);
if (error)
goto done;
@@ -4142,6 +4147,8 @@ done:
}
if (blob)
got_object_blob_close(blob);
+ if (commit)
+ got_object_commit_close(commit);
return error;
}
@@ -4151,6 +4158,7 @@ gw_output_blob_buf(struct gw_trans *gw_trans, struct gw_header *header)
const struct got_error *error = NULL;
struct got_object_id *obj_id = NULL;
struct got_object_id *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
struct got_blob_object *blob = NULL;
char *path = NULL, *in_repo_path = NULL;
int obj_type, set_mime = 0;
@@ -4175,7 +4183,11 @@ gw_output_blob_buf(struct gw_trans *gw_trans, struct gw_header *header)
if (error)
goto done;
- error = got_object_id_by_path(&obj_id, gw_trans->repo, commit_id,
+ error = got_object_open_as_commit(&commit, gw_trans->repo, commit_id);
+ if (error)
+ goto done;
+
+ error = got_object_id_by_path(&obj_id, gw_trans->repo, commit,
in_repo_path);
if (error)
goto done;
@@ -4232,6 +4244,8 @@ done:
free(path);
if (blob)
got_object_blob_close(blob);
+ if (commit)
+ got_object_commit_close(commit);
if (error == NULL && kerr != KCGI_OK)
error = gw_kcgi_error(kerr);
return error;
@@ -4243,6 +4257,7 @@ gw_output_repo_tree(struct gw_trans *gw_trans, struct gw_header *header)
const struct got_error *error = NULL;
struct got_object_id *tree_id = NULL, *commit_id = NULL;
struct got_tree_object *tree = NULL;
+ struct got_commit_object *commit = NULL;
char *path = NULL, *in_repo_path = NULL;
char *id_str = NULL;
char *build_folder = NULL;
@@ -4294,7 +4309,11 @@ gw_output_repo_tree(struct gw_trans *gw_trans, struct gw_header *header)
goto done;
}
- error = got_object_id_by_path(&tree_id, gw_trans->repo, commit_id,
+ error = got_object_open_as_commit(&commit, gw_trans->repo, commit_id);
+ if (error)
+ goto done;
+
+ error = got_object_id_by_path(&tree_id, gw_trans->repo, commit,
path);
if (error)
goto done;
@@ -4466,6 +4485,8 @@ gw_output_repo_tree(struct gw_trans *gw_trans, struct gw_header *header)
done:
if (tree)
got_object_tree_close(tree);
+ if (commit)
+ got_object_commit_close(commit);
free(id_str);
free(href_blob);
free(href_blame);
diff --git a/include/got_object.h b/include/got_object.h
index 592e776..9d6f362 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -106,7 +106,7 @@ const struct got_error *got_object_tree_find_path(struct got_object_id **id,
* The caller should dispose of it with free(3).
*/
const struct got_error *got_object_id_by_path(struct got_object_id **,
- struct got_repository *, struct got_object_id *, const char *);
+ struct got_repository *, struct got_commit_object *, const char *);
/*
* Obtain the type of an object.
@@ -241,7 +241,7 @@ int got_object_tree_entry_is_symlink(struct got_tree_entry *);
* target path. The caller must dispose of it with free(3).
*/
const struct got_error *got_object_resolve_symlinks(char **, const char *,
- struct got_object_id *, struct got_repository *);
+ struct got_commit_object *, struct got_repository *);
/*
* Compare two trees and indicate whether the entry at the specified path
diff --git a/lib/blame.c b/lib/blame.c
index d2db8c1..4fb57b6 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -200,7 +200,7 @@ blame_commit(struct got_blame *blame, struct got_object_id *id,
void *arg)
{
const struct got_error *err = NULL;
- struct got_commit_object *commit = NULL;
+ struct got_commit_object *commit = NULL, *pcommit = NULL;
struct got_object_qid *pid = NULL;
struct got_object_id *pblob_id = NULL;
struct got_blob_object *pblob = NULL;
@@ -216,7 +216,11 @@ blame_commit(struct got_blame *blame, struct got_object_id *id,
return NULL;
}
- err = got_object_id_by_path(&pblob_id, repo, pid->id, path);
+ err = got_object_open_as_commit(&pcommit, repo, pid->id);
+ if (err)
+ goto done;
+
+ err = got_object_id_by_path(&pblob_id, repo, pcommit, path);
if (err) {
if (err->code == GOT_ERR_NO_TREE_ENTRY)
err = NULL;
@@ -267,6 +271,8 @@ done:
diff_result_free(diff_result);
if (commit)
got_object_commit_close(commit);
+ if (pcommit)
+ got_object_commit_close(pcommit);
free(pblob_id);
if (pblob)
got_object_blob_close(pblob);
@@ -498,6 +504,7 @@ blame_open(struct got_blame **blamep, const char *path,
void *arg, got_cancel_cb cancel_cb, void *cancel_arg)
{
const struct got_error *err = NULL;
+ struct got_commit_object *start_commit = NULL;
struct got_object_id *obj_id = NULL;
struct got_blob_object *blob = NULL;
struct got_blame *blame = NULL;
@@ -507,7 +514,11 @@ blame_open(struct got_blame **blamep, const char *path,
*blamep = NULL;
- err = got_object_id_by_path(&obj_id, repo, start_commit_id, path);
+ err = got_object_open_as_commit(&start_commit, repo, start_commit_id);
+ if (err)
+ goto done;
+
+ err = got_object_id_by_path(&obj_id, repo, start_commit, path);
if (err)
goto done;
@@ -621,6 +632,8 @@ done:
free(obj_id);
if (blob)
got_object_blob_close(blob);
+ if (start_commit)
+ got_object_commit_close(start_commit);
if (err) {
if (blame)
blame_close(blame);
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 55b4da2..644fd4c 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -112,7 +112,7 @@ detect_changed_path(int *changed, struct got_commit_object *commit,
pid = STAILQ_FIRST(&commit->parent_ids);
if (pid == NULL) {
struct got_object_id *obj_id;
- err = got_object_id_by_path(&obj_id, repo, commit_id, path);
+ err = got_object_id_by_path(&obj_id, repo, commit, path);
if (err) {
if (err->code == GOT_ERR_NO_TREE_ENTRY)
err = NULL;
@@ -293,20 +293,30 @@ advance_branch(struct got_commit_graph *graph, struct got_object_id *commit_id,
struct got_object_id *merged_id, *prev_id = NULL;
int branches_differ = 0;
- err = got_object_id_by_path(&merged_id, repo, commit_id,
+ err = got_object_id_by_path(&merged_id, repo, commit,
graph->path);
if (err)
return err;
STAILQ_FOREACH(qid, &commit->parent_ids, entry) {
- struct got_object_id *id;
+ struct got_object_id *id = NULL;
+ struct got_commit_object *pcommit = NULL;
if (got_object_idset_contains(graph->open_branches,
qid->id))
continue;
- err = got_object_id_by_path(&id, repo, qid->id,
+ err = got_object_open_as_commit(&pcommit, repo,
+ qid->id);
+ if (err) {
+ free(merged_id);
+ free(prev_id);
+ return err;
+ }
+ err = got_object_id_by_path(&id, repo, pcommit,
graph->path);
+ got_object_commit_close(pcommit);
+ pcommit = NULL;
if (err) {
if (err->code == GOT_ERR_NO_TREE_ENTRY) {
branches_differ = 1;
diff --git a/lib/object.c b/lib/object.c
index 8218b2c..f6a83e1 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1998,18 +1998,13 @@ done:
}
const struct got_error *
got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
- struct got_object_id *commit_id, const char *path)
+ struct got_commit_object *commit, const char *path)
{
const struct got_error *err = NULL;
- struct got_commit_object *commit = NULL;
struct got_tree_object *tree = NULL;
*id = NULL;
- err = got_object_open_as_commit(&commit, repo, commit_id);
- if (err)
- goto done;
-
/* Handle opening of root of commit's tree. */
if (got_path_is_root_dir(path)) {
*id = got_object_id_dup(commit->tree_id);
@@ -2022,8 +2017,6 @@ got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
err = got_object_tree_find_path(id, NULL, repo, tree, path);
}
done:
- if (commit)
- got_object_commit_close(commit);
if (tree)
got_object_tree_close(tree);
return err;
@@ -2187,7 +2180,7 @@ got_object_tree_entry_is_symlink(struct got_tree_entry *te)
static const struct got_error *
resolve_symlink(char **link_target, const char *path,
- struct got_object_id *commit_id, struct got_repository *repo)
+ struct got_commit_object *commit, struct got_repository *repo)
{
const struct got_error *err = NULL;
char buf[PATH_MAX];
@@ -2209,7 +2202,7 @@ resolve_symlink(char **link_target, const char *path,
if (err)
return err;
- err = got_object_id_by_path(&tree_obj_id, repo, commit_id,
+ err = got_object_id_by_path(&tree_obj_id, repo, commit,
parent_path);
if (err) {
if (err->code == GOT_ERR_NO_TREE_ENTRY) {
@@ -2265,7 +2258,7 @@ done:
const struct got_error *
got_object_resolve_symlinks(char **link_target, const char *path,
- struct got_object_id *commit_id, struct got_repository *repo)
+ struct got_commit_object *commit, struct got_repository *repo)
{
const struct got_error *err = NULL;
char *next_target = NULL;
@@ -2275,7 +2268,7 @@ got_object_resolve_symlinks(char **link_target, const char *path,
do {
err = resolve_symlink(&next_target,
- *link_target ? *link_target : path, commit_id, repo);
+ *link_target ? *link_target : path, commit, repo);
if (err)
break;
if (next_target) {
diff --git a/lib/worktree.c b/lib/worktree.c
index 16eebc5..bfebb46 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2459,7 +2459,8 @@ done:
static const struct got_error *
find_tree_entry_for_checkout(int *entry_type, char **tree_relpath,
struct got_object_id **tree_id, const char *wt_relpath,
- struct got_worktree *worktree, struct got_repository *repo)
+ struct got_commit_object *base_commit, struct got_worktree *worktree,
+ struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_object_id *id = NULL;
@@ -2478,8 +2479,8 @@ find_tree_entry_for_checkout(int *entry_type, char **tree_relpath,
err = got_error_from_errno("strdup");
goto done;
}
- err = got_object_id_by_path(tree_id, repo,
- worktree->base_commit_id, worktree->path_prefix);
+ err = got_object_id_by_path(tree_id, repo, base_commit,
+ worktree->path_prefix);
if (err)
goto done;
return NULL;
@@ -2493,8 +2494,7 @@ find_tree_entry_for_checkout(int *entry_type, char **tree_relpath,
goto done;
}
- err = got_object_id_by_path(&id, repo, worktree->base_commit_id,
- in_repo_path);
+ err = got_object_id_by_path(&id, repo, base_commit, in_repo_path);
if (err)
goto done;
@@ -2532,7 +2532,7 @@ find_tree_entry_for_checkout(int *entry_type, char **tree_relpath,
}
}
err = got_object_id_by_path(tree_id, repo,
- worktree->base_commit_id, in_repo_path);
+ base_commit, in_repo_path);
} else {
/* Check out all files within a subdirectory. */
*tree_id = got_object_id_dup(id);
@@ -2644,6 +2644,11 @@ got_worktree_checkout_files(struct got_worktree *worktree,
if (err)
return err;
+ err = got_object_open_as_commit(&commit, repo,
+ worktree->base_commit_id);
+ if (err)
+ goto done;
+
/* Map all specified paths to in-repository trees. */
TAILQ_FOREACH(pe, paths, entry) {
tpd = malloc(sizeof(*tpd));
@@ -2653,7 +2658,8 @@ got_worktree_checkout_files(struct got_worktree *worktree,
}
err = find_tree_entry_for_checkout(&tpd->entry_type,
- &tpd->relpath, &tpd->tree_id, pe->path, worktree, repo);
+ &tpd->relpath, &tpd->tree_id, pe->path, commit,
+ worktree, repo);
if (err) {
free(tpd);
goto done;
@@ -3095,12 +3101,16 @@ merge_files(struct got_worktree *worktree, struct got_fileindex *fileindex,
const struct got_error *err = NULL, *sync_err;
struct got_object_id *tree_id1 = NULL, *tree_id2 = NULL;
struct got_tree_object *tree1 = NULL, *tree2 = NULL;
+ struct got_commit_object *commit1 = NULL, *commit2 = NULL;
struct check_merge_conflicts_arg cmc_arg;
struct merge_file_cb_arg arg;
char *label_orig = NULL;
if (commit_id1) {
- err = got_object_id_by_path(&tree_id1, repo, commit_id1,
+ err = got_object_open_as_commit(&commit1, repo, commit_id1);
+ if (err)
+ goto done;
+ err = got_object_id_by_path(&tree_id1, repo, commit1,
worktree->path_prefix);
if (err && err->code != GOT_ERR_NO_TREE_ENTRY)
goto done;
@@ -3125,7 +3135,11 @@ merge_files(struct got_worktree *worktree, struct got_fileindex *fileindex,
free(id_str);
}
- err = got_object_id_by_path(&tree_id2, repo, commit_id2,
+ err = got_object_open_as_commit(&commit2, repo, commit_id2);
+ if (err)
+ goto done;
+
+ err = got_object_id_by_path(&tree_id2, repo, commit2,
worktree->path_prefix);
if (err)
goto done;
@@ -3156,6 +3170,10 @@ merge_files(struct got_worktree *worktree, struct got_fileindex *fileindex,
if (sync_err && err == NULL)
err = sync_err;
done:
+ if (commit1)
+ got_object_commit_close(commit1);
+ if (commit2)
+ got_object_commit_close(commit2);
if (tree1)
got_object_tree_close(tree1);
if (tree2)
@@ -4544,6 +4562,7 @@ revert_file(void *arg, unsigned char status, unsigned char staged_status,
const struct got_error *err = NULL;
char *parent_path = NULL;
struct got_fileindex_entry *ie;
+ struct got_commit_object *base_commit = NULL;
struct got_tree_object *tree = NULL;
struct got_object_id *tree_id = NULL;
const struct got_tree_entry *te = NULL;
@@ -4597,8 +4616,12 @@ revert_file(void *arg, unsigned char status, unsigned char staged_status,
}
}
- err = got_object_id_by_path(&tree_id, a->repo,
- a->worktree->base_commit_id, tree_path);
+ err = got_object_open_as_commit(&base_commit, a->repo,
+ a->worktree->base_commit_id);
+ if (err)
+ goto done;
+
+ err = got_object_id_by_path(&tree_id, a->repo, base_commit, tree_path);
if (err) {
if (!(err->code == GOT_ERR_NO_TREE_ENTRY &&
(status == GOT_STATUS_ADD ||
@@ -4756,6 +4779,8 @@ done:
if (tree)
got_object_tree_close(tree);
free(tree_id);
+ if (base_commit)
+ got_object_commit_close(base_commit);
return err;
}
@@ -5513,6 +5538,7 @@ check_out_of_date(const char *in_repo_path, unsigned char status,
int ood_errcode)
{
const struct got_error *err = NULL;
+ struct got_commit_object *commit = NULL;
struct got_object_id *id = NULL;
if (status != GOT_STATUS_ADD && staged_status != GOT_STATUS_ADD) {
@@ -5523,8 +5549,10 @@ check_out_of_date(const char *in_repo_path, unsigned char status,
* Ensure file content which local changes were based
* on matches file content in the branch head.
*/
- err = got_object_id_by_path(&id, repo, head_commit_id,
- in_repo_path);
+ err = got_object_open_as_commit(&commit, repo, head_commit_id);
+ if (err)
+ goto done;
+ err = got_object_id_by_path(&id, repo, commit, in_repo_path);
if (err) {
if (err->code == GOT_ERR_NO_TREE_ENTRY)
err = got_error(ood_errcode);
@@ -5533,14 +5561,18 @@ check_out_of_date(const char *in_repo_path, unsigned char status,
err = got_error(ood_errcode);
} else {
/* Require that added files don't exist in the branch head. */
- err = got_object_id_by_path(&id, repo, head_commit_id,
- in_repo_path);
+ err = got_object_open_as_commit(&commit, repo, head_commit_id);
+ if (err)
+ goto done;
+ err = got_object_id_by_path(&id, repo, commit, in_repo_path);
if (err && err->code != GOT_ERR_NO_TREE_ENTRY)
goto done;
err = id ? got_error(ood_errcode) : NULL;
}
done:
free(id);
+ if (commit)
+ got_object_commit_close(commit);
return err;
}
@@ -6692,6 +6724,7 @@ got_worktree_rebase_abort(struct got_worktree *worktree,
const struct got_error *err, *unlockerr, *sync_err;
struct got_reference *resolved = NULL;
struct got_object_id *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
char *fileindex_path = NULL;
struct revert_file_args rfa;
struct got_object_id *tree_id = NULL;
@@ -6700,6 +6733,11 @@ got_worktree_rebase_abort(struct got_worktree *worktree,
if (err)
return err;
+ err = got_object_open_as_commit(&commit, repo,
+ worktree->base_commit_id);
+ if (err)
+ goto done;
+
err = got_ref_open(&resolved, repo,
got_ref_get_symref_target(new_base_branch), 0);
if (err)
@@ -6722,8 +6760,8 @@ got_worktree_rebase_abort(struct got_worktree *worktree,
if (err)
goto done;
- err = got_object_id_by_path(&tree_id, repo,
- worktree->base_commit_id, worktree->path_prefix);
+ err = got_object_id_by_path(&tree_id, repo, commit,
+ worktree->path_prefix);
if (err)
goto done;
@@ -6758,6 +6796,8 @@ done:
got_ref_close(resolved);
free(tree_id);
free(commit_id);
+ if (commit)
+ got_object_commit_close(commit);
if (fileindex)
got_fileindex_free(fileindex);
free(fileindex_path);
@@ -7056,6 +7096,7 @@ got_worktree_histedit_abort(struct got_worktree *worktree,
const struct got_error *err, *unlockerr, *sync_err;
struct got_reference *resolved = NULL;
char *fileindex_path = NULL;
+ struct got_commit_object *commit = NULL;
struct got_object_id *tree_id = NULL;
struct revert_file_args rfa;
@@ -7063,6 +7104,11 @@ got_worktree_histedit_abort(struct got_worktree *worktree,
if (err)
return err;
+ err = got_object_open_as_commit(&commit, repo,
+ worktree->base_commit_id);
+ if (err)
+ goto done;
+
err = got_ref_open(&resolved, repo,
got_ref_get_symref_target(branch), 0);
if (err)
@@ -7076,7 +7122,7 @@ got_worktree_histedit_abort(struct got_worktree *worktree,
if (err)
goto done;
- err = got_object_id_by_path(&tree_id, repo, base_commit_id,
+ err = got_object_id_by_path(&tree_id, repo, commit,
worktree->path_prefix);
if (err)
goto done;
@@ -7269,6 +7315,7 @@ got_worktree_integrate_continue(struct got_worktree *worktree,
const struct got_error *err = NULL, *sync_err, *unlockerr;
char *fileindex_path = NULL;
struct got_object_id *tree_id = NULL, *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
err = get_fileindex_path(&fileindex_path, worktree);
if (err)
@@ -7278,7 +7325,11 @@ got_worktree_integrate_continue(struct got_worktree *worktree,
if (err)
goto done;
- err = got_object_id_by_path(&tree_id, repo, commit_id,
+ err = got_object_open_as_commit(&commit, repo, commit_id);
+ if (err)
+ goto done;
+
+ err = got_object_id_by_path(&tree_id, repo, commit,
worktree->path_prefix);
if (err)
goto done;
@@ -7320,6 +7371,8 @@ done:
got_fileindex_free(fileindex);
free(fileindex_path);
free(tree_id);
+ if (commit)
+ got_object_commit_close(commit);
unlockerr = lock_worktree(worktree, LOCK_SH);
if (unlockerr && err == NULL)
@@ -7780,12 +7833,18 @@ got_worktree_merge_abort(struct got_worktree *worktree,
{
const struct got_error *err, *unlockerr, *sync_err;
struct got_object_id *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
char *fileindex_path = NULL;
struct revert_file_args rfa;
struct got_object_id *tree_id = NULL;
- err = got_object_id_by_path(&tree_id, repo,
- worktree->base_commit_id, worktree->path_prefix);
+ err = got_object_open_as_commit(&commit, repo,
+ worktree->base_commit_id);
+ if (err)
+ goto done;
+
+ err = got_object_id_by_path(&tree_id, repo, commit,
+ worktree->path_prefix);
if (err)
goto done;
@@ -7819,6 +7878,8 @@ sync:
done:
free(tree_id);
free(commit_id);
+ if (commit)
+ got_object_commit_close(commit);
if (fileindex)
got_fileindex_free(fileindex);
free(fileindex_path);
diff --git a/tog/tog.c b/tog/tog.c
index 162cb7c..cf64000 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1910,7 +1910,7 @@ tree_view_visit_subtree(struct tog_tree_view_state *s,
static const struct got_error *
tree_view_walk_path(struct tog_tree_view_state *s,
- struct got_object_id *commit_id, const char *path)
+ struct got_commit_object *commit, const char *path)
{
const struct got_error *err = NULL;
struct got_tree_object *tree = NULL;
@@ -1959,7 +1959,7 @@ tree_view_walk_path(struct tog_tree_view_state *s,
break;
}
- err = got_object_id_by_path(&tree_id, s->repo, commit_id,
+ err = got_object_id_by_path(&tree_id, s->repo, commit,
subpath);
if (err)
break;
@@ -2008,7 +2008,7 @@ browse_commit_tree(struct tog_view **new_view, int begin_x,
if (got_path_is_root_dir(path))
return NULL;
- return tree_view_walk_path(s, entry->id, path);
+ return tree_view_walk_path(s, entry->commit, path);
}
static const struct got_error *
@@ -4329,16 +4329,21 @@ run_blame(struct tog_view *view)
struct tog_blame_view_state *s = &view->state.blame;
struct tog_blame *blame = &s->blame;
const struct got_error *err = NULL;
+ struct got_commit_object *commit = NULL;
struct got_blob_object *blob = NULL;
struct got_repository *thread_repo = NULL;
struct got_object_id *obj_id = NULL;
int obj_type;
- err = got_object_id_by_path(&obj_id, s->repo, s->blamed_commit->id,
- s->path);
+ err = got_object_open_as_commit(&commit, s->repo,
+ s->blamed_commit->id);
if (err)
return err;
+ err = got_object_id_by_path(&obj_id, s->repo, commit, s->path);
+ if (err)
+ goto done;
+
err = got_object_get_type(&obj_type, s->repo, obj_id);
if (err)
goto done;
@@ -4405,6 +4410,8 @@ run_blame(struct tog_view *view)
s->matched_line = 0;
done:
+ if (commit)
+ got_object_commit_close(commit);
if (blob)
got_object_blob_close(blob);
free(obj_id);
@@ -4646,7 +4653,7 @@ input_blame_view(struct tog_view **new_view, struct tog_view *view, int ch)
if (id == NULL)
break;
if (ch == 'p') {
- struct got_commit_object *commit;
+ struct got_commit_object *commit, *pcommit;
struct got_object_qid *pid;
struct got_object_id *blob_id = NULL;
int obj_type;
@@ -4661,8 +4668,13 @@ input_blame_view(struct tog_view **new_view, struct tog_view *view, int ch)
break;
}
/* Check if path history ends here. */
+ err = got_object_open_as_commit(&pcommit,
+ s->repo, pid->id);
+ if (err)
+ break;
err = got_object_id_by_path(&blob_id, s->repo,
- pid->id, s->path);
+ pcommit, s->path);
+ got_object_commit_close(pcommit);
if (err) {
if (err->code == GOT_ERR_NO_TREE_ENTRY)
err = NULL;
@@ -4807,6 +4819,7 @@ cmd_blame(int argc, char *argv[])
char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
char *link_target = NULL;
struct got_object_id *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
char *commit_id_str = NULL;
int ch;
struct tog_view *view;
@@ -4892,8 +4905,12 @@ cmd_blame(int argc, char *argv[])
goto done;
}
+ error = got_object_open_as_commit(&commit, repo, commit_id);
+ if (error)
+ goto done;
+
error = got_object_resolve_symlinks(&link_target, in_repo_path,
- commit_id, repo);
+ commit, repo);
if (error)
goto done;
@@ -4913,6 +4930,8 @@ done:
free(link_target);
free(cwd);
free(commit_id);
+ if (commit)
+ got_object_commit_close(commit);
if (worktree)
got_worktree_close(worktree);
if (repo) {
@@ -5659,6 +5678,7 @@ cmd_tree(int argc, char *argv[])
struct got_worktree *worktree = NULL;
char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
struct got_object_id *commit_id = NULL;
+ struct got_commit_object *commit = NULL;
const char *commit_id_arg = NULL;
char *label = NULL;
struct got_reference *ref = NULL;
@@ -5745,6 +5765,10 @@ cmd_tree(int argc, char *argv[])
goto done;
}
+ error = got_object_open_as_commit(&commit, repo, commit_id);
+ if (error)
+ goto done;
+
view = view_open(0, 0, 0, 0, TOG_VIEW_TREE);
if (view == NULL) {
error = got_error_from_errno("view_open");
@@ -5754,7 +5778,7 @@ cmd_tree(int argc, char *argv[])
if (error)
goto done;
if (!got_path_is_root_dir(in_repo_path)) {
- error = tree_view_walk_path(&view->state.tree, commit_id,
+ error = tree_view_walk_path(&view->state.tree, commit,
in_repo_path);
if (error)
goto done;
@@ -6559,6 +6583,7 @@ tog_log_with_path(int argc, char *argv[])
struct got_repository *repo = NULL;
struct got_worktree *worktree = NULL;
struct got_object_id *commit_id = NULL, *id = NULL;
+ struct got_commit_object *commit = NULL;
char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
char *commit_id_str = NULL, **cmd_argv = NULL;
@@ -6602,7 +6627,11 @@ tog_log_with_path(int argc, char *argv[])
worktree = NULL;
}
- error = got_object_id_by_path(&id, repo, commit_id, in_repo_path);
+ error = got_object_open_as_commit(&commit, repo, commit_id);
+ if (error)
+ goto done;
+
+ error = got_object_id_by_path(&id, repo, commit, in_repo_path);
if (error) {
if (error->code != GOT_ERR_NO_TREE_ENTRY)
goto done;
@@ -6631,6 +6660,8 @@ done:
if (error == NULL)
error = close_err;
}
+ if (commit)
+ got_object_commit_close(commit);
if (worktree)
got_worktree_close(worktree);
free(id);