]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsck.c: move gitmodules_{found,done} into fsck_options
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sun, 28 Mar 2021 13:15:48 +0000 (15:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Mar 2021 02:03:10 +0000 (19:03 -0700)
Move the gitmodules_{found,done} static variables added in
159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the
fsck_options struct. It makes sense to keep all the context in the
same place.

This requires changing the recently added register_found_gitmodules()
function added in 5476e1efde (fetch-pack: print and use dangling
.gitmodules, 2021-02-22) to take fsck_options. That function will be
removed in a subsequent commit, but as it'll require the new
gitmodules_found attribute of "fsck_options" we need this intermediate
step first.

An earlier version of this patch removed the small amount of
duplication we now have between FSCK_OPTIONS_{DEFAULT,STRICT} with a
FSCK_OPTIONS_COMMON macro. I don't think such de-duplication is worth
it for this amount of copy/pasting.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fetch-pack.c
fsck.c
fsck.h

index 6a61a464283e108915d216fb12828e06c8538f58..82c3c2c043b0401a2dbcf89401d2a6a3c91b0cf1 100644 (file)
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
 
        oidset_iter_init(gitmodules_oids, &iter);
        while ((oid = oidset_iter_next(&iter)))
-               register_found_gitmodules(oid);
+               register_found_gitmodules(&fo, oid);
        if (fsck_finish(&fo))
                die("fsck failed");
 }
diff --git a/fsck.c b/fsck.c
index a59832a1650850a937cfe7c1b754f3c9c5ae3725..642bd2ef9dadff088299e58c78932312913a5c39 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -19,9 +19,6 @@
 #include "credential.h"
 #include "help.h"
 
-static struct oidset gitmodules_found = OIDSET_INIT;
-static struct oidset gitmodules_done = OIDSET_INIT;
-
 #define STR(x) #x
 #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
 static struct {
@@ -606,7 +603,7 @@ static int fsck_tree(const struct object_id *oid,
 
                if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
                        if (!S_ISLNK(mode))
-                               oidset_insert(&gitmodules_found, oid);
+                               oidset_insert(&options->gitmodules_found, oid);
                        else
                                retval += report(options,
                                                 oid, OBJ_TREE,
@@ -620,7 +617,7 @@ static int fsck_tree(const struct object_id *oid,
                                has_dotgit |= is_ntfs_dotgit(backslash);
                                if (is_ntfs_dotgitmodules(backslash)) {
                                        if (!S_ISLNK(mode))
-                                               oidset_insert(&gitmodules_found, oid);
+                                               oidset_insert(&options->gitmodules_found, oid);
                                        else
                                                retval += report(options, oid, OBJ_TREE,
                                                                 FSCK_MSG_GITMODULES_SYMLINK,
@@ -1132,9 +1129,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
        struct fsck_gitmodules_data data;
        struct config_options config_opts = { 0 };
 
-       if (!oidset_contains(&gitmodules_found, oid))
+       if (!oidset_contains(&options->gitmodules_found, oid))
                return 0;
-       oidset_insert(&gitmodules_done, oid);
+       oidset_insert(&options->gitmodules_done, oid);
 
        if (object_on_skiplist(options, oid))
                return 0;
@@ -1199,9 +1196,9 @@ int fsck_error_function(struct fsck_options *o,
        return 1;
 }
 
-void register_found_gitmodules(const struct object_id *oid)
+void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
 {
-       oidset_insert(&gitmodules_found, oid);
+       oidset_insert(&options->gitmodules_found, oid);
 }
 
 int fsck_finish(struct fsck_options *options)
@@ -1210,13 +1207,13 @@ int fsck_finish(struct fsck_options *options)
        struct oidset_iter iter;
        const struct object_id *oid;
 
-       oidset_iter_init(&gitmodules_found, &iter);
+       oidset_iter_init(&options->gitmodules_found, &iter);
        while ((oid = oidset_iter_next(&iter))) {
                enum object_type type;
                unsigned long size;
                char *buf;
 
-               if (oidset_contains(&gitmodules_done, oid))
+               if (oidset_contains(&options->gitmodules_done, oid))
                        continue;
 
                buf = read_object_file(oid, &type, &size);
@@ -1241,8 +1238,8 @@ int fsck_finish(struct fsck_options *options)
        }
 
 
-       oidset_clear(&gitmodules_found);
-       oidset_clear(&gitmodules_done);
+       oidset_clear(&options->gitmodules_found);
+       oidset_clear(&options->gitmodules_done);
        return ret;
 }
 
diff --git a/fsck.h b/fsck.h
index d284bac361498e6fb418c973c59941667d01798b..e20f9bcb3940ae101c15f7d0762a334ab5a9b281 100644 (file)
--- a/fsck.h
+++ b/fsck.h
@@ -118,15 +118,21 @@ struct fsck_options {
        unsigned strict:1;
        enum fsck_msg_type *msg_type;
        struct oidset skiplist;
+       struct oidset gitmodules_found;
+       struct oidset gitmodules_done;
        kh_oid_map_t *object_names;
 };
 
 #define FSCK_OPTIONS_DEFAULT { \
        .skiplist = OIDSET_INIT, \
+       .gitmodules_found = OIDSET_INIT, \
+       .gitmodules_done = OIDSET_INIT, \
        .error_func = fsck_error_function \
 }
 #define FSCK_OPTIONS_STRICT { \
        .strict = 1, \
+       .gitmodules_found = OIDSET_INIT, \
+       .gitmodules_done = OIDSET_INIT, \
        .error_func = fsck_error_function, \
 }
 
@@ -146,7 +152,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
 int fsck_object(struct object *obj, void *data, unsigned long size,
        struct fsck_options *options);
 
-void register_found_gitmodules(const struct object_id *oid);
+void register_found_gitmodules(struct fsck_options *options,
+                              const struct object_id *oid);
 
 /*
  * fsck a tag, and pass info about it back to the caller. This is