diff: do not use null sha1 as a sentinel value
[git/git.git] / builtin / unpack-file.c
CommitLineData
c2e86add 1#include "builtin.h"
3407bb49
LT
2
3static char *create_temp_file(unsigned char *sha1)
4{
5 static char path[50];
6 void *buf;
21666f1a 7 enum object_type type;
3407bb49
LT
8 unsigned long size;
9 int fd;
10
21666f1a
NP
11 buf = read_sha1_file(sha1, &type, &size);
12 if (!buf || type != OBJ_BLOB)
3407bb49
LT
13 die("unable to read blob object %s", sha1_to_hex(sha1));
14
15 strcpy(path, ".merge_file_XXXXXX");
7647b17f 16 fd = xmkstemp(path);
93822c22 17 if (write_in_full(fd, buf, size) != size)
0721c314 18 die_errno("unable to write temp-file");
3407bb49
LT
19 close(fd);
20 return path;
21}
22
b5325818 23int cmd_unpack_file(int argc, const char **argv, const char *prefix)
3407bb49
LT
24{
25 unsigned char sha1[20];
26
15073012 27 if (argc != 2 || !strcmp(argv[1], "-h"))
34263de0 28 usage("git unpack-file <sha1>");
31fff305
DL
29 if (get_sha1(argv[1], sha1))
30 die("Not a valid object name %s", argv[1]);
3407bb49 31
ef90d6d4 32 git_config(git_default_config, NULL);
53228a5f 33
3407bb49
LT
34 puts(create_temp_file(sha1));
35 return 0;
36}