blob: d24acc2a67c4b7ba112bd192680b137f30a06003 [file] [log] [blame]
Linus Torvalds3407bb42005-04-18 14:11:01 -07001#include "cache.h"
Peter Eriksen8e440252006-04-02 14:44:09 +02002#include "blob.h"
Linus Torvalds3407bb42005-04-18 14:11:01 -07003
4static char *create_temp_file(unsigned char *sha1)
5{
6 static char path[50];
7 void *buf;
8 char type[100];
9 unsigned long size;
10 int fd;
11
12 buf = read_sha1_file(sha1, type, &size);
Peter Eriksen8e440252006-04-02 14:44:09 +020013 if (!buf || strcmp(type, blob_type))
Linus Torvalds3407bb42005-04-18 14:11:01 -070014 die("unable to read blob object %s", sha1_to_hex(sha1));
15
16 strcpy(path, ".merge_file_XXXXXX");
17 fd = mkstemp(path);
18 if (fd < 0)
19 die("unable to create temp-file");
Andy Whitcroft93822c22007-01-08 15:58:23 +000020 if (write_in_full(fd, buf, size) != size)
Linus Torvalds3407bb42005-04-18 14:11:01 -070021 die("unable to write temp-file");
22 close(fd);
23 return path;
24}
25
26int main(int argc, char **argv)
27{
28 unsigned char sha1[20];
29
Dmitry V. Levin31fff302006-05-09 01:43:38 +040030 if (argc != 2)
Alexey Nezhdanov667bb592005-05-19 15:17:16 +040031 usage("git-unpack-file <sha1>");
Dmitry V. Levin31fff302006-05-09 01:43:38 +040032 if (get_sha1(argv[1], sha1))
33 die("Not a valid object name %s", argv[1]);
Linus Torvalds3407bb42005-04-18 14:11:01 -070034
Junio C Hamano53228a52005-11-26 00:50:02 -080035 setup_git_directory();
Junio C Hamano84a9b582006-03-23 23:41:18 -080036 git_config(git_default_config);
Junio C Hamano53228a52005-11-26 00:50:02 -080037
Linus Torvalds3407bb42005-04-18 14:11:01 -070038 puts(create_temp_file(sha1));
39 return 0;
40}