builtin-tar-tree.con commit Document git-diff whitespace flags -b and -w (8ebe185)
   1/*
   2 * Copyright (c) 2005, 2006 Rene Scharfe
   3 */
   4#include <time.h>
   5#include "cache.h"
   6#include "commit.h"
   7#include "tar.h"
   8#include "builtin.h"
   9#include "quote.h"
  10
  11static const char tar_tree_usage[] =
  12"git-tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
  13"*** Note that this command is now deprecated; use git-archive instead.";
  14
  15int cmd_tar_tree(int argc, const char **argv, const char *prefix)
  16{
  17        /*
  18         * git-tar-tree is now a wrapper around git-archive --format=tar
  19         *
  20         * $0 --remote=<repo> arg... ==>
  21         *      git-archive --format=tar --remote=<repo> arg...
  22         * $0 tree-ish ==>
  23         *      git-archive --format=tar tree-ish
  24         * $0 tree-ish basedir ==>
  25         *      git-archive --format-tar --prefix=basedir tree-ish
  26         */
  27        int i;
  28        const char **nargv = xcalloc(sizeof(*nargv), argc + 2);
  29        char *basedir_arg;
  30        int nargc = 0;
  31
  32        nargv[nargc++] = "git-archive";
  33        nargv[nargc++] = "--format=tar";
  34
  35        if (2 <= argc && !strncmp("--remote=", argv[1], 9)) {
  36                nargv[nargc++] = argv[1];
  37                argv++;
  38                argc--;
  39        }
  40        switch (argc) {
  41        default:
  42                usage(tar_tree_usage);
  43                break;
  44        case 3:
  45                /* base-path */
  46                basedir_arg = xmalloc(strlen(argv[2]) + 11);
  47                sprintf(basedir_arg, "--prefix=%s/", argv[2]);
  48                nargv[nargc++] = basedir_arg;
  49                /* fallthru */
  50        case 2:
  51                /* tree-ish */
  52                nargv[nargc++] = argv[1];
  53        }
  54        nargv[nargc] = NULL;
  55
  56        fprintf(stderr,
  57                "*** git-tar-tree is now deprecated.\n"
  58                "*** Running git-archive instead.\n***");
  59        for (i = 0; i < nargc; i++) {
  60                fputc(' ', stderr);
  61                sq_quote_print(stderr, nargv[i]);
  62        }
  63        fputc('\n', stderr);
  64        return cmd_archive(nargc, nargv, prefix);
  65}
  66
  67/* ustar header + extended global header content */
  68#define RECORDSIZE      (512)
  69#define HEADERSIZE (2 * RECORDSIZE)
  70
  71int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
  72{
  73        char buffer[HEADERSIZE];
  74        struct ustar_header *header = (struct ustar_header *)buffer;
  75        char *content = buffer + RECORDSIZE;
  76        ssize_t n;
  77
  78        n = xread(0, buffer, HEADERSIZE);
  79        if (n < HEADERSIZE)
  80                die("git-get-tar-commit-id: read error");
  81        if (header->typeflag[0] != 'g')
  82                return 1;
  83        if (memcmp(content, "52 comment=", 11))
  84                return 1;
  85
  86        n = xwrite(1, content + 11, 41);
  87        if (n < 41)
  88                die("git-get-tar-commit-id: write error");
  89
  90        return 0;
  91}