]> git.ipfire.org Git - thirdparty/git.git/blame - unpack-file.c
Fix some printf format warnings
[thirdparty/git.git] / unpack-file.c
CommitLineData
3407bb49 1#include "cache.h"
8e440259 2#include "blob.h"
2fb3f6db 3#include "exec_cmd.h"
3407bb49
LT
4
5static char *create_temp_file(unsigned char *sha1)
6{
7 static char path[50];
8 void *buf;
21666f1a 9 enum object_type type;
3407bb49
LT
10 unsigned long size;
11 int fd;
12
21666f1a
NP
13 buf = read_sha1_file(sha1, &type, &size);
14 if (!buf || type != OBJ_BLOB)
3407bb49
LT
15 die("unable to read blob object %s", sha1_to_hex(sha1));
16
17 strcpy(path, ".merge_file_XXXXXX");
7647b17f 18 fd = xmkstemp(path);
93822c22 19 if (write_in_full(fd, buf, size) != size)
0721c314 20 die_errno("unable to write temp-file");
3407bb49
LT
21 close(fd);
22 return path;
23}
24
25int main(int argc, char **argv)
26{
27 unsigned char sha1[20];
28
2fb3f6db
SP
29 git_extract_argv0_path(argv[0]);
30
31fff305 31 if (argc != 2)
34263de0 32 usage("git unpack-file <sha1>");
31fff305
DL
33 if (get_sha1(argv[1], sha1))
34 die("Not a valid object name %s", argv[1]);
3407bb49 35
53228a5f 36 setup_git_directory();
ef90d6d4 37 git_config(git_default_config, NULL);
53228a5f 38
3407bb49
LT
39 puts(create_temp_file(sha1));
40 return 0;
41}