]> git.ipfire.org Git - thirdparty/git.git/blobdiff - archive.c
path: optimize common dir checking
[thirdparty/git.git] / archive.c
index 96057ed830e521a5f12b0a73b4a04a6b5e581e87..01b0899b3f9027c5a392bd58667ed0e216d082ed 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "refs.h"
 #include "commit.h"
 #include "tree-walk.h"
 #include "attr.h"
@@ -33,7 +34,7 @@ static void format_subst(const struct commit *commit,
        char *to_free = NULL;
        struct strbuf fmt = STRBUF_INIT;
        struct pretty_print_context ctx = {0};
-       ctx.date_mode = DATE_NORMAL;
+       ctx.date_mode.type = DATE_NORMAL;
        ctx.abbrev = DEFAULT_ABBREV;
 
        if (src == buf->buf)
@@ -101,7 +102,7 @@ static void setup_archive_check(struct git_attr_check *check)
 
 struct directory {
        struct directory *up;
-       unsigned char sha1[20];
+       struct object_id oid;
        int baselen, len;
        unsigned mode;
        int stage;
@@ -177,7 +178,7 @@ static void queue_directory(const unsigned char *sha1,
        d->stage   = stage;
        c->bottom  = d;
        d->len = sprintf(d->path, "%.*s%s/", (int)base->len, base->buf, filename);
-       hashcpy(d->sha1, sha1);
+       hashcpy(d->oid.hash, sha1);
 }
 
 static int write_directory(struct archiver_context *c)
@@ -191,7 +192,7 @@ static int write_directory(struct archiver_context *c)
        d->path[d->len - 1] = '\0'; /* no trailing slash */
        ret =
                write_directory(c) ||
-               write_archive_entry(d->sha1, d->path, d->baselen,
+               write_archive_entry(d->oid.hash, d->path, d->baselen,
                                    d->path + d->baselen, d->mode,
                                    d->stage, c) != READ_TREE_RECURSIVE;
        free(d);
@@ -354,7 +355,7 @@ static void parse_treeish_arg(const char **argv,
        time_t archive_time;
        struct tree *tree;
        const struct commit *commit;
-       unsigned char sha1[20];
+       struct object_id oid;
 
        /* Remotes are only allowed to fetch actual refs */
        if (remote && !remote_allow_unreachable) {
@@ -362,15 +363,15 @@ static void parse_treeish_arg(const char **argv,
                const char *colon = strchrnul(name, ':');
                int refnamelen = colon - name;
 
-               if (!dwim_ref(name, refnamelen, sha1, &ref))
+               if (!dwim_ref(name, refnamelen, oid.hash, &ref))
                        die("no such ref: %.*s", refnamelen, name);
                free(ref);
        }
 
-       if (get_sha1(name, sha1))
+       if (get_sha1(name, oid.hash))
                die("Not a valid object name");
 
-       commit = lookup_commit_reference_gently(sha1, 1);
+       commit = lookup_commit_reference_gently(oid.hash, 1);
        if (commit) {
                commit_sha1 = commit->object.sha1;
                archive_time = commit->date;
@@ -379,21 +380,21 @@ static void parse_treeish_arg(const char **argv,
                archive_time = time(NULL);
        }
 
-       tree = parse_tree_indirect(sha1);
+       tree = parse_tree_indirect(oid.hash);
        if (tree == NULL)
                die("not a tree object");
 
        if (prefix) {
-               unsigned char tree_sha1[20];
+               struct object_id tree_oid;
                unsigned int mode;
                int err;
 
                err = get_tree_entry(tree->object.sha1, prefix,
-                                    tree_sha1, &mode);
+                                    tree_oid.hash, &mode);
                if (err || !S_ISDIR(mode))
                        die("current working directory is untracked");
 
-               tree = parse_tree_indirect(tree_sha1);
+               tree = parse_tree_indirect(tree_oid.hash);
        }
        ar_args->tree = tree;
        ar_args->commit_sha1 = commit_sha1;