Re: Creating objects manually and repack
- From
Linus Torvalds <torvalds@osdl.org>
- Date
- Aug 4, 2006, 18:06 UTC
- Message-ID
- <Pine.LNX.4.64.0608041052030.5167@g5.osdl.org>
- In-Reply-To
- <Pine.LNX.4.64.0608041027530.5167@g5.osdl.org>
On Fri, 4 Aug 2006, Linus Torvalds wrote:
Show 6 quoted lines
> > You may definitely want to pack the pack-files together every once in a > while. Doing so is not that hard: just list all the objects in all the > pack-files you want to merge, which in turn is trivial from reading the > index of the pack-files (and then you do want to do the filename, > although you can just use the pack-file name if you want to).
Btw, that index format is actually documented (and it really is _very_ simple) in Documentation/technical/pack-format.txt.
To get a list of all object names in a pack-file, you'd basically do just something like the appended. So with this (let's call it "git-list-objects"), you could just do
for i in $packlist do git-list-objects $i.idx done | git-pack-objects combined-pack
and it would combine all the packs in "$packlist" into one new "combined-pack-<sha1>" pack.
And no, I didn't actually _test_ any of this, but it looks pretty damn simple.
Linus
---- #include <unistd.h> #include <fcntl.h> #include <stdio.h>
#define CHUNK (100)
int main(int argc, char **argv)
{
static unsigned char buffer[24*CHUNK];
const char *name = argv[1];
unsigned int n;
int fd;
int i; if (!name)
die("no filename!");fd = open(name, O_RDONLY); if (fd < 0) perror(name);
/* throw away the first-level fan-out */
if (read(fd, buffer, 4*256) != 4*256)
perror("read fan-out");n = (buffer[4*255 + 0] << 24) + (buffer[4*255 + 1] << 16) + (buffer[4*255 + 2] << 8) + (buffer[4*255 + 3] << 0);
for (i = 0; i < n; i += CHUNK) {
int j, left = n - i;
if (left > CHUNK)
left = CHUNK;
if (read(fd, buffer, left*24) != left*24)
perror("read chunk");
for (j = 0; j < left; j++) {
const unsigned char *sha1;
sha1 = buffer + j*24 + 4;
printf("%s %s\n", sha1_to_hex(sha1), name);
}
}
return 0;
}