Fossil SCM

Phase 4, simplify usage of TH1 hooks and make more consistent. Assume that the common transfer TH1 script is idempotent.

mistachkin 2013-10-14 08:19 UTC tkt-change-hook
Commit 0fe1771a766c19a1f5103f3db1fb7e68032ba199
+1 -1
--- src/branch.c
+++ src/branch.c
@@ -153,11 +153,11 @@
153153
brid = content_put_ex(&branch, 0, 0, 0, isPrivate);
154154
if( brid==0 ){
155155
fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
156156
}
157157
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
158
- run_common_script();
158
+ xfer_run_common_script();
159159
if( manifest_crosslink(brid, &branch)==0 ){
160160
fossil_fatal("%s\n", g.zErrMsg);
161161
}
162162
assert( blob_is_reset(&branch) );
163163
content_deltify(rootid, brid, 0);
164164
--- src/branch.c
+++ src/branch.c
@@ -153,11 +153,11 @@
153 brid = content_put_ex(&branch, 0, 0, 0, isPrivate);
154 if( brid==0 ){
155 fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
156 }
157 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
158 run_common_script();
159 if( manifest_crosslink(brid, &branch)==0 ){
160 fossil_fatal("%s\n", g.zErrMsg);
161 }
162 assert( blob_is_reset(&branch) );
163 content_deltify(rootid, brid, 0);
164
--- src/branch.c
+++ src/branch.c
@@ -153,11 +153,11 @@
153 brid = content_put_ex(&branch, 0, 0, 0, isPrivate);
154 if( brid==0 ){
155 fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
156 }
157 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
158 xfer_run_common_script();
159 if( manifest_crosslink(brid, &branch)==0 ){
160 fossil_fatal("%s\n", g.zErrMsg);
161 }
162 assert( blob_is_reset(&branch) );
163 content_deltify(rootid, brid, 0);
164
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -1807,11 +1807,11 @@
18071807
if( nvid==0 ){
18081808
fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
18091809
}
18101810
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
18111811
if( !dryRunFlag ){
1812
- run_common_script();
1812
+ xfer_run_common_script();
18131813
if( manifest_crosslink(nvid, &manifest)==0 ){
18141814
fossil_fatal("%s\n", g.zErrMsg);
18151815
}
18161816
}
18171817
assert( blob_is_reset(&manifest) );
18181818
--- src/checkin.c
+++ src/checkin.c
@@ -1807,11 +1807,11 @@
1807 if( nvid==0 ){
1808 fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
1809 }
1810 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
1811 if( !dryRunFlag ){
1812 run_common_script();
1813 if( manifest_crosslink(nvid, &manifest)==0 ){
1814 fossil_fatal("%s\n", g.zErrMsg);
1815 }
1816 }
1817 assert( blob_is_reset(&manifest) );
1818
--- src/checkin.c
+++ src/checkin.c
@@ -1807,11 +1807,11 @@
1807 if( nvid==0 ){
1808 fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
1809 }
1810 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
1811 if( !dryRunFlag ){
1812 xfer_run_common_script();
1813 if( manifest_crosslink(nvid, &manifest)==0 ){
1814 fossil_fatal("%s\n", g.zErrMsg);
1815 }
1816 }
1817 assert( blob_is_reset(&manifest) );
1818
+1 -1
--- src/info.c
+++ src/info.c
@@ -2178,11 +2178,11 @@
21782178
md5sum_blob(&ctrl, &cksum);
21792179
blob_appendf(&ctrl, "Z %b\n", &cksum);
21802180
db_begin_transaction();
21812181
g.markPrivate = content_is_private(rid);
21822182
nrid = content_put(&ctrl);
2183
- run_common_script();
2183
+ xfer_run_common_script();
21842184
manifest_crosslink(nrid, &ctrl);
21852185
assert( blob_is_reset(&ctrl) );
21862186
db_end_transaction(0);
21872187
}
21882188
cgi_redirectf("ci?name=%s", zUuid);
21892189
--- src/info.c
+++ src/info.c
@@ -2178,11 +2178,11 @@
2178 md5sum_blob(&ctrl, &cksum);
2179 blob_appendf(&ctrl, "Z %b\n", &cksum);
2180 db_begin_transaction();
2181 g.markPrivate = content_is_private(rid);
2182 nrid = content_put(&ctrl);
2183 run_common_script();
2184 manifest_crosslink(nrid, &ctrl);
2185 assert( blob_is_reset(&ctrl) );
2186 db_end_transaction(0);
2187 }
2188 cgi_redirectf("ci?name=%s", zUuid);
2189
--- src/info.c
+++ src/info.c
@@ -2178,11 +2178,11 @@
2178 md5sum_blob(&ctrl, &cksum);
2179 blob_appendf(&ctrl, "Z %b\n", &cksum);
2180 db_begin_transaction();
2181 g.markPrivate = content_is_private(rid);
2182 nrid = content_put(&ctrl);
2183 xfer_run_common_script();
2184 manifest_crosslink(nrid, &ctrl);
2185 assert( blob_is_reset(&ctrl) );
2186 db_end_transaction(0);
2187 }
2188 cgi_redirectf("ci?name=%s", zUuid);
2189
--- src/json_branch.c
+++ src/json_branch.c
@@ -291,11 +291,11 @@
291291
brid = content_put(&branch);
292292
if( brid==0 ){
293293
fossil_fatal("Problem committing manifest: %s", g.zErrMsg);
294294
}
295295
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
296
- run_common_script();
296
+ xfer_run_common_script();
297297
if( manifest_crosslink(brid, &branch)==0 ){
298298
fossil_fatal("%s\n", g.zErrMsg);
299299
}
300300
assert( blob_is_reset(&branch) );
301301
content_deltify(rootid, brid, 0);
302302
--- src/json_branch.c
+++ src/json_branch.c
@@ -291,11 +291,11 @@
291 brid = content_put(&branch);
292 if( brid==0 ){
293 fossil_fatal("Problem committing manifest: %s", g.zErrMsg);
294 }
295 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
296 run_common_script();
297 if( manifest_crosslink(brid, &branch)==0 ){
298 fossil_fatal("%s\n", g.zErrMsg);
299 }
300 assert( blob_is_reset(&branch) );
301 content_deltify(rootid, brid, 0);
302
--- src/json_branch.c
+++ src/json_branch.c
@@ -291,11 +291,11 @@
291 brid = content_put(&branch);
292 if( brid==0 ){
293 fossil_fatal("Problem committing manifest: %s", g.zErrMsg);
294 }
295 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
296 xfer_run_common_script();
297 if( manifest_crosslink(brid, &branch)==0 ){
298 fossil_fatal("%s\n", g.zErrMsg);
299 }
300 assert( blob_is_reset(&branch) );
301 content_deltify(rootid, brid, 0);
302
+6 -6
--- src/manifest.c
+++ src/manifest.c
@@ -1651,15 +1651,15 @@
16511651
** Processing for other control artifacts was added later. The name
16521652
** of the routine, "manifest_crosslink", and the name of this source
16531653
** file, is a legacy of its original use.
16541654
*/
16551655
int manifest_crosslink(int rid, Blob *pContent){
1656
- int i;
1656
+ int i, result;
16571657
Manifest *p;
16581658
Stmt q;
16591659
int parentid = 0;
1660
- const char *hook = 0;
1660
+ const char *zScript = 0;
16611661
const char *zUuid = 0;
16621662
16631663
if( (p = manifest_cache_find(rid))!=0 ){
16641664
blob_reset(pContent);
16651665
}else if( (p = manifest_parse(pContent, rid, 0))==0 ){
@@ -1679,11 +1679,11 @@
16791679
fossil_error(1, "cannot fetch baseline manifest");
16801680
return 0;
16811681
}
16821682
db_begin_transaction();
16831683
if( p->type==CFTYPE_MANIFEST ){
1684
- hook = "xfer-commit-script";
1684
+ zScript = xfer_commit_code();
16851685
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
16861686
if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
16871687
char *zCom;
16881688
for(i=0; i<p->nParent; i++){
16891689
int pid = uuid_to_rid(p->azParent[i], 1);
@@ -1877,11 +1877,11 @@
18771877
}
18781878
}
18791879
if( p->type==CFTYPE_TICKET ){
18801880
char *zTag;
18811881
1882
- hook = "xfer-ticket-script";
1882
+ zScript = xfer_ticket_code();
18831883
zUuid = p->zTicketUuid;
18841884
assert( manifest_crosslink_busy==1 );
18851885
zTag = mprintf("tkt-%s", p->zTicketUuid);
18861886
tag_insert(zTag, 1, 0, rid, p->rDate, rid);
18871887
free(zTag);
@@ -2030,18 +2030,18 @@
20302030
p->rDate, rid, p->zUser, blob_str(&comment)+1
20312031
);
20322032
blob_reset(&comment);
20332033
}
20342034
db_end_transaction(0);
2035
- i = run_script(hook, zUuid)==0;
2035
+ result = (xfer_run_script(zScript, zUuid)==TH_OK);
20362036
if( p->type==CFTYPE_MANIFEST ){
20372037
manifest_cache_insert(p);
20382038
}else{
20392039
manifest_destroy(p);
20402040
}
20412041
assert( blob_is_reset(pContent) );
2042
- return i;
2042
+ return result;
20432043
}
20442044
20452045
/*
20462046
** COMMAND: test-crosslink
20472047
**
20482048
--- src/manifest.c
+++ src/manifest.c
@@ -1651,15 +1651,15 @@
1651 ** Processing for other control artifacts was added later. The name
1652 ** of the routine, "manifest_crosslink", and the name of this source
1653 ** file, is a legacy of its original use.
1654 */
1655 int manifest_crosslink(int rid, Blob *pContent){
1656 int i;
1657 Manifest *p;
1658 Stmt q;
1659 int parentid = 0;
1660 const char *hook = 0;
1661 const char *zUuid = 0;
1662
1663 if( (p = manifest_cache_find(rid))!=0 ){
1664 blob_reset(pContent);
1665 }else if( (p = manifest_parse(pContent, rid, 0))==0 ){
@@ -1679,11 +1679,11 @@
1679 fossil_error(1, "cannot fetch baseline manifest");
1680 return 0;
1681 }
1682 db_begin_transaction();
1683 if( p->type==CFTYPE_MANIFEST ){
1684 hook = "xfer-commit-script";
1685 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1686 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
1687 char *zCom;
1688 for(i=0; i<p->nParent; i++){
1689 int pid = uuid_to_rid(p->azParent[i], 1);
@@ -1877,11 +1877,11 @@
1877 }
1878 }
1879 if( p->type==CFTYPE_TICKET ){
1880 char *zTag;
1881
1882 hook = "xfer-ticket-script";
1883 zUuid = p->zTicketUuid;
1884 assert( manifest_crosslink_busy==1 );
1885 zTag = mprintf("tkt-%s", p->zTicketUuid);
1886 tag_insert(zTag, 1, 0, rid, p->rDate, rid);
1887 free(zTag);
@@ -2030,18 +2030,18 @@
2030 p->rDate, rid, p->zUser, blob_str(&comment)+1
2031 );
2032 blob_reset(&comment);
2033 }
2034 db_end_transaction(0);
2035 i = run_script(hook, zUuid)==0;
2036 if( p->type==CFTYPE_MANIFEST ){
2037 manifest_cache_insert(p);
2038 }else{
2039 manifest_destroy(p);
2040 }
2041 assert( blob_is_reset(pContent) );
2042 return i;
2043 }
2044
2045 /*
2046 ** COMMAND: test-crosslink
2047 **
2048
--- src/manifest.c
+++ src/manifest.c
@@ -1651,15 +1651,15 @@
1651 ** Processing for other control artifacts was added later. The name
1652 ** of the routine, "manifest_crosslink", and the name of this source
1653 ** file, is a legacy of its original use.
1654 */
1655 int manifest_crosslink(int rid, Blob *pContent){
1656 int i, result;
1657 Manifest *p;
1658 Stmt q;
1659 int parentid = 0;
1660 const char *zScript = 0;
1661 const char *zUuid = 0;
1662
1663 if( (p = manifest_cache_find(rid))!=0 ){
1664 blob_reset(pContent);
1665 }else if( (p = manifest_parse(pContent, rid, 0))==0 ){
@@ -1679,11 +1679,11 @@
1679 fossil_error(1, "cannot fetch baseline manifest");
1680 return 0;
1681 }
1682 db_begin_transaction();
1683 if( p->type==CFTYPE_MANIFEST ){
1684 zScript = xfer_commit_code();
1685 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1686 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
1687 char *zCom;
1688 for(i=0; i<p->nParent; i++){
1689 int pid = uuid_to_rid(p->azParent[i], 1);
@@ -1877,11 +1877,11 @@
1877 }
1878 }
1879 if( p->type==CFTYPE_TICKET ){
1880 char *zTag;
1881
1882 zScript = xfer_ticket_code();
1883 zUuid = p->zTicketUuid;
1884 assert( manifest_crosslink_busy==1 );
1885 zTag = mprintf("tkt-%s", p->zTicketUuid);
1886 tag_insert(zTag, 1, 0, rid, p->rDate, rid);
1887 free(zTag);
@@ -2030,18 +2030,18 @@
2030 p->rDate, rid, p->zUser, blob_str(&comment)+1
2031 );
2032 blob_reset(&comment);
2033 }
2034 db_end_transaction(0);
2035 result = (xfer_run_script(zScript, zUuid)==TH_OK);
2036 if( p->type==CFTYPE_MANIFEST ){
2037 manifest_cache_insert(p);
2038 }else{
2039 manifest_destroy(p);
2040 }
2041 assert( blob_is_reset(pContent) );
2042 return result;
2043 }
2044
2045 /*
2046 ** COMMAND: test-crosslink
2047 **
2048
+1 -1
--- src/tag.c
+++ src/tag.c
@@ -326,11 +326,11 @@
326326
}
327327
blob_appendf(&ctrl, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
328328
md5sum_blob(&ctrl, &cksum);
329329
blob_appendf(&ctrl, "Z %b\n", &cksum);
330330
nrid = content_put(&ctrl);
331
- run_common_script();
331
+ xfer_run_common_script();
332332
manifest_crosslink(nrid, &ctrl);
333333
assert( blob_is_reset(&ctrl) );
334334
}
335335
336336
/*
337337
--- src/tag.c
+++ src/tag.c
@@ -326,11 +326,11 @@
326 }
327 blob_appendf(&ctrl, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
328 md5sum_blob(&ctrl, &cksum);
329 blob_appendf(&ctrl, "Z %b\n", &cksum);
330 nrid = content_put(&ctrl);
331 run_common_script();
332 manifest_crosslink(nrid, &ctrl);
333 assert( blob_is_reset(&ctrl) );
334 }
335
336 /*
337
--- src/tag.c
+++ src/tag.c
@@ -326,11 +326,11 @@
326 }
327 blob_appendf(&ctrl, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
328 md5sum_blob(&ctrl, &cksum);
329 blob_appendf(&ctrl, "Z %b\n", &cksum);
330 nrid = content_put(&ctrl);
331 xfer_run_common_script();
332 manifest_crosslink(nrid, &ctrl);
333 assert( blob_is_reset(&ctrl) );
334 }
335
336 /*
337
+6 -5
--- src/tkt.c
+++ src/tkt.c
@@ -534,10 +534,11 @@
534534
}else{
535535
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d);", rid);
536536
db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", rid);
537537
}
538538
manifest_crosslink_begin();
539
+ xfer_run_common_script();
539540
result = manifest_crosslink(rid, pTicket)==0;
540541
assert( blob_is_reset(pTicket) );
541542
manifest_crosslink_end();
542543
return result;
543544
}
@@ -682,12 +683,12 @@
682683
}
683684
captcha_generate(0);
684685
@ </form>
685686
if( g.thTrace ) Th_Trace("END_TKTVIEW<br />\n", -1);
686687
style_footer();
687
- run_common_script();
688
- run_script("xfer-ticket-script", zNewUuid);
688
+ xfer_run_common_script();
689
+ xfer_run_script(xfer_ticket_code(), zNewUuid);
689690
}
690691
691692
/*
692693
** WEBPAGE: tktedit
693694
** WEBPAGE: debug_tktedit
@@ -752,12 +753,12 @@
752753
}
753754
captcha_generate(0);
754755
@ </form>
755756
if( g.thTrace ) Th_Trace("BEGIN_TKTEDIT<br />\n", -1);
756757
style_footer();
757
- run_common_script();
758
- run_script("xfer-ticket-script", zName);
758
+ xfer_run_common_script();
759
+ xfer_run_script(xfer_ticket_code(), zName);
759760
}
760761
761762
/*
762763
** Check the ticket table schema in zSchema to see if it appears to
763764
** be well-formed. If everything is OK, return NULL. If something is
@@ -1349,14 +1350,14 @@
13491350
}
13501351
blob_appendf(&tktchng, "K %s\n", zTktUuid);
13511352
blob_appendf(&tktchng, "U %F\n", zUser);
13521353
md5sum_blob(&tktchng, &cksum);
13531354
blob_appendf(&tktchng, "Z %b\n", &cksum);
1354
- if( run_common_script() || ticket_put(&tktchng, zTktUuid, 0)){
1355
+ if( ticket_put(&tktchng, zTktUuid, 0) ){
13551356
fossil_fatal("%s\n", g.zErrMsg);
13561357
}else{
13571358
fossil_print("ticket %s succeeded for %s\n",
13581359
(eCmd==set?"set":"add"),zTktUuid);
13591360
}
13601361
}
13611362
}
13621363
}
13631364
--- src/tkt.c
+++ src/tkt.c
@@ -534,10 +534,11 @@
534 }else{
535 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d);", rid);
536 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", rid);
537 }
538 manifest_crosslink_begin();
 
539 result = manifest_crosslink(rid, pTicket)==0;
540 assert( blob_is_reset(pTicket) );
541 manifest_crosslink_end();
542 return result;
543 }
@@ -682,12 +683,12 @@
682 }
683 captcha_generate(0);
684 @ </form>
685 if( g.thTrace ) Th_Trace("END_TKTVIEW<br />\n", -1);
686 style_footer();
687 run_common_script();
688 run_script("xfer-ticket-script", zNewUuid);
689 }
690
691 /*
692 ** WEBPAGE: tktedit
693 ** WEBPAGE: debug_tktedit
@@ -752,12 +753,12 @@
752 }
753 captcha_generate(0);
754 @ </form>
755 if( g.thTrace ) Th_Trace("BEGIN_TKTEDIT<br />\n", -1);
756 style_footer();
757 run_common_script();
758 run_script("xfer-ticket-script", zName);
759 }
760
761 /*
762 ** Check the ticket table schema in zSchema to see if it appears to
763 ** be well-formed. If everything is OK, return NULL. If something is
@@ -1349,14 +1350,14 @@
1349 }
1350 blob_appendf(&tktchng, "K %s\n", zTktUuid);
1351 blob_appendf(&tktchng, "U %F\n", zUser);
1352 md5sum_blob(&tktchng, &cksum);
1353 blob_appendf(&tktchng, "Z %b\n", &cksum);
1354 if( run_common_script() || ticket_put(&tktchng, zTktUuid, 0)){
1355 fossil_fatal("%s\n", g.zErrMsg);
1356 }else{
1357 fossil_print("ticket %s succeeded for %s\n",
1358 (eCmd==set?"set":"add"),zTktUuid);
1359 }
1360 }
1361 }
1362 }
1363
--- src/tkt.c
+++ src/tkt.c
@@ -534,10 +534,11 @@
534 }else{
535 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d);", rid);
536 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", rid);
537 }
538 manifest_crosslink_begin();
539 xfer_run_common_script();
540 result = manifest_crosslink(rid, pTicket)==0;
541 assert( blob_is_reset(pTicket) );
542 manifest_crosslink_end();
543 return result;
544 }
@@ -682,12 +683,12 @@
683 }
684 captcha_generate(0);
685 @ </form>
686 if( g.thTrace ) Th_Trace("END_TKTVIEW<br />\n", -1);
687 style_footer();
688 xfer_run_common_script();
689 xfer_run_script(xfer_ticket_code(), zNewUuid);
690 }
691
692 /*
693 ** WEBPAGE: tktedit
694 ** WEBPAGE: debug_tktedit
@@ -752,12 +753,12 @@
753 }
754 captcha_generate(0);
755 @ </form>
756 if( g.thTrace ) Th_Trace("BEGIN_TKTEDIT<br />\n", -1);
757 style_footer();
758 xfer_run_common_script();
759 xfer_run_script(xfer_ticket_code(), zName);
760 }
761
762 /*
763 ** Check the ticket table schema in zSchema to see if it appears to
764 ** be well-formed. If everything is OK, return NULL. If something is
@@ -1349,14 +1350,14 @@
1350 }
1351 blob_appendf(&tktchng, "K %s\n", zTktUuid);
1352 blob_appendf(&tktchng, "U %F\n", zUser);
1353 md5sum_blob(&tktchng, &cksum);
1354 blob_appendf(&tktchng, "Z %b\n", &cksum);
1355 if( ticket_put(&tktchng, zTktUuid, 0) ){
1356 fossil_fatal("%s\n", g.zErrMsg);
1357 }else{
1358 fossil_print("ticket %s succeeded for %s\n",
1359 (eCmd==set?"set":"add"),zTktUuid);
1360 }
1361 }
1362 }
1363 }
1364
+58 -40
--- src/xfer.c
+++ src/xfer.c
@@ -819,48 +819,66 @@
819819
*/
820820
static void server_private_xfer_not_authorized(void){
821821
@ error not\sauthorized\sto\ssync\sprivate\scontent
822822
}
823823
824
-static int commonScriptRan = 0;
825
-
826
-/*
827
-** Run the specified TH1 script, if any, and returns 1 on error.
828
-*/
829
-int run_script(const char *zScript, const char *zUuid){
830
- int result = 0;
831
- if( !commonScriptRan || !zScript || !(zScript = db_get(zScript, 0))){
832
- return 0; /* No script or common script didn't run, return success. */
833
- }
834
- if( commonScriptRan == 1 ){
835
- if( zUuid ){
836
- Th_SetVar(g.interp, "uuid", -1, zUuid, strlen(zUuid));
837
- }
838
- result = Th_Eval(g.interp, 0, zScript, -1) != TH_OK;
839
- }else{
840
- result = TH_ERROR;
841
- }
842
- if (result) fossil_error(1, "%s", Th_GetResult(g.interp, 0));
843
- return result;
844
-}
845
-
846
-/*
847
-** Run the pre-transfer TH1 script, if any, and returns the return code.
848
-** Prepare the "http" command for use in other hook scripts.
849
-*/
850
-int run_common_script(void){
851
- int result = 0;
852
- if( !commonScriptRan ){
853
- Th_FossilInit(TH_INIT_DEFAULT); /* Make sure TH1 is ready. */
854
- commonScriptRan = 1; /* enable run_script to do something */
855
- result = run_script("xfer-common-script", 0);
856
- if( result == TH_ERROR ){
857
- /* Error message is left in th interpreter. */
858
- commonScriptRan = 2;
859
- }
860
- }
861
- return result;
824
+/*
825
+** Return the common TH1 code to evaluate prior to evaluating any other
826
+** TH1 transfer notification scripts.
827
+*/
828
+const char *xfer_common_code(void){
829
+ return db_get("xfer-common-script", 0);
830
+}
831
+
832
+/*
833
+** Return the TH1 code to evaluate when a push is processed.
834
+*/
835
+const char *xfer_push_code(void){
836
+ return db_get("xfer-push-script", 0);
837
+}
838
+
839
+/*
840
+** Return the TH1 code to evaluate when a commit is processed.
841
+*/
842
+const char *xfer_commit_code(void){
843
+ return db_get("xfer-commit-script", 0);
844
+}
845
+
846
+/*
847
+** Return the TH1 code to evaluate when a ticket change is processed.
848
+*/
849
+const char *xfer_ticket_code(void){
850
+ return db_get("xfer-ticket-script", 0);
851
+}
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
+*/
877
+int xfer_run_common_script(void){
878
+ Th_FossilInit(TH_INIT_DEFAULT);
879
+ return xfer_run_script(xfer_common_code(), 0);
862880
}
863881
864882
/*
865883
** If this variable is set, disable login checks. Used for debugging
866884
** only.
@@ -918,11 +936,11 @@
918936
db_begin_transaction();
919937
db_multi_exec(
920938
"CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
921939
);
922940
manifest_crosslink_begin();
923
- if( run_common_script() ){
941
+ if( xfer_run_common_script()!=TH_OK ){
924942
cgi_reset_content();
925943
@ error common\sscript\sfailed:\s%F(Th_GetResult(g.interp, 0))
926944
nErr++;
927945
}
928946
while( blob_line(xfer.pIn, &xfer.line) ){
@@ -1245,11 +1263,11 @@
12451263
}
12461264
blobarray_reset(xfer.aToken, xfer.nToken);
12471265
blob_reset(&xfer.line);
12481266
}
12491267
if( isPush ){
1250
- if( run_script("xfer-push-script", 0) ){
1268
+ if( xfer_run_script(xfer_push_code(), 0)!=TH_OK ){
12511269
cgi_reset_content();
12521270
@ error push\sscript\sfailed:\s%F(g.zErrMsg)
12531271
nErr++;
12541272
}
12551273
request_phantoms(&xfer, 500);
12561274
--- src/xfer.c
+++ src/xfer.c
@@ -819,48 +819,66 @@
819 */
820 static void server_private_xfer_not_authorized(void){
821 @ error not\sauthorized\sto\ssync\sprivate\scontent
822 }
823
824 static int commonScriptRan = 0;
825
826 /*
827 ** Run the specified TH1 script, if any, and returns 1 on error.
828 */
829 int run_script(const char *zScript, const char *zUuid){
830 int result = 0;
831 if( !commonScriptRan || !zScript || !(zScript = db_get(zScript, 0))){
832 return 0; /* No script or common script didn't run, return success. */
833 }
834 if( commonScriptRan == 1 ){
835 if( zUuid ){
836 Th_SetVar(g.interp, "uuid", -1, zUuid, strlen(zUuid));
837 }
838 result = Th_Eval(g.interp, 0, zScript, -1) != TH_OK;
839 }else{
840 result = TH_ERROR;
841 }
842 if (result) fossil_error(1, "%s", Th_GetResult(g.interp, 0));
843 return result;
844 }
845
846 /*
847 ** Run the pre-transfer TH1 script, if any, and returns the return code.
848 ** Prepare the "http" command for use in other hook scripts.
849 */
850 int run_common_script(void){
851 int result = 0;
852 if( !commonScriptRan ){
853 Th_FossilInit(TH_INIT_DEFAULT); /* Make sure TH1 is ready. */
854 commonScriptRan = 1; /* enable run_script to do something */
855 result = run_script("xfer-common-script", 0);
856 if( result == TH_ERROR ){
857 /* Error message is left in th interpreter. */
858 commonScriptRan = 2;
859 }
860 }
861 return result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
862 }
863
864 /*
865 ** If this variable is set, disable login checks. Used for debugging
866 ** only.
@@ -918,11 +936,11 @@
918 db_begin_transaction();
919 db_multi_exec(
920 "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
921 );
922 manifest_crosslink_begin();
923 if( run_common_script() ){
924 cgi_reset_content();
925 @ error common\sscript\sfailed:\s%F(Th_GetResult(g.interp, 0))
926 nErr++;
927 }
928 while( blob_line(xfer.pIn, &xfer.line) ){
@@ -1245,11 +1263,11 @@
1245 }
1246 blobarray_reset(xfer.aToken, xfer.nToken);
1247 blob_reset(&xfer.line);
1248 }
1249 if( isPush ){
1250 if( run_script("xfer-push-script", 0) ){
1251 cgi_reset_content();
1252 @ error push\sscript\sfailed:\s%F(g.zErrMsg)
1253 nErr++;
1254 }
1255 request_phantoms(&xfer, 500);
1256
--- src/xfer.c
+++ src/xfer.c
@@ -819,48 +819,66 @@
819 */
820 static void server_private_xfer_not_authorized(void){
821 @ error not\sauthorized\sto\ssync\sprivate\scontent
822 }
823
824 /*
825 ** Return the common TH1 code to evaluate prior to evaluating any other
826 ** TH1 transfer notification scripts.
827 */
828 const char *xfer_common_code(void){
829 return db_get("xfer-common-script", 0);
830 }
831
832 /*
833 ** Return the TH1 code to evaluate when a push is processed.
834 */
835 const char *xfer_push_code(void){
836 return db_get("xfer-push-script", 0);
837 }
838
839 /*
840 ** Return the TH1 code to evaluate when a commit is processed.
841 */
842 const char *xfer_commit_code(void){
843 return db_get("xfer-commit-script", 0);
844 }
845
846 /*
847 ** Return the TH1 code to evaluate when a ticket change is processed.
848 */
849 const char *xfer_ticket_code(void){
850 return db_get("xfer-ticket-script", 0);
851 }
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 */
877 int xfer_run_common_script(void){
878 Th_FossilInit(TH_INIT_DEFAULT);
879 return xfer_run_script(xfer_common_code(), 0);
880 }
881
882 /*
883 ** If this variable is set, disable login checks. Used for debugging
884 ** only.
@@ -918,11 +936,11 @@
936 db_begin_transaction();
937 db_multi_exec(
938 "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
939 );
940 manifest_crosslink_begin();
941 if( xfer_run_common_script()!=TH_OK ){
942 cgi_reset_content();
943 @ error common\sscript\sfailed:\s%F(Th_GetResult(g.interp, 0))
944 nErr++;
945 }
946 while( blob_line(xfer.pIn, &xfer.line) ){
@@ -1245,11 +1263,11 @@
1263 }
1264 blobarray_reset(xfer.aToken, xfer.nToken);
1265 blob_reset(&xfer.line);
1266 }
1267 if( isPush ){
1268 if( xfer_run_script(xfer_push_code(), 0)!=TH_OK ){
1269 cgi_reset_content();
1270 @ error push\sscript\sfailed:\s%F(g.zErrMsg)
1271 nErr++;
1272 }
1273 request_phantoms(&xfer, 500);
1274

Keyboard Shortcuts

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