+static void unpack_entry(struct pack_entry *entry)
+{
+ unsigned long size;
+ unsigned long offset;
+ unsigned char *pack;
+
+ /* Have we done this one already due to deltas based on it? */
+ if (lookup_object(entry->sha1))
+ return;
+
+ offset = ntohl(entry->offset);
+ if (offset > pack_size - 5)
+ die("object offset outside of pack file");
+ pack = pack_base + offset;
+ offset = pack_size - offset;
+ switch (*pack) {
+ case 'C': case 'T': case 'B':
+ size = (pack[1] << 24) + (pack[2] << 16) + (pack[3] << 8) + pack[4];
+ printf("%s %c %lu\n", sha1_to_hex(entry->sha1), *pack, size);
+ break;
+ case 'D':
+ printf("%s D", sha1_to_hex(entry->sha1));
+ printf(" %s\n", sha1_to_hex(pack+1));
+ break;
+ default:
+ die("corrupted pack file");
+ }
+}
+
+/*
+ * We unpack from the end, older files first. Now, usually
+ * there are deltas etc, so we'll not actually write the
+ * objects in that order, but we might as well try..
+ */
+static void unpack_all(void)
+{
+ int i = nr_entries;
+
+ while (--i >= 0) {
+ struct pack_entry *entry = pack_list[i];
+ unpack_entry(entry);
+ }
+}
+