Fossil SCM

some error corrections for force hook

wolfgang 2010-10-18 19:40 StvPrivateHook2
Commit a94ef5c00dd9e6467fc93481003b541e54e33e13
1 file changed +29 -7
+29 -7
--- src/xfer.c
+++ src/xfer.c
@@ -91,12 +91,14 @@
9191
** TO DO: get the string cmd from a config file? Or the database local
9292
** settings, as someone suggested? Ditto output and error logs. /fatman
9393
*/
9494
const char *zCmd = db_get("push-hook-cmd", "");
9595
int allowForced = db_get_boolean("push-hook-force", 0);
96
-
97
- if( requestType=='P' && !allowForced){
96
+
97
+ if( requestType!='P' && requestType!='C' && requestType!='F' ){
98
+ fossil_print("Push hook wrong request type '%c'\n", requestType);
99
+ }else if( requestType=='F' && !allowForced ){
98100
fossil_print("Forced push call from client not allowed,"
99101
" skipping call for '%s'\n", zPushHookLine);
100102
}else if( zCmd && zCmd[0] ){
101103
int rc;
102104
char * zCalledCmd;
@@ -106,13 +108,30 @@
106108
107109
zDate = db_text(0, "SELECT strftime('%%Y%%m%%d%%H%%M%%f','now')");
108110
zRnd = db_text(0, "SELECT lower(hex(randomblob(6)))");
109111
110112
zCalledCmd = mprintf("%s %s-%s %s >hook-log-%s-%s 2>&1",zCmd,zDate,zRnd,zPushHookLine,zDate,zRnd);
113
+ { /* remove newlines from command */
114
+ char *zSrc, *zDest;
115
+
116
+ for (zSrc=zDest=zCalledCmd;;zSrc++){
117
+ switch( *zSrc ){
118
+ case '\0':
119
+ *zDest=0;
120
+ break;
121
+ default:
122
+ *zDest++ = *zSrc;
123
+ /* fall through is intended! */
124
+ case '\n':
125
+ continue;
126
+ }
127
+ break;
128
+ }
129
+ }
111130
rc = system(zCalledCmd);
112131
if (rc != 0) {
113
- fossil_print("The post-push-hook command \"%s\" failed.", zCalledCmd);
132
+ fossil_print("The post-push-hook command '%s' failed.", zCalledCmd);
114133
}
115134
free(zCalledCmd);
116135
free(zDate);
117136
}else{
118137
fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine);
@@ -698,12 +717,14 @@
698717
@ # timestamp %s(zNow)
699718
manifest_crosslink_begin();
700719
while( blob_line(xfer.pIn, &xfer.line) ){
701720
if( blob_buffer(&xfer.line)[0]=='#' ){
702721
if( lenPushHookPattern
703
- && 0 == memcmp(blob_buffer(&xfer.line)+1,
704
- zPushHookPattern, lenPushHookPattern)
722
+ && blob_buffer(&xfer.line)[1]
723
+ && blob_buffer(&xfer.line)[2]
724
+ && (0 == memcmp(blob_buffer(&xfer.line)+2,
725
+ zPushHookPattern, lenPushHookPattern))
705726
){
706727
post_push_hook(blob_buffer(&xfer.line)+2,blob_buffer(&xfer.line)[1]);
707728
}
708729
continue;
709730
}
@@ -1422,12 +1443,13 @@
14221443
/* If this is a clone, the go at least two rounds */
14231444
if( cloneFlag && nCycle==1 ) go = 1;
14241445
};
14251446
if( pushFlag && ( (nFileSend > 0) || allowForced ) ){
14261447
if( zPushHookPattern && zPushHookPattern[0] ){
1427
- blob_appendf(&send, "#%c%s\n",
1428
- ((nFileSend > 0)?'P':'F'), zPushHookPattern);
1448
+ blob_appendf(&send, "#%s%s\n",
1449
+ ((nFileSend > 0)?"P":"F"), zPushHookPattern);
1450
+ fossil_print("Triggering push hook %s '%s'\n",((nFileSend > 0)?"P":"F"),zPushHookPattern);
14291451
http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
14301452
blob_reset(&send);
14311453
nCardSent++;
14321454
}
14331455
int allowForced = db_get_boolean("push-hook-force", 0);
14341456
--- src/xfer.c
+++ src/xfer.c
@@ -91,12 +91,14 @@
91 ** TO DO: get the string cmd from a config file? Or the database local
92 ** settings, as someone suggested? Ditto output and error logs. /fatman
93 */
94 const char *zCmd = db_get("push-hook-cmd", "");
95 int allowForced = db_get_boolean("push-hook-force", 0);
96
97 if( requestType=='P' && !allowForced){
 
 
98 fossil_print("Forced push call from client not allowed,"
99 " skipping call for '%s'\n", zPushHookLine);
100 }else if( zCmd && zCmd[0] ){
101 int rc;
102 char * zCalledCmd;
@@ -106,13 +108,30 @@
106
107 zDate = db_text(0, "SELECT strftime('%%Y%%m%%d%%H%%M%%f','now')");
108 zRnd = db_text(0, "SELECT lower(hex(randomblob(6)))");
109
110 zCalledCmd = mprintf("%s %s-%s %s >hook-log-%s-%s 2>&1",zCmd,zDate,zRnd,zPushHookLine,zDate,zRnd);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111 rc = system(zCalledCmd);
112 if (rc != 0) {
113 fossil_print("The post-push-hook command \"%s\" failed.", zCalledCmd);
114 }
115 free(zCalledCmd);
116 free(zDate);
117 }else{
118 fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine);
@@ -698,12 +717,14 @@
698 @ # timestamp %s(zNow)
699 manifest_crosslink_begin();
700 while( blob_line(xfer.pIn, &xfer.line) ){
701 if( blob_buffer(&xfer.line)[0]=='#' ){
702 if( lenPushHookPattern
703 && 0 == memcmp(blob_buffer(&xfer.line)+1,
704 zPushHookPattern, lenPushHookPattern)
 
 
705 ){
706 post_push_hook(blob_buffer(&xfer.line)+2,blob_buffer(&xfer.line)[1]);
707 }
708 continue;
709 }
@@ -1422,12 +1443,13 @@
1422 /* If this is a clone, the go at least two rounds */
1423 if( cloneFlag && nCycle==1 ) go = 1;
1424 };
1425 if( pushFlag && ( (nFileSend > 0) || allowForced ) ){
1426 if( zPushHookPattern && zPushHookPattern[0] ){
1427 blob_appendf(&send, "#%c%s\n",
1428 ((nFileSend > 0)?'P':'F'), zPushHookPattern);
 
1429 http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
1430 blob_reset(&send);
1431 nCardSent++;
1432 }
1433 int allowForced = db_get_boolean("push-hook-force", 0);
1434
--- src/xfer.c
+++ src/xfer.c
@@ -91,12 +91,14 @@
91 ** TO DO: get the string cmd from a config file? Or the database local
92 ** settings, as someone suggested? Ditto output and error logs. /fatman
93 */
94 const char *zCmd = db_get("push-hook-cmd", "");
95 int allowForced = db_get_boolean("push-hook-force", 0);
96
97 if( requestType!='P' && requestType!='C' && requestType!='F' ){
98 fossil_print("Push hook wrong request type '%c'\n", requestType);
99 }else if( requestType=='F' && !allowForced ){
100 fossil_print("Forced push call from client not allowed,"
101 " skipping call for '%s'\n", zPushHookLine);
102 }else if( zCmd && zCmd[0] ){
103 int rc;
104 char * zCalledCmd;
@@ -106,13 +108,30 @@
108
109 zDate = db_text(0, "SELECT strftime('%%Y%%m%%d%%H%%M%%f','now')");
110 zRnd = db_text(0, "SELECT lower(hex(randomblob(6)))");
111
112 zCalledCmd = mprintf("%s %s-%s %s >hook-log-%s-%s 2>&1",zCmd,zDate,zRnd,zPushHookLine,zDate,zRnd);
113 { /* remove newlines from command */
114 char *zSrc, *zDest;
115
116 for (zSrc=zDest=zCalledCmd;;zSrc++){
117 switch( *zSrc ){
118 case '\0':
119 *zDest=0;
120 break;
121 default:
122 *zDest++ = *zSrc;
123 /* fall through is intended! */
124 case '\n':
125 continue;
126 }
127 break;
128 }
129 }
130 rc = system(zCalledCmd);
131 if (rc != 0) {
132 fossil_print("The post-push-hook command '%s' failed.", zCalledCmd);
133 }
134 free(zCalledCmd);
135 free(zDate);
136 }else{
137 fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine);
@@ -698,12 +717,14 @@
717 @ # timestamp %s(zNow)
718 manifest_crosslink_begin();
719 while( blob_line(xfer.pIn, &xfer.line) ){
720 if( blob_buffer(&xfer.line)[0]=='#' ){
721 if( lenPushHookPattern
722 && blob_buffer(&xfer.line)[1]
723 && blob_buffer(&xfer.line)[2]
724 && (0 == memcmp(blob_buffer(&xfer.line)+2,
725 zPushHookPattern, lenPushHookPattern))
726 ){
727 post_push_hook(blob_buffer(&xfer.line)+2,blob_buffer(&xfer.line)[1]);
728 }
729 continue;
730 }
@@ -1422,12 +1443,13 @@
1443 /* If this is a clone, the go at least two rounds */
1444 if( cloneFlag && nCycle==1 ) go = 1;
1445 };
1446 if( pushFlag && ( (nFileSend > 0) || allowForced ) ){
1447 if( zPushHookPattern && zPushHookPattern[0] ){
1448 blob_appendf(&send, "#%s%s\n",
1449 ((nFileSend > 0)?"P":"F"), zPushHookPattern);
1450 fossil_print("Triggering push hook %s '%s'\n",((nFileSend > 0)?"P":"F"),zPushHookPattern);
1451 http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
1452 blob_reset(&send);
1453 nCardSent++;
1454 }
1455 int allowForced = db_get_boolean("push-hook-force", 0);
1456

Keyboard Shortcuts

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