🌐 AI搜索 & 代理 主页
blob: ccddf1d4b0cf7fd3a699d8b33cf5bc4c5c4435b7 [file] [log] [blame]
Linus Torvalds3407bb42005-04-18 21:11:011#include "cache.h"
Peter Eriksen8e440252006-04-02 12:44:092#include "blob.h"
Linus Torvalds3407bb42005-04-18 21:11:013
4static 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 Eriksen8e440252006-04-02 12:44:0913 if (!buf || strcmp(type, blob_type))
Linus Torvalds3407bb42005-04-18 21:11:0114 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
26int main(int argc, char **argv)
27{
28 unsigned char sha1[20];
29
Dmitry V. Levin31fff302006-05-08 21:43:3830 if (argc != 2)
Alexey Nezhdanov667bb592005-05-19 11:17:1631 usage("git-unpack-file <sha1>");
Dmitry V. Levin31fff302006-05-08 21:43:3832 if (get_sha1(argv[1], sha1))
33 die("Not a valid object name %s", argv[1]);
Linus Torvalds3407bb42005-04-18 21:11:0134
Junio C Hamano53228a52005-11-26 08:50:0235 setup_git_directory();
Junio C Hamano84a9b582006-03-24 07:41:1836 git_config(git_default_config);
Junio C Hamano53228a52005-11-26 08:50:0237
Linus Torvalds3407bb42005-04-18 21:11:0138 puts(create_temp_file(sha1));
39 return 0;
40}