1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-04 11:16:11 +02:00

git-remote-fd

This remote helper reflects raw smart remote transport stream back to the
calling program. This is useful for example if some UI wants to handle
ssh itself and not use hacks via GIT_SSH.

Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ilari Liusvaara 2010-10-12 19:39:42 +03:00 committed by Junio C Hamano
parent 419f37db4d
commit 3a9ed4bdee
6 changed files with 142 additions and 0 deletions

1
.gitignore vendored
View File

@ -112,6 +112,7 @@
/git-remote-https
/git-remote-ftp
/git-remote-ftps
/git-remote-fd
/git-remote-testgit
/git-repack
/git-replace

View File

@ -0,0 +1,59 @@
git-remote-fd(1)
=================
NAME
----
git-remote-fd - Reflect smart transport stream back to caller
SYNOPSIS
--------
"fd::<infd>[,<outfd>][/<anything>]" (as URL)
DESCRIPTION
-----------
This helper uses specified file descriptors to connect to remote git server.
This is not meant for end users but for programs and scripts calling git
fetch, push or archive.
If only <infd> is given, it is assumed to be bidirectional socket connected
to remote git server (git-upload-pack, git-receive-pack or
git-upload-achive). If both <infd> and <outfd> are given, they are assumed
to be pipes connected to remote git server (<infd> being the inbound pipe
and <outfd> being the outbound pipe.
It is assumed that any handshaking procedures have already been completed
(such as sending service request for git://) before this helper is started.
<anything> can be any string. It is ignored. It is meant for provoding
information to user in the URL in case that URL is displayed in some
context.
ENVIRONMENT VARIABLES:
----------------------
GIT_TRANSLOOP_DEBUG::
If set, prints debugging information about various reads/writes.
EXAMPLES:
---------
git fetch fd::17 master::
Fetch master, using file descriptor #17 to communicate with
git-upload-pack.
git fetch fd::17/foo master::
Same as above.
git push fd::7,8 master (as URL)::
Push master, using file descriptor #7 to read data from
git-receive-pack and file descriptor #8 to write data to
same service.
git push fd::7,8/bar master::
Same as above.
Documentation
--------------
Documentation by Ilari Liusvaara and the git list <git@vger.kernel.org>
GIT
---
Part of the linkgit:git[1] suite

View File

@ -723,6 +723,7 @@ BUILTIN_OBJS += builtin/read-tree.o
BUILTIN_OBJS += builtin/receive-pack.o
BUILTIN_OBJS += builtin/reflog.o
BUILTIN_OBJS += builtin/remote.o
BUILTIN_OBJS += builtin/remote-fd.o
BUILTIN_OBJS += builtin/replace.o
BUILTIN_OBJS += builtin/rerere.o
BUILTIN_OBJS += builtin/reset.o

View File

@ -107,6 +107,7 @@ extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
extern int cmd_reflog(int argc, const char **argv, const char *prefix);
extern int cmd_remote(int argc, const char **argv, const char *prefix);
extern int cmd_remote_fd(int argc, const char **argv, const char *prefix);
extern int cmd_config(int argc, const char **argv, const char *prefix);
extern int cmd_rerere(int argc, const char **argv, const char *prefix);
extern int cmd_reset(int argc, const char **argv, const char *prefix);

79
builtin/remote-fd.c Normal file
View File

@ -0,0 +1,79 @@
#include "git-compat-util.h"
#include "transport.h"
/*
* URL syntax:
* 'fd::<inoutfd>[/<anything>]' Read/write socket pair
* <inoutfd>.
* 'fd::<infd>,<outfd>[/<anything>]' Read pipe <infd> and write
* pipe <outfd>.
* [foo] indicates 'foo' is optional. <anything> is any string.
*
* The data output to <outfd>/<inoutfd> should be passed unmolested to
* git-receive-pack/git-upload-pack/git-upload-archive and output of
* git-receive-pack/git-upload-pack/git-upload-archive should be passed
* unmolested to <infd>/<inoutfd>.
*
*/
#define MAXCOMMAND 4096
static void command_loop(int input_fd, int output_fd)
{
char buffer[MAXCOMMAND];
while (1) {
size_t i;
if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
if (ferror(stdin))
die("Input error");
return;
}
/* Strip end of line characters. */
i = strlen(buffer);
while (isspace(buffer[i - 1]))
buffer[--i] = 0;
if (!strcmp(buffer, "capabilities")) {
printf("*connect\n\n");
fflush(stdout);
} else if (!strncmp(buffer, "connect ", 8)) {
printf("\n");
fflush(stdout);
if (bidirectional_transfer_loop(input_fd,
output_fd))
die("Copying data between file descriptors failed");
return;
} else {
die("Bad command: %s", buffer);
}
}
}
int cmd_remote_fd(int argc, const char **argv, const char *prefix)
{
int input_fd = -1;
int output_fd = -1;
char *end;
if (argc < 3)
die("URL missing");
input_fd = (int)strtoul(argv[2], &end, 10);
if ((end == argv[2]) || (*end != ',' && *end != '/' && *end))
die("Bad URL syntax");
if (*end == '/' || !*end) {
output_fd = input_fd;
} else {
char *end2;
output_fd = (int)strtoul(end + 1, &end2, 10);
if ((end2 == end + 1) || (*end2 != '/' && *end2))
die("Bad URL syntax");
}
command_loop(input_fd, output_fd);
return 0;
}

1
git.c
View File

@ -374,6 +374,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "receive-pack", cmd_receive_pack },
{ "reflog", cmd_reflog, RUN_SETUP },
{ "remote", cmd_remote, RUN_SETUP },
{ "remote-fd", cmd_remote_fd },
{ "replace", cmd_replace, RUN_SETUP },
{ "repo-config", cmd_config, RUN_SETUP_GENTLY },
{ "rerere", cmd_rerere, RUN_SETUP },