|
19 | 19 | #include "packfile.h" |
20 | 20 | #include "object-store.h" |
21 | 21 | #include "run-command.h" |
| 22 | +#include "worktree.h" |
22 | 23 |
|
23 | 24 | #define REACHABLE 0x0001 |
24 | 25 | #define SEEN 0x0002 |
@@ -444,7 +445,11 @@ static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid |
444 | 445 | static int fsck_handle_reflog(const char *logname, const struct object_id *oid, |
445 | 446 | int flag, void *cb_data) |
446 | 447 | { |
447 | | - for_each_reflog_ent(logname, fsck_handle_reflog_ent, (void *)logname); |
| 448 | + struct strbuf refname = STRBUF_INIT; |
| 449 | + |
| 450 | + strbuf_worktree_ref(cb_data, &refname, logname); |
| 451 | + for_each_reflog_ent(refname.buf, fsck_handle_reflog_ent, refname.buf); |
| 452 | + strbuf_release(&refname); |
448 | 453 | return 0; |
449 | 454 | } |
450 | 455 |
|
@@ -482,20 +487,34 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, |
482 | 487 | return 0; |
483 | 488 | } |
484 | 489 |
|
485 | | -static int fsck_head_link(const char **head_points_at, |
| 490 | +static int fsck_head_link(const char *head_ref_name, |
| 491 | + const char **head_points_at, |
486 | 492 | struct object_id *head_oid); |
487 | 493 |
|
488 | 494 | static void get_default_heads(void) |
489 | 495 | { |
| 496 | + struct worktree **worktrees, **p; |
490 | 497 | const char *head_points_at; |
491 | 498 | struct object_id head_oid; |
492 | 499 |
|
493 | | - fsck_head_link(&head_points_at, &head_oid); |
494 | | - if (head_points_at && !is_null_oid(&head_oid)) |
495 | | - fsck_handle_ref("HEAD", &head_oid, 0, NULL); |
496 | 500 | for_each_rawref(fsck_handle_ref, NULL); |
497 | | - if (include_reflogs) |
498 | | - for_each_reflog(fsck_handle_reflog, NULL); |
| 501 | + |
| 502 | + worktrees = get_worktrees(0); |
| 503 | + for (p = worktrees; *p; p++) { |
| 504 | + struct worktree *wt = *p; |
| 505 | + struct strbuf ref = STRBUF_INIT; |
| 506 | + |
| 507 | + strbuf_worktree_ref(wt, &ref, "HEAD"); |
| 508 | + fsck_head_link(ref.buf, &head_points_at, &head_oid); |
| 509 | + if (head_points_at && !is_null_oid(&head_oid)) |
| 510 | + fsck_handle_ref(ref.buf, &head_oid, 0, NULL); |
| 511 | + strbuf_release(&ref); |
| 512 | + |
| 513 | + if (include_reflogs) |
| 514 | + refs_for_each_reflog(get_worktree_ref_store(wt), |
| 515 | + fsck_handle_reflog, wt); |
| 516 | + } |
| 517 | + free_worktrees(worktrees); |
499 | 518 |
|
500 | 519 | /* |
501 | 520 | * Not having any default heads isn't really fatal, but |
@@ -584,34 +603,36 @@ static void fsck_object_dir(const char *path) |
584 | 603 | stop_progress(&progress); |
585 | 604 | } |
586 | 605 |
|
587 | | -static int fsck_head_link(const char **head_points_at, |
| 606 | +static int fsck_head_link(const char *head_ref_name, |
| 607 | + const char **head_points_at, |
588 | 608 | struct object_id *head_oid) |
589 | 609 | { |
590 | 610 | int null_is_error = 0; |
591 | 611 |
|
592 | 612 | if (verbose) |
593 | | - fprintf(stderr, "Checking HEAD link\n"); |
| 613 | + fprintf(stderr, "Checking %s link\n", head_ref_name); |
594 | 614 |
|
595 | | - *head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid, NULL); |
| 615 | + *head_points_at = resolve_ref_unsafe(head_ref_name, 0, head_oid, NULL); |
596 | 616 | if (!*head_points_at) { |
597 | 617 | errors_found |= ERROR_REFS; |
598 | | - return error("Invalid HEAD"); |
| 618 | + return error("Invalid %s", head_ref_name); |
599 | 619 | } |
600 | | - if (!strcmp(*head_points_at, "HEAD")) |
| 620 | + if (!strcmp(*head_points_at, head_ref_name)) |
601 | 621 | /* detached HEAD */ |
602 | 622 | null_is_error = 1; |
603 | 623 | else if (!starts_with(*head_points_at, "refs/heads/")) { |
604 | 624 | errors_found |= ERROR_REFS; |
605 | | - return error("HEAD points to something strange (%s)", |
606 | | - *head_points_at); |
| 625 | + return error("%s points to something strange (%s)", |
| 626 | + head_ref_name, *head_points_at); |
607 | 627 | } |
608 | 628 | if (is_null_oid(head_oid)) { |
609 | 629 | if (null_is_error) { |
610 | 630 | errors_found |= ERROR_REFS; |
611 | | - return error("HEAD: detached HEAD points at nothing"); |
| 631 | + return error("%s: detached HEAD points at nothing", |
| 632 | + head_ref_name); |
612 | 633 | } |
613 | | - fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n", |
614 | | - *head_points_at + 11); |
| 634 | + fprintf(stderr, "notice: %s points to an unborn branch (%s)\n", |
| 635 | + head_ref_name, *head_points_at + 11); |
615 | 636 | } |
616 | 637 | return 0; |
617 | 638 | } |
|
0 commit comments