Windows: Revert to default paths and convert them by RUNTIME_PREFIX
[git/mingw/4msysgit/wingit-dll.git] / unpack-file.c
blobf8bfda7d33b386e180cce95d3264e3e669807f34
1 #include "cache.h"
2 #include "blob.h"
3 #include "exec_cmd.h"
5 static char *create_temp_file(unsigned char *sha1)
7 static char path[50];
8 void *buf;
9 enum object_type type;
10 unsigned long size;
11 int fd;
13 buf = read_sha1_file(sha1, &type, &size);
14 if (!buf || type != OBJ_BLOB)
15 die("unable to read blob object %s", sha1_to_hex(sha1));
17 strcpy(path, ".merge_file_XXXXXX");
18 fd = xmkstemp(path);
19 if (write_in_full(fd, buf, size) != size)
20 die("unable to write temp-file");
21 close(fd);
22 return path;
25 int main(int argc, char **argv)
27 unsigned char sha1[20];
29 if (argv[0] && *argv[0])
30 git_extract_argv0_path(argv[0]);
32 if (argc != 2)
33 usage("git-unpack-file <sha1>");
34 if (get_sha1(argv[1], sha1))
35 die("Not a valid object name %s", argv[1]);
37 setup_git_directory();
38 git_config(git_default_config, NULL);
40 puts(create_temp_file(sha1));
41 return 0;