Fossil

Check-in [97b47ddadf]
Login

Check-in [97b47ddadf]

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

Overview
Comment:Better error reporting using fossil_error mechanism.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | tkt-change-hook
Files: files | file ages | folders
SHA1: 97b47ddadfcc7ba050b9d6500ca3cad84a70be7c
User & Date: jan.nijtmans 2013-07-12 12:39:06.516
Context
2013-07-12
13:54
submitTicketCmd() must not return TH_ERROR if ticket_put() fails. ... (check-in: ebfd7020aa user: jan.nijtmans tags: tkt-change-hook)
12:39
Better error reporting using fossil_error mechanism. ... (check-in: 97b47ddadf user: jan.nijtmans tags: tkt-change-hook)
11:38
rebase ... (check-in: ebc22d22d2 user: jan.nijtmans tags: tkt-change-hook)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/branch.c.
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  }

  brid = content_put_ex(&branch, 0, 0, 0, isPrivate);
  if( brid==0 ){
    fossil_panic("trouble committing manifest: %s", g.zErrMsg);
  }
  db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
  if( run_common_script()!=TH_OK || manifest_crosslink(brid, &branch)==0 ){
    fossil_panic("%s\n", Th_GetResult(g.interp, 0));
  }
  assert( blob_is_reset(&branch) );
  content_deltify(rootid, brid, 0);
  zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", brid);
  fossil_print("New branch: %s\n", zUuid);
  if( g.argc==3 ){
    fossil_print(







|
|







151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  }

  brid = content_put_ex(&branch, 0, 0, 0, isPrivate);
  if( brid==0 ){
    fossil_panic("trouble committing manifest: %s", g.zErrMsg);
  }
  db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
  if( run_common_script() || manifest_crosslink(brid, &branch) ){
    fossil_panic("%s\n", g.zErrMsg);
  }
  assert( blob_is_reset(&branch) );
  content_deltify(rootid, brid, 0);
  zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", brid);
  fossil_print("New branch: %s\n", zUuid);
  if( g.argc==3 ){
    fossil_print(
Changes to src/checkin.c.
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
  }
  nvid = content_put(&manifest);
  if( nvid==0 ){
    fossil_panic("trouble committing manifest: %s", g.zErrMsg);
  }
  db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
  if( !dryRunFlag ){
    if( run_common_script()!=TH_OK || manifest_crosslink(nvid, &manifest)==0 ){
      fossil_panic("%s\n", Th_GetResult(g.interp, 0));
    }
  }
  assert( blob_is_reset(&manifest) );
  content_deltify(vid, nvid, 0);
  zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nvid);
  fossil_print("New_Version: %s\n", zUuid);
  if( outputManifest ){







|
|







1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
  }
  nvid = content_put(&manifest);
  if( nvid==0 ){
    fossil_panic("trouble committing manifest: %s", g.zErrMsg);
  }
  db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
  if( !dryRunFlag ){
    if( run_common_script() || manifest_crosslink(nvid, &manifest) ){
      fossil_panic("%s\n", g.zErrMsg);
    }
  }
  assert( blob_is_reset(&manifest) );
  content_deltify(vid, nvid, 0);
  zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nvid);
  fossil_print("New_Version: %s\n", zUuid);
  if( outputManifest ){
Changes to src/json_branch.c.
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

  brid = content_put(&branch);
  if( brid==0 ){
    fossil_panic("Problem committing manifest: %s", g.zErrMsg);
  }
  db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
  run_common_script();
  if( manifest_crosslink(brid, &branch)==0 ){
    fossil_panic("unable to install new manifest");
  }
  assert( blob_is_reset(&branch) );
  content_deltify(rootid, brid, 0);
  if( zNewRid ){
    *zNewRid = brid;
  }








|
|







290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

  brid = content_put(&branch);
  if( brid==0 ){
    fossil_panic("Problem committing manifest: %s", g.zErrMsg);
  }
  db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", brid);
  run_common_script();
  if( manifest_crosslink(brid, &branch) ){
    fossil_panic("%s\n", g.zErrMsg);
  }
  assert( blob_is_reset(&branch) );
  content_deltify(rootid, brid, 0);
  if( zNewRid ){
    *zNewRid = brid;
  }

Changes to src/manifest.c.
1647
1648
1649
1650
1651
1652
1653

1654
1655
1656
1657
1658

1659
1660
1661
1662
1663

1664
1665
1666
1667
1668
1669
1670
1671
  const char *hook = 0;
  const char *zUuid = 0;

  if( (p = manifest_cache_find(rid))!=0 ){
    blob_reset(pContent);
  }else if( (p = manifest_parse(pContent, rid, 0))==0 ){
    assert( blob_is_reset(pContent) || pContent==0 );

    return 0;
  }
  if( g.xlinkClusterOnly && p->type!=CFTYPE_CLUSTER ){
    manifest_destroy(p);
    assert( blob_is_reset(pContent) );

    return 0;
  }
  if( p->type==CFTYPE_MANIFEST && fetch_baseline(p, 0) ){
    manifest_destroy(p);
    assert( blob_is_reset(pContent) );

    return 0;
  }
  db_begin_transaction();
  if( p->type==CFTYPE_MANIFEST ){
    hook = "xfer-commit-script";
    zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
    if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
      char *zCom;







>
|




>
|




>
|







1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
  const char *hook = 0;
  const char *zUuid = 0;

  if( (p = manifest_cache_find(rid))!=0 ){
    blob_reset(pContent);
  }else if( (p = manifest_parse(pContent, rid, 0))==0 ){
    assert( blob_is_reset(pContent) || pContent==0 );
    fossil_error(1, "syntax error in manifest");
    return 1;
  }
  if( g.xlinkClusterOnly && p->type!=CFTYPE_CLUSTER ){
    manifest_destroy(p);
    assert( blob_is_reset(pContent) );
    fossil_error(1, "no manifest");
    return 1;
  }
  if( p->type==CFTYPE_MANIFEST && fetch_baseline(p, 0) ){
    manifest_destroy(p);
    assert( blob_is_reset(pContent) );
    fossil_error(1, "cannot fetch baseline manifest");
    return 1;
  }
  db_begin_transaction();
  if( p->type==CFTYPE_MANIFEST ){
    hook = "xfer-commit-script";
    zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
    if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
      char *zCom;
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
      }
      if( tid ){
        switch( p->aTag[i].zName[0] ){
          case '-':  type = 0;  break;  /* Cancel prior occurrences */
          case '+':  type = 1;  break;  /* Apply to target only */
          case '*':  type = 2;  break;  /* Propagate to descendants */
          default:
            fossil_fatal("unknown tag type in manifest: %s", p->aTag);
            return 0;
        }
        tag_insert(&p->aTag[i].zName[1], type, p->aTag[i].zValue, 
                   rid, p->rDate, tid);
      }
    }
    if( parentid ){
      tag_propagate_all(parentid);







|
|







1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
      }
      if( tid ){
        switch( p->aTag[i].zName[0] ){
          case '-':  type = 0;  break;  /* Cancel prior occurrences */
          case '+':  type = 1;  break;  /* Apply to target only */
          case '*':  type = 2;  break;  /* Propagate to descendants */
          default:
            fossil_error(1, "unknown tag type in manifest: %s", p->aTag);
            return 1;
        }
        tag_insert(&p->aTag[i].zName[1], type, p->aTag[i].zValue, 
                   rid, p->rDate, tid);
      }
    }
    if( parentid ){
      tag_propagate_all(parentid);
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
  i = run_script(hook, zUuid);
  if( p->type==CFTYPE_MANIFEST ){
    manifest_cache_insert(p);
  }else{
    manifest_destroy(p);
  }
  assert( blob_is_reset(pContent) );
  return (i == TH_OK);
}

/*
** COMMAND: test-crosslink
**
** Usage:  %fossil test-crosslink RECORDID
**







|







2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
  i = run_script(hook, zUuid);
  if( p->type==CFTYPE_MANIFEST ){
    manifest_cache_insert(p);
  }else{
    manifest_destroy(p);
  }
  assert( blob_is_reset(pContent) );
  return i;
}

/*
** COMMAND: test-crosslink
**
** Usage:  %fossil test-crosslink RECORDID
**
Changes to src/tkt.c.
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
    @ <blockquote><pre>%h(blob_str(&tktchng))</pre></blockquote>
    @ <hr /></font>
    return TH_OK;
  }else if( g.thTrace ){
    Th_Trace("submit_ticket {\n<blockquote><pre>\n%h\n</pre></blockquote>\n"
             "}<br />\n",
       blob_str(&tktchng));
  }else if( !ticket_put(&tktchng, zUuid,
      (g.perm.ModTkt==0 && db_get_boolean("modreq-tkt",0)==1))) {
    return TH_ERROR;
  }
  return TH_OK;
}









|







615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
    @ <blockquote><pre>%h(blob_str(&tktchng))</pre></blockquote>
    @ <hr /></font>
    return TH_OK;
  }else if( g.thTrace ){
    Th_Trace("submit_ticket {\n<blockquote><pre>\n%h\n</pre></blockquote>\n"
             "}<br />\n",
       blob_str(&tktchng));
  }else if( ticket_put(&tktchng, zUuid,
      (g.perm.ModTkt==0 && db_get_boolean("modreq-tkt",0)==1))) {
    return TH_ERROR;
  }
  return TH_OK;
}


1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
                       aField[i].zName, strlen(zValue), zValue);
        }
      }
      blob_appendf(&tktchng, "K %s\n", zTktUuid);
      blob_appendf(&tktchng, "U %F\n", zUser);
      md5sum_blob(&tktchng, &cksum);
      blob_appendf(&tktchng, "Z %b\n", &cksum);
      if( run_common_script()!=TH_OK || ticket_put(&tktchng, zTktUuid, 0)){
        fossil_panic("%s\n", Th_GetResult(g.interp, 0));
      }else{
        fossil_print("ticket %s succeeded for %s\n",
             (eCmd==set?"set":"add"),zTktUuid);
      }
    }
  }
}







|
|







1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
                       aField[i].zName, strlen(zValue), zValue);
        }
      }
      blob_appendf(&tktchng, "K %s\n", zTktUuid);
      blob_appendf(&tktchng, "U %F\n", zUser);
      md5sum_blob(&tktchng, &cksum);
      blob_appendf(&tktchng, "Z %b\n", &cksum);
      if( run_common_script() || ticket_put(&tktchng, zTktUuid, 0)){
        fossil_panic("%s\n", g.zErrMsg);
      }else{
        fossil_print("ticket %s succeeded for %s\n",
             (eCmd==set?"set":"add"),zTktUuid);
      }
    }
  }
}
Changes to src/xfer.c.
892
893
894
895
896
897
898
899
900
901
902
903

904
905
906
907
908
909
910


911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
  Th_SetResult(interp, "", -1);
  return TH_OK;
}

static int commonScriptRan = 0;

/*
** Run the specified TH1 script, if any, and returns the return code or TH_OK
** when there is no script. If run_common_script() was not ran before, this
** function will return TH_OK without doing anything.
*/
int run_script(const char *zScript, const char *zUuid){

  if( !commonScriptRan || !zScript || !(zScript = db_get(zScript, 0))){
    return TH_OK; /* No script or common script didn't run, return success. */
  }
  if( zUuid ){
    Th_SetVar(g.interp, "uuid", -1, zUuid, strlen(zUuid));
  }
  return Th_Eval(g.interp, 0, zScript, -1);


}

/*
** Run the pre-transfer TH1 script, if any, and returns the return code.
** Prepare the "http" command for use in other hook scripts.
*/
int run_common_script(void){
  int result = TH_OK;
  if( !commonScriptRan ){
    Th_FossilInit(0, 0); /* Make sure TH1 is ready. */
    commonScriptRan = 1; /* enable run_script to do something */
    result = run_script("xfer-common-script", 0);
    Th_CreateCommand(g.interp, "http", httpCmd, 0, 0);
  }
  return result;







|
<
<


>

|




|
>
>







|







892
893
894
895
896
897
898
899


900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
  Th_SetResult(interp, "", -1);
  return TH_OK;
}

static int commonScriptRan = 0;

/*
** Run the specified TH1 script, if any, and returns 1 on error.


*/
int run_script(const char *zScript, const char *zUuid){
  int result = 0;
  if( !commonScriptRan || !zScript || !(zScript = db_get(zScript, 0))){
    return 0; /* No script or common script didn't run, return success. */
  }
  if( zUuid ){
    Th_SetVar(g.interp, "uuid", -1, zUuid, strlen(zUuid));
  }
  result = Th_Eval(g.interp, 0, zScript, -1) != TH_OK;
  if (result) fossil_error(1, "%s", Th_GetResult(g.interp, 0));
  return result;
}

/*
** Run the pre-transfer TH1 script, if any, and returns the return code.
** Prepare the "http" command for use in other hook scripts.
*/
int run_common_script(void){
  int result = 0;
  if( !commonScriptRan ){
    Th_FossilInit(0, 0); /* Make sure TH1 is ready. */
    commonScriptRan = 1; /* enable run_script to do something */
    result = run_script("xfer-common-script", 0);
    Th_CreateCommand(g.interp, "http", httpCmd, 0, 0);
  }
  return result;
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
  g.xferPanic = 1;

  db_begin_transaction();
  db_multi_exec(
     "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
  );
  manifest_crosslink_begin();
  if( run_common_script()==TH_ERROR ){
    cgi_reset_content();
    @ error common\sscript\sfailed:\s%F(Th_GetResult(g.interp, 0))
    nErr++;
  }
  while( blob_line(xfer.pIn, &xfer.line) ){
    if( blob_buffer(&xfer.line)[0]=='#' ) continue;
    if( blob_size(&xfer.line)==0 ) continue;







|







981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
  g.xferPanic = 1;

  db_begin_transaction();
  db_multi_exec(
     "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
  );
  manifest_crosslink_begin();
  if( run_common_script() ){
    cgi_reset_content();
    @ error common\sscript\sfailed:\s%F(Th_GetResult(g.interp, 0))
    nErr++;
  }
  while( blob_line(xfer.pIn, &xfer.line) ){
    if( blob_buffer(&xfer.line)[0]=='#' ) continue;
    if( blob_size(&xfer.line)==0 ) continue;
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
    {
      cgi_reset_content();
      @ error bad\scommand:\s%F(blob_str(&xfer.line))
    }
    blobarray_reset(xfer.aToken, xfer.nToken);
  }
  if( isPush ){
    if( run_script("xfer-push-script", 0)==TH_ERROR ){
      cgi_reset_content();
      @ error push\sscript\sfailed:\s%F(Th_GetResult(g.interp, 0))
      nErr++;
    }
    request_phantoms(&xfer, 500);
  }
  if( isClone && nGimme==0 ){
    /* The initial "clone" message from client to server contains no
    ** "gimme" cards. On that initial message, send the client an "igot"







|

|







1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
    {
      cgi_reset_content();
      @ error bad\scommand:\s%F(blob_str(&xfer.line))
    }
    blobarray_reset(xfer.aToken, xfer.nToken);
  }
  if( isPush ){
    if( run_script("xfer-push-script", 0) ){
      cgi_reset_content();
      @ error push\sscript\sfailed:\s%F(g.zErrMsg)
      nErr++;
    }
    request_phantoms(&xfer, 500);
  }
  if( isClone && nGimme==0 ){
    /* The initial "clone" message from client to server contains no
    ** "gimme" cards. On that initial message, send the client an "igot"