Ignore:
Timestamp:
Jun 23, 2014, 9:45:51 PM (11 years ago)
Author:
dmik
Message:

git: Merge version 2.0.0 from vendor to dmik branch.

Location:
git/branches/dmik
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • git/branches/dmik

  • TabularUnified git/branches/dmik/archive.c

    r626 r782  
    88
    99static char const * const archive_usage[] = {
    10         "git archive [options] <tree-ish> [<path>...]",
    11         "git archive --list",
    12         "git archive --remote <repo> [--exec <cmd>] [options] <tree-ish> [<path>...]",
    13         "git archive --remote <repo> [--exec <cmd>] --list",
     10        N_("git archive [options] <tree-ish> [<path>...]"),
     11        N_("git archive --list"),
     12        N_("git archive --remote <repo> [--exec <cmd>] [options] <tree-ish> [<path>...]"),
     13        N_("git archive --remote <repo> [--exec <cmd>] --list"),
    1414        NULL
    1515};
     
    1818static int nr_archivers;
    1919static int alloc_archivers;
     20static int remote_allow_unreachable;
    2021
    2122void register_archiver(struct archiver *ar)
     
    6061}
    6162
    62 static void *sha1_file_to_archive(const char *path, const unsigned char *sha1,
    63                 unsigned int mode, enum object_type *type,
    64                 unsigned long *sizep, const struct commit *commit)
     63void *sha1_file_to_archive(const struct archiver_args *args,
     64                           const char *path, const unsigned char *sha1,
     65                           unsigned int mode, enum object_type *type,
     66                           unsigned long *sizep)
    6567{
    6668        void *buffer;
    67 
     69        const struct commit *commit = args->convert ? args->commit : NULL;
     70
     71        path += args->baselen;
    6872        buffer = read_sha1_file(sha1, type, sizep);
    6973        if (buffer && S_ISREG(mode)) {
     
    110114        struct git_attr_check check[2];
    111115        const char *path_without_prefix;
    112         int convert = 0;
    113116        int err;
    114         enum object_type type;
    115         unsigned long size;
    116         void *buffer;
    117 
     117
     118        args->convert = 0;
    118119        strbuf_reset(&path);
    119120        strbuf_grow(&path, PATH_MAX);
     
    121122        strbuf_add(&path, base, baselen);
    122123        strbuf_addstr(&path, filename);
     124        if (S_ISDIR(mode) || S_ISGITLINK(mode))
     125                strbuf_addch(&path, '/');
    123126        path_without_prefix = path.buf + args->baselen;
    124127
     
    127130                if (ATTR_TRUE(check[0].value))
    128131                        return 0;
    129                 convert = ATTR_TRUE(check[1].value);
     132                args->convert = ATTR_TRUE(check[1].value);
    130133        }
    131134
    132135        if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
    133                 strbuf_addch(&path, '/');
    134136                if (args->verbose)
    135137                        fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
    136                 err = write_entry(args, sha1, path.buf, path.len, mode, NULL, 0);
     138                err = write_entry(args, sha1, path.buf, path.len, mode);
    137139                if (err)
    138140                        return err;
     
    140142        }
    141143
    142         buffer = sha1_file_to_archive(path_without_prefix, sha1, mode,
    143                         &type, &size, convert ? args->commit : NULL);
    144         if (!buffer)
    145                 return error("cannot read %s", sha1_to_hex(sha1));
    146144        if (args->verbose)
    147145                fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
    148         err = write_entry(args, sha1, path.buf, path.len, mode, buffer, size);
    149         free(buffer);
    150         return err;
     146        return write_entry(args, sha1, path.buf, path.len, mode);
    151147}
    152148
     
    157153        struct unpack_trees_options opts;
    158154        struct tree_desc t;
    159         struct pathspec pathspec;
    160155        int err;
    161156
     
    168163                        fprintf(stderr, "%.*s\n", (int)len, args->base);
    169164                err = write_entry(args, args->tree->object.sha1, args->base,
    170                                 len, 040777, NULL, 0);
     165                                  len, 040777);
    171166                if (err)
    172167                        return err;
     
    192187        }
    193188
    194         init_pathspec(&pathspec, args->pathspec);
    195         err = read_tree_recursive(args->tree, "", 0, 0, &pathspec,
     189        err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
    196190                                  write_archive_entry, &context);
    197         free_pathspec(&pathspec);
    198191        if (err == READ_TREE_RECURSIVE)
    199192                err = 0;
     
    228221        int ret;
    229222
    230         init_pathspec(&pathspec, paths);
     223        parse_pathspec(&pathspec, 0, 0, "", paths);
    231224        ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
    232225        free_pathspec(&pathspec);
     
    237230                struct archiver_args *ar_args)
    238231{
    239         ar_args->pathspec = pathspec = get_pathspec("", pathspec);
     232        /*
     233         * must be consistent with parse_pathspec in path_exists()
     234         * Also if pathspec patterns are dependent, we're in big
     235         * trouble as we test each one separately
     236         */
     237        parse_pathspec(&ar_args->pathspec, 0,
     238                       PATHSPEC_PREFER_FULL,
     239                       "", pathspec);
    240240        if (pathspec) {
    241241                while (*pathspec) {
    242                         if (!path_exists(ar_args->tree, *pathspec))
    243                                 die("path not found: %s", *pathspec);
     242                        if (**pathspec && !path_exists(ar_args->tree, *pathspec))
     243                                die(_("pathspec '%s' did not match any files"), *pathspec);
    244244                        pathspec++;
    245245                }
     
    259259
    260260        /* Remotes are only allowed to fetch actual refs */
    261         if (remote) {
     261        if (remote && !remote_allow_unreachable) {
    262262                char *ref = NULL;
    263                 const char *refname, *colon = NULL;
    264 
    265                 colon = strchr(name, ':');
    266                 if (colon)
    267                         refname = xstrndup(name, colon - name);
    268                 else
    269                         refname = name;
    270 
    271                 if (!dwim_ref(refname, strlen(refname), sha1, &ref))
    272                         die("no such ref: %s", refname);
    273                 if (refname != name)
    274                         free((void *)refname);
     263                const char *colon = strchrnul(name, ':');
     264                int refnamelen = colon - name;
     265
     266                if (!dwim_ref(name, refnamelen, sha1, &ref))
     267                        die("no such ref: %.*s", refnamelen, name);
    275268                free(ref);
    276269        }
     
    333326        struct option opts[] = {
    334327                OPT_GROUP(""),
    335                 OPT_STRING(0, "format", &format, "fmt", "archive format"),
    336                 OPT_STRING(0, "prefix", &base, "prefix",
    337                         "prepend prefix to each pathname in the archive"),
    338                 OPT_STRING('o', "output", &output, "file",
    339                         "write the archive to this file"),
     328                OPT_STRING(0, "format", &format, N_("fmt"), N_("archive format")),
     329                OPT_STRING(0, "prefix", &base, N_("prefix"),
     330                        N_("prepend prefix to each pathname in the archive")),
     331                OPT_STRING('o', "output", &output, N_("file"),
     332                        N_("write the archive to this file")),
    340333                OPT_BOOL(0, "worktree-attributes", &worktree_attributes,
    341                         "read .gitattributes in working directory"),
    342                 OPT__VERBOSE(&verbose, "report archived files on stderr"),
    343                 OPT__COMPR('0', &compression_level, "store only", 0),
    344                 OPT__COMPR('1', &compression_level, "compress faster", 1),
     334                        N_("read .gitattributes in working directory")),
     335                OPT__VERBOSE(&verbose, N_("report archived files on stderr")),
     336                OPT__COMPR('0', &compression_level, N_("store only"), 0),
     337                OPT__COMPR('1', &compression_level, N_("compress faster"), 1),
    345338                OPT__COMPR_HIDDEN('2', &compression_level, 2),
    346339                OPT__COMPR_HIDDEN('3', &compression_level, 3),
     
    350343                OPT__COMPR_HIDDEN('7', &compression_level, 7),
    351344                OPT__COMPR_HIDDEN('8', &compression_level, 8),
    352                 OPT__COMPR('9', &compression_level, "compress better", 9),
     345                OPT__COMPR('9', &compression_level, N_("compress better"), 9),
    353346                OPT_GROUP(""),
    354347                OPT_BOOL('l', "list", &list,
    355                         "list supported archive formats"),
     348                        N_("list supported archive formats")),
    356349                OPT_GROUP(""),
    357                 OPT_STRING(0, "remote", &remote, "repo",
    358                         "retrieve the archive from remote repository <repo>"),
    359                 OPT_STRING(0, "exec", &exec, "cmd",
    360                         "path to the remote git-upload-archive command"),
     350                OPT_STRING(0, "remote", &remote, N_("repo"),
     351                        N_("retrieve the archive from remote repository <repo>")),
     352                OPT_STRING(0, "exec", &exec, N_("command"),
     353                        N_("path to the remote git-upload-archive command")),
    361354                OPT_END()
    362355        };
     
    410403}
    411404
     405static int git_default_archive_config(const char *var, const char *value,
     406                                      void *cb)
     407{
     408        if (!strcmp(var, "uploadarchive.allowunreachable"))
     409                remote_allow_unreachable = git_config_bool(var, value);
     410        return git_default_config(var, value, cb);
     411}
     412
    412413int write_archive(int argc, const char **argv, const char *prefix,
    413414                  int setup_prefix, const char *name_hint, int remote)
     
    420421                prefix = setup_git_directory_gently(&nongit);
    421422
    422         git_config(git_default_config, NULL);
     423        git_config(git_default_archive_config, NULL);
    423424        init_tar_archiver();
    424425        init_zip_archiver();
     
    449450         * filename).
    450451         */
    451         if (prefixlen < 2 || filename[prefixlen-1] != '.')
     452        if (prefixlen < 2 || filename[prefixlen - 1] != '.')
    452453                return 0;
    453454        return !strcmp(filename + prefixlen, ext);
Note: See TracChangeset for help on using the changeset viewer.