Merge branch 'jc/tartree' into jc/builtin-n-tar-tree
authorJunio C Hamano <junkio@cox.net>
Tue, 23 May 2006 21:44:31 +0000 (14:44 -0700)
committerJunio C Hamano <junkio@cox.net>
Tue, 23 May 2006 21:44:31 +0000 (14:44 -0700)
* jc/tartree:
  built-in tar-tree and remote tar-tree

1  2 
Makefile
builtin-tar-tree.c
builtin.h
git.c

diff --cc Makefile
index fc5f98b908d1485315c82341f697a4ef8af9dad5,f4bcec496a616d111bad42b70b8289a9cde74d7c..14873fa3591516d9aa2a8e3a4bf43341deaa8da0
+++ b/Makefile
@@@ -169,10 -171,7 +169,11 @@@ 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-tar-tree$X git-upload-tar$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-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-diff-index$X git-diff-stages$X git-diff-tree$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)
@@@ -221,10 -220,7 +222,11 @@@ 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-tar-tree.o builtin-upload-tar.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-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
++      builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
++      builtin-tar-tree.o builtin-upload-tar.o
  
  GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
  LIBS = $(GITLIBS) -lz
index 6ada04ce3846ec9e973d79cd97e99b9fe84f17db,e97e0af985515df14b37a6f0e5cc84b2c943f8c6..2d5e06fb692968829df00e7166eaaeb9d5902119
@@@ -302,7 -304,7 +304,7 @@@ static void traverse_tree(struct tree_d
        }
  }
  
- int cmd_tar_tree(int argc, const char **argv, char** envp)
 -int generate_tar(int argc, const char **argv)
++static int generate_tar(int argc, const char **argv, char** envp)
  {
        unsigned char sha1[20], tree_sha1[20];
        struct commit *commit;
        free(current_path.buf);
        return 0;
  }
 -      return generate_tar(argc, argv);
+ 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=<repo> */
+       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, envp);
+ }
diff --cc builtin.h
index 7620984624abee4be236a38b31cfb7af966519f9,f22783c499a94c3953d098d6edf04984cb25711a..2249c5fae0f8f9134d2328d2835743a8f5d89d46
+++ b/builtin.h
@@@ -27,17 -27,7 +27,17 @@@ extern int cmd_grep(int argc, const cha
  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_tar_tree(int argc, const char **argv, char **envp);
+ extern int cmd_upload_tar(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);
 +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 --cc git.c
index 874974874bf4fe2202587ff396816f5ae5f59247,fd8e9bf7f2b2f7c26984248d0afe2d2143c82cf8..38e84618dcfdc4bd91a5aec6155696416bace6bd
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -50,20 -50,11 +50,22 @@@ static void handle_internal_command(in
                { "count-objects", cmd_count_objects },
                { "diff", cmd_diff },
                { "grep", cmd_grep },
 +              { "rev-list", cmd_rev_list },
                { "init-db", cmd_init_db },
 -              { "rev-list", cmd_rev_list },
 -              { "check-ref-format", cmd_check_ref_format }
+               { "tar-tree", cmd_tar_tree },
+               { "upload-tar", cmd_upload_tar },
 +              { "check-ref-format", cmd_check_ref_format },
 +              { "ls-files", cmd_ls_files },
 +              { "ls-tree", cmd_ls_tree },
 +              { "tar-tree", cmd_tar_tree },
 +              { "read-tree", cmd_read_tree },
 +              { "commit-tree", cmd_commit_tree },
 +              { "apply", cmd_apply },
 +              { "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;