Add init-serve, the remote side of "git init --remote=host:path"
PATCH 1/2 Add init-serve, the remote side of "git init --remote=host:path"
This is still sprinkled with a few NEEDSWORK, but should be good enough to start developing and testing the requesting side of the protocol pair.
Signed-off-by Junio C Hamano <[email protected]>
--- Makefile | 1 + builtin-init-serve.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ builtin.h | 1 + git.c | 1 + 4 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 builtin-init-serve.c
Makefile +1 -0
@@ -544,6 +544,7 @@ BUILTIN_OBJS += builtin-gc.o BUILTIN_OBJS += builtin-grep.o BUILTIN_OBJS += builtin-help.o BUILTIN_OBJS += builtin-init-db.o +BUILTIN_OBJS += builtin-init-serve.o BUILTIN_OBJS += builtin-log.o BUILTIN_OBJS += builtin-ls-files.o BUILTIN_OBJS += builtin-ls-remote.o
builtin-init-serve.c new file +117 -0
117 lines not on this page · raw message
builtin.h +1 -0
@@ -59,6 +59,7 @@ extern int cmd_grep(int argc, const char **argv, const char *prefix);extern int cmd_help (int argc,const char **argv,const char *prefix);extern int cmd_http_fetch (int argc,const char **argv,const char *prefix);extern int cmd_init_db (int argc,const char **argv,const char *prefix); +extern int cmd_init_serve (int argc,const char **argv,const char *prefix);extern int cmd_log (int argc,const char **argv,const char *prefix);extern int cmd_log_reflog (int argc,const char **argv,const char *prefix);extern int cmd_ls_files (int argc,const char **argv,const char *prefix);
git.c +1 -0
@@ -311,6 +311,7 @@ static void handle_internal_command(int argc, const char **argv)#endif { "init", cmd_init_db }, { "init-db", cmd_init_db }, + { "init-serve", cmd_init_serve }, { "log", cmd_log, RUN_SETUP | USE_PAGER }, { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-tree", cmd_ls_tree, RUN_SETUP },
Signature · 1 line
1.6.2.rc2.99.g9f3bb
I've cleaned up the series somewhat and now it is two independent clean-up followed by the updated version of these two patches.
PATCH 2/2 "git init --remote=host:path"
In reply to Junio C HamanoThis implements the requesting side of the pair.
It probably should take the same --exec=init-serve parameter similar to the way other programs like receive-pack and send-pack does, but I am too lazy to add it.
Signed-off-by Junio C Hamano <[email protected]>
--- builtin-init-db.c | 34 +++++++++++++++++++++++++++++++++- t/t0001-init.sh | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletions(-)
builtin-init-db.c +33 -1
@@ -6,6 +6,7 @@#include "cache.h" #include "builtin.h" #include "exec_cmd.h" +#include "pkt-line.h" #ifndef DEFAULT_GIT_TEMPLATE_DIR #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -363,6 +364,33 @@ static int guess_repository_type(const char *git_dir)return 1 ; } +static int remote_init (const char *remote,int argc,const char **argv) +{ +struct child_process *child; +int fd[2 ], i, len, status; +char line[1000 ]; + + child =git_connect (fd, remote,"git init-serve" ,0 ); +for (i =1 ; i < argc; i++) { +fprintf (stderr,"writing %d (%s)\n" , i, argv[i]); +packet_write (fd[1 ], argv[i]); + } +packet_flush (fd[1 ]); + + status =0 ; + len =packet_read_line (fd[0 ], line,sizeof (line)); +if (len <3 || + (memcmp (line,"ok " ,3 ) &&memcmp (line,"ng " ,3 ))) +die ("protocol error: %s\n" , line); + +if (line[0 ] !='o' ) { +error ("%s" , line); + status =-1 ; + } + status |=finish_connect (child); +return status; +} +static const char init_db_usage[] ="git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]" ;
@@ -394,7 +422,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) init_shared_repository =git_config_perm ("arg" , arg+9 ); else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) flags |=INIT_DB_QUIET ; - else + else if (!prefixcmp(arg, "--remote=")) { +if (i !=1 ) +die ("--remote option must be given first" ); +return remote_init (arg+9 , argc-1 , argv+1 ); + } elseusage (init_db_usage ); }
t/t0001-init.sh +7 -0
@@ -199,4 +199,11 @@ test_expect_success 'init honors global core.sharedRepository' ' x`git config -f shared-honor-global/.git/config core.sharedRepository` ' +test_expect_success 'init --remote' ' + R="$(pwd)/test-of-remote" && + git init --remote="$R" --bare && + test -d "$R/objects/pack" && + test_must_fail git init --remote="$R" +' + test_done
Signature · 1 line
1.6.2.rc2.99.g9f3bb