This is a plumbing command for generating metapack files. Right now it understands only the "commits" metapack (and there is not yet a reader). Eventually we may want to build this metapack automatically when we generate a new pack. Let's be conservative for now, though, and let the idea prove itself in practice before turning it on for everyone. The commits metapack generated by this command is 84 bytes per commit; for linux-2.6.git, this is about 31M. TODO: documentation Signed-off-by: Jeff King <peff@xxxxxxxx> --- .gitignore | 1 + Makefile | 1 + builtin.h | 1 + builtin/metapack.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ git-repack.sh | 2 +- git.c | 1 + 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 builtin/metapack.c diff --git a/.gitignore b/.gitignore index 6669bf0..3f67a36 100644 --- a/.gitignore +++ b/.gitignore @@ -93,6 +93,7 @@ /git-merge-subtree /git-mergetool /git-mergetool--lib +/git-metapack /git-mktag /git-mktree /git-name-rev diff --git a/Makefile b/Makefile index 6ca5320..3899699 100644 --- a/Makefile +++ b/Makefile @@ -905,6 +905,7 @@ BUILTIN_OBJS += builtin/merge-tree.o BUILTIN_OBJS += builtin/merge-ours.o BUILTIN_OBJS += builtin/merge-recursive.o BUILTIN_OBJS += builtin/merge-tree.o +BUILTIN_OBJS += builtin/metapack.o BUILTIN_OBJS += builtin/mktag.o BUILTIN_OBJS += builtin/mktree.o BUILTIN_OBJS += builtin/mv.o diff --git a/builtin.h b/builtin.h index faef559..30108ab 100644 --- a/builtin.h +++ b/builtin.h @@ -97,6 +97,7 @@ extern int cmd_merge_tree(int argc, const char **argv, const char *prefix); extern int cmd_merge_file(int argc, const char **argv, const char *prefix); extern int cmd_merge_recursive(int argc, const char **argv, const char *prefix); extern int cmd_merge_tree(int argc, const char **argv, const char *prefix); +extern int cmd_metapack(int argc, const char **argv, const char *prefix); extern int cmd_mktag(int argc, const char **argv, const char *prefix); extern int cmd_mktree(int argc, const char **argv, const char *prefix); extern int cmd_mv(int argc, const char **argv, const char *prefix); diff --git a/builtin/metapack.c b/builtin/metapack.c new file mode 100644 index 0000000..5fee6cf --- /dev/null +++ b/builtin/metapack.c @@ -0,0 +1,73 @@ +#include "builtin.h" +#include "parse-options.h" +#include "commit-metapack.h" + +static const char *metapack_usage[] = { + N_("git metapack [options] <packindex...>"), + NULL +}; + +#define METAPACK_COMMITS (1<<0) + +static void metapack_one(const char *idx, int type) +{ + if (type & METAPACK_COMMITS) + commit_metapack_write(idx); +} + +static void metapack_all(int type) +{ + struct strbuf path = STRBUF_INIT; + size_t dirlen; + DIR *dh; + struct dirent *de; + + strbuf_addstr(&path, get_object_directory()); + strbuf_addstr(&path, "/pack"); + dirlen = path.len; + + dh = opendir(path.buf); + if (!dh) + die_errno("unable to open pack directory '%s'", path.buf); + while ((de = readdir(dh))) { + if (!has_extension(de->d_name, ".idx")) + continue; + + strbuf_addch(&path, '/'); + strbuf_addstr(&path, de->d_name); + metapack_one(path.buf, type); + strbuf_setlen(&path, dirlen); + } + + closedir(dh); + strbuf_release(&path); +} + +int cmd_metapack(int argc, const char **argv, const char *prefix) +{ + int all = 0; + int type = 0; + struct option opts[] = { + OPT_BOOL(0, "all", &all, N_("create metapacks for all packs")), + OPT_BIT(0, "commits", &type, N_("create commit metapacks"), + METAPACK_COMMITS), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, opts, metapack_usage, 0); + + if (all && argc) + usage_msg_opt(_("pack arguments do not make sense with --all"), + metapack_usage, opts); + if (!type) + usage_msg_opt(_("no metapack type specified"), + metapack_usage, opts); + + if (all) + metapack_all(type); + else + for (; *argv; argv++) + metapack_one(*argv, type); + + return 0; +} diff --git a/git-repack.sh b/git-repack.sh index 7579331..e6a9773 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -180,7 +180,7 @@ then do case " $fullbases " in *" $e "*) ;; - *) rm -f "$e.pack" "$e.idx" "$e.keep" ;; + *) rm -f "$e.pack" "$e.idx" "$e.keep" "$e.commits";; esac done ) diff --git a/git.c b/git.c index b10c18b..f6e5552 100644 --- a/git.c +++ b/git.c @@ -365,6 +365,7 @@ static void handle_internal_command(int argc, const char **argv) { "merge-recursive-theirs", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE }, { "merge-subtree", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE }, { "merge-tree", cmd_merge_tree, RUN_SETUP }, + { "metapack", cmd_metapack, RUN_SETUP }, { "mktag", cmd_mktag, RUN_SETUP }, { "mktree", cmd_mktree, RUN_SETUP }, { "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE }, -- 1.8.0.2.16.g72e2fc9 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html