]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/unpack-file.c
path.c: clarify trie_find()'s in-code comment
[thirdparty/git.git] / builtin / unpack-file.c
CommitLineData
c2e86add 1#include "builtin.h"
b2141fc1 2#include "config.h"
cbd53a21 3#include "object-store.h"
3407bb49 4
c300b1ed 5static char *create_temp_file(struct object_id *oid)
3407bb49
LT
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
b4f5aca4 13 buf = read_object_file(oid, &type, &size);
21666f1a 14 if (!buf || type != OBJ_BLOB)
c300b1ed 15 die("unable to read blob object %s", oid_to_hex(oid));
3407bb49 16
5096d490 17 xsnprintf(path, sizeof(path), ".merge_file_XXXXXX");
7647b17f 18 fd = xmkstemp(path);
06f46f23 19 if (write_in_full(fd, buf, size) < 0)
0721c314 20 die_errno("unable to write temp-file");
3407bb49
LT
21 close(fd);
22 return path;
23}
24
b5325818 25int cmd_unpack_file(int argc, const char **argv, const char *prefix)
3407bb49 26{
c300b1ed 27 struct object_id oid;
3407bb49 28
15073012 29 if (argc != 2 || !strcmp(argv[1], "-h"))
34263de0 30 usage("git unpack-file <sha1>");
c300b1ed 31 if (get_oid(argv[1], &oid))
31fff305 32 die("Not a valid object name %s", argv[1]);
3407bb49 33
ef90d6d4 34 git_config(git_default_config, NULL);
53228a5f 35
c300b1ed 36 puts(create_temp_file(&oid));
3407bb49
LT
37 return 0;
38}