2006-06-24 15:59:49 +08:00
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
int main(int ac, char **av)
|
|
|
|
{
|
2008-10-02 02:05:20 +08:00
|
|
|
git_SHA_CTX ctx;
|
2006-06-24 15:59:49 +08:00
|
|
|
unsigned char sha1[20];
|
2006-06-24 17:59:20 +08:00
|
|
|
unsigned bufsz = 8192;
|
2013-08-23 07:12:42 +08:00
|
|
|
int binary = 0;
|
2006-06-24 17:59:20 +08:00
|
|
|
char *buffer;
|
|
|
|
|
2013-08-23 07:12:42 +08:00
|
|
|
if (ac == 2) {
|
|
|
|
if (!strcmp(av[1], "-b"))
|
|
|
|
binary = 1;
|
|
|
|
else
|
|
|
|
bufsz = strtoul(av[1], NULL, 10) * 1024 * 1024;
|
|
|
|
}
|
2006-06-24 17:59:20 +08: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 15:59:49 +08:00
|
|
|
|
2008-10-02 02:05:20 +08:00
|
|
|
git_SHA1_Init(&ctx);
|
2006-06-24 15:59:49 +08:00
|
|
|
|
|
|
|
while (1) {
|
2006-06-24 17:59:20 +08: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 23:58:46 +08:00
|
|
|
die_errno("test-sha1");
|
2006-06-24 17:59:20 +08:00
|
|
|
this_sz += sz;
|
|
|
|
cp += sz;
|
|
|
|
room -= sz;
|
|
|
|
}
|
|
|
|
if (this_sz == 0)
|
2006-06-24 15:59:49 +08:00
|
|
|
break;
|
2008-10-02 02:05:20 +08:00
|
|
|
git_SHA1_Update(&ctx, buffer, this_sz);
|
2006-06-24 15:59:49 +08:00
|
|
|
}
|
2008-10-02 02:05:20 +08:00
|
|
|
git_SHA1_Final(sha1, &ctx);
|
2013-08-23 07:12:42 +08:00
|
|
|
|
|
|
|
if (binary)
|
|
|
|
fwrite(sha1, 1, 20, stdout);
|
|
|
|
else
|
|
|
|
puts(sha1_to_hex(sha1));
|
2006-06-24 15:59:49 +08:00
|
|
|
exit(0);
|
|
|
|
}
|