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