submodule: Use cat instead of echo to avoid DOS line-endings
[git/dscho.git] / builtin / unpack-file.c
blob19200291a2632554223b1a675d5324b4682248ab
1 #include "builtin.h"
3 static char *create_temp_file(unsigned char *sha1)
5 static char path[50];
6 void *buf;
7 enum object_type type;
8 unsigned long size;
9 int fd;
11 buf = read_sha1_file(sha1, &type, &size);
12 if (!buf || type != OBJ_BLOB)
13 die("unable to read blob object %s", sha1_to_hex(sha1));
15 strcpy(path, ".merge_file_XXXXXX");
16 fd = xmkstemp(path);
17 if (write_in_full(fd, buf, size) != size)
18 die_errno("unable to write temp-file");
19 close(fd);
20 return path;
23 int cmd_unpack_file(int argc, const char **argv, const char *prefix)
25 unsigned char sha1[20];
27 if (argc != 2 || !strcmp(argv[1], "-h"))
28 usage("git unpack-file <sha1>");
29 if (get_sha1(argv[1], sha1))
30 die("Not a valid object name %s", argv[1]);
32 git_config(git_default_config, NULL);
34 puts(create_temp_file(sha1));
35 return 0;