]> git.ipfire.org Git - thirdparty/git.git/blame - unpack-file.c
Teach bash completion about recent log long options
[thirdparty/git.git] / unpack-file.c
CommitLineData
3407bb49 1#include "cache.h"
8e440259 2#include "blob.h"
3407bb49
LT
3
4static char *create_temp_file(unsigned char *sha1)
5{
6 static char path[50];
7 void *buf;
21666f1a 8 enum object_type type;
3407bb49
LT
9 unsigned long size;
10 int fd;
11
21666f1a
NP
12 buf = read_sha1_file(sha1, &type, &size);
13 if (!buf || type != OBJ_BLOB)
3407bb49
LT
14 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");
93822c22 20 if (write_in_full(fd, buf, size) != size)
3407bb49
LT
21 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
31fff305 30 if (argc != 2)
667bb59b 31 usage("git-unpack-file <sha1>");
31fff305
DL
32 if (get_sha1(argv[1], sha1))
33 die("Not a valid object name %s", argv[1]);
3407bb49 34
53228a5f 35 setup_git_directory();
84a9b58c 36 git_config(git_default_config);
53228a5f 37
3407bb49
LT
38 puts(create_temp_file(sha1));
39 return 0;
40}