Imported Upstream version 2.28.0
[platform/upstream/git.git] / reachable.c
index 43616d4..77a60c7 100644 (file)
@@ -9,6 +9,10 @@
 #include "cache-tree.h"
 #include "progress.h"
 #include "list-objects.h"
+#include "packfile.h"
+#include "worktree.h"
+#include "object-store.h"
+#include "pack-bitmap.h"
 
 struct connectivity_progress {
        struct progress *progress;
@@ -33,7 +37,7 @@ static int add_one_ref(const char *path, const struct object_id *oid,
                return 0;
        }
 
-       object = parse_object_or_die(oid->hash, path);
+       object = parse_object_or_die(oid, path);
        add_pending_object(revs, object, "");
 
        return 0;
@@ -43,24 +47,23 @@ static int add_one_ref(const char *path, const struct object_id *oid,
  * The traversal will have already marked us as SEEN, so we
  * only need to handle any progress reporting here.
  */
-static void mark_object(struct object *obj, const struct name_path *path,
-                       const char *name, void *data)
+static void mark_object(struct object *obj, const char *name, void *data)
 {
        update_progress(data);
 }
 
 static void mark_commit(struct commit *c, void *data)
 {
-       mark_object(&c->object, NULL, NULL, data);
+       mark_object(&c->object, NULL, data);
 }
 
 struct recent_data {
        struct rev_info *revs;
-       unsigned long timestamp;
+       timestamp_t timestamp;
 };
 
-static void add_recent_object(const unsigned char *sha1,
-                             unsigned long mtime,
+static void add_recent_object(const struct object_id *oid,
+                             timestamp_t mtime,
                              struct recent_data *data)
 {
        struct object *obj;
@@ -76,37 +79,37 @@ static void add_recent_object(const unsigned char *sha1,
         * later processing, and the revision machinery expects
         * commits and tags to have been parsed.
         */
-       type = sha1_object_info(sha1, NULL);
+       type = oid_object_info(the_repository, oid, NULL);
        if (type < 0)
-               die("unable to get object info for %s", sha1_to_hex(sha1));
+               die("unable to get object info for %s", oid_to_hex(oid));
 
        switch (type) {
        case OBJ_TAG:
        case OBJ_COMMIT:
-               obj = parse_object_or_die(sha1, NULL);
+               obj = parse_object_or_die(oid, NULL);
                break;
        case OBJ_TREE:
-               obj = (struct object *)lookup_tree(sha1);
+               obj = (struct object *)lookup_tree(the_repository, oid);
                break;
        case OBJ_BLOB:
-               obj = (struct object *)lookup_blob(sha1);
+               obj = (struct object *)lookup_blob(the_repository, oid);
                break;
        default:
                die("unknown object type for %s: %s",
-                   sha1_to_hex(sha1), typename(type));
+                   oid_to_hex(oid), type_name(type));
        }
 
        if (!obj)
-               die("unable to lookup %s", sha1_to_hex(sha1));
+               die("unable to lookup %s", oid_to_hex(oid));
 
        add_pending_object(data->revs, obj, "");
 }
 
-static int add_recent_loose(const unsigned char *sha1,
+static int add_recent_loose(const struct object_id *oid,
                            const char *path, void *data)
 {
        struct stat st;
-       struct object *obj = lookup_object(sha1);
+       struct object *obj = lookup_object(the_repository, oid);
 
        if (obj && obj->flags & SEEN)
                return 0;
@@ -120,28 +123,27 @@ static int add_recent_loose(const unsigned char *sha1,
                 */
                if (errno == ENOENT)
                        return 0;
-               return error("unable to stat %s: %s",
-                            sha1_to_hex(sha1), strerror(errno));
+               return error_errno("unable to stat %s", oid_to_hex(oid));
        }
 
-       add_recent_object(sha1, st.st_mtime, data);
+       add_recent_object(oid, st.st_mtime, data);
        return 0;
 }
 
-static int add_recent_packed(const unsigned char *sha1,
+static int add_recent_packed(const struct object_id *oid,
                             struct packed_git *p, uint32_t pos,
                             void *data)
 {
-       struct object *obj = lookup_object(sha1);
+       struct object *obj = lookup_object(the_repository, oid);
 
        if (obj && obj->flags & SEEN)
                return 0;
-       add_recent_object(sha1, p->mtime, data);
+       add_recent_object(oid, p->mtime, data);
        return 0;
 }
 
 int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
-                                          unsigned long timestamp)
+                                          timestamp_t timestamp)
 {
        struct recent_data data;
        int r;
@@ -157,11 +159,44 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
                                      FOR_EACH_OBJECT_LOCAL_ONLY);
 }
 
+static void *lookup_object_by_type(struct repository *r,
+                                  const struct object_id *oid,
+                                  enum object_type type)
+{
+       switch (type) {
+       case OBJ_COMMIT:
+               return lookup_commit(r, oid);
+       case OBJ_TREE:
+               return lookup_tree(r, oid);
+       case OBJ_TAG:
+               return lookup_tag(r, oid);
+       case OBJ_BLOB:
+               return lookup_blob(r, oid);
+       default:
+               die("BUG: unknown object type %d", type);
+       }
+}
+
+static int mark_object_seen(const struct object_id *oid,
+                            enum object_type type,
+                            int exclude,
+                            uint32_t name_hash,
+                            struct packed_git *found_pack,
+                            off_t found_offset)
+{
+       struct object *obj = lookup_object_by_type(the_repository, oid, type);
+       if (!obj)
+               die("unable to create object '%s'", oid_to_hex(oid));
+
+       obj->flags |= SEEN;
+       return 0;
+}
+
 void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
-                           unsigned long mark_recent,
-                           struct progress *progress)
+                           timestamp_t mark_recent, struct progress *progress)
 {
        struct connectivity_progress cp;
+       struct bitmap_index *bitmap_git;
 
        /*
         * Set up revision parsing, and mark us as being interested
@@ -179,6 +214,7 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
 
        /* detached HEAD is not included in the list above */
        head_ref(add_one_ref, revs);
+       other_head_refs(add_one_ref, revs);
 
        /* Add all reflog info */
        if (mark_reflog)
@@ -187,6 +223,13 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
        cp.progress = progress;
        cp.count = 0;
 
+       bitmap_git = prepare_bitmap_walk(revs, NULL);
+       if (bitmap_git) {
+               traverse_bitmap_commit_list(bitmap_git, revs, mark_object_seen);
+               free_bitmap_index(bitmap_git);
+               return;
+       }
+
        /*
         * Set up the revision walk - this will move all commits
         * from the pending list to the commit walking list.