debian: new upstream point release
[git/debian.git] / builtin / unpack-file.c
blobc129e2bb6cbffaf80898c8a9c1c4e49fdeb001a4
1 #include "builtin.h"
2 #include "config.h"
3 #include "hex.h"
4 #include "object-name.h"
5 #include "object-store-ll.h"
7 static char *create_temp_file(struct object_id *oid)
9 static char path[50];
10 void *buf;
11 enum object_type type;
12 unsigned long size;
13 int fd;
15 buf = repo_read_object_file(the_repository, oid, &type, &size);
16 if (!buf || type != OBJ_BLOB)
17 die("unable to read blob object %s", oid_to_hex(oid));
19 xsnprintf(path, sizeof(path), ".merge_file_XXXXXX");
20 fd = xmkstemp(path);
21 if (write_in_full(fd, buf, size) < 0)
22 die_errno("unable to write temp-file");
23 close(fd);
24 free(buf);
25 return path;
28 int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED)
30 struct object_id oid;
32 if (argc != 2 || !strcmp(argv[1], "-h"))
33 usage("git unpack-file <blob>");
34 if (repo_get_oid(the_repository, argv[1], &oid))
35 die("Not a valid object name %s", argv[1]);
37 git_config(git_default_config, NULL);
39 puts(create_temp_file(&oid));
40 return 0;