Built-in git-get-tar-commit-id
authorRene Scharfe <rene.scharfe@lsrfire.ath.cx>
Sat, 10 Jun 2006 14:13:41 +0000 (16:13 +0200)
committerJunio C Hamano <junkio@cox.net>
Sat, 10 Jun 2006 18:14:00 +0000 (11:14 -0700)
By being an internal command git-get-commit-id can make use of
struct ustar_header and other stuff and stops wasting precious
disk space.

Note: I recycled one of the two "tar-tree" entries instead of
splitting that cleanup into a separate patch.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Makefile
builtin-tar-tree.c
builtin.h
get-tar-commit-id.c [deleted file]
git.c

index 5226fa1881bf5c2df4f1a11c2daaf6b5a2fec2a5..2a1e6392dddeac520b90e5bccfb841f58018f858 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -144,7 +144,7 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
 
 # The ones that do not have to link with lcrypto, lz nor xdiff.
 SIMPLE_PROGRAMS = \
-       git-get-tar-commit-id$X git-mailsplit$X \
+       git-mailsplit$X \
        git-stripspace$X git-daemon$X
 
 # ... and all the rest that could be moved out of bindir to gitexecdir
@@ -169,7 +169,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \
        git-grep$X git-add$X git-rm$X git-rev-list$X \
        git-check-ref-format$X git-rev-parse$X \
        git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
-       git-ls-files$X git-ls-tree$X \
+       git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
        git-read-tree$X git-commit-tree$X \
        git-apply$X git-show-branch$X git-diff-files$X \
        git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
index 7663b9bd8e5f10ee45e34752f631d435687cf1b3..58a8ccd4d6af0d755fca28b06a12ca9b8efa5300 100644 (file)
@@ -402,3 +402,28 @@ int cmd_tar_tree(int argc, const char **argv, char **envp)
                return remote_tar(argc, argv);
        return generate_tar(argc, argv, envp);
 }
+
+/* ustar header + extended global header content */
+#define HEADERSIZE (2 * RECORDSIZE)
+
+int cmd_get_tar_commit_id(int argc, const char **argv, char **envp)
+{
+       char buffer[HEADERSIZE];
+       struct ustar_header *header = (struct ustar_header *)buffer;
+       char *content = buffer + RECORDSIZE;
+       ssize_t n;
+
+       n = xread(0, buffer, HEADERSIZE);
+       if (n < HEADERSIZE)
+               die("git-get-tar-commit-id: read error");
+       if (header->typeflag[0] != 'g')
+               return 1;
+       if (memcmp(content, "52 comment=", 11))
+               return 1;
+
+       n = xwrite(1, content + 11, 41);
+       if (n < 41)
+               die("git-get-tar-commit-id: write error");
+
+       return 0;
+}
index ffa9340c37702e2fdc9e1484290ee0751b8e5922..b9f36beb66042f00653508b5edeec53b336516aa 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -32,6 +32,7 @@ extern int cmd_check_ref_format(int argc, const char **argv, char **envp);
 extern int cmd_init_db(int argc, const char **argv, char **envp);
 extern int cmd_tar_tree(int argc, const char **argv, char **envp);
 extern int cmd_upload_tar(int argc, const char **argv, char **envp);
+extern int cmd_get_tar_commit_id(int argc, const char **argv, char **envp);
 extern int cmd_ls_files(int argc, const char **argv, char **envp);
 extern int cmd_ls_tree(int argc, const char **argv, char **envp);
 extern int cmd_read_tree(int argc, const char **argv, char **envp);
diff --git a/get-tar-commit-id.c b/get-tar-commit-id.c
deleted file mode 100644 (file)
index 4166290..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2005 Rene Scharfe
- */
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#define HEADERSIZE     1024
-
-int main(int argc, char **argv)
-{
-       char buffer[HEADERSIZE];
-       ssize_t n;
-
-       n = read(0, buffer, HEADERSIZE);
-       if (n < HEADERSIZE) {
-               fprintf(stderr, "read error\n");
-               return 3;
-       }
-       if (buffer[156] != 'g')
-               return 1;
-       if (memcmp(&buffer[512], "52 comment=", 11))
-               return 1;
-       n = write(1, &buffer[523], 41);
-       if (n < 41) {
-               fprintf(stderr, "write error\n");
-               return 2;
-       }
-       return 0;
-}
diff --git a/git.c b/git.c
index 6db8f2bc23abb328d8d0bed83a581a1cda10e9a4..9469d44b4bcb459f61839103a8650cb6965f88a9 100644 (file)
--- a/git.c
+++ b/git.c
@@ -163,7 +163,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "add", cmd_add },
                { "rev-list", cmd_rev_list },
                { "init-db", cmd_init_db },
-               { "tar-tree", cmd_tar_tree },
+               { "get-tar-commit-id", cmd_get_tar_commit_id },
                { "upload-tar", cmd_upload_tar },
                { "check-ref-format", cmd_check_ref_format },
                { "ls-files", cmd_ls_files },