2006-06-24 11:59:49 +04:00
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
int main(int ac, char **av)
|
|
|
|
{
|
2008-10-01 22:05:20 +04:00
|
|
|
git_SHA_CTX ctx;
|
2006-06-24 11:59:49 +04:00
|
|
|
unsigned char sha1[20];
|
2006-06-24 13:59:20 +04:00
|
|
|
unsigned bufsz = 8192;
|
2013-08-23 03:12:42 +04:00
|
|
|
int binary = 0;
|
2006-06-24 13:59:20 +04:00
|
|
|
char *buffer;
|
|
|
|
|
2013-08-23 03:12:42 +04:00
|
|
|
if (ac == 2) {
|
|
|
|
if (!strcmp(av[1], "-b"))
|
|
|
|
binary = 1;
|
|
|
|
else
|
|
|
|
bufsz = strtoul(av[1], NULL, 10) * 1024 * 1024;
|
|
|
|
}
|
2006-06-24 13:59:20 +04:00
|
|
|
|
|
|
|
if (!bufsz)
|
|
|
|
bufsz = 8192;
|
|
|
|
|
|
|
|
while ((buffer = malloc(bufsz)) == NULL) {
|
|
|
|
fprintf(stderr, "bufsz %u is too big, halving...\n", bufsz);
|
|
|
|
bufsz /= 2;
|
|
|
|
if (bufsz < 1024)
|
|
|
|
die("OOPS");
|
|
|
|
}
|
2006-06-24 11:59:49 +04:00
|
|
|
|
2008-10-01 22:05:20 +04:00
|
|
|
git_SHA1_Init(&ctx);
|
2006-06-24 11:59:49 +04:00
|
|
|
|
|
|
|
while (1) {
|
2006-06-24 13:59:20 +04:00
|
|
|
ssize_t sz, this_sz;
|
|
|
|
char *cp = buffer;
|
|
|
|
unsigned room = bufsz;
|
|
|
|
this_sz = 0;
|
|
|
|
while (room) {
|
|
|
|
sz = xread(0, cp, room);
|
|
|
|
if (sz == 0)
|
|
|
|
break;
|
|
|
|
if (sz < 0)
|
2009-06-27 19:58:46 +04:00
|
|
|
die_errno("test-sha1");
|
2006-06-24 13:59:20 +04:00
|
|
|
this_sz += sz;
|
|
|
|
cp += sz;
|
|
|
|
room -= sz;
|
|
|
|
}
|
|
|
|
if (this_sz == 0)
|
2006-06-24 11:59:49 +04:00
|
|
|
break;
|
2008-10-01 22:05:20 +04:00
|
|
|
git_SHA1_Update(&ctx, buffer, this_sz);
|
2006-06-24 11:59:49 +04:00
|
|
|
}
|
2008-10-01 22:05:20 +04:00
|
|
|
git_SHA1_Final(sha1, &ctx);
|
2013-08-23 03:12:42 +04:00
|
|
|
|
|
|
|
if (binary)
|
|
|
|
fwrite(sha1, 1, 20, stdout);
|
|
|
|
else
|
|
|
|
puts(sha1_to_hex(sha1));
|
2006-06-24 11:59:49 +04:00
|
|
|
exit(0);
|
|
|
|
}
|