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