Fossil SCM

The common script should be run even when no hook is set. Improvements to consistency and style of hook integration.

mistachkin 2014-01-10 22:13 delay-ticket-hook
Commit 7f39fb61cb0039ad4525f4d510eef85d7e5b84ab
2 files changed +17 -12 +13 -13
+17 -12
--- src/manifest.c
+++ src/manifest.c
@@ -1502,20 +1502,20 @@
15021502
int rc = TH_OK;
15031503
int permitHooks = (flags & MC_PERMIT_HOOKS);
15041504
const char *zScript = 0;
15051505
assert( manifest_crosslink_busy==1 );
15061506
if( permitHooks ){
1507
- zScript = xfer_ticket_code();
1508
- if( zScript ){
1509
- rc = xfer_run_common_script();
1507
+ rc = xfer_run_common_script();
1508
+ if( rc==TH_OK ){
1509
+ zScript = xfer_ticket_code();
15101510
}
15111511
}
15121512
db_prepare(&q, "SELECT uuid FROM pending_tkt");
15131513
while( db_step(&q)==SQLITE_ROW ){
15141514
const char *zUuid = db_column_text(&q, 0);
15151515
ticket_rebuild_entry(zUuid);
1516
- if( rc==TH_OK && zScript ){
1516
+ if( permitHooks && rc==TH_OK ){
15171517
rc = xfer_run_script(zScript, zUuid);
15181518
}
15191519
}
15201520
db_finalize(&q);
15211521
db_multi_exec("DROP TABLE pending_tkt");
@@ -1670,14 +1670,15 @@
16701670
** Processing for other control artifacts was added later. The name
16711671
** of the routine, "manifest_crosslink", and the name of this source
16721672
** file, is a legacy of its original use.
16731673
*/
16741674
int manifest_crosslink(int rid, Blob *pContent, int flags){
1675
- int i, result = TH_OK;
1675
+ int i, rc = TH_OK;
16761676
Manifest *p;
16771677
Stmt q;
16781678
int parentid = 0;
1679
+ int permitHooks = (flags & MC_PERMIT_HOOKS);
16791680
const char *zScript = 0;
16801681
const char *zUuid = 0;
16811682
16821683
if( (p = manifest_cache_find(rid))!=0 ){
16831684
blob_reset(pContent);
@@ -1698,11 +1699,13 @@
16981699
fossil_error(1, "cannot fetch baseline manifest");
16991700
return 0;
17001701
}
17011702
db_begin_transaction();
17021703
if( p->type==CFTYPE_MANIFEST ){
1703
- zScript = xfer_commit_code();
1704
+ if( permitHooks ){
1705
+ zScript = xfer_commit_code();
1706
+ }
17041707
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
17051708
if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
17061709
char *zCom;
17071710
for(i=0; i<p->nParent; i++){
17081711
int pid = uuid_to_rid(p->azParent[i], 1);
@@ -1979,11 +1982,13 @@
19791982
zTagUuid);
19801983
branchMove = 0;
19811984
if( db_exists("SELECT 1 FROM event, blob"
19821985
" WHERE event.type='ci' AND event.objid=blob.rid"
19831986
" AND blob.uuid='%s'", zTagUuid) ){
1984
- zScript = xfer_commit_code();
1987
+ if( permitHooks ){
1988
+ zScript = xfer_commit_code();
1989
+ }
19851990
zUuid = zTagUuid;
19861991
}
19871992
}
19881993
zName = p->aTag[i].zName;
19891994
zValue = p->aTag[i].zValue;
@@ -2053,23 +2058,23 @@
20532058
p->rDate, rid, p->zUser, blob_str(&comment)+1
20542059
);
20552060
blob_reset(&comment);
20562061
}
20572062
db_end_transaction(0);
2058
- if( zScript && (flags & MC_PERMIT_HOOKS) ){
2059
- result = xfer_run_common_script();
2060
- if( result==TH_OK ){
2061
- result = xfer_run_script(zScript, zUuid);
2063
+ if( permitHooks ){
2064
+ rc = xfer_run_common_script();
2065
+ if( rc==TH_OK ){
2066
+ rc = xfer_run_script(zScript, zUuid);
20622067
}
20632068
}
20642069
if( p->type==CFTYPE_MANIFEST ){
20652070
manifest_cache_insert(p);
20662071
}else{
20672072
manifest_destroy(p);
20682073
}
20692074
assert( blob_is_reset(pContent) );
2070
- return ( result!=TH_ERROR );
2075
+ return ( rc!=TH_ERROR );
20712076
}
20722077
20732078
/*
20742079
** COMMAND: test-crosslink
20752080
**
20762081
--- src/manifest.c
+++ src/manifest.c
@@ -1502,20 +1502,20 @@
1502 int rc = TH_OK;
1503 int permitHooks = (flags & MC_PERMIT_HOOKS);
1504 const char *zScript = 0;
1505 assert( manifest_crosslink_busy==1 );
1506 if( permitHooks ){
1507 zScript = xfer_ticket_code();
1508 if( zScript ){
1509 rc = xfer_run_common_script();
1510 }
1511 }
1512 db_prepare(&q, "SELECT uuid FROM pending_tkt");
1513 while( db_step(&q)==SQLITE_ROW ){
1514 const char *zUuid = db_column_text(&q, 0);
1515 ticket_rebuild_entry(zUuid);
1516 if( rc==TH_OK && zScript ){
1517 rc = xfer_run_script(zScript, zUuid);
1518 }
1519 }
1520 db_finalize(&q);
1521 db_multi_exec("DROP TABLE pending_tkt");
@@ -1670,14 +1670,15 @@
1670 ** Processing for other control artifacts was added later. The name
1671 ** of the routine, "manifest_crosslink", and the name of this source
1672 ** file, is a legacy of its original use.
1673 */
1674 int manifest_crosslink(int rid, Blob *pContent, int flags){
1675 int i, result = TH_OK;
1676 Manifest *p;
1677 Stmt q;
1678 int parentid = 0;
 
1679 const char *zScript = 0;
1680 const char *zUuid = 0;
1681
1682 if( (p = manifest_cache_find(rid))!=0 ){
1683 blob_reset(pContent);
@@ -1698,11 +1699,13 @@
1698 fossil_error(1, "cannot fetch baseline manifest");
1699 return 0;
1700 }
1701 db_begin_transaction();
1702 if( p->type==CFTYPE_MANIFEST ){
1703 zScript = xfer_commit_code();
 
 
1704 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1705 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
1706 char *zCom;
1707 for(i=0; i<p->nParent; i++){
1708 int pid = uuid_to_rid(p->azParent[i], 1);
@@ -1979,11 +1982,13 @@
1979 zTagUuid);
1980 branchMove = 0;
1981 if( db_exists("SELECT 1 FROM event, blob"
1982 " WHERE event.type='ci' AND event.objid=blob.rid"
1983 " AND blob.uuid='%s'", zTagUuid) ){
1984 zScript = xfer_commit_code();
 
 
1985 zUuid = zTagUuid;
1986 }
1987 }
1988 zName = p->aTag[i].zName;
1989 zValue = p->aTag[i].zValue;
@@ -2053,23 +2058,23 @@
2053 p->rDate, rid, p->zUser, blob_str(&comment)+1
2054 );
2055 blob_reset(&comment);
2056 }
2057 db_end_transaction(0);
2058 if( zScript && (flags & MC_PERMIT_HOOKS) ){
2059 result = xfer_run_common_script();
2060 if( result==TH_OK ){
2061 result = xfer_run_script(zScript, zUuid);
2062 }
2063 }
2064 if( p->type==CFTYPE_MANIFEST ){
2065 manifest_cache_insert(p);
2066 }else{
2067 manifest_destroy(p);
2068 }
2069 assert( blob_is_reset(pContent) );
2070 return ( result!=TH_ERROR );
2071 }
2072
2073 /*
2074 ** COMMAND: test-crosslink
2075 **
2076
--- src/manifest.c
+++ src/manifest.c
@@ -1502,20 +1502,20 @@
1502 int rc = TH_OK;
1503 int permitHooks = (flags & MC_PERMIT_HOOKS);
1504 const char *zScript = 0;
1505 assert( manifest_crosslink_busy==1 );
1506 if( permitHooks ){
1507 rc = xfer_run_common_script();
1508 if( rc==TH_OK ){
1509 zScript = xfer_ticket_code();
1510 }
1511 }
1512 db_prepare(&q, "SELECT uuid FROM pending_tkt");
1513 while( db_step(&q)==SQLITE_ROW ){
1514 const char *zUuid = db_column_text(&q, 0);
1515 ticket_rebuild_entry(zUuid);
1516 if( permitHooks && rc==TH_OK ){
1517 rc = xfer_run_script(zScript, zUuid);
1518 }
1519 }
1520 db_finalize(&q);
1521 db_multi_exec("DROP TABLE pending_tkt");
@@ -1670,14 +1670,15 @@
1670 ** Processing for other control artifacts was added later. The name
1671 ** of the routine, "manifest_crosslink", and the name of this source
1672 ** file, is a legacy of its original use.
1673 */
1674 int manifest_crosslink(int rid, Blob *pContent, int flags){
1675 int i, rc = TH_OK;
1676 Manifest *p;
1677 Stmt q;
1678 int parentid = 0;
1679 int permitHooks = (flags & MC_PERMIT_HOOKS);
1680 const char *zScript = 0;
1681 const char *zUuid = 0;
1682
1683 if( (p = manifest_cache_find(rid))!=0 ){
1684 blob_reset(pContent);
@@ -1698,11 +1699,13 @@
1699 fossil_error(1, "cannot fetch baseline manifest");
1700 return 0;
1701 }
1702 db_begin_transaction();
1703 if( p->type==CFTYPE_MANIFEST ){
1704 if( permitHooks ){
1705 zScript = xfer_commit_code();
1706 }
1707 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1708 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
1709 char *zCom;
1710 for(i=0; i<p->nParent; i++){
1711 int pid = uuid_to_rid(p->azParent[i], 1);
@@ -1979,11 +1982,13 @@
1982 zTagUuid);
1983 branchMove = 0;
1984 if( db_exists("SELECT 1 FROM event, blob"
1985 " WHERE event.type='ci' AND event.objid=blob.rid"
1986 " AND blob.uuid='%s'", zTagUuid) ){
1987 if( permitHooks ){
1988 zScript = xfer_commit_code();
1989 }
1990 zUuid = zTagUuid;
1991 }
1992 }
1993 zName = p->aTag[i].zName;
1994 zValue = p->aTag[i].zValue;
@@ -2053,23 +2058,23 @@
2058 p->rDate, rid, p->zUser, blob_str(&comment)+1
2059 );
2060 blob_reset(&comment);
2061 }
2062 db_end_transaction(0);
2063 if( permitHooks ){
2064 rc = xfer_run_common_script();
2065 if( rc==TH_OK ){
2066 rc = xfer_run_script(zScript, zUuid);
2067 }
2068 }
2069 if( p->type==CFTYPE_MANIFEST ){
2070 manifest_cache_insert(p);
2071 }else{
2072 manifest_destroy(p);
2073 }
2074 assert( blob_is_reset(pContent) );
2075 return ( rc!=TH_ERROR );
2076 }
2077
2078 /*
2079 ** COMMAND: test-crosslink
2080 **
2081
+13 -13
--- src/xfer.c
+++ src/xfer.c
@@ -852,25 +852,25 @@
852852
853853
/*
854854
** Run the specified TH1 script, if any, and returns 1 on error.
855855
*/
856856
int xfer_run_script(const char *zScript, const char *zUuid){
857
- int result;
857
+ int rc;
858858
if( !zScript ) return TH_OK;
859859
Th_FossilInit(TH_INIT_DEFAULT);
860860
if( zUuid ){
861
- result = Th_SetVar(g.interp, "uuid", -1, zUuid, -1);
862
- if( result!=TH_OK ){
861
+ rc = Th_SetVar(g.interp, "uuid", -1, zUuid, -1);
862
+ if( rc!=TH_OK ){
863863
fossil_error(1, "%s", Th_GetResult(g.interp, 0));
864
- return result;
864
+ return rc;
865865
}
866866
}
867
- result = Th_Eval(g.interp, 0, zScript, -1);
868
- if( result!=TH_OK ){
867
+ rc = Th_Eval(g.interp, 0, zScript, -1);
868
+ if( rc!=TH_OK ){
869869
fossil_error(1, "%s", Th_GetResult(g.interp, 0));
870870
}
871
- return result;
871
+ return rc;
872872
}
873873
874874
/*
875875
** Runs the pre-transfer TH1 script, if any, and returns its return code.
876876
** This script may be run multiple times. If the script performs actions
@@ -914,11 +914,11 @@
914914
int isClone = 0;
915915
int nGimme = 0;
916916
int size;
917917
int recvConfig = 0;
918918
char *zNow;
919
- int result;
919
+ int rc;
920920
921921
if( fossil_strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
922922
fossil_redirect_home();
923923
}
924924
g.zLogin = "anonymous";
@@ -944,12 +944,12 @@
944944
db_begin_transaction();
945945
db_multi_exec(
946946
"CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
947947
);
948948
manifest_crosslink_begin();
949
- result = xfer_run_common_script();
950
- if( result==TH_ERROR ){
949
+ rc = xfer_run_common_script();
950
+ if( rc==TH_ERROR ){
951951
cgi_reset_content();
952952
@ error common\sscript\sfailed:\s%F(g.zErrMsg)
953953
nErr++;
954954
}
955955
while( blob_line(xfer.pIn, &xfer.line) ){
@@ -1272,13 +1272,13 @@
12721272
}
12731273
blobarray_reset(xfer.aToken, xfer.nToken);
12741274
blob_reset(&xfer.line);
12751275
}
12761276
if( isPush ){
1277
- if( result==TH_OK ){
1278
- result = xfer_run_script(xfer_push_code(), 0);
1279
- if( result==TH_ERROR ){
1277
+ if( rc==TH_OK ){
1278
+ rc = xfer_run_script(xfer_push_code(), 0);
1279
+ if( rc==TH_ERROR ){
12801280
cgi_reset_content();
12811281
@ error push\sscript\sfailed:\s%F(g.zErrMsg)
12821282
nErr++;
12831283
}
12841284
}
12851285
--- src/xfer.c
+++ src/xfer.c
@@ -852,25 +852,25 @@
852
853 /*
854 ** Run the specified TH1 script, if any, and returns 1 on error.
855 */
856 int xfer_run_script(const char *zScript, const char *zUuid){
857 int result;
858 if( !zScript ) return TH_OK;
859 Th_FossilInit(TH_INIT_DEFAULT);
860 if( zUuid ){
861 result = Th_SetVar(g.interp, "uuid", -1, zUuid, -1);
862 if( result!=TH_OK ){
863 fossil_error(1, "%s", Th_GetResult(g.interp, 0));
864 return result;
865 }
866 }
867 result = Th_Eval(g.interp, 0, zScript, -1);
868 if( result!=TH_OK ){
869 fossil_error(1, "%s", Th_GetResult(g.interp, 0));
870 }
871 return result;
872 }
873
874 /*
875 ** Runs the pre-transfer TH1 script, if any, and returns its return code.
876 ** This script may be run multiple times. If the script performs actions
@@ -914,11 +914,11 @@
914 int isClone = 0;
915 int nGimme = 0;
916 int size;
917 int recvConfig = 0;
918 char *zNow;
919 int result;
920
921 if( fossil_strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
922 fossil_redirect_home();
923 }
924 g.zLogin = "anonymous";
@@ -944,12 +944,12 @@
944 db_begin_transaction();
945 db_multi_exec(
946 "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
947 );
948 manifest_crosslink_begin();
949 result = xfer_run_common_script();
950 if( result==TH_ERROR ){
951 cgi_reset_content();
952 @ error common\sscript\sfailed:\s%F(g.zErrMsg)
953 nErr++;
954 }
955 while( blob_line(xfer.pIn, &xfer.line) ){
@@ -1272,13 +1272,13 @@
1272 }
1273 blobarray_reset(xfer.aToken, xfer.nToken);
1274 blob_reset(&xfer.line);
1275 }
1276 if( isPush ){
1277 if( result==TH_OK ){
1278 result = xfer_run_script(xfer_push_code(), 0);
1279 if( result==TH_ERROR ){
1280 cgi_reset_content();
1281 @ error push\sscript\sfailed:\s%F(g.zErrMsg)
1282 nErr++;
1283 }
1284 }
1285
--- src/xfer.c
+++ src/xfer.c
@@ -852,25 +852,25 @@
852
853 /*
854 ** Run the specified TH1 script, if any, and returns 1 on error.
855 */
856 int xfer_run_script(const char *zScript, const char *zUuid){
857 int rc;
858 if( !zScript ) return TH_OK;
859 Th_FossilInit(TH_INIT_DEFAULT);
860 if( zUuid ){
861 rc = Th_SetVar(g.interp, "uuid", -1, zUuid, -1);
862 if( rc!=TH_OK ){
863 fossil_error(1, "%s", Th_GetResult(g.interp, 0));
864 return rc;
865 }
866 }
867 rc = Th_Eval(g.interp, 0, zScript, -1);
868 if( rc!=TH_OK ){
869 fossil_error(1, "%s", Th_GetResult(g.interp, 0));
870 }
871 return rc;
872 }
873
874 /*
875 ** Runs the pre-transfer TH1 script, if any, and returns its return code.
876 ** This script may be run multiple times. If the script performs actions
@@ -914,11 +914,11 @@
914 int isClone = 0;
915 int nGimme = 0;
916 int size;
917 int recvConfig = 0;
918 char *zNow;
919 int rc;
920
921 if( fossil_strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
922 fossil_redirect_home();
923 }
924 g.zLogin = "anonymous";
@@ -944,12 +944,12 @@
944 db_begin_transaction();
945 db_multi_exec(
946 "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
947 );
948 manifest_crosslink_begin();
949 rc = xfer_run_common_script();
950 if( rc==TH_ERROR ){
951 cgi_reset_content();
952 @ error common\sscript\sfailed:\s%F(g.zErrMsg)
953 nErr++;
954 }
955 while( blob_line(xfer.pIn, &xfer.line) ){
@@ -1272,13 +1272,13 @@
1272 }
1273 blobarray_reset(xfer.aToken, xfer.nToken);
1274 blob_reset(&xfer.line);
1275 }
1276 if( isPush ){
1277 if( rc==TH_OK ){
1278 rc = xfer_run_script(xfer_push_code(), 0);
1279 if( rc==TH_ERROR ){
1280 cgi_reset_content();
1281 @ error push\sscript\sfailed:\s%F(g.zErrMsg)
1282 nErr++;
1283 }
1284 }
1285

Keyboard Shortcuts

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