git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/6] add git-metapack command

From
Jeff King <peff@peff.net>
Date
Jan 29, 2013, 09:16 UTC
Message-ID
<20130129091630.GE9999@sigill.intra.peff.net>
In-Reply-To
<20130129091434.GA6975@sigill.intra.peff.net>

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@peff.net>
---
 .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
Previous: Jeff KingNext: Jeff King
Message 36 of 43 in “commit caching”
  1. 0/6 commit cachingJeff King, Jan 29, 2013
  2. 1/6 csum-file: make sha1write const-correctJeff King, Jan 29, 2013
  3. 2/6 strbuf: add string-chomping functionsJeff King, Jan 29, 2013
  4. Michael HaggertyJan 29, 2013
  5. Jeff KingJan 29, 2013
  6. Michael HaggertyJan 30, 2013
  7. 3/6 introduce pack metadata cache filesJeff King, Jan 29, 2013
  8. Junio C HamanoJan 29, 2013
  9. Jeff KingJan 30, 2013
  10. Duy NguyenJan 30, 2013
  11. Jeff KingJan 30, 2013
  12. 4/6 introduce a commit metapackJeff King, Jan 29, 2013
  13. Michael HaggertyJan 29, 2013
  14. Jeff KingJan 29, 2013
  15. Junio C HamanoJan 29, 2013
  16. Junio C HamanoJan 29, 2013
  17. Jeff KingJan 30, 2013
  18. Junio C HamanoJan 30, 2013
  19. Jeff KingFeb 1, 2013
  20. Junio C HamanoJan 30, 2013
  21. Shawn PearceJan 31, 2013
  22. Jeff KingFeb 1, 2013
  23. Junio C HamanoFeb 2, 2013
  24. Jeff KingJan 30, 2013
  25. Duy NguyenJan 30, 2013
  26. Jeff KingJan 30, 2013
  27. Duy NguyenJan 30, 2013
  28. Duy NguyenJan 30, 2013
  29. Duy NguyenJan 31, 2013
  30. Jeff KingFeb 1, 2013
  31. Duy NguyenFeb 2, 2013
  32. Jeff KingFeb 1, 2013
  33. Duy NguyenMar 17, 2013
  34. Jeff KingMar 18, 2013
  35. Jeff KingFeb 1, 2013
  36. 5/6 add git-metapack commandJeff King, Jan 29, 2013
  37. 6/6 commit: look up commit info in metapackJeff King, Jan 29, 2013
  38. Duy NguyenJan 30, 2013
  39. Jeff KingJan 30, 2013
  40. Duy NguyenJan 30, 2013
  41. Shawn PearceJan 31, 2013
  42. Jeff KingFeb 1, 2013
  43. Shawn PearceFeb 2, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.