commit-graph: build graph from starting commits
[gitweb.git] / commit-graph.c
index 70472840a3bfb99fb0e1c63978f49d464df1fdb1..a59d1e387bea6ae1004eea0c5fe72a4a0b809d7e 100644 (file)
@@ -551,7 +551,9 @@ static void close_reachable(struct packed_oid_list *oids)
 
 void write_commit_graph(const char *obj_dir,
                        const char **pack_indexes,
-                       int nr_packs)
+                       int nr_packs,
+                       const char **commit_hex,
+                       int nr_commits)
 {
        struct packed_oid_list oids;
        struct packed_commit_list commits;
@@ -591,7 +593,28 @@ void write_commit_graph(const char *obj_dir,
                        close_pack(p);
                }
                strbuf_release(&packname);
-       } else
+       }
+
+       if (commit_hex) {
+               for (i = 0; i < nr_commits; i++) {
+                       const char *end;
+                       struct object_id oid;
+                       struct commit *result;
+
+                       if (commit_hex[i] && parse_oid_hex(commit_hex[i], &oid, &end))
+                               continue;
+
+                       result = lookup_commit_reference_gently(&oid, 1);
+
+                       if (result) {
+                               ALLOC_GROW(oids.list, oids.nr + 1, oids.alloc);
+                               oidcpy(&oids.list[oids.nr], &(result->object.oid));
+                               oids.nr++;
+                       }
+               }
+       }
+
+       if (!pack_indexes && !commit_hex)
                for_each_packed_object(add_packed_commits, &oids, 0);
 
        close_reachable(&oids);