builtin / unpack-file.con commit i18n: mark clone nonexistent repository message for translation (d3e1ddf)
   1#include "builtin.h"
   2
   3static char *create_temp_file(unsigned char *sha1)
   4{
   5        static char path[50];
   6        void *buf;
   7        enum object_type type;
   8        unsigned long size;
   9        int fd;
  10
  11        buf = read_sha1_file(sha1, &type, &size);
  12        if (!buf || type != OBJ_BLOB)
  13                die("unable to read blob object %s", sha1_to_hex(sha1));
  14
  15        strcpy(path, ".merge_file_XXXXXX");
  16        fd = xmkstemp(path);
  17        if (write_in_full(fd, buf, size) != size)
  18                die_errno("unable to write temp-file");
  19        close(fd);
  20        return path;
  21}
  22
  23int cmd_unpack_file(int argc, const char **argv, const char *prefix)
  24{
  25        unsigned char sha1[20];
  26
  27        if (argc != 2 || !strcmp(argv[1], "-h"))
  28                usage("git unpack-file <sha1>");
  29        if (get_sha1(argv[1], sha1))
  30                die("Not a valid object name %s", argv[1]);
  31
  32        git_config(git_default_config, NULL);
  33
  34        puts(create_temp_file(sha1));
  35        return 0;
  36}