Fossil

Check-in [a94ef5c0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:some error corrections for force hook
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | StvPrivateHook2
Files: files | file ages | folders
SHA1:a94ef5c00dd9e6467fc93481003b541e54e33e13
User & Date: wolfgang 2010-10-18 19:40:55
References
2010-10-19
08:03 Ticket [77de516a] Post-push patch status still Open with 1 other change artifact: 5f9da2a9 user: wolfgang
Context
2010-10-19
14:55
adding flush to system-command, windows needs all buffers flushed before system execution check-in: a64b48cb user: wolfgang tags: StvPrivateHook2
2010-10-18
19:40
some error corrections for force hook check-in: a94ef5c0 user: wolfgang tags: StvPrivateHook2
15:46
added output redirect and client force for hook check-in: ccef28b5 user: wolfgang tags: StvPrivateHook2
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/xfer.c.

89
90
91
92
93
94
95
96


97
98
99
100
101
102
103
104
105
106
107
108
109
110

















111
112
113
114
115
116
117
118
119
120
...
696
697
698
699
700
701
702


703
704
705
706
707
708
709
710
711
....
1420
1421
1422
1423
1424
1425
1426
1427
1428

1429
1430
1431
1432
1433
1434
1435
void post_push_hook(char const * const zPushHookLine, const char requestType){
  /*
  ** TO DO: get the string cmd from a config file? Or the database local
  ** settings, as someone suggested? Ditto output and error logs. /fatman
  */
  const char *zCmd = db_get("push-hook-cmd", "");
  int allowForced = db_get_boolean("push-hook-force", 0);
  


  if( requestType=='P' && !allowForced){
    fossil_print("Forced push call from client not allowed,"
                 " skipping call for '%s'\n", zPushHookLine);
  }else if( zCmd && zCmd[0] ){
    int rc;
    char * zCalledCmd;
    char * zDate;
    const char *zRnd;


    zDate = db_text(0, "SELECT strftime('%%Y%%m%%d%%H%%M%%f','now')");
    zRnd = db_text(0, "SELECT lower(hex(randomblob(6)))");

    zCalledCmd = mprintf("%s %s-%s %s >hook-log-%s-%s 2>&1",zCmd,zDate,zRnd,zPushHookLine,zDate,zRnd);

















    rc = system(zCalledCmd);
    if (rc != 0) {
      fossil_print("The post-push-hook command \"%s\" failed.", zCalledCmd);
    }
    free(zCalledCmd);
    free(zDate);
  }else{
    fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine);
  }
}
................................................................................
  );
  zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
  @ # timestamp %s(zNow)
  manifest_crosslink_begin();
  while( blob_line(xfer.pIn, &xfer.line) ){
    if( blob_buffer(&xfer.line)[0]=='#' ){
      if(    lenPushHookPattern


          && 0 == memcmp(blob_buffer(&xfer.line)+1,
                         zPushHookPattern, lenPushHookPattern)
      ){
        post_push_hook(blob_buffer(&xfer.line)+2,blob_buffer(&xfer.line)[1]);
      }
      continue;
    }
    xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));

................................................................................
    }

    /* If this is a clone, the go at least two rounds */
    if( cloneFlag && nCycle==1 ) go = 1;
  };
  if( pushFlag && ( (nFileSend > 0) || allowForced ) ){
    if( zPushHookPattern && zPushHookPattern[0] ){
      blob_appendf(&send, "#%c%s\n",
                   ((nFileSend > 0)?'P':'F'), zPushHookPattern);

      http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
      blob_reset(&send);
      nCardSent++;
    }
  int allowForced = db_get_boolean("push-hook-force", 0);
  }
  transport_stats(&nSent, &nRcvd, 1);







|
>
>
|













>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|







 







>
>
|
|







 







|
|
>







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
....
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
void post_push_hook(char const * const zPushHookLine, const char requestType){
  /*
  ** TO DO: get the string cmd from a config file? Or the database local
  ** settings, as someone suggested? Ditto output and error logs. /fatman
  */
  const char *zCmd = db_get("push-hook-cmd", "");
  int allowForced = db_get_boolean("push-hook-force", 0);

  if( requestType!='P' &&  requestType!='C' && requestType!='F' ){
    fossil_print("Push hook wrong request type '%c'\n", requestType);
  }else if( requestType=='F' && !allowForced ){
    fossil_print("Forced push call from client not allowed,"
                 " skipping call for '%s'\n", zPushHookLine);
  }else if( zCmd && zCmd[0] ){
    int rc;
    char * zCalledCmd;
    char * zDate;
    const char *zRnd;


    zDate = db_text(0, "SELECT strftime('%%Y%%m%%d%%H%%M%%f','now')");
    zRnd = db_text(0, "SELECT lower(hex(randomblob(6)))");

    zCalledCmd = mprintf("%s %s-%s %s >hook-log-%s-%s 2>&1",zCmd,zDate,zRnd,zPushHookLine,zDate,zRnd);
    { /* remove newlines from command */
      char *zSrc, *zDest;

      for (zSrc=zDest=zCalledCmd;;zSrc++){
        switch( *zSrc ){
          case '\0':
            *zDest=0;
            break;
          default:
            *zDest++ = *zSrc;
            /* fall through is intended! */
          case '\n':
            continue;
        }
        break;
      }
    }
    rc = system(zCalledCmd);
    if (rc != 0) {
      fossil_print("The post-push-hook command '%s' failed.", zCalledCmd);
    }
    free(zCalledCmd);
    free(zDate);
  }else{
    fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine);
  }
}
................................................................................
  );
  zNow = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%S', 'now')");
  @ # timestamp %s(zNow)
  manifest_crosslink_begin();
  while( blob_line(xfer.pIn, &xfer.line) ){
    if( blob_buffer(&xfer.line)[0]=='#' ){
      if(    lenPushHookPattern
          && blob_buffer(&xfer.line)[1]
          && blob_buffer(&xfer.line)[2]
          && (0 == memcmp(blob_buffer(&xfer.line)+2,
                          zPushHookPattern, lenPushHookPattern))
      ){
        post_push_hook(blob_buffer(&xfer.line)+2,blob_buffer(&xfer.line)[1]);
      }
      continue;
    }
    xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));

................................................................................
    }

    /* If this is a clone, the go at least two rounds */
    if( cloneFlag && nCycle==1 ) go = 1;
  };
  if( pushFlag && ( (nFileSend > 0) || allowForced ) ){
    if( zPushHookPattern && zPushHookPattern[0] ){
      blob_appendf(&send, "#%s%s\n",
                   ((nFileSend > 0)?"P":"F"), zPushHookPattern);
      fossil_print("Triggering push hook %s '%s'\n",((nFileSend > 0)?"P":"F"),zPushHookPattern);
      http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
      blob_reset(&send);
      nCardSent++;
    }
  int allowForced = db_get_boolean("push-hook-force", 0);
  }
  transport_stats(&nSent, &nRcvd, 1);