-
- for (i = 0; i < num_pack; i++) {
- fprintf(fp, "D %1d", i);
- for (j = 0; j < num_pack; j++) {
- if ((i == j) || !(info[i]->dep[j]))
- continue;
- fprintf(fp, " %1d", j);
- }
- fputc('\n', fp);
- }
-
- for (i = 0; i < num_pack; i++) {
- struct pack_info *this = info[i];
- for (j = 0; j < this->nr_heads; j++) {
- struct object *o = lookup_object(this->head[j]);
- fprintf(fp, "T %1d %s %s\n",
- i, sha1_to_hex(this->head[j]), o->type);
- }
- }
-
-}
-
-#define REFERENCED 01
-#define INTERNAL 02
-#define EMITTED 04
-
-static void show(struct object *o, int pack_ix)
-{
- /*
- * We are interested in objects that are not referenced,
- * and objects that are referenced but not internal.
- */
- if (o->flags & EMITTED)
- return;
-
- if (!(o->flags & REFERENCED))
- add_head_def(info[pack_ix], o->sha1);
- else if ((o->flags & REFERENCED) && !(o->flags & INTERNAL)) {
- int i;
-
- /* Which pack contains this object? That is what
- * pack_ix can depend on. We earlier sorted info
- * array from youngest to oldest, so try newer packs
- * first to favor them here.
- */
- for (i = num_pack - 1; 0 <= i; i--) {
- struct packed_git *p = info[i]->p;
- struct pack_entry ent;
- if (find_pack_entry_one(o->sha1, &ent, p)) {
- info[pack_ix]->dep[i] = 1;
- break;
- }
- }
- }
- o->flags |= EMITTED;
-}
-
-static void find_pack_info_one(int pack_ix)
-{
- unsigned char sha1[20];
- struct object *o;
- int i;
- struct packed_git *p = info[pack_ix]->p;
- int num = num_packed_objects(p);
-
- /* Scan objects, clear flags from all the edge ones and
- * internal ones, possibly marked in the previous round.
- */
- for (i = 0; i < num; i++) {
- if (nth_packed_object_sha1(p, i, sha1))
- die("corrupt pack file %s?", p->pack_name);
- if ((o = lookup_object(sha1)) == NULL)
- die("cannot parse %s", sha1_to_hex(sha1));
- if (o->refs) {
- struct object_refs *refs = o->refs;
- int j;
- for (j = 0; j < refs->count; j++)
- refs->ref[j]->flags = 0;
- }
- o->flags = 0;
- }
-
- /* Mark all the internal ones */
- for (i = 0; i < num; i++) {
- if (nth_packed_object_sha1(p, i, sha1))
- die("corrupt pack file %s?", p->pack_name);
- if ((o = lookup_object(sha1)) == NULL)
- die("cannot find %s", sha1_to_hex(sha1));
- if (o->refs) {
- struct object_refs *refs = o->refs;
- int j;
- for (j = 0; j < refs->count; j++)
- refs->ref[j]->flags |= REFERENCED;
- }
- o->flags |= INTERNAL;
- }
-
- for (i = 0; i < num; i++) {
- if (nth_packed_object_sha1(p, i, sha1))
- die("corrupt pack file %s?", p->pack_name);
- if ((o = lookup_object(sha1)) == NULL)
- die("cannot find %s", sha1_to_hex(sha1));
-
- show(o, pack_ix);
- if (o->refs) {
- struct object_refs *refs = o->refs;
- int j;
- for (j = 0; j < refs->count; j++)
- show(refs->ref[j], pack_ix);
- }
- }
-
-}
-
-static void find_pack_info(void)
-{
- int i;
- for (i = 0; i < num_pack; i++) {
- /* The packed objects are cast in stone, and a head
- * in a pack will stay as head, so is the set of missing
- * objects. If the repo has been reorganized and we
- * are missing some packs available back then, we have
- * already discarded the info read from the file, so
- * we will find (old_num < 0) in that case.
- */
- if (0 <= info[i]->old_num)
- continue;
- find_pack_info_one(i);
- }