sequencer: introduce todo_list_write_to_file()
[gitweb.git] / builtin / fsck.c
index dcf72859a6e24004c06c37492e3a3e764d6c2334..bf5ddff43f74e0dba77d05e04bc14c0c59884287 100644 (file)
@@ -19,6 +19,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "run-command.h"
+#include "worktree.h"
 
 #define REACHABLE 0x0001
 #define SEEN      0x0002
@@ -36,8 +37,6 @@ static int check_strict;
 static int keep_cache_objects;
 static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
 static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT;
-static struct object_id head_oid;
-static const char *head_points_at;
 static int errors_found;
 static int write_lost_and_found;
 static int verbose;
@@ -468,7 +467,11 @@ static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid
 static int fsck_handle_reflog(const char *logname, const struct object_id *oid,
                              int flag, void *cb_data)
 {
-       for_each_reflog_ent(logname, fsck_handle_reflog_ent, (void *)logname);
+       struct strbuf refname = STRBUF_INIT;
+
+       strbuf_worktree_ref(cb_data, &refname, logname);
+       for_each_reflog_ent(refname.buf, fsck_handle_reflog_ent, refname.buf);
+       strbuf_release(&refname);
        return 0;
 }
 
@@ -507,13 +510,34 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
        return 0;
 }
 
+static int fsck_head_link(const char *head_ref_name,
+                         const char **head_points_at,
+                         struct object_id *head_oid);
+
 static void get_default_heads(void)
 {
-       if (head_points_at && !is_null_oid(&head_oid))
-               fsck_handle_ref("HEAD", &head_oid, 0, NULL);
+       struct worktree **worktrees, **p;
+       const char *head_points_at;
+       struct object_id head_oid;
+
        for_each_rawref(fsck_handle_ref, NULL);
-       if (include_reflogs)
-               for_each_reflog(fsck_handle_reflog, NULL);
+
+       worktrees = get_worktrees(0);
+       for (p = worktrees; *p; p++) {
+               struct worktree *wt = *p;
+               struct strbuf ref = STRBUF_INIT;
+
+               strbuf_worktree_ref(wt, &ref, "HEAD");
+               fsck_head_link(ref.buf, &head_points_at, &head_oid);
+               if (head_points_at && !is_null_oid(&head_oid))
+                       fsck_handle_ref(ref.buf, &head_oid, 0, NULL);
+               strbuf_release(&ref);
+
+               if (include_reflogs)
+                       refs_for_each_reflog(get_worktree_ref_store(wt),
+                                            fsck_handle_reflog, wt);
+       }
+       free_worktrees(worktrees);
 
        /*
         * Not having any default heads isn't really fatal, but
@@ -602,33 +626,37 @@ static void fsck_object_dir(const char *path)
        stop_progress(&progress);
 }
 
-static int fsck_head_link(void)
+static int fsck_head_link(const char *head_ref_name,
+                         const char **head_points_at,
+                         struct object_id *head_oid)
 {
        int null_is_error = 0;
 
        if (verbose)
-               fprintf_ln(stderr, _("Checking HEAD link"));
+               fprintf_ln(stderr, _("Checking %s link"), head_ref_name);
 
-       head_points_at = resolve_ref_unsafe("HEAD", 0, &head_oid, NULL);
-       if (!head_points_at) {
+       *head_points_at = resolve_ref_unsafe(head_ref_name, 0, head_oid, NULL);
+       if (!*head_points_at) {
                errors_found |= ERROR_REFS;
-               return error(_("invalid HEAD"));
+               return error(_("invalid %s"), head_ref_name);
        }
-       if (!strcmp(head_points_at, "HEAD"))
+       if (!strcmp(*head_points_at, head_ref_name))
                /* detached HEAD */
                null_is_error = 1;
-       else if (!starts_with(head_points_at, "refs/heads/")) {
+       else if (!starts_with(*head_points_at, "refs/heads/")) {
                errors_found |= ERROR_REFS;
-               return error(_("HEAD points to something strange (%s)"),
-                            head_points_at);
+               return error(_("%s points to something strange (%s)"),
+                            head_ref_name, *head_points_at);
        }
-       if (is_null_oid(&head_oid)) {
+       if (is_null_oid(head_oid)) {
                if (null_is_error) {
                        errors_found |= ERROR_REFS;
-                       return error(_("HEAD: detached HEAD points at nothing"));
+                       return error(_("%s: detached HEAD points at nothing"),
+                                    head_ref_name);
                }
-               fprintf_ln(stderr, _("notice: HEAD points to an unborn branch (%s)"),
-                          head_points_at + 11);
+               fprintf_ln(stderr,
+                          _("notice: %s points to an unborn branch (%s)"),
+                          head_ref_name, *head_points_at + 11);
        }
        return 0;
 }
@@ -711,7 +739,7 @@ static struct option fsck_opts[] = {
 int cmd_fsck(int argc, const char **argv, const char *prefix)
 {
        int i;
-       struct alternate_object_database *alt;
+       struct object_directory *odb;
 
        /* fsck knows how to handle missing promisor objects */
        fetch_if_missing = 0;
@@ -743,19 +771,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 
        git_config(fsck_config, NULL);
 
-       fsck_head_link();
        if (connectivity_only) {
                for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
                for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
        } else {
-               struct alternate_object_database *alt_odb_list;
-
-               fsck_object_dir(get_object_directory());
-
                prepare_alt_odb(the_repository);
-               alt_odb_list = the_repository->objects->alt_odb_list;
-               for (alt = alt_odb_list; alt; alt = alt->next)
-                       fsck_object_dir(alt->path);
+               for (odb = the_repository->objects->odb; odb; odb = odb->next)
+                       fsck_object_dir(odb->path);
 
                if (check_full) {
                        struct packed_git *p;
@@ -775,7 +797,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                        for (p = get_all_packs(the_repository); p;
                             p = p->next) {
                                /* verify gives error messages itself */
-                               if (verify_pack(p, fsck_obj_buffer,
+                               if (verify_pack(the_repository,
+                                               p, fsck_obj_buffer,
                                                progress, count))
                                        errors_found |= ERROR_PACK;
                                count += p->num_objects;
@@ -857,15 +880,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
                const char *verify_argv[] = { "commit-graph", "verify", NULL, NULL, NULL };
 
-               commit_graph_verify.argv = verify_argv;
-               commit_graph_verify.git_cmd = 1;
-               if (run_command(&commit_graph_verify))
-                       errors_found |= ERROR_COMMIT_GRAPH;
-
                prepare_alt_odb(the_repository);
-               for (alt =  the_repository->objects->alt_odb_list; alt; alt = alt->next) {
+               for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+                       child_process_init(&commit_graph_verify);
+                       commit_graph_verify.argv = verify_argv;
+                       commit_graph_verify.git_cmd = 1;
                        verify_argv[2] = "--object-dir";
-                       verify_argv[3] = alt->path;
+                       verify_argv[3] = odb->path;
                        if (run_command(&commit_graph_verify))
                                errors_found |= ERROR_COMMIT_GRAPH;
                }
@@ -875,15 +896,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                struct child_process midx_verify = CHILD_PROCESS_INIT;
                const char *midx_argv[] = { "multi-pack-index", "verify", NULL, NULL, NULL };
 
-               midx_verify.argv = midx_argv;
-               midx_verify.git_cmd = 1;
-               if (run_command(&midx_verify))
-                       errors_found |= ERROR_COMMIT_GRAPH;
-
                prepare_alt_odb(the_repository);
-               for (alt =  the_repository->objects->alt_odb_list; alt; alt = alt->next) {
+               for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+                       child_process_init(&midx_verify);
+                       midx_verify.argv = midx_argv;
+                       midx_verify.git_cmd = 1;
                        midx_argv[2] = "--object-dir";
-                       midx_argv[3] = alt->path;
+                       midx_argv[3] = odb->path;
                        if (run_command(&midx_verify))
                                errors_found |= ERROR_COMMIT_GRAPH;
                }