{"thread":{"id":"7239","subject":"[PATCH] Make gc a builtin.","startedAt":"2007-03-13T23:03:47Z","lastAt":"2007-03-14T01:37:54Z","messageCount":3,"participants":["James Bowes","Johannes Schindelin","Brian Gernhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"37033","messageId":"11738270273757-git-send-email-jbowes@dangerouslyinc.com","threadId":"7239","inReplyTo":null,"subject":"[PATCH] Make gc a builtin.","fromName":"James Bowes","fromEmail":"jbowes@dangerouslyinc.com","sentAt":"2007-03-13T23:03:47Z","receivedAt":"2007-03-13T23:03:47Z","isPatch":true,"sender":{"key":"jbowes@dangerouslyinc.com","avatar":"https://gravatar.com/avatar/a2fe98c66b2b47a9fa9d2ba92ff949d54c3208b1f8acc2e745b4b84ae3c4483a?d=mp&s=160"},"body":"Signed-off-by: James Bowes <jbowes@dangerouslyinc.com>\n---\n\nTake 3. The changes are pretty much all of Shawn's suggestions. If a command\nfails this code just returns -1, rather than calling error(), so that two\nduplicate error messages aren't printed out.\n\n-James\n\n Makefile     |    3 +-\n builtin-gc.c |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n builtin.h    |    1 +\n git-gc.sh    |   37 ----------------------------\n git.c        |    1 +\n 5 files changed, 80 insertions(+), 38 deletions(-)\n create mode 100644 builtin-gc.c\n delete mode 100755 git-gc.sh\n\ndiff --git a/Makefile b/Makefile\nindex f0fc2f8..fb17cfb 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -177,7 +177,7 @@ BASIC_LDFLAGS =\n SCRIPT_SH = \\\n \tgit-bisect.sh git-checkout.sh \\\n \tgit-clean.sh git-clone.sh git-commit.sh \\\n-\tgit-fetch.sh git-gc.sh \\\n+\tgit-fetch.sh \\\n \tgit-ls-remote.sh \\\n \tgit-merge-one-file.sh git-parse-remote.sh \\\n \tgit-pull.sh git-rebase.sh \\\n@@ -297,6 +297,7 @@ BUILTIN_OBJS = \\\n \tbuiltin-fmt-merge-msg.o \\\n \tbuiltin-for-each-ref.o \\\n \tbuiltin-fsck.o \\\n+\tbuiltin-gc.o \\\n \tbuiltin-grep.o \\\n \tbuiltin-init-db.o \\\n \tbuiltin-log.o \\\ndiff --git a/builtin-gc.c b/builtin-gc.c\nnew file mode 100644\nindex 0000000..d86f07c\n--- /dev/null\n+++ b/builtin-gc.c\n@@ -0,0 +1,76 @@\n+/*\n+ * git gc builtin command\n+ *\n+ * Cleanup unreachable files and optimize the repository.\n+ *\n+ * Copyright (c) 2007 James Bowes\n+ *\n+ * Based on git-gc.sh, which is\n+ *\n+ * Copyright (c) 2006 Shawn O. Pearce\n+ */\n+\n+#include \"cache.h\"\n+#include \"run-command.h\"\n+\n+static const char builtin_gc_usage[] = \"git-gc [--prune]\";\n+\n+static int pack_refs = -1;\n+\n+static const char *argv_pack_refs[] = {\"pack-refs\", \"--prune\", NULL};\n+static const char *argv_reflog[] = {\"reflog\", \"expire\", \"--all\", NULL};\n+static const char *argv_repack[] = {\"repack\", \"-a\", \"-d\", \"-l\", NULL};\n+static const char *argv_prune[] = {\"prune\", NULL};\n+static const char *argv_rerere[] = {\"rerere\", \"gc\", NULL};\n+\n+static int gc_config(const char *var, const char *value)\n+{\n+\tif (!strcmp(var, \"gc.packrefs\")) {\n+\t\tif (!strcmp(value, \"notbare\"))\n+\t\t\tpack_refs = -1;\n+\t\telse\n+\t\t\tpack_refs = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n+\treturn git_default_config(var, value);\n+}\n+\n+int cmd_gc(int argc, const char **argv, const char *prefix)\n+{\n+\tint i;\n+\tint prune = 0;\n+\n+\tgit_config(gc_config);\n+\n+\tif (pack_refs < 0)\n+\t\tpack_refs = !is_bare_repository();\n+\n+\tfor (i = 1; i < argc; i++) {\n+\t\tconst char *arg = argv[i];\n+\t\tif (!strcmp(arg, \"--prune\")) {\n+\t\t\tprune = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\t/* perhaps other parameters later... */\n+\t\tbreak;\n+\t}\n+\tif (i != argc)\n+\t\tusage(builtin_gc_usage);\n+\n+\tif (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))\n+\t\treturn -1;\n+\n+\tif (run_command_v_opt(argv_reflog, RUN_GIT_CMD))\n+\t\treturn -1;\n+\n+\tif (run_command_v_opt(argv_repack, RUN_GIT_CMD))\n+\t\treturn -1;\n+\n+\tif (prune && run_command_v_opt(argv_prune, RUN_GIT_CMD))\n+\t\treturn -1;\n+\n+\tif (run_command_v_opt(argv_rerere, RUN_GIT_CMD))\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\ndiff --git a/builtin.h b/builtin.h\nindex 1cb64b7..af203e9 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -37,6 +37,7 @@ extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);\n extern int cmd_for_each_ref(int argc, const char **argv, const char *prefix);\n extern int cmd_format_patch(int argc, const char **argv, const char *prefix);\n extern int cmd_fsck(int argc, const char **argv, const char *prefix);\n+extern int cmd_gc(int argc, const char **argv, const char *prefix);\n extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);\n extern int cmd_grep(int argc, const char **argv, const char *prefix);\n extern int cmd_help(int argc, const char **argv, const char *prefix);\ndiff --git a/git-gc.sh b/git-gc.sh\ndeleted file mode 100755\nindex 436d7ca..0000000\n--- a/git-gc.sh\n+++ /dev/null\n@@ -1,37 +0,0 @@\n-#!/bin/sh\n-#\n-# Copyright (c) 2006, Shawn O. Pearce\n-#\n-# Cleanup unreachable files and optimize the repository.\n-\n-USAGE='[--prune]'\n-SUBDIRECTORY_OK=Yes\n-. git-sh-setup\n-\n-no_prune=:\n-while case $# in 0) break ;; esac\n-do\n-\tcase \"$1\" in\n-\t--prune)\n-\t\tno_prune=\n-\t\t;;\n-\t--)\n-\t\tusage\n-\t\t;;\n-\tesac\n-\tshift\n-done\n-\n-case \"$(git config --get gc.packrefs)\" in\n-notbare|\"\")\n-\ttest $(is_bare_repository) = true || pack_refs=true;;\n-*)\n-\tpack_refs=$(git config --bool --get gc.packrefs)\n-esac\n-\n-test \"true\" != \"$pack_refs\" ||\n-git-pack-refs --prune &&\n-git-reflog expire --all &&\n-git-repack -a -d -l &&\n-$no_prune git-prune &&\n-git-rerere gc || exit\ndiff --git a/git.c b/git.c\nindex dde4d07..ed1c65e 100644\n--- a/git.c\n+++ b/git.c\n@@ -249,6 +249,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)\n \t\t{ \"format-patch\", cmd_format_patch, RUN_SETUP },\n \t\t{ \"fsck\", cmd_fsck, RUN_SETUP },\n \t\t{ \"fsck-objects\", cmd_fsck, RUN_SETUP },\n+\t\t{ \"gc\", cmd_gc, RUN_SETUP },\n \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n \t\t{ \"grep\", cmd_grep, RUN_SETUP | USE_PAGER },\n \t\t{ \"help\", cmd_help },\n-- \n1.5.0.2\n"},{"id":"37039","messageId":"Pine.LNX.4.63.0703140203250.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7239","inReplyTo":"11738270273757-git-send-email-jbowes@dangerouslyinc.com","subject":"Re: [PATCH] Make gc a builtin.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-03-14T01:05:11Z","receivedAt":"2007-03-14T01:05:11Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 13 Mar 2007, James Bowes wrote:\n\n> Take 3. The changes are pretty much all of Shawn's suggestions. If a \n> command fails this code just returns -1, rather than calling error(), so \n> that two duplicate error messages aren't printed out.\n\nIf you say \"return error(...);\", there is _no_ way that multiple error \nmessages are printed out.\n\nIf you say \"return -1;\", however, the user is likely to _never_ know that \ngit-gc failed. (I, for one, do not check $? after running a program which \ndoes not say _anything_.)\n\nCiao,\nDscho\n"},{"id":"37048","messageId":"7F86A2D8-0407-4663-A97F-7D003F370E0F@silverinsanity.com","threadId":"7239","inReplyTo":"Pine.LNX.4.63.0703140203250.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Make gc a builtin.","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2007-03-14T01:37:54Z","receivedAt":"2007-03-14T01:37:54Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Mar 13, 2007, at 9:05 PM, Johannes Schindelin wrote:\n\n> If you say \"return error(...);\", there is _no_ way that multiple error\n> messages are printed out.\n\nExcept that cmd_gc() is littered with run_command* calls, which fork  \noff a subprocess to do the heavy lifting.  So if git-repack fails an  \nerror will be printed by that process, making the error() call  \nredundant.  (If I'm understanding things correctly.)\n\n~~ Brian\n"}]}