{"thread":{"id":"790","subject":"[PATCH] One Git To Rule Them All - Final","startedAt":"2005-06-01T06:00:17Z","lastAt":"2005-06-01T06:00:17Z","messageCount":1,"participants":["Jason McMullan"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4350","messageId":"20050601060017.GA15937@port.evillabs.net","threadId":"790","inReplyTo":null,"subject":"[PATCH] One Git To Rule Them All - Final","fromName":"Jason McMullan","fromEmail":"jason.mcmullan@timesys.com","sentAt":"2005-06-01T06:00:17Z","receivedAt":"2005-06-01T06:00:17Z","isPatch":true,"sender":{"key":"jason.mcmullan@timesys.com","avatar":null},"body":"one-git\n\nOne git to rule them all... \n\nThis patch make a 'git' binary that has all of the git-* commands linked in,\ninstead of a zillion little git-* commands. As an interesting side effect,\ndocumentation for each command is required in Documention/git-<mumble>.txt\nfor compilation to succeed. ;^)\n\nThe install still creates git-<mumble> commands in $HOME/bin, so there should\nbe no compatability issues.\n\nThis patch saves 2.4M on my Athlon 64 system - a 7x size reduction. Whee!\n\nREQURIES one-git pre patches 1 and 2\n\nSigned-off-by: Jason McMullan <jason.mcmullan@timesys.com>\n\ndiff --git a/Makefile b/Makefile\n--- a/Makefile\n+++ b/Makefile\n@@ -24,19 +24,48 @@ SCRIPTS=git-apply-patch-script git-merge\n \tgit-pull-script git-tag-script git-resolve-script git-whatchanged \\\n \tgit-deltafy-script git-fetch-script git-status-script git-commit-script\n \n-PROG=   git-update-cache git-diff-files git-init-db git-write-tree \\\n-\tgit-read-tree git-commit-tree git-cat-file git-fsck-cache \\\n-\tgit-checkout-cache git-diff-tree git-rev-tree git-ls-files \\\n-\tgit-check-files git-ls-tree git-merge-base git-merge-cache \\\n-\tgit-unpack-file git-export git-diff-cache git-convert-cache \\\n-\tgit-http-pull git-rpush git-rpull git-rev-list git-mktag \\\n-\tgit-diff-helper git-tar-tree git-local-pull git-write-blob \\\n-\tgit-get-tar-commit-id git-mkdelta git-apply git-stripspace\n-\n-all: $(PROG)\n-\n-install: $(PROG) $(SCRIPTS)\n-\t$(INSTALL) $(PROG) $(SCRIPTS) $(dest)$(bin)\n+# The following order determines 'git help' command order.\n+# The general idea is 'pull, push, inspect, commit, db, misc'\n+PROG=   \\\n+\tgit-local-pull \\\n+\tgit-http-pull \\\n+\tgit-rpull \\\n+\tgit-rpush \\\n+\tgit-rev-tree \\\n+\tgit-rev-list \\\n+\tgit-export \\\n+\tgit-read-tree \\\n+\tgit-checkout-cache \\\n+\tgit-update-cache \\\n+\tgit-ls-tree \\\n+\tgit-ls-files \\\n+\tgit-cat-file \\\n+\tgit-unpack-file \\\n+\tgit-diff-files \\\n+\tgit-diff-cache \\\n+\tgit-diff-tree \\\n+\tgit-merge-base \\\n+\tgit-merge-cache \\\n+\tgit-apply \\\n+\tgit-check-files \\\n+\tgit-write-tree \\\n+\tgit-commit-tree \\\n+\tgit-mktag \\\n+\tgit-init-db \\\n+\tgit-fsck-cache \\\n+\tgit-convert-cache \\\n+\tgit-mkdelta \\\n+\tgit-tar-tree \\\n+\tgit-get-tar-commit-id \\\n+\tgit-write-blob \\\n+\tgit-diff-helper \\\n+\tgit-stripspace\n+\n+all: git $(PROG)\n+\n+install: git $(PROG) $(SCRIPTS)\n+\t$(INSTALL) git $(SCRIPTS) $(dest)$(bin)\n+\tfor prog in $(PROG); do ln -sf git $(dest)$(bin)/$$prog; done\n \n LIB_OBJS=read-cache.o sha1_file.o usage.o object.o commit.o tree.o blob.o \\\n \t tag.o delta.o date.o index.o diff-delta.o patch-delta.o\n@@ -52,9 +81,16 @@ LIB_OBJS += diff.o diffcore-rename.o dif\n \n LIB_OBJS += gitenv.o\n \n+LIB_OBJS += pull.o\n+\n+LIB_OBJS += rsh.o\n+\n LIBS = $(LIB_FILE)\n LIBS += -lz\n \n+# For git-http-pull\n+LIBS += -lcurl\n+\n ifdef MOZILLA_SHA1\n   SHA1_HEADER=\"mozilla-sha1/sha1.h\"\n   LIB_OBJS += mozilla-sha1/sha1.o\n@@ -79,42 +115,39 @@ test-date: test-date.c date.o\n test-delta: test-delta.c diff-delta.o patch-delta.o\n \t$(CC) $(CFLAGS) -o $@ $^\n \n-git-%: %.c $(LIB_FILE)\n-\t$(CC) $(CFLAGS) -o $@ $(filter %.c,$^) $(LIBS)\n+git-%.o: %.c #Makefile\n+\t$(CC) $(CFLAGS) -c -o $@ $*.c -Dmain=git_$(subst -,_,$*) -Ddesc=git_$(subst -,_,$*)_desc\n+\n+$(PROG):\n+\tln -s git $@\n+\n+git.o: git-commands.h\n \n-git-update-cache: update-cache.c\n-git-diff-files: diff-files.c\n-git-init-db: init-db.c\n-git-write-tree: write-tree.c\n-git-read-tree: read-tree.c\n-git-commit-tree: commit-tree.c\n-git-cat-file: cat-file.c\n-git-fsck-cache: fsck-cache.c\n-git-checkout-cache: checkout-cache.c\n-git-diff-tree: diff-tree.c\n-git-rev-tree: rev-tree.c\n-git-ls-files: ls-files.c\n-git-check-files: check-files.c\n-git-ls-tree: ls-tree.c\n-git-merge-base: merge-base.c\n-git-merge-cache: merge-cache.c\n-git-unpack-file: unpack-file.c\n-git-export: export.c\n-git-diff-cache: diff-cache.c\n-git-convert-cache: convert-cache.c\n-git-http-pull: http-pull.c pull.c\n-git-local-pull: local-pull.c pull.c\n-git-rpush: rsh.c\n-git-rpull: rsh.c pull.c\n-git-rev-list: rev-list.c\n-git-mktag: mktag.c\n-git-diff-helper: diff-helper.c\n-git-tar-tree: tar-tree.c\n-git-write-blob: write-blob.c\n-git-mkdelta: mkdelta.c\n-git-stripspace: stripspace.c\n+git: git.o $(patsubst %,%.o,$(PROG)) $(LIBS)\n+\t$(CC) $(CFLAGS) -o $@ $^ $(LIBS)\n+\n+git-commands.h: Makefile $(patsubst %,Documentation/%.txt,$(PROG))\n+\techo -n >git-commands.h\n+\tfor prog in $(subst -,_,$(PROG)); do \\\n+\t\techo \"extern int $${prog}(int argc, char **argv);\" >>git-commands.h ; \\\n+\t\techo \"extern const char *$${prog}_desc;\" >>git-commands.h ; \\\n+\tdone\n+\techo \"struct git_command { \">>git-commands.h\n+\techo \"\tconst char *command;\" >>git-commands.h\n+\techo \"\tint (*main)(int argc,char **argv);\" >>git-commands.h\n+\techo \"\tconst char *desc; } commands[]={\" >>git-commands.h\n+\tfor cmd in $(patsubst git-%,%,$(PROG)); do \\\n+\t\tprog=`echo $$cmd | sed -e 's/-/_/g'` ; \\\n+\t\tdesc=`grep \"^git-$$cmd - \" Documentation/git-$$cmd.txt | cut -d' ' -f3-` ; \\\n+\t\tdesc=`echo \"$$desc\" | sed -e 's/\"/\\\\\\\\\"/g'` ; \\\n+\t\techo -n \"\t{ \" >>git-commands.h ; \\\n+\t\techo -n \".command = \\\"$${cmd}\\\", \" >>git-commands.h ; \\\n+\t\techo -n \".main = git_$${prog}, \" >>git-commands.h ; \\\n+\t        echo -n \".desc = \\\"$$desc\\\", \" >>git-commands.h ; \\\n+\t\techo \"},\" >>git-commands.h ; \\\n+\tdone\n+\techo \"};\" >>git-commands.h\n \n-git-http-pull: LIBS += -lcurl\n \n # Library objects..\n blob.o: $(LIB_H)\n@@ -138,7 +171,7 @@ test: all\n \t$(MAKE) -C t/ all\n \n clean:\n-\trm -f *.o mozilla-sha1/*.o ppc/*.o $(PROG) $(LIB_FILE)\n+\trm -f *.o mozilla-sha1/*.o ppc/*.o git $(PROG) $(LIB_FILE)\n \t$(MAKE) -C Documentation/ clean\n \n backup: clean\ndiff --git a/git.c b/git.c\nnew file mode 100644\n--- /dev/null\n+++ b/git.c\n@@ -0,0 +1,57 @@\n+#include <stdio.h>\n+#include <string.h>\n+#include <stdlib.h>\n+\n+#include \"git-commands.h\"\n+\n+#define COMMAND_LEN\t(sizeof(commands)/sizeof(commands[0]))\n+\n+typedef int (*func)(int argc, char **argv);\n+\n+func lookup_basename(const char *program)\n+{\n+\tconst char *cp;\n+\tint i;\n+\n+\tcp=strrchr(program,'/');\n+\tif (cp==NULL)\n+\t\tcp=program;\n+\telse\n+\t\tcp++;\n+\n+\tif (strncmp(cp,\"git-\",4)==0)\n+\t\tcp+=4;\n+\n+\tfor (i = 0; i < COMMAND_LEN; i++)\n+\t\tif (!strcmp(cp,commands[i].command))\n+\t\t\treturn commands[i].main;\n+\n+\treturn NULL;\n+}\n+\n+int main(int argc, char **argv)\n+{\n+\tint (*do_main)(int argc, char **argv);\n+\tint i;\n+\n+\tdo_main = lookup_basename(argv[0]);\n+\n+\tif (!do_main && argc > 1 ) {\n+\t\tdo_main = lookup_basename(argv[1]);\n+\t\tif (do_main) {\n+\t\t\targc--;\n+\t\t\targv++;\n+\t\t}\n+\t}\n+\n+\tif (do_main) {\n+\t\treturn do_main(argc, argv);\n+\t}\n+\n+\tfprintf(stderr,\"GIT Commands:\\n\\n\");\n+\tfor (i = 0; i < COMMAND_LEN; i++)\n+\t\tfprintf(stderr,\"\\t%-24s%s\\n\",commands[i].command,commands[i].desc);\n+\tfprintf(stderr,\"\\n\");\n+\n+\treturn 1;\n+}\n"}]}