You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
845 B
39 lines
845 B
20 years ago
|
#include "cache.h"
|
||
19 years ago
|
#include "blob.h"
|
||
16 years ago
|
#include "exec_cmd.h"
|
||
20 years ago
|
|
||
|
static char *create_temp_file(unsigned char *sha1)
|
||
|
{
|
||
|
static char path[50];
|
||
|
void *buf;
|
||
18 years ago
|
enum object_type type;
|
||
20 years ago
|
unsigned long size;
|
||
|
int fd;
|
||
|
|
||
18 years ago
|
buf = read_sha1_file(sha1, &type, &size);
|
||
|
if (!buf || type != OBJ_BLOB)
|
||
20 years ago
|
die("unable to read blob object %s", sha1_to_hex(sha1));
|
||
|
|
||
|
strcpy(path, ".merge_file_XXXXXX");
|
||
18 years ago
|
fd = xmkstemp(path);
|
||
18 years ago
|
if (write_in_full(fd, buf, size) != size)
|
||
16 years ago
|
die_errno("unable to write temp-file");
|
||
20 years ago
|
close(fd);
|
||
|
return path;
|
||
|
}
|
||
|
|
||
15 years ago
|
int cmd_unpack_file(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
|
unsigned char sha1[20];
|
||
|
|
||
15 years ago
|
if (argc != 2 || !strcmp(argv[1], "-h"))
|
||
16 years ago
|
usage("git unpack-file <sha1>");
|
||
19 years ago
|
if (get_sha1(argv[1], sha1))
|
||
|
die("Not a valid object name %s", argv[1]);
|
||
20 years ago
|
|
||
17 years ago
|
git_config(git_default_config, NULL);
|
||
19 years ago
|
|
||
20 years ago
|
puts(create_temp_file(sha1));
|
||
|
return 0;
|
||
|
}
|