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