Overview
Artifact ID: | bd5b83c0e4afc14b95e1792864df31043d70b35b |
---|---|
Ticket: | 77de516a1f2bfc1bd996a8520d0ce59b1b324e77 |
Date: | 2010-10-16 15:13:45 |
User: | wolfgang |
Artifact Attached: | cf43d53bceca4ca4c28304bc2377870922038c65 |
Filename: | patch-hook.txt |
Description: |
Content Appended
1 CHANGED src/db.c 2 Index: src/db.c 3 =================================================================== 4 --- src/db.c 5 +++ src/db.c 6 @@ -1525,10 +1525,16 @@ 7 { "http-port", 0, 16, "8080" }, 8 { "localauth", 0, 0, "0" }, 9 { "mtime-changes", 0, 0, "0" }, 10 { "pgp-command", 0, 32, "gpg --clearsign -o " }, 11 { "proxy", 0, 32, "off" }, 12 + { "push-hook-pattern-client", 13 + 0, 32, "" }, 14 + { "push-hook-pattern-cmd", 15 + 0, 32, "" }, 16 + { "push-hook-pattern-server", 17 + 0, 32, "" }, 18 { "ssh-command", 0, 32, "" }, 19 { "web-browser", 0, 32, "" }, 20 { 0,0,0,0 } 21 }; 22 23 @@ -1596,10 +1602,26 @@ 24 ** 25 ** proxy URL of the HTTP proxy. If undefined or "off" then 26 ** the "http_proxy" environment variable is consulted. 27 ** If the http_proxy environment variable is undefined 28 ** then a direct HTTP connection is used. 29 +** 30 +** push-hook-pattern-client 31 +** if set, a client push will sent this message to the 32 +** server, to activate the push hook command. 33 +** 34 +** push-hook-pattern-cmd 35 +** this is the command line, that will be activated 36 +** as push hook. Output redirects should be added to 37 +** this command line. 38 +** The complete pattern, sent by the client will be 39 +** appended to the command line. 40 +** 41 +** push-hook-pattern-server 42 +** if set, and a client send this pattern at the end of 43 +** a push, the push hook command will be executed. This 44 +** might be a prefix of the pattern, sent by the client. 45 ** 46 ** ssh-command Command used to talk to a remote machine with 47 ** the "ssh://" protocol. 48 ** 49 ** web-browser A shell command used to launch your preferred 50 51 CHANGED src/xfer.c 52 Index: src/xfer.c 53 =================================================================== 54 --- src/xfer.c 55 +++ src/xfer.c 56 @@ -40,10 +40,32 @@ 57 int nDeltaRcvd; /* Number of deltas received */ 58 int nDanglingFile; /* Number of dangling deltas received */ 59 int mxSend; /* Stop sending "file" with pOut reaches this size */ 60 }; 61 62 +/* 63 +** Let a server-side external agent know that a push has completed. /fatman 64 +*/ 65 +void post_push_hook(char const * const zPushHookLine){ 66 + /* 67 + ** TO DO: get the string cmd from a config file? Or the database local 68 + ** settings, as someone suggested? Ditto output and error logs. /fatman 69 + */ 70 + const char *zCmd = db_get("push-hook-pattern-cmd", ""); 71 + 72 + if( zCmd && zCmd[0] ){ 73 + int rc; 74 + char * zCalledCmd; 75 + 76 + zCalledCmd = mprintf("%s %s",zCmd,zPushHookLine); 77 + rc = system(zCalledCmd); 78 + if (rc != 0) { 79 + fossil_print("The post-push-hook command \"%s\" failed.", zCalledCmd); 80 + } 81 + free(zCalledCmd); 82 + } 83 +} 84 85 /* 86 ** The input blob contains a UUID. Convert it into a record ID. 87 ** Create a phantom record if no prior record exists and 88 ** phantomize is true. 89 @@ -596,10 +618,13 @@ 90 int isClone = 0; 91 int nGimme = 0; 92 int size; 93 int recvConfig = 0; 94 char *zNow; 95 + const char *zPushHookPattern = db_get("push-hook-pattern-server", ""); 96 + int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0]) 97 + ? strlen(zPushHookPattern) : 0; 98 99 if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){ 100 fossil_redirect_home(); 101 } 102 memset(&xfer, 0, sizeof(xfer)); 103 @@ -617,11 +642,19 @@ 104 ); 105 zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')"); 106 @ # timestamp %s(zNow) 107 manifest_crosslink_begin(); 108 while( blob_line(xfer.pIn, &xfer.line) ){ 109 - if( blob_buffer(&xfer.line)[0]=='#' ) continue; 110 + if( blob_buffer(&xfer.line)[0]=='#' ){ 111 + if( lenPushHookPattern 112 + && 0 == memcmp(blob_buffer(&xfer.line)+1, 113 + zPushHookPattern, lenPushHookPattern) 114 + ){ 115 + post_push_hook(blob_buffer(&xfer.line)+1); 116 + } 117 + continue; 118 + } 119 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken)); 120 121 /* file UUID SIZE \n CONTENT 122 ** file UUID DELTASRC SIZE \n CONTENT 123 ** 124 @@ -948,10 +981,12 @@ 125 Blob send; /* Text we are sending to the server */ 126 Blob recv; /* Reply we got back from the server */ 127 Xfer xfer; /* Transfer data */ 128 const char *zSCode = db_get("server-code", "x"); 129 const char *zPCode = db_get("project-code", 0); 130 + const char *zPushHookPattern = db_get("push-hook-pattern-client", ""); 131 + 132 133 if( db_get_boolean("dont-push", 0) ) pushFlag = 0; 134 if( pushFlag + pullFlag + cloneFlag == 0 135 && configRcvMask==0 && configSendMask==0 ) return; 136 137 @@ -1330,14 +1365,22 @@ 138 } 139 140 /* If this is a clone, the go at least two rounds */ 141 if( cloneFlag && nCycle==1 ) go = 1; 142 }; 143 + if (pushFlag && nFileSend > 0) { 144 + if( zPushHookPattern && zPushHookPattern[0] ){ 145 + blob_appendf(&send, "#%s\n", zPushHookPattern); 146 + http_exchange(&send, &recv, cloneFlag==0 || nCycle>0); 147 + blob_reset(&send); 148 + nCardSent++; 149 + } 150 + } 151 transport_stats(&nSent, &nRcvd, 1); 152 fossil_print("Total network traffic: %d bytes sent, %d bytes received\n", 153 nSent, nRcvd); 154 transport_close(); 155 transport_global_shutdown(); 156 db_multi_exec("DROP TABLE onremote"); 157 manifest_crosslink_end(); 158 db_end_transaction(0); 159 } 160