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