Fossil SCM

merge from old hook branch

wolfgang 2010-10-17 16:37 StvPrivateHook2 --bgcolor yellow --private
Commit 9cf288de27c2eb720cab38f03b0890ae926e79e5
3 files changed +20 +3 +83 -1
+20
--- src/db.c
+++ src/db.c
@@ -1525,10 +1525,15 @@
15251525
{ "http-port", 0, 16, "8080" },
15261526
{ "localauth", 0, 0, "0" },
15271527
{ "mtime-changes", 0, 0, "0" },
15281528
{ "pgp-command", 0, 32, "gpg --clearsign -o " },
15291529
{ "proxy", 0, 32, "off" },
1530
+ { "push-hook-cmd", 0, 32, "" },
1531
+ { "push-hook-pattern-client",
1532
+ 0, 32, "" },
1533
+ { "push-hook-pattern-server",
1534
+ 0, 32, "" },
15301535
{ "ssh-command", 0, 32, "" },
15311536
{ "web-browser", 0, 32, "" },
15321537
{ 0,0,0,0 }
15331538
};
15341539
@@ -1597,10 +1602,25 @@
15971602
** proxy URL of the HTTP proxy. If undefined or "off" then
15981603
** the "http_proxy" environment variable is consulted.
15991604
** If the http_proxy environment variable is undefined
16001605
** then a direct HTTP connection is used.
16011606
**
1607
+** push-hook-cmd this is the command line, that will be activated
1608
+** as push hook. Output redirects should be added to
1609
+** this command line.
1610
+** The complete pattern, sent by the client will be
1611
+** appended to the command line.
1612
+**
1613
+** push-hook-pattern-client
1614
+** if set, a client push will sent this message to the
1615
+** server, to activate the push hook command.
1616
+**
1617
+** push-hook-pattern-server
1618
+** if set, and a client send this pattern at the end of
1619
+** a push, the push hook command will be executed. This
1620
+** might be a prefix of the pattern, sent by the client.
1621
+**
16021622
** ssh-command Command used to talk to a remote machine with
16031623
** the "ssh://" protocol.
16041624
**
16051625
** web-browser A shell command used to launch your preferred
16061626
** web browser when given a URL as an argument.
16071627
--- src/db.c
+++ src/db.c
@@ -1525,10 +1525,15 @@
1525 { "http-port", 0, 16, "8080" },
1526 { "localauth", 0, 0, "0" },
1527 { "mtime-changes", 0, 0, "0" },
1528 { "pgp-command", 0, 32, "gpg --clearsign -o " },
1529 { "proxy", 0, 32, "off" },
 
 
 
 
 
1530 { "ssh-command", 0, 32, "" },
1531 { "web-browser", 0, 32, "" },
1532 { 0,0,0,0 }
1533 };
1534
@@ -1597,10 +1602,25 @@
1597 ** proxy URL of the HTTP proxy. If undefined or "off" then
1598 ** the "http_proxy" environment variable is consulted.
1599 ** If the http_proxy environment variable is undefined
1600 ** then a direct HTTP connection is used.
1601 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1602 ** ssh-command Command used to talk to a remote machine with
1603 ** the "ssh://" protocol.
1604 **
1605 ** web-browser A shell command used to launch your preferred
1606 ** web browser when given a URL as an argument.
1607
--- src/db.c
+++ src/db.c
@@ -1525,10 +1525,15 @@
1525 { "http-port", 0, 16, "8080" },
1526 { "localauth", 0, 0, "0" },
1527 { "mtime-changes", 0, 0, "0" },
1528 { "pgp-command", 0, 32, "gpg --clearsign -o " },
1529 { "proxy", 0, 32, "off" },
1530 { "push-hook-cmd", 0, 32, "" },
1531 { "push-hook-pattern-client",
1532 0, 32, "" },
1533 { "push-hook-pattern-server",
1534 0, 32, "" },
1535 { "ssh-command", 0, 32, "" },
1536 { "web-browser", 0, 32, "" },
1537 { 0,0,0,0 }
1538 };
1539
@@ -1597,10 +1602,25 @@
1602 ** proxy URL of the HTTP proxy. If undefined or "off" then
1603 ** the "http_proxy" environment variable is consulted.
1604 ** If the http_proxy environment variable is undefined
1605 ** then a direct HTTP connection is used.
1606 **
1607 ** push-hook-cmd this is the command line, that will be activated
1608 ** as push hook. Output redirects should be added to
1609 ** this command line.
1610 ** The complete pattern, sent by the client will be
1611 ** appended to the command line.
1612 **
1613 ** push-hook-pattern-client
1614 ** if set, a client push will sent this message to the
1615 ** server, to activate the push hook command.
1616 **
1617 ** push-hook-pattern-server
1618 ** if set, and a client send this pattern at the end of
1619 ** a push, the push hook command will be executed. This
1620 ** might be a prefix of the pattern, sent by the client.
1621 **
1622 ** ssh-command Command used to talk to a remote machine with
1623 ** the "ssh://" protocol.
1624 **
1625 ** web-browser A shell command used to launch your preferred
1626 ** web browser when given a URL as an argument.
1627
+3
--- src/sync.c
+++ src/sync.c
@@ -164,10 +164,13 @@
164164
**
165165
** The URL specified normally becomes the new "remote-url" used for
166166
** subsequent <a>push</a>, <a>pull</a>, and <a>sync</a> operations. However,
167167
** the "--once" command-line option makes the URL a one-time-use URL
168168
** that is not saved.
169
+**
170
+** If configured (<a>setting</a> push-hook-..), the push hook command will be executed
171
+** after pushing files to the server.
169172
**
170173
** See also: <a>clone</a>, <a>pull</a>, <a>sync</a>, <a>remote-url</a>
171174
*/
172175
void push_cmd(void){
173176
process_sync_args();
174177
--- src/sync.c
+++ src/sync.c
@@ -164,10 +164,13 @@
164 **
165 ** The URL specified normally becomes the new "remote-url" used for
166 ** subsequent <a>push</a>, <a>pull</a>, and <a>sync</a> operations. However,
167 ** the "--once" command-line option makes the URL a one-time-use URL
168 ** that is not saved.
 
 
 
169 **
170 ** See also: <a>clone</a>, <a>pull</a>, <a>sync</a>, <a>remote-url</a>
171 */
172 void push_cmd(void){
173 process_sync_args();
174
--- src/sync.c
+++ src/sync.c
@@ -164,10 +164,13 @@
164 **
165 ** The URL specified normally becomes the new "remote-url" used for
166 ** subsequent <a>push</a>, <a>pull</a>, and <a>sync</a> operations. However,
167 ** the "--once" command-line option makes the URL a one-time-use URL
168 ** that is not saved.
169 **
170 ** If configured (<a>setting</a> push-hook-..), the push hook command will be executed
171 ** after pushing files to the server.
172 **
173 ** See also: <a>clone</a>, <a>pull</a>, <a>sync</a>, <a>remote-url</a>
174 */
175 void push_cmd(void){
176 process_sync_args();
177
+83 -1
--- src/xfer.c
+++ src/xfer.c
@@ -40,10 +40,71 @@
4040
int nDeltaRcvd; /* Number of deltas received */
4141
int nDanglingFile; /* Number of dangling deltas received */
4242
int mxSend; /* Stop sending "file" with pOut reaches this size */
4343
};
4444
45
+/*
46
+** COMMAND: callhook
47
+** %fossil callhook PUSHHOOKPATTERN ?--force|-f?
48
+**
49
+** Call the push hook command on a server, which will normally be called
50
+** after a client push (<a>setting</a> push-hook-cmd).
51
+**
52
+** If --force is used, the given pattern is not checked against the
53
+** configuration (<a>setting</a> push-hook-pattern-server).
54
+**
55
+** This command only works on the server side, it does not send a message
56
+** from a client, but executes the hook directly on the server.
57
+**
58
+** See also <a>push</a>, <a>sync</a>, <a>setting</a>
59
+*/
60
+void callhook_cmd(void){
61
+ int forceFlag = find_option("force","f",0)!=0;
62
+
63
+ db_open_config(1);
64
+ db_find_and_open_repository(0);
65
+ if( (g.argc!=3) || (!g.argv[2]) || (!g.argv[2][0]) ){
66
+ usage("PUSHHOOKPATTERN ?--force?");
67
+ }
68
+ if( !forceFlag ){
69
+ const char *zPushHookPattern = db_get("push-hook-pattern-server", "");
70
+ int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0])
71
+ ? strlen(zPushHookPattern) : 0;
72
+ if( (!lenPushHookPattern)
73
+ || memcmp(g.argv[2], zPushHookPattern, lenPushHookPattern)
74
+ ){
75
+ fossil_fatal("push hook pattern '%s' doesn't match configuration '%s'\n",
76
+ g.argv[2],zPushHookPattern);
77
+ }
78
+ }
79
+ post_push_hook(g.argv[2]);
80
+}
81
+
82
+/*
83
+** Let a server-side external agent know that a push has completed. /fatman
84
+*/
85
+void post_push_hook(char const * const zPushHookLine){
86
+ /*
87
+ ** TO DO: get the string cmd from a config file? Or the database local
88
+ ** settings, as someone suggested? Ditto output and error logs. /fatman
89
+ */
90
+ const char *zCmd = db_get("push-hook-cmd", "");
91
+
92
+ if( zCmd && zCmd[0] ){
93
+ int rc;
94
+ char * zCalledCmd;
95
+
96
+ zCalledCmd = mprintf("%s %s",zCmd,zPushHookLine);
97
+ rc = system(zCalledCmd);
98
+ if (rc != 0) {
99
+ fossil_print("The post-push-hook command \"%s\" failed.", zCalledCmd);
100
+ }
101
+ free(zCalledCmd);
102
+ }else{
103
+ fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine);
104
+ }
105
+}
45106
46107
/*
47108
** The input blob contains a UUID. Convert it into a record ID.
48109
** Create a phantom record if no prior record exists and
49110
** phantomize is true.
@@ -596,10 +657,13 @@
596657
int isClone = 0;
597658
int nGimme = 0;
598659
int size;
599660
int recvConfig = 0;
600661
char *zNow;
662
+ const char *zPushHookPattern = db_get("push-hook-pattern-server", "");
663
+ int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0])
664
+ ? strlen(zPushHookPattern) : 0;
601665
602666
if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
603667
fossil_redirect_home();
604668
}
605669
memset(&xfer, 0, sizeof(xfer));
@@ -617,11 +681,19 @@
617681
);
618682
zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
619683
@ # timestamp %s(zNow)
620684
manifest_crosslink_begin();
621685
while( blob_line(xfer.pIn, &xfer.line) ){
622
- if( blob_buffer(&xfer.line)[0]=='#' ) continue;
686
+ if( blob_buffer(&xfer.line)[0]=='#' ){
687
+ if( lenPushHookPattern
688
+ && 0 == memcmp(blob_buffer(&xfer.line)+1,
689
+ zPushHookPattern, lenPushHookPattern)
690
+ ){
691
+ post_push_hook(blob_buffer(&xfer.line)+1);
692
+ }
693
+ continue;
694
+ }
623695
xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
624696
625697
/* file UUID SIZE \n CONTENT
626698
** file UUID DELTASRC SIZE \n CONTENT
627699
**
@@ -948,10 +1020,12 @@
9481020
Blob send; /* Text we are sending to the server */
9491021
Blob recv; /* Reply we got back from the server */
9501022
Xfer xfer; /* Transfer data */
9511023
const char *zSCode = db_get("server-code", "x");
9521024
const char *zPCode = db_get("project-code", 0);
1025
+ const char *zPushHookPattern = db_get("push-hook-pattern-client", "");
1026
+
9531027
9541028
if( db_get_boolean("dont-push", 0) ) pushFlag = 0;
9551029
if( pushFlag + pullFlag + cloneFlag == 0
9561030
&& configRcvMask==0 && configSendMask==0 ) return;
9571031
@@ -1330,14 +1404,22 @@
13301404
}
13311405
13321406
/* If this is a clone, the go at least two rounds */
13331407
if( cloneFlag && nCycle==1 ) go = 1;
13341408
};
1409
+ if (pushFlag && nFileSend > 0) {
1410
+ if( zPushHookPattern && zPushHookPattern[0] ){
1411
+ blob_appendf(&send, "#%s\n", zPushHookPattern);
1412
+ http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
1413
+ blob_reset(&send);
1414
+ nCardSent++;
1415
+ }
1416
+ }
13351417
transport_stats(&nSent, &nRcvd, 1);
13361418
fossil_print("Total network traffic: %d bytes sent, %d bytes received\n",
13371419
nSent, nRcvd);
13381420
transport_close();
13391421
transport_global_shutdown();
13401422
db_multi_exec("DROP TABLE onremote");
13411423
manifest_crosslink_end();
13421424
db_end_transaction(0);
13431425
}
13441426
--- src/xfer.c
+++ src/xfer.c
@@ -40,10 +40,71 @@
40 int nDeltaRcvd; /* Number of deltas received */
41 int nDanglingFile; /* Number of dangling deltas received */
42 int mxSend; /* Stop sending "file" with pOut reaches this size */
43 };
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46 /*
47 ** The input blob contains a UUID. Convert it into a record ID.
48 ** Create a phantom record if no prior record exists and
49 ** phantomize is true.
@@ -596,10 +657,13 @@
596 int isClone = 0;
597 int nGimme = 0;
598 int size;
599 int recvConfig = 0;
600 char *zNow;
 
 
 
601
602 if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
603 fossil_redirect_home();
604 }
605 memset(&xfer, 0, sizeof(xfer));
@@ -617,11 +681,19 @@
617 );
618 zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
619 @ # timestamp %s(zNow)
620 manifest_crosslink_begin();
621 while( blob_line(xfer.pIn, &xfer.line) ){
622 if( blob_buffer(&xfer.line)[0]=='#' ) continue;
 
 
 
 
 
 
 
 
623 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
624
625 /* file UUID SIZE \n CONTENT
626 ** file UUID DELTASRC SIZE \n CONTENT
627 **
@@ -948,10 +1020,12 @@
948 Blob send; /* Text we are sending to the server */
949 Blob recv; /* Reply we got back from the server */
950 Xfer xfer; /* Transfer data */
951 const char *zSCode = db_get("server-code", "x");
952 const char *zPCode = db_get("project-code", 0);
 
 
953
954 if( db_get_boolean("dont-push", 0) ) pushFlag = 0;
955 if( pushFlag + pullFlag + cloneFlag == 0
956 && configRcvMask==0 && configSendMask==0 ) return;
957
@@ -1330,14 +1404,22 @@
1330 }
1331
1332 /* If this is a clone, the go at least two rounds */
1333 if( cloneFlag && nCycle==1 ) go = 1;
1334 };
 
 
 
 
 
 
 
 
1335 transport_stats(&nSent, &nRcvd, 1);
1336 fossil_print("Total network traffic: %d bytes sent, %d bytes received\n",
1337 nSent, nRcvd);
1338 transport_close();
1339 transport_global_shutdown();
1340 db_multi_exec("DROP TABLE onremote");
1341 manifest_crosslink_end();
1342 db_end_transaction(0);
1343 }
1344
--- src/xfer.c
+++ src/xfer.c
@@ -40,10 +40,71 @@
40 int nDeltaRcvd; /* Number of deltas received */
41 int nDanglingFile; /* Number of dangling deltas received */
42 int mxSend; /* Stop sending "file" with pOut reaches this size */
43 };
44
45 /*
46 ** COMMAND: callhook
47 ** %fossil callhook PUSHHOOKPATTERN ?--force|-f?
48 **
49 ** Call the push hook command on a server, which will normally be called
50 ** after a client push (<a>setting</a> push-hook-cmd).
51 **
52 ** If --force is used, the given pattern is not checked against the
53 ** configuration (<a>setting</a> push-hook-pattern-server).
54 **
55 ** This command only works on the server side, it does not send a message
56 ** from a client, but executes the hook directly on the server.
57 **
58 ** See also <a>push</a>, <a>sync</a>, <a>setting</a>
59 */
60 void callhook_cmd(void){
61 int forceFlag = find_option("force","f",0)!=0;
62
63 db_open_config(1);
64 db_find_and_open_repository(0);
65 if( (g.argc!=3) || (!g.argv[2]) || (!g.argv[2][0]) ){
66 usage("PUSHHOOKPATTERN ?--force?");
67 }
68 if( !forceFlag ){
69 const char *zPushHookPattern = db_get("push-hook-pattern-server", "");
70 int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0])
71 ? strlen(zPushHookPattern) : 0;
72 if( (!lenPushHookPattern)
73 || memcmp(g.argv[2], zPushHookPattern, lenPushHookPattern)
74 ){
75 fossil_fatal("push hook pattern '%s' doesn't match configuration '%s'\n",
76 g.argv[2],zPushHookPattern);
77 }
78 }
79 post_push_hook(g.argv[2]);
80 }
81
82 /*
83 ** Let a server-side external agent know that a push has completed. /fatman
84 */
85 void post_push_hook(char const * const zPushHookLine){
86 /*
87 ** TO DO: get the string cmd from a config file? Or the database local
88 ** settings, as someone suggested? Ditto output and error logs. /fatman
89 */
90 const char *zCmd = db_get("push-hook-cmd", "");
91
92 if( zCmd && zCmd[0] ){
93 int rc;
94 char * zCalledCmd;
95
96 zCalledCmd = mprintf("%s %s",zCmd,zPushHookLine);
97 rc = system(zCalledCmd);
98 if (rc != 0) {
99 fossil_print("The post-push-hook command \"%s\" failed.", zCalledCmd);
100 }
101 free(zCalledCmd);
102 }else{
103 fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine);
104 }
105 }
106
107 /*
108 ** The input blob contains a UUID. Convert it into a record ID.
109 ** Create a phantom record if no prior record exists and
110 ** phantomize is true.
@@ -596,10 +657,13 @@
657 int isClone = 0;
658 int nGimme = 0;
659 int size;
660 int recvConfig = 0;
661 char *zNow;
662 const char *zPushHookPattern = db_get("push-hook-pattern-server", "");
663 int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0])
664 ? strlen(zPushHookPattern) : 0;
665
666 if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
667 fossil_redirect_home();
668 }
669 memset(&xfer, 0, sizeof(xfer));
@@ -617,11 +681,19 @@
681 );
682 zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
683 @ # timestamp %s(zNow)
684 manifest_crosslink_begin();
685 while( blob_line(xfer.pIn, &xfer.line) ){
686 if( blob_buffer(&xfer.line)[0]=='#' ){
687 if( lenPushHookPattern
688 && 0 == memcmp(blob_buffer(&xfer.line)+1,
689 zPushHookPattern, lenPushHookPattern)
690 ){
691 post_push_hook(blob_buffer(&xfer.line)+1);
692 }
693 continue;
694 }
695 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
696
697 /* file UUID SIZE \n CONTENT
698 ** file UUID DELTASRC SIZE \n CONTENT
699 **
@@ -948,10 +1020,12 @@
1020 Blob send; /* Text we are sending to the server */
1021 Blob recv; /* Reply we got back from the server */
1022 Xfer xfer; /* Transfer data */
1023 const char *zSCode = db_get("server-code", "x");
1024 const char *zPCode = db_get("project-code", 0);
1025 const char *zPushHookPattern = db_get("push-hook-pattern-client", "");
1026
1027
1028 if( db_get_boolean("dont-push", 0) ) pushFlag = 0;
1029 if( pushFlag + pullFlag + cloneFlag == 0
1030 && configRcvMask==0 && configSendMask==0 ) return;
1031
@@ -1330,14 +1404,22 @@
1404 }
1405
1406 /* If this is a clone, the go at least two rounds */
1407 if( cloneFlag && nCycle==1 ) go = 1;
1408 };
1409 if (pushFlag && nFileSend > 0) {
1410 if( zPushHookPattern && zPushHookPattern[0] ){
1411 blob_appendf(&send, "#%s\n", zPushHookPattern);
1412 http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
1413 blob_reset(&send);
1414 nCardSent++;
1415 }
1416 }
1417 transport_stats(&nSent, &nRcvd, 1);
1418 fossil_print("Total network traffic: %d bytes sent, %d bytes received\n",
1419 nSent, nRcvd);
1420 transport_close();
1421 transport_global_shutdown();
1422 db_multi_exec("DROP TABLE onremote");
1423 manifest_crosslink_end();
1424 db_end_transaction(0);
1425 }
1426

Keyboard Shortcuts

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