From 217542640ed219c980fff2b3c307c4520120f20f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 18 May 2006 18:46:44 -0700 Subject: [PATCH 1/9] built-in tar-tree and remote tar-tree This makes tar-tree a built-in. As an added bonus, you can now say: git tar-tree --remote=remote-repository [] This does not work with git-daemon yet, but should work with localhost and git over ssh transports. Signed-off-by: Junio C Hamano --- Makefile | 6 +-- tar-tree.c => builtin-tar-tree.c | 62 +++++++++++++++++++++++++- builtin-upload-tar.c | 74 ++++++++++++++++++++++++++++++++ builtin.h | 2 + git.c | 4 +- 5 files changed, 142 insertions(+), 6 deletions(-) rename tar-tree.c => builtin-tar-tree.c (85%) create mode 100644 builtin-upload-tar.c diff --git a/Makefile b/Makefile index 4fd6520b7e..f4bcec496a 100644 --- a/Makefile +++ b/Makefile @@ -161,7 +161,7 @@ PROGRAMS = \ git-receive-pack$X git-rev-parse$X \ git-send-pack$X git-show-branch$X git-shell$X \ git-show-index$X git-ssh-fetch$X \ - git-ssh-upload$X git-tar-tree$X git-unpack-file$X \ + git-ssh-upload$X git-unpack-file$X \ git-unpack-objects$X git-update-index$X git-update-server-info$X \ git-upload-pack$X git-verify-pack$X git-write-tree$X \ git-update-ref$X git-symbolic-ref$X \ @@ -171,7 +171,7 @@ PROGRAMS = \ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-count-objects$X git-diff$X git-push$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ - git-init-db$X + git-init-db$X git-tar-tree$X git-upload-tar$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -220,7 +220,7 @@ LIB_OBJS = \ BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ - builtin-init-db.o + builtin-init-db.o builtin-tar-tree.o builtin-upload-tar.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/tar-tree.c b/builtin-tar-tree.c similarity index 85% rename from tar-tree.c rename to builtin-tar-tree.c index 33087366c3..e97e0af985 100644 --- a/tar-tree.c +++ b/builtin-tar-tree.c @@ -7,11 +7,14 @@ #include "commit.h" #include "strbuf.h" #include "tar.h" +#include "builtin.h" +#include "pkt-line.h" #define RECORDSIZE (512) #define BLOCKSIZE (RECORDSIZE * 20) -static const char tar_tree_usage[] = "git-tar-tree [basedir]"; +static const char tar_tree_usage[] = +"git-tar-tree [--remote=] [basedir]"; static char block[BLOCKSIZE]; static unsigned long offset; @@ -301,7 +304,7 @@ static void traverse_tree(struct tree_desc *tree, struct strbuf *path) } } -int main(int argc, char **argv) +int generate_tar(int argc, const char **argv) { unsigned char sha1[20], tree_sha1[20]; struct commit *commit; @@ -348,3 +351,58 @@ int main(int argc, char **argv) free(current_path.buf); return 0; } + +static const char *exec = "git-upload-tar"; + +static int remote_tar(int argc, const char **argv) +{ + int fd[2], ret, len; + pid_t pid; + char buf[1024]; + char *url; + + if (argc < 3 || 4 < argc) + usage(tar_tree_usage); + + /* --remote= */ + url = strdup(argv[1]+9); + pid = git_connect(fd, url, exec); + if (pid < 0) + return 1; + + packet_write(fd[1], "want %s\n", argv[2]); + if (argv[3]) + packet_write(fd[1], "base %s\n", argv[3]); + packet_flush(fd[1]); + + len = packet_read_line(fd[0], buf, sizeof(buf)); + if (!len) + die("git-tar-tree: expected ACK/NAK, got EOF"); + if (buf[len-1] == '\n') + buf[--len] = 0; + if (strcmp(buf, "ACK")) { + if (5 < len && !strncmp(buf, "NACK ", 5)) + die("git-tar-tree: NACK %s", buf + 5); + die("git-tar-tree: protocol error"); + } + /* expect a flush */ + len = packet_read_line(fd[0], buf, sizeof(buf)); + if (len) + die("git-tar-tree: expected a flush"); + + /* Now, start reading from fd[0] and spit it out to stdout */ + ret = copy_fd(fd[0], 1); + close(fd[0]); + + ret |= finish_connect(pid); + return !!ret; +} + +int cmd_tar_tree(int argc, const char **argv, char **envp) +{ + if (argc < 2) + usage(tar_tree_usage); + if (!strncmp("--remote=", argv[1], 9)) + return remote_tar(argc, argv); + return generate_tar(argc, argv); +} diff --git a/builtin-upload-tar.c b/builtin-upload-tar.c new file mode 100644 index 0000000000..d4fa7b56c3 --- /dev/null +++ b/builtin-upload-tar.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2006 Junio C Hamano + */ +#include "cache.h" +#include "pkt-line.h" +#include "exec_cmd.h" +#include "builtin.h" + +static const char upload_tar_usage[] = "git-upload-tar "; + +static int nak(const char *reason) +{ + packet_write(1, "NACK %s\n", reason); + packet_flush(1); + return 1; +} + +int cmd_upload_tar(int argc, const char **argv, char **envp) +{ + int len; + const char *dir = argv[1]; + char buf[8192]; + unsigned char sha1[20]; + char *base = NULL; + char hex[41]; + int ac; + const char *av[4]; + + if (argc != 2) + usage(upload_tar_usage); + if (strlen(dir) < sizeof(buf)-1) + strcpy(buf, dir); /* enter-repo smudges its argument */ + else + packet_write(1, "NACK insanely long repository name %s\n", dir); + if (!enter_repo(buf, 0)) { + packet_write(1, "NACK not a git archive %s\n", dir); + packet_flush(1); + return 1; + } + + len = packet_read_line(0, buf, sizeof(buf)); + if (len < 5 || strncmp("want ", buf, 5)) + return nak("expected want"); + if (buf[len-1] == '\n') + buf[--len] = 0; + if (get_sha1(buf + 5, sha1)) + return nak("expected sha1"); + strcpy(hex, sha1_to_hex(sha1)); + + len = packet_read_line(0, buf, sizeof(buf)); + if (len) { + if (len < 5 || strncmp("base ", buf, 5)) + return nak("expected (optional) base"); + if (buf[len-1] == '\n') + buf[--len] = 0; + base = strdup(buf + 5); + len = packet_read_line(0, buf, sizeof(buf)); + } + if (len) + return nak("expected flush"); + + packet_write(1, "ACK\n"); + packet_flush(1); + + ac = 0; + av[ac++] = "tar-tree"; + av[ac++] = hex; + if (base) + av[ac++] = base; + av[ac++] = NULL; + execv_git_cmd(av); + /* should it return that is an error */ + return 1; +} diff --git a/builtin.h b/builtin.h index 60541262c4..f22783c499 100644 --- a/builtin.h +++ b/builtin.h @@ -27,5 +27,7 @@ extern int cmd_grep(int argc, const char **argv, char **envp); extern int cmd_rev_list(int argc, const char **argv, char **envp); 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); #endif diff --git a/git.c b/git.c index 3216d311b2..fd8e9bf7f2 100644 --- a/git.c +++ b/git.c @@ -50,8 +50,10 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "count-objects", cmd_count_objects }, { "diff", cmd_diff }, { "grep", cmd_grep }, - { "rev-list", cmd_rev_list }, { "init-db", cmd_init_db }, + { "tar-tree", cmd_tar_tree }, + { "upload-tar", cmd_upload_tar }, + { "rev-list", cmd_rev_list }, { "check-ref-format", cmd_check_ref_format } }; int i; From 0864f26421b3c599b462bc867de948d14b268d76 Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 23 May 2006 14:15:29 +0200 Subject: [PATCH 2/9] Builtin git-ls-files. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- Makefile | 6 +++--- ls-files.c => builtin-ls-files.c | 3 ++- builtin.h | 1 + git.c | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) rename ls-files.c => builtin-ls-files.c (99%) diff --git a/Makefile b/Makefile index 5423b7a79b..c540d7d9f1 100644 --- a/Makefile +++ b/Makefile @@ -155,7 +155,7 @@ PROGRAMS = \ git-diff-index$X git-diff-stages$X \ git-diff-tree$X git-fetch-pack$X git-fsck-objects$X \ git-hash-object$X git-index-pack$X git-local-fetch$X \ - git-ls-files$X git-ls-tree$X git-mailinfo$X git-merge-base$X \ + git-ls-tree$X git-mailinfo$X git-merge-base$X \ git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \ git-peek-remote$X git-prune-packed$X git-read-tree$X \ git-receive-pack$X git-rev-parse$X \ @@ -171,7 +171,7 @@ PROGRAMS = \ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-count-objects$X git-diff$X git-push$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ - git-init-db$X + git-init-db$X git-ls-files$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -220,7 +220,7 @@ LIB_OBJS = \ BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ - builtin-init-db.o + builtin-init-db.o builtin-ls-files.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/ls-files.c b/builtin-ls-files.c similarity index 99% rename from ls-files.c rename to builtin-ls-files.c index 4a4af1ca3b..3a0c5f2150 100644 --- a/ls-files.c +++ b/builtin-ls-files.c @@ -10,6 +10,7 @@ #include "cache.h" #include "quote.h" +#include "builtin.h" static int abbrev = 0; static int show_deleted = 0; @@ -648,7 +649,7 @@ static const char ls_files_usage[] = "[ --exclude-per-directory= ] [--full-name] [--abbrev] " "[--] []*"; -int main(int argc, const char **argv) +int cmd_ls_files(int argc, const char **argv, char** envp) { int i; int exc_given = 0; diff --git a/builtin.h b/builtin.h index 60541262c4..a0713d3747 100644 --- a/builtin.h +++ b/builtin.h @@ -27,5 +27,6 @@ extern int cmd_grep(int argc, const char **argv, char **envp); extern int cmd_rev_list(int argc, const char **argv, char **envp); 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_ls_files(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index 3216d311b2..9cfa9ebced 100644 --- a/git.c +++ b/git.c @@ -52,7 +52,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "grep", cmd_grep }, { "rev-list", cmd_rev_list }, { "init-db", cmd_init_db }, - { "check-ref-format", cmd_check_ref_format } + { "check-ref-format", cmd_check_ref_format }, + { "ls-files", cmd_ls_files } }; int i; From aae01bda7f6d3224cf6b2ce0aa9aa668ce35d0b7 Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 23 May 2006 14:15:30 +0200 Subject: [PATCH 3/9] Builtin git-ls-tree. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- Makefile | 6 +++--- ls-tree.c => builtin-ls-tree.c | 5 +++-- builtin.h | 1 + git.c | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) rename ls-tree.c => builtin-ls-tree.c (96%) diff --git a/Makefile b/Makefile index c540d7d9f1..2afd089a0d 100644 --- a/Makefile +++ b/Makefile @@ -155,7 +155,7 @@ PROGRAMS = \ git-diff-index$X git-diff-stages$X \ git-diff-tree$X git-fetch-pack$X git-fsck-objects$X \ git-hash-object$X git-index-pack$X git-local-fetch$X \ - git-ls-tree$X git-mailinfo$X git-merge-base$X \ + git-mailinfo$X git-merge-base$X \ git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \ git-peek-remote$X git-prune-packed$X git-read-tree$X \ git-receive-pack$X git-rev-parse$X \ @@ -171,7 +171,7 @@ PROGRAMS = \ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-count-objects$X git-diff$X git-push$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ - git-init-db$X git-ls-files$X + git-init-db$X git-ls-files$X git-ls-tree$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -220,7 +220,7 @@ LIB_OBJS = \ BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ - builtin-init-db.o builtin-ls-files.o + builtin-init-db.o builtin-ls-files.o builtin-ls-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/ls-tree.c b/builtin-ls-tree.c similarity index 96% rename from ls-tree.c rename to builtin-ls-tree.c index f2b3bc1231..48385d59f6 100644 --- a/ls-tree.c +++ b/builtin-ls-tree.c @@ -7,6 +7,7 @@ #include "blob.h" #include "tree.h" #include "quote.h" +#include "builtin.h" static int line_termination = '\n'; #define LS_RECURSIVE 1 @@ -15,7 +16,7 @@ static int line_termination = '\n'; #define LS_NAME_ONLY 8 static int abbrev = 0; static int ls_options = 0; -const char **pathspec; +static const char **pathspec; static int chomp_prefix = 0; static const char *prefix; @@ -84,7 +85,7 @@ static int show_tree(unsigned char *sha1, const char *base, int baselen, return retval; } -int main(int argc, const char **argv) +int cmd_ls_tree(int argc, const char **argv, char **envp) { unsigned char sha1[20]; struct tree *tree; diff --git a/builtin.h b/builtin.h index a0713d3747..951f206372 100644 --- a/builtin.h +++ b/builtin.h @@ -28,5 +28,6 @@ extern int cmd_rev_list(int argc, const char **argv, char **envp); 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_ls_files(int argc, const char **argv, char **envp); +extern int cmd_ls_tree(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index 9cfa9ebced..8574775418 100644 --- a/git.c +++ b/git.c @@ -53,7 +53,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "rev-list", cmd_rev_list }, { "init-db", cmd_init_db }, { "check-ref-format", cmd_check_ref_format }, - { "ls-files", cmd_ls_files } + { "ls-files", cmd_ls_files }, + { "ls-tree", cmd_ls_tree } }; int i; From 56d1398ad305498faf57d6e433f97ad393d7909e Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 23 May 2006 14:15:31 +0200 Subject: [PATCH 4/9] Builtin git-tar-tree. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- Makefile | 8 +++++--- tar-tree.c => builtin-tar-tree.c | 3 ++- builtin.h | 1 + git.c | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) rename tar-tree.c => builtin-tar-tree.c (99%) diff --git a/Makefile b/Makefile index 2afd089a0d..a3164f8ef0 100644 --- a/Makefile +++ b/Makefile @@ -161,7 +161,7 @@ PROGRAMS = \ git-receive-pack$X git-rev-parse$X \ git-send-pack$X git-show-branch$X git-shell$X \ git-show-index$X git-ssh-fetch$X \ - git-ssh-upload$X git-tar-tree$X git-unpack-file$X \ + git-ssh-upload$X git-unpack-file$X \ git-unpack-objects$X git-update-index$X git-update-server-info$X \ git-upload-pack$X git-verify-pack$X git-write-tree$X \ git-update-ref$X git-symbolic-ref$X \ @@ -171,7 +171,8 @@ PROGRAMS = \ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-count-objects$X git-diff$X git-push$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ - git-init-db$X git-ls-files$X git-ls-tree$X + git-init-db$X git-ls-files$X git-ls-tree$X \ + git-tar-tree$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -220,7 +221,8 @@ LIB_OBJS = \ BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ - builtin-init-db.o builtin-ls-files.o builtin-ls-tree.o + builtin-init-db.o builtin-ls-files.o builtin-ls-tree.o \ + builtin-tar-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/tar-tree.c b/builtin-tar-tree.c similarity index 99% rename from tar-tree.c rename to builtin-tar-tree.c index 33087366c3..6ada04ce38 100644 --- a/tar-tree.c +++ b/builtin-tar-tree.c @@ -7,6 +7,7 @@ #include "commit.h" #include "strbuf.h" #include "tar.h" +#include "builtin.h" #define RECORDSIZE (512) #define BLOCKSIZE (RECORDSIZE * 20) @@ -301,7 +302,7 @@ static void traverse_tree(struct tree_desc *tree, struct strbuf *path) } } -int main(int argc, char **argv) +int cmd_tar_tree(int argc, const char **argv, char** envp) { unsigned char sha1[20], tree_sha1[20]; struct commit *commit; diff --git a/builtin.h b/builtin.h index 951f206372..d210543948 100644 --- a/builtin.h +++ b/builtin.h @@ -29,5 +29,6 @@ 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_ls_files(int argc, const char **argv, char **envp); extern int cmd_ls_tree(int argc, const char **argv, char **envp); +extern int cmd_tar_tree(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index 8574775418..c253e60953 100644 --- a/git.c +++ b/git.c @@ -54,7 +54,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "init-db", cmd_init_db }, { "check-ref-format", cmd_check_ref_format }, { "ls-files", cmd_ls_files }, - { "ls-tree", cmd_ls_tree } + { "ls-tree", cmd_ls_tree }, + { "tar-tree", cmd_tar_tree } }; int i; From d147e501f37a596e73a430ce46f125f83e06aa07 Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 23 May 2006 14:15:32 +0200 Subject: [PATCH 5/9] Builtin git-read-tree. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- Makefile | 6 +++--- read-tree.c => builtin-read-tree.c | 3 ++- builtin.h | 1 + git.c | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) rename read-tree.c => builtin-read-tree.c (99%) diff --git a/Makefile b/Makefile index a3164f8ef0..1aebcf5978 100644 --- a/Makefile +++ b/Makefile @@ -157,7 +157,7 @@ PROGRAMS = \ git-hash-object$X git-index-pack$X git-local-fetch$X \ git-mailinfo$X git-merge-base$X \ git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \ - git-peek-remote$X git-prune-packed$X git-read-tree$X \ + git-peek-remote$X git-prune-packed$X \ git-receive-pack$X git-rev-parse$X \ git-send-pack$X git-show-branch$X git-shell$X \ git-show-index$X git-ssh-fetch$X \ @@ -172,7 +172,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-count-objects$X git-diff$X git-push$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ git-init-db$X git-ls-files$X git-ls-tree$X \ - git-tar-tree$X + git-tar-tree$X git-read-tree$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -222,7 +222,7 @@ BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ builtin-init-db.o builtin-ls-files.o builtin-ls-tree.o \ - builtin-tar-tree.o + builtin-tar-tree.o builtin-read-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/read-tree.c b/builtin-read-tree.c similarity index 99% rename from read-tree.c rename to builtin-read-tree.c index 82e2a9a4d3..ec40d013c4 100644 --- a/read-tree.c +++ b/builtin-read-tree.c @@ -11,6 +11,7 @@ #include "tree.h" #include #include +#include "builtin.h" static int reset = 0; static int merge = 0; @@ -763,7 +764,7 @@ static const char read_tree_usage[] = "git-read-tree ( | -m [--aggressive] static struct cache_file cache_file; -int main(int argc, char **argv) +int cmd_read_tree(int argc, const char **argv, char **envp) { int i, newfd, stage = 0; unsigned char sha1[20]; diff --git a/builtin.h b/builtin.h index d210543948..88b3523c25 100644 --- a/builtin.h +++ b/builtin.h @@ -30,5 +30,6 @@ extern int cmd_init_db(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_tar_tree(int argc, const char **argv, char **envp); +extern int cmd_read_tree(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index c253e60953..300e2b269c 100644 --- a/git.c +++ b/git.c @@ -55,7 +55,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "check-ref-format", cmd_check_ref_format }, { "ls-files", cmd_ls_files }, { "ls-tree", cmd_ls_tree }, - { "tar-tree", cmd_tar_tree } + { "tar-tree", cmd_tar_tree }, + { "read-tree", cmd_read_tree } }; int i; From 6d96ac18e52aca19ff1087ffa64e2d616cc75c6f Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 23 May 2006 14:15:33 +0200 Subject: [PATCH 6/9] Builtin git-commit-tree. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- Makefile | 6 +++--- commit-tree.c => builtin-commit-tree.c | 5 +++-- builtin.h | 1 + git.c | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) rename commit-tree.c => builtin-commit-tree.c (96%) diff --git a/Makefile b/Makefile index 1aebcf5978..a1bee61e57 100644 --- a/Makefile +++ b/Makefile @@ -150,7 +150,7 @@ SIMPLE_PROGRAMS = \ # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS = \ git-apply$X git-cat-file$X \ - git-checkout-index$X git-clone-pack$X git-commit-tree$X \ + git-checkout-index$X git-clone-pack$X \ git-convert-objects$X git-diff-files$X \ git-diff-index$X git-diff-stages$X \ git-diff-tree$X git-fetch-pack$X git-fsck-objects$X \ @@ -172,7 +172,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-count-objects$X git-diff$X git-push$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ git-init-db$X git-ls-files$X git-ls-tree$X \ - git-tar-tree$X git-read-tree$X + git-tar-tree$X git-read-tree$X git-commit-tree$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -222,7 +222,7 @@ BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ builtin-init-db.o builtin-ls-files.o builtin-ls-tree.o \ - builtin-tar-tree.o builtin-read-tree.o + builtin-tar-tree.o builtin-read-tree.o builtin-commit-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/commit-tree.c b/builtin-commit-tree.c similarity index 96% rename from commit-tree.c rename to builtin-commit-tree.c index 0320036e80..ec082bf754 100644 --- a/commit-tree.c +++ b/builtin-commit-tree.c @@ -6,6 +6,7 @@ #include "cache.h" #include "commit.h" #include "tree.h" +#include "builtin.h" #define BLOCKING (1ul << 14) @@ -76,7 +77,7 @@ static int new_parent(int idx) return 1; } -int main(int argc, char **argv) +int cmd_commit_tree(int argc, const char **argv, char **envp) { int i; int parents = 0; @@ -98,7 +99,7 @@ int main(int argc, char **argv) check_valid(tree_sha1, tree_type); for (i = 2; i < argc; i += 2) { - char *a, *b; + const char *a, *b; a = argv[i]; b = argv[i+1]; if (!b || strcmp(a, "-p")) usage(commit_tree_usage); diff --git a/builtin.h b/builtin.h index 88b3523c25..c6b07d9a65 100644 --- a/builtin.h +++ b/builtin.h @@ -31,5 +31,6 @@ 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_tar_tree(int argc, const char **argv, char **envp); extern int cmd_read_tree(int argc, const char **argv, char **envp); +extern int cmd_commit_tree(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index 300e2b269c..4c2c062e36 100644 --- a/git.c +++ b/git.c @@ -56,7 +56,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "ls-files", cmd_ls_files }, { "ls-tree", cmd_ls_tree }, { "tar-tree", cmd_tar_tree }, - { "read-tree", cmd_read_tree } + { "read-tree", cmd_read_tree }, + { "commit-tree", cmd_commit_tree } }; int i; From ac6245e31a359200b65bfdd910bba9a0fbe90c11 Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 23 May 2006 14:15:34 +0200 Subject: [PATCH 7/9] Builtin git-apply. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- Makefile | 8 +++++--- apply.c => builtin-apply.c | 3 ++- builtin.h | 1 + git.c | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) rename apply.c => builtin-apply.c (99%) diff --git a/Makefile b/Makefile index a1bee61e57..3da576838f 100644 --- a/Makefile +++ b/Makefile @@ -149,7 +149,7 @@ SIMPLE_PROGRAMS = \ # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS = \ - git-apply$X git-cat-file$X \ + git-cat-file$X \ git-checkout-index$X git-clone-pack$X \ git-convert-objects$X git-diff-files$X \ git-diff-index$X git-diff-stages$X \ @@ -172,7 +172,8 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-count-objects$X git-diff$X git-push$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ git-init-db$X git-ls-files$X git-ls-tree$X \ - git-tar-tree$X git-read-tree$X git-commit-tree$X + git-tar-tree$X git-read-tree$X git-commit-tree$X \ + git-apply$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -222,7 +223,8 @@ BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ builtin-init-db.o builtin-ls-files.o builtin-ls-tree.o \ - builtin-tar-tree.o builtin-read-tree.o builtin-commit-tree.o + builtin-tar-tree.o builtin-read-tree.o builtin-commit-tree.o \ + builtin-apply.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/apply.c b/builtin-apply.c similarity index 99% rename from apply.c rename to builtin-apply.c index 0ed9d132e8..4056b9d67b 100644 --- a/apply.c +++ b/builtin-apply.c @@ -11,6 +11,7 @@ #include "quote.h" #include "blob.h" #include "delta.h" +#include "builtin.h" // --check turns on checking that the working tree matches the // files that are being modified, but doesn't apply the patch @@ -2151,7 +2152,7 @@ static int git_apply_config(const char *var, const char *value) } -int main(int argc, char **argv) +int cmd_apply(int argc, const char **argv, char **envp) { int i; int read_stdin = 1; diff --git a/builtin.h b/builtin.h index c6b07d9a65..d6ff88ebc1 100644 --- a/builtin.h +++ b/builtin.h @@ -32,5 +32,6 @@ extern int cmd_ls_tree(int argc, const char **argv, char **envp); extern int cmd_tar_tree(int argc, const char **argv, char **envp); extern int cmd_read_tree(int argc, const char **argv, char **envp); extern int cmd_commit_tree(int argc, const char **argv, char **envp); +extern int cmd_apply(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index 4c2c062e36..f44e08b9ce 100644 --- a/git.c +++ b/git.c @@ -57,7 +57,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "ls-tree", cmd_ls_tree }, { "tar-tree", cmd_tar_tree }, { "read-tree", cmd_read_tree }, - { "commit-tree", cmd_commit_tree } + { "commit-tree", cmd_commit_tree }, + { "apply", cmd_apply } }; int i; From 51ce34b9923d9b119ac53414584f80e05520abea Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 23 May 2006 14:15:35 +0200 Subject: [PATCH 8/9] Builtin git-show-branch. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- Makefile | 6 +++--- show-branch.c => builtin-show-branch.c | 7 ++++--- builtin.h | 1 + git.c | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) rename show-branch.c => builtin-show-branch.c (99%) diff --git a/Makefile b/Makefile index 3da576838f..69377e37b4 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,7 @@ PROGRAMS = \ git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \ git-peek-remote$X git-prune-packed$X \ git-receive-pack$X git-rev-parse$X \ - git-send-pack$X git-show-branch$X git-shell$X \ + git-send-pack$X git-shell$X \ git-show-index$X git-ssh-fetch$X \ git-ssh-upload$X git-unpack-file$X \ git-unpack-objects$X git-update-index$X git-update-server-info$X \ @@ -173,7 +173,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ git-init-db$X git-ls-files$X git-ls-tree$X \ git-tar-tree$X git-read-tree$X git-commit-tree$X \ - git-apply$X + git-apply$X git-show-branch$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -224,7 +224,7 @@ BUILTIN_OBJS = \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ builtin-init-db.o builtin-ls-files.o builtin-ls-tree.o \ builtin-tar-tree.o builtin-read-tree.o builtin-commit-tree.o \ - builtin-apply.o + builtin-apply.o builtin-show-branch.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/show-branch.c b/builtin-show-branch.c similarity index 99% rename from show-branch.c rename to builtin-show-branch.c index 268c57b180..3af24e767b 100644 --- a/show-branch.c +++ b/builtin-show-branch.c @@ -3,13 +3,14 @@ #include "cache.h" #include "commit.h" #include "refs.h" +#include "builtin.h" static const char show_branch_usage[] = "git-show-branch [--dense] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [...]"; static int default_num = 0; static int default_alloc = 0; -static char **default_arg = NULL; +static const char **default_arg = NULL; #define UNINTERESTING 01 @@ -548,7 +549,7 @@ static int omit_in_dense(struct commit *commit, struct commit **rev, int n) return 0; } -int main(int ac, char **av) +int cmd_show_branch(int ac, const char **av, char **envp) { struct commit *rev[MAX_REVS], *commit; struct commit_list *list = NULL, *seen = NULL; @@ -581,7 +582,7 @@ int main(int ac, char **av) } while (1 < ac && av[1][0] == '-') { - char *arg = av[1]; + const char *arg = av[1]; if (!strcmp(arg, "--")) { ac--; av++; break; diff --git a/builtin.h b/builtin.h index d6ff88ebc1..01882ec93d 100644 --- a/builtin.h +++ b/builtin.h @@ -33,5 +33,6 @@ extern int cmd_tar_tree(int argc, const char **argv, char **envp); extern int cmd_read_tree(int argc, const char **argv, char **envp); extern int cmd_commit_tree(int argc, const char **argv, char **envp); extern int cmd_apply(int argc, const char **argv, char **envp); +extern int cmd_show_branch(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index f44e08b9ce..d29505c4c9 100644 --- a/git.c +++ b/git.c @@ -58,7 +58,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "tar-tree", cmd_tar_tree }, { "read-tree", cmd_read_tree }, { "commit-tree", cmd_commit_tree }, - { "apply", cmd_apply } + { "apply", cmd_apply }, + { "show-branch", cmd_show_branch } }; int i; From e8cc9cd98e2ecd7fd8bb03e725d470405c8e2b94 Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Tue, 23 May 2006 14:15:36 +0200 Subject: [PATCH 9/9] Builtin git-diff-files, git-diff-index, git-diff-stages, and git-diff-tree. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano --- Makefile | 12 ++++++------ diff-files.c => builtin-diff-files.c | 3 ++- diff-index.c => builtin-diff-index.c | 3 ++- diff-stages.c => builtin-diff-stages.c | 3 ++- diff-tree.c => builtin-diff-tree.c | 3 ++- builtin.h | 5 +++++ git.c | 6 +++++- 7 files changed, 24 insertions(+), 11 deletions(-) rename diff-files.c => builtin-diff-files.c (94%) rename diff-index.c => builtin-diff-index.c (91%) rename diff-stages.c => builtin-diff-stages.c (96%) rename diff-tree.c => builtin-diff-tree.c (97%) diff --git a/Makefile b/Makefile index 69377e37b4..fc5f98b908 100644 --- a/Makefile +++ b/Makefile @@ -151,9 +151,7 @@ SIMPLE_PROGRAMS = \ PROGRAMS = \ git-cat-file$X \ git-checkout-index$X git-clone-pack$X \ - git-convert-objects$X git-diff-files$X \ - git-diff-index$X git-diff-stages$X \ - git-diff-tree$X git-fetch-pack$X git-fsck-objects$X \ + git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \ git-hash-object$X git-index-pack$X git-local-fetch$X \ git-mailinfo$X git-merge-base$X \ git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \ @@ -173,7 +171,8 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \ git-grep$X git-rev-list$X git-check-ref-format$X \ git-init-db$X git-ls-files$X git-ls-tree$X \ git-tar-tree$X git-read-tree$X git-commit-tree$X \ - git-apply$X git-show-branch$X + git-apply$X git-show-branch$X git-diff-files$X \ + git-diff-index$X git-diff-stages$X git-diff-tree$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -223,8 +222,9 @@ BUILTIN_OBJS = \ builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \ builtin-grep.o builtin-rev-list.o builtin-check-ref-format.o \ builtin-init-db.o builtin-ls-files.o builtin-ls-tree.o \ - builtin-tar-tree.o builtin-read-tree.o builtin-commit-tree.o \ - builtin-apply.o builtin-show-branch.o + builtin-tar-tree.o builtin-read-tree.o builtin-commit-tree.o \ + builtin-apply.o builtin-show-branch.o builtin-diff-files.o \ + builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/diff-files.c b/builtin-diff-files.c similarity index 94% rename from diff-files.c rename to builtin-diff-files.c index b9d193d506..cebda828ee 100644 --- a/diff-files.c +++ b/builtin-diff-files.c @@ -7,12 +7,13 @@ #include "diff.h" #include "commit.h" #include "revision.h" +#include "builtin.h" static const char diff_files_usage[] = "git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [] [...]" COMMON_DIFF_OPTIONS_HELP; -int main(int argc, const char **argv) +int cmd_diff_files(int argc, const char **argv, char **envp) { struct rev_info rev; int silent = 0; diff --git a/diff-index.c b/builtin-diff-index.c similarity index 91% rename from diff-index.c rename to builtin-diff-index.c index 8c9f60173b..1958580d82 100644 --- a/diff-index.c +++ b/builtin-diff-index.c @@ -2,13 +2,14 @@ #include "diff.h" #include "commit.h" #include "revision.h" +#include "builtin.h" static const char diff_cache_usage[] = "git-diff-index [-m] [--cached] " "[] [...]" COMMON_DIFF_OPTIONS_HELP; -int main(int argc, const char **argv) +int cmd_diff_index(int argc, const char **argv, char **envp) { struct rev_info rev; int cached = 0; diff --git a/diff-stages.c b/builtin-diff-stages.c similarity index 96% rename from diff-stages.c rename to builtin-diff-stages.c index dcd20e79e4..7c157ca889 100644 --- a/diff-stages.c +++ b/builtin-diff-stages.c @@ -4,6 +4,7 @@ #include "cache.h" #include "diff.h" +#include "builtin.h" static struct diff_options diff_options; @@ -54,7 +55,7 @@ static void diff_stages(int stage1, int stage2, const char **pathspec) } } -int main(int ac, const char **av) +int cmd_diff_stages(int ac, const char **av, char **envp) { int stage1, stage2; const char *prefix = setup_git_directory(); diff --git a/diff-tree.c b/builtin-diff-tree.c similarity index 97% rename from diff-tree.c rename to builtin-diff-tree.c index 69bb74b310..cc53b81ac4 100644 --- a/diff-tree.c +++ b/builtin-diff-tree.c @@ -2,6 +2,7 @@ #include "diff.h" #include "commit.h" #include "log-tree.h" +#include "builtin.h" static struct rev_info log_tree_opt; @@ -58,7 +59,7 @@ static const char diff_tree_usage[] = " --root include the initial commit as diff against /dev/null\n" COMMON_DIFF_OPTIONS_HELP; -int main(int argc, const char **argv) +int cmd_diff_tree(int argc, const char **argv, char **envp) { int nr_sha1; char line[1000]; diff --git a/builtin.h b/builtin.h index 01882ec93d..7620984624 100644 --- a/builtin.h +++ b/builtin.h @@ -34,5 +34,10 @@ extern int cmd_read_tree(int argc, const char **argv, char **envp); extern int cmd_commit_tree(int argc, const char **argv, char **envp); extern int cmd_apply(int argc, const char **argv, char **envp); extern int cmd_show_branch(int argc, const char **argv, char **envp); +extern int cmd_diff_files(int argc, const char **argv, char **envp); +extern int cmd_diff_index(int argc, const char **argv, char **envp); +extern int cmd_diff_stages(int argc, const char **argv, char **envp); +extern int cmd_diff_tree(int argc, const char **argv, char **envp); + #endif diff --git a/git.c b/git.c index d29505c4c9..874974874b 100644 --- a/git.c +++ b/git.c @@ -59,7 +59,11 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "read-tree", cmd_read_tree }, { "commit-tree", cmd_commit_tree }, { "apply", cmd_apply }, - { "show-branch", cmd_show_branch } + { "show-branch", cmd_show_branch }, + { "diff-files", cmd_diff_files }, + { "diff-index", cmd_diff_index }, + { "diff-stages", cmd_diff_stages }, + { "diff-tree", cmd_diff_tree } }; int i;