Fossil SCM
some error corrections for force hook
Commit
a94ef5c00dd9e6467fc93481003b541e54e33e13
Parent
ccef28b54b3662d…
1 file changed
+29
-7
+29
-7
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -91,12 +91,14 @@ | ||
| 91 | 91 | ** TO DO: get the string cmd from a config file? Or the database local |
| 92 | 92 | ** settings, as someone suggested? Ditto output and error logs. /fatman |
| 93 | 93 | */ |
| 94 | 94 | const char *zCmd = db_get("push-hook-cmd", ""); |
| 95 | 95 | 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 ){ | |
| 98 | 100 | fossil_print("Forced push call from client not allowed," |
| 99 | 101 | " skipping call for '%s'\n", zPushHookLine); |
| 100 | 102 | }else if( zCmd && zCmd[0] ){ |
| 101 | 103 | int rc; |
| 102 | 104 | char * zCalledCmd; |
| @@ -106,13 +108,30 @@ | ||
| 106 | 108 | |
| 107 | 109 | zDate = db_text(0, "SELECT strftime('%%Y%%m%%d%%H%%M%%f','now')"); |
| 108 | 110 | zRnd = db_text(0, "SELECT lower(hex(randomblob(6)))"); |
| 109 | 111 | |
| 110 | 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 | + } | |
| 111 | 130 | rc = system(zCalledCmd); |
| 112 | 131 | 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); | |
| 114 | 133 | } |
| 115 | 134 | free(zCalledCmd); |
| 116 | 135 | free(zDate); |
| 117 | 136 | }else{ |
| 118 | 137 | fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine); |
| @@ -698,12 +717,14 @@ | ||
| 698 | 717 | @ # timestamp %s(zNow) |
| 699 | 718 | manifest_crosslink_begin(); |
| 700 | 719 | while( blob_line(xfer.pIn, &xfer.line) ){ |
| 701 | 720 | if( blob_buffer(&xfer.line)[0]=='#' ){ |
| 702 | 721 | 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)) | |
| 705 | 726 | ){ |
| 706 | 727 | post_push_hook(blob_buffer(&xfer.line)+2,blob_buffer(&xfer.line)[1]); |
| 707 | 728 | } |
| 708 | 729 | continue; |
| 709 | 730 | } |
| @@ -1422,12 +1443,13 @@ | ||
| 1422 | 1443 | /* If this is a clone, the go at least two rounds */ |
| 1423 | 1444 | if( cloneFlag && nCycle==1 ) go = 1; |
| 1424 | 1445 | }; |
| 1425 | 1446 | if( pushFlag && ( (nFileSend > 0) || allowForced ) ){ |
| 1426 | 1447 | 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); | |
| 1429 | 1451 | http_exchange(&send, &recv, cloneFlag==0 || nCycle>0); |
| 1430 | 1452 | blob_reset(&send); |
| 1431 | 1453 | nCardSent++; |
| 1432 | 1454 | } |
| 1433 | 1455 | int allowForced = db_get_boolean("push-hook-force", 0); |
| 1434 | 1456 |
| --- 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 |