Imported Upstream version 2.24.1
[platform/upstream/git.git] / fsck.c
diff --git a/fsck.c b/fsck.c
index 6b1e5c1..ef8b343 100644 (file)
--- a/fsck.c
+++ b/fsck.c
 #include "fsck.h"
 #include "refs.h"
 #include "utf8.h"
-#include "sha1-array.h"
 #include "decorate.h"
 #include "oidset.h"
 #include "packfile.h"
 #include "submodule-config.h"
 #include "config.h"
-#include "credential.h"
 #include "help.h"
 
 static struct oidset gitmodules_found = OIDSET_INIT;
@@ -184,44 +182,6 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
        return msg_type;
 }
 
-static void init_skiplist(struct fsck_options *options, const char *path)
-{
-       static struct oid_array skiplist = OID_ARRAY_INIT;
-       int sorted, fd;
-       char buffer[GIT_MAX_HEXSZ + 1];
-       struct object_id oid;
-
-       if (options->skiplist)
-               sorted = options->skiplist->sorted;
-       else {
-               sorted = 1;
-               options->skiplist = &skiplist;
-       }
-
-       fd = open(path, O_RDONLY);
-       if (fd < 0)
-               die("Could not open skip list: %s", path);
-       for (;;) {
-               const char *p;
-               int result = read_in_full(fd, buffer, sizeof(buffer));
-               if (result < 0)
-                       die_errno("Could not read '%s'", path);
-               if (!result)
-                       break;
-               if (parse_oid_hex(buffer, &oid, &p) || *p != '\n')
-                       die("Invalid SHA-1: %s", buffer);
-               oid_array_append(&skiplist, &oid);
-               if (sorted && skiplist.nr > 1 &&
-                               oidcmp(&skiplist.oid[skiplist.nr - 2],
-                                      &oid) > 0)
-                       sorted = 0;
-       }
-       close(fd);
-
-       if (sorted)
-               skiplist.sorted = 1;
-}
-
 static int parse_msg_type(const char *str)
 {
        if (!strcmp(str, "error"))
@@ -290,7 +250,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
                if (!strcmp(buf, "skiplist")) {
                        if (equal == len)
                                die("skiplist requires a path");
-                       init_skiplist(options, buf + equal + 1);
+                       oidset_parse_file(&options->skiplist, buf + equal + 1);
                        buf += len + 1;
                        continue;
                }
@@ -324,9 +284,7 @@ static void append_msg_id(struct strbuf *sb, const char *msg_id)
 
 static int object_on_skiplist(struct fsck_options *opts, struct object *obj)
 {
-       if (opts && opts->skiplist && obj)
-               return oid_array_lookup(opts->skiplist, &obj->oid) >= 0;
-       return 0;
+       return opts && obj && oidset_contains(&opts->skiplist, &obj->oid);
 }
 
 __attribute__((format (printf, 4, 5)))
@@ -418,14 +376,14 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
                        continue;
 
                if (S_ISDIR(entry.mode)) {
-                       obj = (struct object *)lookup_tree(the_repository, entry.oid);
+                       obj = (struct object *)lookup_tree(the_repository, &entry.oid);
                        if (name && obj)
                                put_object_name(options, obj, "%s%s/", name,
                                        entry.path);
                        result = options->walk(obj, OBJ_TREE, data, options);
                }
                else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
-                       obj = (struct object *)lookup_blob(the_repository, entry.oid);
+                       obj = (struct object *)lookup_blob(the_repository, &entry.oid);
                        if (name && obj)
                                put_object_name(options, obj, "%s%s", name,
                                        entry.path);
@@ -612,7 +570,7 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
        o_name = NULL;
 
        while (desc.size) {
-               unsigned mode;
+               unsigned short mode;
                const char *name, *backslash;
                const struct object_id *oid;
 
@@ -989,19 +947,6 @@ static int fsck_tag(struct tag *tag, const char *data,
        return fsck_tag_buffer(tag, data, size, options);
 }
 
-static int check_submodule_url(const char *url)
-{
-       struct credential c = CREDENTIAL_INIT;
-       int ret;
-
-       if (looks_like_command_line_option(url))
-               return -1;
-
-       ret = credential_from_url_gently(&c, url, 1);
-       credential_clear(&c);
-       return ret;
-}
-
 struct fsck_gitmodules_data {
        struct object *obj;
        struct fsck_options *options;
@@ -1026,7 +971,7 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
                                    "disallowed submodule name: %s",
                                    name);
        if (!strcmp(key, "url") && value &&
-           check_submodule_url(value) < 0)
+           looks_like_command_line_option(value))
                data->ret |= report(data->options, data->obj,
                                    FSCK_MSG_GITMODULES_URL,
                                    "disallowed submodule url: %s",
@@ -1135,7 +1080,7 @@ int fsck_finish(struct fsck_options *options)
 
                blob = lookup_blob(the_repository, oid);
                if (!blob) {
-                       struct object *obj = lookup_unknown_object(oid->hash);
+                       struct object *obj = lookup_unknown_object(oid);
                        ret |= report(options, obj,
                                      FSCK_MSG_GITMODULES_BLOB,
                                      "non-blob found at .gitmodules");