gitweb: Do not use esc_html in esc_path
[git/gitweb-caching.git] / unpack-file.c
blobccddf1d4b0cf7fd3a699d8b33cf5bc4c5c4435b7
1 #include "cache.h"
2 #include "blob.h"
4 static char *create_temp_file(unsigned char *sha1)
6 static char path[50];
7 void *buf;
8 char type[100];
9 unsigned long size;
10 int fd;
12 buf = read_sha1_file(sha1, type, &size);
13 if (!buf || strcmp(type, blob_type))
14 die("unable to read blob object %s", sha1_to_hex(sha1));
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;
26 int main(int argc, char **argv)
28 unsigned char sha1[20];
30 if (argc != 2)
31 usage("git-unpack-file <sha1>");
32 if (get_sha1(argv[1], sha1))
33 die("Not a valid object name %s", argv[1]);
35 setup_git_directory();
36 git_config(git_default_config);
38 puts(create_temp_file(sha1));
39 return 0;