git/rsh.c
Junio C Hamano d19938ab60 Rename environment variables.
H. Peter Anvin mentioned that using SHA1_whatever as an
environment variable name is not nice and we should instead use
names starting with "GIT_" prefix to avoid conflicts.  Here is
what this patch does:

 * Renames the following environment variables:

    New name                           Old Name

    GIT_AUTHOR_DATE                    AUTHOR_DATE
    GIT_AUTHOR_EMAIL                   AUTHOR_EMAIL
    GIT_AUTHOR_NAME                    AUTHOR_NAME
    GIT_COMMITTER_EMAIL                COMMIT_AUTHOR_EMAIL
    GIT_COMMITTER_NAME                 COMMIT_AUTHOR_NAME
    GIT_ALTERNATE_OBJECT_DIRECTORIES   SHA1_FILE_DIRECTORIES
    GIT_OBJECT_DIRECTORY               SHA1_FILE_DIRECTORY

 * Introduces a compatibility macro, gitenv(), which does an
   getenv() and if it fails calls gitenv_bc(), which in turn
   picks up the value from old name while giving a warning about
   using an old name.

 * Changes all users of the environment variable to fetch
   environment variable with the new name using gitenv().

 * Updates the documentation and scripts shipped with Linus GIT
   distribution.

The transition plan is as follows:

 * We will keep the backward compatibility list used by gitenv()
   for now, so the current scripts and user environments
   continue to work as before.  The users will get warnings when
   they have old name but not new name in their environment to
   the stderr.

 * The Porcelain layers should start using new names.  However,
   just in case it ends up calling old Plumbing layer
   implementation, they should also export old names, taking
   values from the corresponding new names, during the
   transition period.

 * After a transition period, we would drop the compatibility
   support and drop gitenv().  Revert the callers to directly
   call getenv() but keep using the new names.

   The last part is probably optional and the transition
   duration needs to be set to a reasonable value.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-05-09 17:57:56 -07:00

65 lines
1.3 KiB
C

#include "rsh.h"
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "cache.h"
#define COMMAND_SIZE 4096
int setup_connection(int *fd_in, int *fd_out, char *remote_prog,
char *url, int rmt_argc, char **rmt_argv)
{
char *host;
char *path;
int sv[2];
char command[COMMAND_SIZE];
char *posn;
int i;
if (!strcmp(url, "-")) {
*fd_in = 0;
*fd_out = 1;
return 0;
}
host = strstr(url, "//");
if (!host) {
return error("Bad URL: %s", url);
}
host += 2;
path = strchr(host, '/');
if (!path) {
return error("Bad URL: %s", url);
}
*(path++) = '\0';
/* ssh <host> 'cd /<path>; stdio-pull <arg...> <commit-id>' */
snprintf(command, COMMAND_SIZE,
"cd /%s; %s=objects %s",
path, DB_ENVIRONMENT, remote_prog);
posn = command + strlen(command);
for (i = 0; i < rmt_argc; i++) {
*(posn++) = ' ';
strncpy(posn, rmt_argv[i], COMMAND_SIZE - (posn - command));
posn += strlen(rmt_argv[i]);
if (posn - command + 4 >= COMMAND_SIZE) {
return error("Command line too long");
}
}
strcpy(posn, " -");
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv)) {
return error("Couldn't create socket");
}
if (!fork()) {
close(sv[1]);
dup2(sv[0], 0);
dup2(sv[0], 1);
execlp("ssh", "ssh", host, command, NULL);
}
close(sv[0]);
*fd_in = sv[1];
*fd_out = sv[1];
return 0;
}