Linus Torvalds | 3407bb4 | 2005-04-18 14:11:01 -0700 | [diff] [blame] | 1 | #include "cache.h" |
Peter Eriksen | 8e44025 | 2006-04-02 14:44:09 +0200 | [diff] [blame] | 2 | #include "blob.h" |
Steffen Prohaska | 2fb3f6d | 2009-01-18 13:00:12 +0100 | [diff] [blame] | 3 | #include "exec_cmd.h" |
Linus Torvalds | 3407bb4 | 2005-04-18 14:11:01 -0700 | [diff] [blame] | 4 | |
| 5 | static char *create_temp_file(unsigned char *sha1) |
| 6 | { |
| 7 | static char path[50]; |
| 8 | void *buf; |
Nicolas Pitre | 21666f1 | 2007-02-26 14:55:59 -0500 | [diff] [blame] | 9 | enum object_type type; |
Linus Torvalds | 3407bb4 | 2005-04-18 14:11:01 -0700 | [diff] [blame] | 10 | unsigned long size; |
| 11 | int fd; |
| 12 | |
Nicolas Pitre | 21666f1 | 2007-02-26 14:55:59 -0500 | [diff] [blame] | 13 | buf = read_sha1_file(sha1, &type, &size); |
| 14 | if (!buf || type != OBJ_BLOB) |
Linus Torvalds | 3407bb4 | 2005-04-18 14:11:01 -0700 | [diff] [blame] | 15 | die("unable to read blob object %s", sha1_to_hex(sha1)); |
| 16 | |
| 17 | strcpy(path, ".merge_file_XXXXXX"); |
Luiz Fernando N. Capitulino | 7647b17 | 2007-08-14 16:45:58 -0300 | [diff] [blame] | 18 | fd = xmkstemp(path); |
Andy Whitcroft | 93822c2 | 2007-01-08 15:58:23 +0000 | [diff] [blame] | 19 | if (write_in_full(fd, buf, size) != size) |
Thomas Rast | 0721c31 | 2009-06-27 17:58:47 +0200 | [diff] [blame] | 20 | die_errno("unable to write temp-file"); |
Linus Torvalds | 3407bb4 | 2005-04-18 14:11:01 -0700 | [diff] [blame] | 21 | close(fd); |
| 22 | return path; |
| 23 | } |
| 24 | |
| 25 | int main(int argc, char **argv) |
| 26 | { |
| 27 | unsigned char sha1[20]; |
| 28 | |
Steffen Prohaska | 2fb3f6d | 2009-01-18 13:00:12 +0100 | [diff] [blame] | 29 | git_extract_argv0_path(argv[0]); |
| 30 | |
Dmitry V. Levin | 31fff30 | 2006-05-09 01:43:38 +0400 | [diff] [blame] | 31 | if (argc != 2) |
Alexander Potashev | 34263de | 2009-01-04 21:39:27 +0300 | [diff] [blame] | 32 | usage("git unpack-file <sha1>"); |
Dmitry V. Levin | 31fff30 | 2006-05-09 01:43:38 +0400 | [diff] [blame] | 33 | if (get_sha1(argv[1], sha1)) |
| 34 | die("Not a valid object name %s", argv[1]); |
Linus Torvalds | 3407bb4 | 2005-04-18 14:11:01 -0700 | [diff] [blame] | 35 | |
Junio C Hamano | 53228a5 | 2005-11-26 00:50:02 -0800 | [diff] [blame] | 36 | setup_git_directory(); |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 37 | git_config(git_default_config, NULL); |
Junio C Hamano | 53228a5 | 2005-11-26 00:50:02 -0800 | [diff] [blame] | 38 | |
Linus Torvalds | 3407bb4 | 2005-04-18 14:11:01 -0700 | [diff] [blame] | 39 | puts(create_temp_file(sha1)); |
| 40 | return 0; |
| 41 | } |