fetch-pack: test explicitly that --all can fetch tag references pointing to non-commits
[gitweb.git] / archive.c
index 01b0899b3f9027c5a392bd58667ed0e216d082ed..01751e574bc10c1211d0253d215917ecc4ce82dd 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -171,13 +171,14 @@ static void queue_directory(const unsigned char *sha1,
                unsigned mode, int stage, struct archiver_context *c)
 {
        struct directory *d;
-       d = xmallocz(sizeof(*d) + base->len + 1 + strlen(filename));
+       size_t len = st_add4(base->len, 1, strlen(filename), 1);
+       d = xmalloc(st_add(sizeof(*d), len));
        d->up      = c->bottom;
        d->baselen = base->len;
        d->mode    = mode;
        d->stage   = stage;
        c->bottom  = d;
-       d->len = sprintf(d->path, "%.*s%s/", (int)base->len, base->buf, filename);
+       d->len = xsnprintf(d->path, len, "%.*s%s/", (int)base->len, base->buf, filename);
        hashcpy(d->oid.hash, sha1);
 }
 
@@ -240,7 +241,7 @@ int write_archive_entries(struct archiver_args *args,
                        len--;
                if (args->verbose)
                        fprintf(stderr, "%.*s\n", (int)len, args->base);
-               err = write_entry(args, args->tree->object.sha1, args->base,
+               err = write_entry(args, args->tree->object.oid.hash, args->base,
                                  len, 040777);
                if (err)
                        return err;
@@ -321,7 +322,7 @@ static int path_exists(struct tree *tree, const char *path)
        pathspec.recursive = 1;
        ret = read_tree_recursive(tree, "", 0, 0, &pathspec,
                                  reject_entry, &pathspec);
-       free_pathspec(&pathspec);
+       clear_pathspec(&pathspec);
        return ret != 0;
 }
 
@@ -373,7 +374,7 @@ static void parse_treeish_arg(const char **argv,
 
        commit = lookup_commit_reference_gently(oid.hash, 1);
        if (commit) {
-               commit_sha1 = commit->object.sha1;
+               commit_sha1 = commit->object.oid.hash;
                archive_time = commit->date;
        } else {
                commit_sha1 = NULL;
@@ -389,7 +390,7 @@ static void parse_treeish_arg(const char **argv,
                unsigned int mode;
                int err;
 
-               err = get_tree_entry(tree->object.sha1, prefix,
+               err = get_tree_entry(tree->object.oid.hash, prefix,
                                     tree_oid.hash, &mode);
                if (err || !S_ISDIR(mode))
                        die("current working directory is untracked");
@@ -457,11 +458,11 @@ static int parse_archive_args(int argc, const char **argv,
        argc = parse_options(argc, argv, NULL, opts, archive_usage, 0);
 
        if (remote)
-               die("Unexpected option --remote");
+               die(_("Unexpected option --remote"));
        if (exec)
-               die("Option --exec can only be used together with --remote");
+               die(_("Option --exec can only be used together with --remote"));
        if (output)
-               die("Unexpected option --output");
+               die(_("Unexpected option --output"));
 
        if (!base)
                base = "";
@@ -483,14 +484,14 @@ static int parse_archive_args(int argc, const char **argv,
                usage_with_options(archive_usage, opts);
        *ar = lookup_archiver(format);
        if (!*ar || (is_remote && !((*ar)->flags & ARCHIVER_REMOTE)))
-               die("Unknown archive format '%s'", format);
+               die(_("Unknown archive format '%s'"), format);
 
        args->compression_level = Z_DEFAULT_COMPRESSION;
        if (compression_level != -1) {
                if ((*ar)->flags & ARCHIVER_WANT_COMPRESSION_LEVELS)
                        args->compression_level = compression_level;
                else {
-                       die("Argument not supported for format '%s': -%d",
+                       die(_("Argument not supported for format '%s': -%d"),
                                        format, compression_level);
                }
        }
@@ -503,15 +504,11 @@ static int parse_archive_args(int argc, const char **argv,
 }
 
 int write_archive(int argc, const char **argv, const char *prefix,
-                 int setup_prefix, const char *name_hint, int remote)
+                 const char *name_hint, int remote)
 {
-       int nongit = 0;
        const struct archiver *ar = NULL;
        struct archiver_args args;
 
-       if (setup_prefix && prefix == NULL)
-               prefix = setup_git_directory_gently(&nongit);
-
        git_config_get_bool("uploadarchive.allowunreachable", &remote_allow_unreachable);
        git_config(git_default_config, NULL);
 
@@ -519,7 +516,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
        init_zip_archiver();
 
        argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
-       if (nongit) {
+       if (!startup_info->have_repository) {
                /*
                 * We know this will die() with an error, so we could just
                 * die ourselves; but its error message will be more specific