{"thread":{"id":"799","subject":"[PATCH] One-Git Part 2 (Patch 3/3)","startedAt":"2005-06-01T18:23:08Z","lastAt":"2005-06-01T18:23:08Z","messageCount":1,"participants":["Jason McMullan"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4379","messageId":"20050601182308.GA2704@jmcmullan.timesys","threadId":"799","inReplyTo":null,"subject":"[PATCH] One-Git Part 2 (Patch 3/3)","fromName":"Jason McMullan","fromEmail":"jason.mcmullan@timesys.com","sentAt":"2005-06-01T18:23:08Z","receivedAt":"2005-06-01T18:23:08Z","isPatch":true,"sender":{"key":"jason.mcmullan@timesys.com","avatar":null},"body":"Add: 'compiled in' scripts, using zlib\n\none-git now includes everything!\n\nRequires: one-git Part 1 (all patches), and one-git Part 2 (pre 1, pre 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@@ -20,18 +20,16 @@ CC=gcc\n AR=ar\n INSTALL=install\n \n-SCRIPTS=git git-apply-patch-script git-merge-one-file-script git-prune-script \\\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-\tgit-log-script\n-\n # The following order determines 'git help' command order.\n # The general idea is 'pull, push, inspect, commit, db, misc'\n PROG=   \\\n+\tgit-pull \\\n \tgit-local-pull \\\n \tgit-http-pull \\\n \tgit-rpull \\\n \tgit-rpush \\\n+\tgit-whatchanged \\\n+\tgit-log \\\n \tgit-rev-tree \\\n \tgit-rev-list \\\n \tgit-export \\\n@@ -45,20 +43,29 @@ PROG=   \\\n \tgit-diff-files \\\n \tgit-diff-cache \\\n \tgit-diff-tree \\\n+\tgit-status \\\n \tgit-merge-base \\\n \tgit-merge-cache \\\n+\tgit-merge-one-file \\\n+\tgit-resolve \\\n \tgit-apply \\\n+\tgit-apply-patch \\\n \tgit-check-files \\\n \tgit-write-tree \\\n \tgit-commit-tree \\\n+\tgit-commit \\\n \tgit-mktag \\\n+\tgit-tag \\\n \tgit-init-db \\\n \tgit-fsck-cache \\\n+\tgit-prune \\\n \tgit-convert-cache \\\n \tgit-mkdelta \\\n+\tgit-deltafy \\\n \tgit-tar-tree \\\n \tgit-get-tar-commit-id \\\n \tgit-write-blob \\\n+\tgit-fetch \\\n \tgit-diff-helper \\\n \tgit-stripspace\n \n@@ -86,6 +93,8 @@ LIB_OBJS += pull.o\n \n LIB_OBJS += rsh.o\n \n+LIB_OBJS += zscript.o\n+\n LIBS = $(LIB_FILE)\n LIBS += -lz\n \n@@ -116,8 +125,14 @@ 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-%.o: %.c #Makefile\n-\t$(CC) $(CFLAGS) -c -o $@ $*.c -Dmain=git_$(subst -,_,$*) -Ddesc=git_$(subst -,_,$*)_desc\n+git-%-script.h: git-%-script\n+\t./zwrap script <git-$*-script >git-$*-script.h\n+\n+git-%.o: zwrap git-%-script git-%-script.h git-script.c\n+\t$(CC) $(CFLAGS) -c -o $@ git-script.c -Dscript=git_$(subst -,_,$*)_script -Dmain=git_$(subst -,_,$*) --include git-$*-script.h\n+\n+git-%.o: %.c Makefile\n+\t$(CC) $(CFLAGS) -c -o $@ $*.c -Dmain=git_$(subst -,_,$*)\n \n $(PROG):\n \tln -s git $@\n@@ -127,7 +142,10 @@ git.o: git-commands.h\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+zwrap: zwrap.o $(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@@ -139,7 +157,14 @@ git-commands.h: Makefile $(patsubst %,Do\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\tif [ -f Documentation/git-$${cmd}-script.txt ]; then \\\n+\t\t  doc=Documentation/git-$${cmd}-script.txt; \\\n+\t\telse doc=Documentation/git-$${cmd}.txt; fi; \\\n+\t\tif [ ! -e $${doc} ]; then \\\n+\t\t\techo \"MISSING: $$doc\" 1>&2; \\\n+\t\t\trm -f git-commands.h; \\\n+\t\t\texit 1; fi; \\\n+\t\tdesc=`grep \"^git-$$cmd - \" $$doc | 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@@ -172,7 +197,8 @@ test: all\n \t$(MAKE) -C t/ all\n \n clean:\n-\trm -f *.o mozilla-sha1/*.o ppc/*.o git $(PROG) $(LIB_FILE)\n+\trm -f *.o mozilla-sha1/*.o ppc/*.o \\\n+\t\tzwrap git $(PROG) $(LIB_FILE) git-*-script.h\n \t$(MAKE) -C Documentation/ clean\n \n backup: clean\ndiff --git a/git b/git\ndeleted file mode 100755\n--- a/git\n+++ /dev/null\n@@ -1,4 +0,0 @@\n-#!/bin/sh\n-cmd=\"git-$1-script\"\n-shift\n-exec $cmd \"$@\"\ndiff --git a/git-script.c b/git-script.c\nnew file mode 100644\n--- /dev/null\n+++ b/git-script.c\n@@ -0,0 +1,8 @@\n+#include <stdio.h>\n+\n+extern int zscript(const void *s, size_t s_len, int argc, char **argv);\n+\n+int main(int argc, char **argv)\n+{\n+\treturn zscript(script,sizeof(script),argc,argv);\n+}\ndiff --git a/zscript.c b/zscript.c\nnew file mode 100644\n--- /dev/null\n+++ b/zscript.c\n@@ -0,0 +1,62 @@\n+#include <stdio.h>\n+#include <sys/wait.h>\n+#include <sys/types.h>\n+\n+#include <zlib.h>\n+\n+#include \"cache.h\"\n+\n+int zscript(void *script, size_t script_len, int argc, char **argv)\n+{\n+\tz_stream stream;\n+\tchar buff[8192];\n+\tint fd, ret, status;\n+\tpid_t pid;\n+\tchar template[]=\"/tmp/git-script.XXXXXX\";\n+\n+\tfd = mkstemp(template);\n+\tif (fd < 0)\n+\t\tdie(\"Can't create file %s\\n\",template);\n+\n+\tmemset(&stream, 0, sizeof(stream));\n+\tstream.next_in = script;\n+\tstream.avail_in = script_len;\n+\n+\tinflateInit(&stream);\n+\tdo {\n+\t\tstream.next_out = buff;\n+\t\tstream.avail_out = sizeof(buff);\n+\t\tret = inflate(&stream, Z_SYNC_FLUSH);\n+\t\twrite(fd,buff,sizeof(buff)-stream.avail_out);\n+\t} while (stream.avail_in && ret == Z_OK);\n+\tinflateEnd(&stream);\n+\n+\tpid = fork();\n+\tif (pid < 0) {\n+\t\tunlink(template);\n+\t\tdie(\"Can't fork.\");\n+\t}\n+\n+\tif (! pid) {\t/* Child */\n+\t\tchar **args;\n+\t\targs=xmalloc(sizeof(char *)*(argc+1));\n+\t\tmemcpy(&args[2],&argv[1],sizeof(char *)*(argc-1));\n+\t\targv[0]=\"/bin/sh\";\n+\t\targv[1]=template;\n+\t\texecv(\"/bin/sh\",argv);\n+\t\texit(1);\t/* Hopefully unreachable */\n+\t}\n+\n+\tif (waitpid(pid, &status, 0) < 0 ||\n+\t\t!WIFEXITED(status) || WEXITSTATUS(status))\n+\t\tgoto error;\n+\n+\tunlink(template);\n+\treturn 0;\n+\n+\n+error:\n+\tunlink(template);\n+\treturn 1;\n+}\n+\t\t\ndiff --git a/zwrap.c b/zwrap.c\nnew file mode 100644\n--- /dev/null\n+++ b/zwrap.c\n@@ -0,0 +1,88 @@\n+/* Takes stdin, and makes a C header file out of it, compressed\n+ * with zlib.\n+ *\n+ * Author: Jason McMullan <jason.mcmullan@timesys.com>\n+ */\n+\n+#include <stdio.h>\n+#include <zlib.h>\n+\n+#include \"cache.h\"\n+\n+unsigned char *read_from(int fd, size_t *bsize)\n+{\n+\tunsigned char *buff;\n+\tint len;\n+\tsize_t size;\n+\n+\tbuff=xmalloc(1024);\n+\tsize = 0;\n+\n+\twhile ((len = read(fd, buff, 1024-(size % 1024))) > 0) {\n+\t\tsize += len;\n+\t\tif ((size % 1024)==0)\n+\t\t\tbuff = xrealloc(buff, size+1024);\n+\t}\n+\n+\tif (len < 0) {\n+\t\tsize=0;\n+\t\tfree(buff);\n+\t\tbuff=NULL;\n+\t}\n+\n+\t*bsize = size;\n+\treturn buff;\n+}\n+\n+\n+int main(int argc, char **argv)\n+{\n+\tconst char *name=\"data\";\n+\tz_stream stream;\n+\tsize_t size, dsize;\n+\tunsigned char *dbuff,*buff;\n+\n+\tif (argc == 2)\n+\t\tname=argv[1];\n+\telse if (argc != 1) {\n+\t\tfprintf(stderr,\"Usage:\\n%s [name] <somefile\\n\",argv[0]);\n+\t\treturn 1;\n+\t}\n+\n+\tbuff=read_from(0, &size);\n+\tif (buff == NULL)\n+\t\treturn 1;\n+\n+\t/* Init zlib */\n+\tmemset(&stream, 0, sizeof(stream));\n+\tdeflateInit(&stream, Z_BEST_COMPRESSION);\n+\tdsize = deflateBound(&stream, size);\n+\tdbuff = xmalloc(dsize);\n+\n+\tstream.next_out = dbuff;\n+\tstream.avail_out = dsize;\n+\n+\twhile (deflate(&stream, 0) == Z_OK)\n+\t\t/* nothing */;\n+\n+\tstream.next_in  = buff;\n+\tstream.avail_in  = size;\n+\twhile (deflate(&stream, Z_FINISH) == Z_OK)\n+\t\t/* nothing */;\n+\tdeflateEnd(&stream);\n+\n+\tdsize = stream.total_out;\n+\n+\tprintf(\"const unsigned char %s[] = {\\n\", name);\n+\tfor ( size = 0; size < dsize; size++) {\n+\t\tif ((size % 8) == 0)\n+\t\t\tprintf(\"\\t\");\n+\t\tprintf(\"0x%.2x,\",dbuff[size]);\n+\t\tif ((size % 8) == 7)\n+\t\t\tprintf(\"\\n\");\n+\t}\n+\tprintf(\"};\\n\");\n+\n+\treturn 0;\n+}\n+\n======== end ========\n\n"}]}