]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/unpack-file.c
object-name.h: move declarations for object-name.c functions from cache.h
[thirdparty/git.git] / builtin / unpack-file.c
CommitLineData
c2e86add 1#include "builtin.h"
b2141fc1 2#include "config.h"
41771fa4 3#include "hex.h"
dabab1d6 4#include "object-name.h"
cbd53a21 5#include "object-store.h"
d5ebb50d 6#include "wrapper.h"
3407bb49 7
c300b1ed 8static char *create_temp_file(struct object_id *oid)
3407bb49
LT
9{
10 static char path[50];
11 void *buf;
21666f1a 12 enum object_type type;
3407bb49
LT
13 unsigned long size;
14 int fd;
15
bc726bd0 16 buf = repo_read_object_file(the_repository, oid, &type, &size);
21666f1a 17 if (!buf || type != OBJ_BLOB)
c300b1ed 18 die("unable to read blob object %s", oid_to_hex(oid));
3407bb49 19
5096d490 20 xsnprintf(path, sizeof(path), ".merge_file_XXXXXX");
7647b17f 21 fd = xmkstemp(path);
06f46f23 22 if (write_in_full(fd, buf, size) < 0)
0721c314 23 die_errno("unable to write temp-file");
3407bb49 24 close(fd);
e84a26e3 25 free(buf);
3407bb49
LT
26 return path;
27}
28
b5325818 29int cmd_unpack_file(int argc, const char **argv, const char *prefix)
3407bb49 30{
c300b1ed 31 struct object_id oid;
3407bb49 32
15073012 33 if (argc != 2 || !strcmp(argv[1], "-h"))
f6a8ef07 34 usage("git unpack-file <blob>");
d850b7a5 35 if (repo_get_oid(the_repository, argv[1], &oid))
31fff305 36 die("Not a valid object name %s", argv[1]);
3407bb49 37
ef90d6d4 38 git_config(git_default_config, NULL);
53228a5f 39
c300b1ed 40 puts(create_temp_file(&oid));
3407bb49
LT
41 return 0;
42}