| Linus Torvalds | 3407bb4 | 2005-04-18 21:11:01 | [diff] [blame] | 1 | #include "cache.h" |
| Peter Eriksen | 8e44025 | 2006-04-02 12:44:09 | [diff] [blame] | 2 | #include "blob.h" |
| Linus Torvalds | 3407bb4 | 2005-04-18 21:11:01 | [diff] [blame] | 3 | |
| 4 | static char *create_temp_file(unsigned char *sha1) |
| 5 | { |
| 6 | static char path[50]; |
| 7 | void *buf; |
| 8 | char type[100]; |
| 9 | unsigned long size; |
| 10 | int fd; |
| 11 | |
| 12 | buf = read_sha1_file(sha1, type, &size); |
| Peter Eriksen | 8e44025 | 2006-04-02 12:44:09 | [diff] [blame] | 13 | if (!buf || strcmp(type, blob_type)) |
| Linus Torvalds | 3407bb4 | 2005-04-18 21:11:01 | [diff] [blame] | 14 | die("unable to read blob object %s", sha1_to_hex(sha1)); |
| 15 | |
| 16 | strcpy(path, ".merge_file_XXXXXX"); |
| 17 | fd = mkstemp(path); |
| 18 | if (fd < 0) |
| 19 | die("unable to create temp-file"); |
| 20 | if (write(fd, buf, size) != size) |
| 21 | die("unable to write temp-file"); |
| 22 | close(fd); |
| 23 | return path; |
| 24 | } |
| 25 | |
| 26 | int main(int argc, char **argv) |
| 27 | { |
| 28 | unsigned char sha1[20]; |
| 29 | |
| Dmitry V. Levin | 31fff30 | 2006-05-08 21:43:38 | [diff] [blame] | 30 | if (argc != 2) |
| Alexey Nezhdanov | 667bb59 | 2005-05-19 11:17:16 | [diff] [blame] | 31 | usage("git-unpack-file <sha1>"); |
| Dmitry V. Levin | 31fff30 | 2006-05-08 21:43:38 | [diff] [blame] | 32 | if (get_sha1(argv[1], sha1)) |
| 33 | die("Not a valid object name %s", argv[1]); |
| Linus Torvalds | 3407bb4 | 2005-04-18 21:11:01 | [diff] [blame] | 34 | |
| Junio C Hamano | 53228a5 | 2005-11-26 08:50:02 | [diff] [blame] | 35 | setup_git_directory(); |
| Junio C Hamano | 84a9b58 | 2006-03-24 07:41:18 | [diff] [blame] | 36 | git_config(git_default_config); |
| Junio C Hamano | 53228a5 | 2005-11-26 08:50:02 | [diff] [blame] | 37 | |
| Linus Torvalds | 3407bb4 | 2005-04-18 21:11:01 | [diff] [blame] | 38 | puts(create_temp_file(sha1)); |
| 39 | return 0; |
| 40 | } |