Fossil SCM

Add the shell= query parameter to the ssh: scheme for cloning and syncing.

drh 2013-02-07 00:24 trunk
Commit 2163cd9666f2ae12d7cef23f41acb0816c74479b
3 files changed +12 -6 +2 -1 +10 -1
--- src/http_transport.c
+++ src/http_transport.c
@@ -183,10 +183,11 @@
183183
** and run an SSH command to talk to the remote machine.
184184
*/
185185
const char *zSsh; /* The base SSH command */
186186
Blob zCmd; /* The SSH command */
187187
char *zHost; /* The host name to contact */
188
+ int n; /* Size of prefix string */
188189
189190
zSsh = db_get("ssh-command", zDefaultSshCmd);
190191
blob_init(&zCmd, zSsh, -1);
191192
if( g.urlPort!=g.urlDfltPort ){
192193
#ifdef __MINGW32__
@@ -219,13 +220,15 @@
219220
}
220221
#endif
221222
}else{
222223
zHost = mprintf("%s", g.urlName);
223224
}
225
+ n = blob_size(&zCmd);
224226
blob_append(&zCmd, " ", 1);
225227
shell_escape(&zCmd, zHost);
226
- fossil_print(" %s\n", zHost); /* Show the conclusion of the SSH command */
228
+ if( g.urlShell ) blob_appendf(&zCmd, " %s", g.urlShell);
229
+ fossil_print("%s\n", blob_str(&zCmd)+n); /* Show tail of SSH command */
227230
free(zHost);
228231
popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid);
229232
if( sshPid==0 ){
230233
fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd);
231234
}
@@ -251,13 +254,13 @@
251254
Blob cmd;
252255
blob_zero(&cmd);
253256
shell_escape(&cmd, g.urlFossil);
254257
blob_append(&cmd, " test-http ", -1);
255258
shell_escape(&cmd, g.urlPath);
256
- /* printf("%s\n", blob_str(&cmd)); fflush(stdout); */
257
- fprintf(sshOut, "%s\n", blob_str(&cmd));
259
+ fprintf(sshOut, "%s || true\n", blob_str(&cmd));
258260
fflush(sshOut);
261
+ if( g.fSshTrace ) printf("Sent: [%s]\n", blob_str(&cmd));
259262
blob_reset(&cmd);
260263
}else if( g.urlIsHttps ){
261264
#ifdef FOSSIL_ENABLE_SSL
262265
rc = ssl_open();
263266
if( rc==0 ) transport.isOpen = 1;
@@ -403,11 +406,10 @@
403406
int got;
404407
if( sshIn ){
405408
int x;
406409
int wanted = N;
407410
got = 0;
408
- /* printf("want %d bytes...\n", wanted); fflush(stdout); */
409411
while( wanted>0 ){
410412
x = read(sshIn, &zBuf[got], wanted);
411413
if( x<=0 ) break;
412414
got += x;
413415
wanted -= x;
@@ -438,11 +440,14 @@
438440
int transport_receive(char *zBuf, int N){
439441
int onHand; /* Bytes current held in the transport buffer */
440442
int nByte = 0; /* Bytes of content received */
441443
442444
onHand = transport.nUsed - transport.iCursor;
443
- /* printf("request %d with %d on hand\n", N, onHand); fflush(stdout); */
445
+ if( g.fSshTrace){
446
+ printf("Reading %d bytes with %d on hand... ", N, onHand);
447
+ fflush(stdout);
448
+ }
444449
if( onHand>0 ){
445450
int toMove = onHand;
446451
if( toMove>N ) toMove = N;
447452
/* printf("bytes on hand: %d of %d\n", toMove, N); fflush(stdout); */
448453
memcpy(zBuf, &transport.pBuf[transport.iCursor], toMove);
@@ -460,10 +465,11 @@
460465
if( got>0 ){
461466
nByte += got;
462467
transport.nRcvd += got;
463468
}
464469
}
470
+ if( g.fSshTrace ) printf("Got %d bytes\n", nByte);
465471
return nByte;
466472
}
467473
468474
/*
469475
** Load up to N new bytes of content into the transport.pBuf buffer.
@@ -532,11 +538,11 @@
532538
}
533539
break;
534540
}
535541
i++;
536542
}
537
- /* printf("Got line: [%s]\n", &transport.pBuf[iStart]); */
543
+ if( g.fSshTrace ) printf("Got line: [%s]\n", &transport.pBuf[iStart]);
538544
return &transport.pBuf[iStart];
539545
}
540546
541547
void transport_global_shutdown(void){
542548
if( g.urlIsSsh && sshPid ){
543549
--- src/http_transport.c
+++ src/http_transport.c
@@ -183,10 +183,11 @@
183 ** and run an SSH command to talk to the remote machine.
184 */
185 const char *zSsh; /* The base SSH command */
186 Blob zCmd; /* The SSH command */
187 char *zHost; /* The host name to contact */
 
188
189 zSsh = db_get("ssh-command", zDefaultSshCmd);
190 blob_init(&zCmd, zSsh, -1);
191 if( g.urlPort!=g.urlDfltPort ){
192 #ifdef __MINGW32__
@@ -219,13 +220,15 @@
219 }
220 #endif
221 }else{
222 zHost = mprintf("%s", g.urlName);
223 }
 
224 blob_append(&zCmd, " ", 1);
225 shell_escape(&zCmd, zHost);
226 fossil_print(" %s\n", zHost); /* Show the conclusion of the SSH command */
 
227 free(zHost);
228 popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid);
229 if( sshPid==0 ){
230 fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd);
231 }
@@ -251,13 +254,13 @@
251 Blob cmd;
252 blob_zero(&cmd);
253 shell_escape(&cmd, g.urlFossil);
254 blob_append(&cmd, " test-http ", -1);
255 shell_escape(&cmd, g.urlPath);
256 /* printf("%s\n", blob_str(&cmd)); fflush(stdout); */
257 fprintf(sshOut, "%s\n", blob_str(&cmd));
258 fflush(sshOut);
 
259 blob_reset(&cmd);
260 }else if( g.urlIsHttps ){
261 #ifdef FOSSIL_ENABLE_SSL
262 rc = ssl_open();
263 if( rc==0 ) transport.isOpen = 1;
@@ -403,11 +406,10 @@
403 int got;
404 if( sshIn ){
405 int x;
406 int wanted = N;
407 got = 0;
408 /* printf("want %d bytes...\n", wanted); fflush(stdout); */
409 while( wanted>0 ){
410 x = read(sshIn, &zBuf[got], wanted);
411 if( x<=0 ) break;
412 got += x;
413 wanted -= x;
@@ -438,11 +440,14 @@
438 int transport_receive(char *zBuf, int N){
439 int onHand; /* Bytes current held in the transport buffer */
440 int nByte = 0; /* Bytes of content received */
441
442 onHand = transport.nUsed - transport.iCursor;
443 /* printf("request %d with %d on hand\n", N, onHand); fflush(stdout); */
 
 
 
444 if( onHand>0 ){
445 int toMove = onHand;
446 if( toMove>N ) toMove = N;
447 /* printf("bytes on hand: %d of %d\n", toMove, N); fflush(stdout); */
448 memcpy(zBuf, &transport.pBuf[transport.iCursor], toMove);
@@ -460,10 +465,11 @@
460 if( got>0 ){
461 nByte += got;
462 transport.nRcvd += got;
463 }
464 }
 
465 return nByte;
466 }
467
468 /*
469 ** Load up to N new bytes of content into the transport.pBuf buffer.
@@ -532,11 +538,11 @@
532 }
533 break;
534 }
535 i++;
536 }
537 /* printf("Got line: [%s]\n", &transport.pBuf[iStart]); */
538 return &transport.pBuf[iStart];
539 }
540
541 void transport_global_shutdown(void){
542 if( g.urlIsSsh && sshPid ){
543
--- src/http_transport.c
+++ src/http_transport.c
@@ -183,10 +183,11 @@
183 ** and run an SSH command to talk to the remote machine.
184 */
185 const char *zSsh; /* The base SSH command */
186 Blob zCmd; /* The SSH command */
187 char *zHost; /* The host name to contact */
188 int n; /* Size of prefix string */
189
190 zSsh = db_get("ssh-command", zDefaultSshCmd);
191 blob_init(&zCmd, zSsh, -1);
192 if( g.urlPort!=g.urlDfltPort ){
193 #ifdef __MINGW32__
@@ -219,13 +220,15 @@
220 }
221 #endif
222 }else{
223 zHost = mprintf("%s", g.urlName);
224 }
225 n = blob_size(&zCmd);
226 blob_append(&zCmd, " ", 1);
227 shell_escape(&zCmd, zHost);
228 if( g.urlShell ) blob_appendf(&zCmd, " %s", g.urlShell);
229 fossil_print("%s\n", blob_str(&zCmd)+n); /* Show tail of SSH command */
230 free(zHost);
231 popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid);
232 if( sshPid==0 ){
233 fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd);
234 }
@@ -251,13 +254,13 @@
254 Blob cmd;
255 blob_zero(&cmd);
256 shell_escape(&cmd, g.urlFossil);
257 blob_append(&cmd, " test-http ", -1);
258 shell_escape(&cmd, g.urlPath);
259 fprintf(sshOut, "%s || true\n", blob_str(&cmd));
 
260 fflush(sshOut);
261 if( g.fSshTrace ) printf("Sent: [%s]\n", blob_str(&cmd));
262 blob_reset(&cmd);
263 }else if( g.urlIsHttps ){
264 #ifdef FOSSIL_ENABLE_SSL
265 rc = ssl_open();
266 if( rc==0 ) transport.isOpen = 1;
@@ -403,11 +406,10 @@
406 int got;
407 if( sshIn ){
408 int x;
409 int wanted = N;
410 got = 0;
 
411 while( wanted>0 ){
412 x = read(sshIn, &zBuf[got], wanted);
413 if( x<=0 ) break;
414 got += x;
415 wanted -= x;
@@ -438,11 +440,14 @@
440 int transport_receive(char *zBuf, int N){
441 int onHand; /* Bytes current held in the transport buffer */
442 int nByte = 0; /* Bytes of content received */
443
444 onHand = transport.nUsed - transport.iCursor;
445 if( g.fSshTrace){
446 printf("Reading %d bytes with %d on hand... ", N, onHand);
447 fflush(stdout);
448 }
449 if( onHand>0 ){
450 int toMove = onHand;
451 if( toMove>N ) toMove = N;
452 /* printf("bytes on hand: %d of %d\n", toMove, N); fflush(stdout); */
453 memcpy(zBuf, &transport.pBuf[transport.iCursor], toMove);
@@ -460,10 +465,11 @@
465 if( got>0 ){
466 nByte += got;
467 transport.nRcvd += got;
468 }
469 }
470 if( g.fSshTrace ) printf("Got %d bytes\n", nByte);
471 return nByte;
472 }
473
474 /*
475 ** Load up to N new bytes of content into the transport.pBuf buffer.
@@ -532,11 +538,11 @@
538 }
539 break;
540 }
541 i++;
542 }
543 if( g.fSshTrace ) printf("Got line: [%s]\n", &transport.pBuf[iStart]);
544 return &transport.pBuf[iStart];
545 }
546
547 void transport_global_shutdown(void){
548 if( g.urlIsSsh && sshPid ){
549
+2 -1
--- src/main.c
+++ src/main.c
@@ -170,11 +170,12 @@
170170
char *urlPath; /* Pathname for http: */
171171
char *urlUser; /* User id for http: */
172172
char *urlPasswd; /* Password for http: */
173173
char *urlCanonical; /* Canonical representation of the URL */
174174
char *urlProxyAuth; /* Proxy-Authorizer: string */
175
- char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */
175
+ char *urlFossil; /* The fossil query parameter on ssh: */
176
+ char *urlShell; /* The shell query parameter on ssh: */
176177
int dontKeepUrl; /* Do not persist the URL */
177178
178179
const char *zLogin; /* Login name. "" if not logged in. */
179180
const char *zSSLIdentity; /* Value of --ssl-identity option, filename of SSL client identity */
180181
int useLocalauth; /* No login required if from 127.0.0.1 */
181182
--- src/main.c
+++ src/main.c
@@ -170,11 +170,12 @@
170 char *urlPath; /* Pathname for http: */
171 char *urlUser; /* User id for http: */
172 char *urlPasswd; /* Password for http: */
173 char *urlCanonical; /* Canonical representation of the URL */
174 char *urlProxyAuth; /* Proxy-Authorizer: string */
175 char *urlFossil; /* The path of the ?fossil=path suffix on ssh: */
 
176 int dontKeepUrl; /* Do not persist the URL */
177
178 const char *zLogin; /* Login name. "" if not logged in. */
179 const char *zSSLIdentity; /* Value of --ssl-identity option, filename of SSL client identity */
180 int useLocalauth; /* No login required if from 127.0.0.1 */
181
--- src/main.c
+++ src/main.c
@@ -170,11 +170,12 @@
170 char *urlPath; /* Pathname for http: */
171 char *urlUser; /* User id for http: */
172 char *urlPasswd; /* Password for http: */
173 char *urlCanonical; /* Canonical representation of the URL */
174 char *urlProxyAuth; /* Proxy-Authorizer: string */
175 char *urlFossil; /* The fossil query parameter on ssh: */
176 char *urlShell; /* The shell query parameter on ssh: */
177 int dontKeepUrl; /* Do not persist the URL */
178
179 const char *zLogin; /* Login name. "" if not logged in. */
180 const char *zSSLIdentity; /* Value of --ssl-identity option, filename of SSL client identity */
181 int useLocalauth; /* No login required if from 127.0.0.1 */
182
+10 -1
--- src/url.c
+++ src/url.c
@@ -63,10 +63,11 @@
6363
|| strncmp(zUrl, "ssh://", 6)==0
6464
){
6565
int iStart;
6666
char *zLogin;
6767
char *zExe;
68
+ char cQuerySep = '?';
6869
6970
g.urlIsFile = 0;
7071
if( zUrl[4]=='s' ){
7172
g.urlIsHttps = 1;
7273
g.urlProtocol = "https";
@@ -75,10 +76,11 @@
7576
}else if( zUrl[0]=='s' ){
7677
g.urlIsSsh = 1;
7778
g.urlProtocol = "ssh";
7879
g.urlDfltPort = 22;
7980
g.urlFossil = "fossil";
81
+ g.urlShell = 0;
8082
iStart = 6;
8183
}else{
8284
g.urlIsHttps = 0;
8385
g.urlProtocol = "http";
8486
g.urlDfltPort = 80;
@@ -144,11 +146,18 @@
144146
i++;
145147
}
146148
if( fossil_strcmp(zName,"fossil")==0 ){
147149
g.urlFossil = zValue;
148150
dehttpize(g.urlFossil);
149
- zExe = mprintf("?fossil=%T", g.urlFossil);
151
+ zExe = mprintf("%cfossil=%T", cQuerySep, g.urlFossil);
152
+ cQuerySep = '&';
153
+ }
154
+ if( fossil_strcmp(zName,"shell")==0 ){
155
+ g.urlShell = zValue;
156
+ dehttpize(g.urlShell);
157
+ zExe = mprintf("%cshell=%T", cQuerySep, g.urlFossil);
158
+ cQuerySep = '&';
150159
}
151160
}
152161
153162
dehttpize(g.urlPath);
154163
if( g.urlDfltPort==g.urlPort ){
155164
--- src/url.c
+++ src/url.c
@@ -63,10 +63,11 @@
63 || strncmp(zUrl, "ssh://", 6)==0
64 ){
65 int iStart;
66 char *zLogin;
67 char *zExe;
 
68
69 g.urlIsFile = 0;
70 if( zUrl[4]=='s' ){
71 g.urlIsHttps = 1;
72 g.urlProtocol = "https";
@@ -75,10 +76,11 @@
75 }else if( zUrl[0]=='s' ){
76 g.urlIsSsh = 1;
77 g.urlProtocol = "ssh";
78 g.urlDfltPort = 22;
79 g.urlFossil = "fossil";
 
80 iStart = 6;
81 }else{
82 g.urlIsHttps = 0;
83 g.urlProtocol = "http";
84 g.urlDfltPort = 80;
@@ -144,11 +146,18 @@
144 i++;
145 }
146 if( fossil_strcmp(zName,"fossil")==0 ){
147 g.urlFossil = zValue;
148 dehttpize(g.urlFossil);
149 zExe = mprintf("?fossil=%T", g.urlFossil);
 
 
 
 
 
 
 
150 }
151 }
152
153 dehttpize(g.urlPath);
154 if( g.urlDfltPort==g.urlPort ){
155
--- src/url.c
+++ src/url.c
@@ -63,10 +63,11 @@
63 || strncmp(zUrl, "ssh://", 6)==0
64 ){
65 int iStart;
66 char *zLogin;
67 char *zExe;
68 char cQuerySep = '?';
69
70 g.urlIsFile = 0;
71 if( zUrl[4]=='s' ){
72 g.urlIsHttps = 1;
73 g.urlProtocol = "https";
@@ -75,10 +76,11 @@
76 }else if( zUrl[0]=='s' ){
77 g.urlIsSsh = 1;
78 g.urlProtocol = "ssh";
79 g.urlDfltPort = 22;
80 g.urlFossil = "fossil";
81 g.urlShell = 0;
82 iStart = 6;
83 }else{
84 g.urlIsHttps = 0;
85 g.urlProtocol = "http";
86 g.urlDfltPort = 80;
@@ -144,11 +146,18 @@
146 i++;
147 }
148 if( fossil_strcmp(zName,"fossil")==0 ){
149 g.urlFossil = zValue;
150 dehttpize(g.urlFossil);
151 zExe = mprintf("%cfossil=%T", cQuerySep, g.urlFossil);
152 cQuerySep = '&';
153 }
154 if( fossil_strcmp(zName,"shell")==0 ){
155 g.urlShell = zValue;
156 dehttpize(g.urlShell);
157 zExe = mprintf("%cshell=%T", cQuerySep, g.urlFossil);
158 cQuerySep = '&';
159 }
160 }
161
162 dehttpize(g.urlPath);
163 if( g.urlDfltPort==g.urlPort ){
164

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button