Fossil

Check-in Differences
Login

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

Difference From:

[643123d5] Fix password change reported on Fossil Forum bug by ending the form tag properly. (user: andybradford tags: trunk, date: 2019-03-23 21:47:15)

To:

[f8d7f76b] Version 2.8 (user: drh tags: trunk, release, version-2.8, date: 2019-02-20 15:01:32)

Changes to Makefile.osx-jaguar.

    36     36   #
    37     37   BCC = cc
    38     38   BCCFLAGS = $(CFLAGS)
    39     39   
    40     40   #### The suffix to add to final executable file.  When cross-compiling
    41     41   #    to windows, make this ".exe".  Otherwise leave it blank.
    42     42   #
    43         -E =
           43  +E = 
    44     44   
    45     45   TCC = cc
    46     46   TCCFLAGS = $(CFLAGS)
    47     47   
    48     48   #### Tcl shell for use in running the fossil testsuite.  If you do not
    49     49   #    care about testing the end result, this can be blank.
    50     50   #
................................................................................
    57     57   TCC += -DSQLITE_WITHOUT_ZONEMALLOC
    58     58   TCC += -D_BSD_SOURCE=1
    59     59   TCC += -DWITHOUT_ICONV
    60     60   TCC += -Dsocklen_t=int
    61     61   TCC += -DSQLITE_MAX_MMAP_SIZE=0
    62     62   TCC += -DFOSSIL_ENABLE_LEGACY_MV_RM=1
    63     63   INSTALLDIR = $(DESTDIR)/usr/local/bin
    64         -USE_SYSTEM_SQLITE =
           64  +USE_SYSTEM_SQLITE = 
    65     65   USE_LINENOISE = 1
    66     66   # FOSSIL_ENABLE_TCL = @FOSSIL_ENABLE_TCL@
    67     67   FOSSIL_ENABLE_TCL = 0
    68     68   FOSSIL_ENABLE_MINIZ = 0
    69     69   
    70     70   include $(SRCDIR)/main.mk
    71     71   
    72     72   distclean: clean
    73     73   	rm -f autoconfig.h config.log Makefile

Deleted README.md.

     1         -# About Fossil
     2         -
     3         -Fossil is a distributed version control system that has been widely
     4         -used since 2007.  Fossil was originally designed to support the
     5         -[SQLite](https://sqlite.org) project but has been adopted by many other
     6         -projects as well.
     7         -
     8         -Fossil is self-hosting at <https://fossil-scm.org>.
     9         -
    10         -If you are reading this on GitHub, then you are looking at a Git mirror
    11         -of the self-hosting Fossil repository.  The purpose of that mirror is to
    12         -test and exercise Fossil's ability to export a Git mirror.  Nobody much
    13         -uses the GitHub mirror, except to verify that the mirror logic works.  If
    14         -you want to know more about Fossil, visit the official self-hosting site
    15         -linked above.

Changes to VERSION.

     1         -2.9
            1  +2.8

Changes to auto.def.

   124    124       # search for the system SQLite once with -ldl, and once without. If
   125    125       # the library can only be found with $extralibs set to -ldl, then
   126    126       # the code below will append -ldl to LIBS.
   127    127       #
   128    128       foreach extralibs {{} {-ldl}} {
   129    129   
   130    130         # Locate the system SQLite by searching for sqlite3_open(). Then check
   131         -      # if sqlite3_stmt_isexplain can be found as well. If we can find open() but
   132         -      # not stmt_isexplain(), then the system SQLite is too old to link against
          131  +      # if sqlite3_create_window_function can be found as well. If we can find open() but
          132  +      # not create_window_function(), then the system SQLite is too old to link against
   133    133         # fossil.
   134    134         #
   135    135         if {[check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
   136         -        if {![check-function-in-lib sqlite3_stmt_isexplain sqlite3 $extralibs]} {
   137         -          user-error "system sqlite3 too old (require >= 3.28.0)"
          136  +        if {![check-function-in-lib sqlite3_create_window_function sqlite3 $extralibs]} {
          137  +          user-error "system sqlite3 too old (require >= 3.25.0)"
   138    138           }
   139    139   
   140    140           # Success. Update symbols and return.
   141    141           #
   142    142           define USE_SYSTEM_SQLITE 1
   143    143           define-append LIBS -lsqlite3
   144    144           define-append LIBS $extralibs

Changes to skins/enhanced1/header.txt.

    61     61       set logourl [getLogoUrl $baseurl]
    62     62       </th1>
    63     63       <a href="$logourl">
    64     64         <img src="$logo_image_url" border="0" alt="$project_name">
    65     65       </a>
    66     66     </div>
    67     67     <div class="title">$<title></div>
    68         -  <div class="status"><nobr><th1>
           68  +  <div class="status"><th1>
    69     69        if {[info exists login]} {
    70     70          puts "Logged in as $login"
    71     71        } else {
    72     72          puts "Not logged in"
    73     73        }
    74     74     </th1></nobr><small><div id="clock"></div></small></div>
    75     75   </div>

Changes to src/backoffice.c.

    78     78   # include <unistd.h>
    79     79   # include <sys/types.h>
    80     80   # include <signal.h>
    81     81   # include <errno.h>
    82     82   # include <fcntl.h>
    83     83   # define GETPID getpid
    84     84   #endif
    85         -#include <time.h>
    86     85   
    87     86   /*
    88     87   ** The BKOFCE_LEASE_TIME is the amount of time for which a single backoffice
    89     88   ** processing run is valid.  Each backoffice run monopolizes the lease for
    90     89   ** at least this amount of time.  Hopefully all backoffice processing is
    91     90   ** finished much faster than this - usually in less than a second.  But
    92     91   ** regardless of how long each invocation lasts, successive backoffice runs
................................................................................
   453    452        && x.idNext!=idSelf
   454    453        && backofficeProcessExists(x.idNext)
   455    454       ){
   456    455         /* Another backoffice process is already queued up to run.  This
   457    456         ** process does not need to do any backoffice work and can stop
   458    457         ** immediately. */
   459    458         db_end_transaction(0);
   460         -      backofficeTrace("/***** Backoffice Processing Not Needed In %d *****/\n",
   461         -                      GETPID());
   462    459         break;
   463    460       }
   464    461       if( x.tmCurrent<tmNow && backofficeProcessDone(x.idCurrent) ){
   465    462         /* This process can start doing backoffice work immediately */
   466    463         x.idCurrent = idSelf;
   467    464         x.tmCurrent = tmNow + BKOFCE_LEASE_TIME;
   468    465         x.idNext = 0;
................................................................................
   475    472         break;
   476    473       }
   477    474       if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){
   478    475         /* If the no-delay flag is set, exit immediately rather than queuing
   479    476         ** up.  Assume that some future request will come along and handle any
   480    477         ** necessary backoffice work. */
   481    478         db_end_transaction(0);
   482         -      backofficeTrace(
   483         -           "/***** Backoffice No-Delay Exit For %d *****/\n",
   484         -           GETPID());
   485    479         break;
   486    480       }
   487    481       /* This process needs to queue up and wait for the current lease
   488    482       ** to expire before continuing. */
   489    483       x.idNext = idSelf;
   490    484       x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
   491    485       backofficeWriteLease(&x);
................................................................................
   539    533     alert_backoffice(0);
   540    534     smtp_cleanup();
   541    535   }
   542    536   
   543    537   /*
   544    538   ** COMMAND: backoffice*
   545    539   **
   546         -** Usage: backoffice [OPTIONS...] [REPOSITORIES...]
          540  +** Usage: backoffice [-R repository]
   547    541   **
   548         -** Run backoffice processing on the repositories listed.  If no
   549         -** repository is specified, run it on the repository of the local checkout.
   550         -**
   551         -** This might be done by a cron job or similar to make sure backoffice
   552         -** processing happens periodically.  Or, the --poll option can be used
   553         -** to run this command as a daemon that will periodically invoke backoffice
   554         -** on collection of repositories.
   555         -**
   556         -** OPTIONS:
   557         -**
   558         -**    --debug                 Show what this command is doing.
   559         -**
   560         -**    --nodelay               Do not queue up or wait for a backoffice job
   561         -**                            to complete. If no work is available or if
   562         -**                            backoffice has run recently, return immediately.
   563         -**                            The --nodelay option is implied if more than
   564         -**                            one repository is listed on the command-line.
   565         -**
   566         -**    --poll N                Repeat backoffice calls for repositories that
   567         -**                            change in appoximately N-second intervals.
   568         -**                            N less than 1 turns polling off (the default).
   569         -**
   570         -**    --trace                 Enable debugging output on stderr
          542  +** Run backoffice processing.  This might be done by a cron job or
          543  +** similar to make sure backoffice processing happens periodically.
   571    544   */
   572    545   void backoffice_command(void){
   573         -  int nPoll;
   574         -  const char *zPoll;
   575         -  int bDebug = 0;
   576         -  unsigned int nCmd = 0;
   577    546     if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1;
   578         -  if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1;
   579         -  zPoll = find_option("poll",0,1);
   580         -  nPoll = zPoll ? atoi(zPoll) : 0;
   581         -  bDebug = find_option("debug",0,0)!=0;
   582         -
   583         -  /* Silently consume the -R or --repository flag, leaving behind its
   584         -  ** argument. This is for legacy compatibility. Older versions of the
   585         -  ** backoffice command only ran on a single repository that was specified
   586         -  ** using the -R option. */
   587         -  (void)find_option("repository","R",0);
   588         -
          547  +  db_find_and_open_repository(0,0);
   589    548     verify_all_options();
   590         -  if( g.argc>3 || nPoll>0 ){
   591         -    /* Either there are multiple repositories named on the command-line
   592         -    ** or we are polling.  In either case, each backoffice should be run
   593         -    ** using a separate sub-process */
   594         -    int i;
   595         -    time_t iNow = 0;
   596         -    time_t ix;
   597         -    while( 1 /* exit via "break;" */){
   598         -      time_t iNext = time(0);
   599         -      for(i=2; i<g.argc; i++){
   600         -        Blob cmd;
   601         -        if( !file_isfile(g.argv[i], ExtFILE) ) continue;
   602         -        if( iNow && iNow>file_mtime(g.argv[i],ExtFILE) ) continue;
   603         -        blob_init(&cmd, 0, 0);
   604         -        blob_append_escaped_arg(&cmd, g.nameOfExe);
   605         -        blob_append(&cmd, " backoffice --nodelay", -1);
   606         -        if( g.fAnyTrace ){
   607         -          blob_append(&cmd, " --trace", -1);
   608         -        }
   609         -        blob_append_escaped_arg(&cmd, g.argv[i]);
   610         -        nCmd++;
   611         -        if( bDebug ){
   612         -          fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd));
   613         -        }
   614         -        fossil_system(blob_str(&cmd));
   615         -        blob_reset(&cmd);
   616         -      }
   617         -      if( nPoll<1 ) break;
   618         -      iNow = iNext;
   619         -      ix = time(0);
   620         -      if( ix < iNow+nPoll ){
   621         -        sqlite3_int64 nMS = (iNow + nPoll - ix)*1000;
   622         -        if( bDebug )fossil_print("SLEEP: %lld\n", nMS);
   623         -        sqlite3_sleep((int)nMS);
   624         -      }
   625         -    }
   626         -  }else{
   627         -    if( g.argc==3 ){
   628         -      g.zRepositoryOption = g.argv[2];
   629         -      g.argc--;
   630         -    }
   631         -    db_find_and_open_repository(0,0);
   632         -    backoffice_thread();
   633         -  }
          549  +  backoffice_thread();
   634    550   }
   635    551   
   636    552   /*
   637    553   ** This is the main interface to backoffice from the rest of the system.
   638    554   ** This routine launches either backoffice_thread() directly or as a
   639    555   ** subprocess.
   640    556   */

Changes to src/checkout.c.

    37     37     return db_exists("SELECT 1 FROM vfile WHERE chnged"
    38     38                      " OR coalesce(origname!=pathname,0)");
    39     39   }
    40     40   
    41     41   /*
    42     42   ** Undo the current check-out.  Unlink all files from the disk.
    43     43   ** Clear the VFILE table.
    44         -**
    45         -** Also delete any directory that becomes empty as a result of deleting
    46         -** files due to this operation, as long as that directory is not the
    47         -** current working directory and is not on the empty-dirs list.
    48     44   */
    49     45   void uncheckout(int vid){
    50         -  char *zPwd;
    51         -  if( vid<=0 ) return;
    52         -  sqlite3_create_function(g.db, "dirname",1,SQLITE_UTF8,0,
    53         -                          file_dirname_sql_function, 0, 0);
    54         -  sqlite3_create_function(g.db, "unlink",1,SQLITE_UTF8,0,
    55         -                          file_delete_sql_function, 0, 0);
    56         -  sqlite3_create_function(g.db, "rmdir", 1, SQLITE_UTF8, 0,
    57         -                          file_rmdir_sql_function, 0, 0);
    58         -  db_multi_exec(
    59         -    "CREATE TEMP TABLE dir_to_delete(name TEXT %s PRIMARY KEY)WITHOUT ROWID",
    60         -    filename_collation()
    61         -  );
    62         -  db_multi_exec(
    63         -    "INSERT OR IGNORE INTO dir_to_delete(name)"
    64         -    "  SELECT dirname(pathname) FROM vfile"
    65         -    "   WHERE vid=%d AND mrid>0",
    66         -    vid
    67         -  );
    68         -  do{
    69         -    db_multi_exec(
    70         -      "INSERT OR IGNORE INTO dir_to_delete(name)"
    71         -      " SELECT dirname(name) FROM dir_to_delete;"
    72         -    );
    73         -  }while( db_changes() );
    74         -  db_multi_exec(
    75         -    "SELECT unlink(%Q||pathname) FROM vfile"
    76         -    " WHERE vid=%d AND mrid>0;",
    77         -    g.zLocalRoot, vid
    78         -  );
    79         -  ensure_empty_dirs_created(1);
    80         -  zPwd = file_getcwd(0,0);
    81         -  db_multi_exec(
    82         -    "SELECT rmdir(%Q||name) FROM dir_to_delete"
    83         -    " WHERE (%Q||name)<>%Q ORDER BY name DESC",
    84         -    g.zLocalRoot, g.zLocalRoot, zPwd
    85         -  );
    86         -  fossil_free(zPwd);
           46  +  if( vid>0 ){
           47  +    vfile_unlink(vid);
           48  +  }
    87     49     db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid);
    88     50   }
    89     51   
    90     52   
    91     53   /*
    92     54   ** Given the abbreviated UUID name of a version, load the content of that
    93     55   ** version in the VFILE table.  Return the VID for the version.
................................................................................
   339    301     }
   340    302     db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
   341    303     if( !keepFlag ){
   342    304       vfile_to_disk(vid, 0, !g.fQuiet, promptFlag);
   343    305     }
   344    306     checkout_set_all_exe(vid);
   345    307     manifest_to_disk(vid);
   346         -  ensure_empty_dirs_created(0);
          308  +  ensure_empty_dirs_created();
   347    309     db_set_checkout(vid);
   348    310     undo_reset();
   349    311     db_multi_exec("DELETE FROM vmerge");
   350    312     if( !keepFlag && db_get_boolean("repo-cksum",1) ){
   351    313       vfile_aggregate_checksum_manifest(vid, &cksum1, &cksum1b);
   352    314       vfile_aggregate_checksum_disk(vid, &cksum2);
   353    315       if( blob_compare(&cksum1, &cksum2) ){

Changes to src/db.c.

   360    360       va_start(ap, zFormat);
   361    361       rc = db_vprepare(pStmt, DB_PREPARE_PERSISTENT, zFormat, ap);
   362    362       va_end(ap);
   363    363     }
   364    364     return rc;
   365    365   }
   366    366   
   367         -/* Return TRUE if static Stmt object pStmt has been initialized.
   368         -*/
   369         -int db_static_stmt_is_init(Stmt *pStmt){
   370         -  return blob_size(&pStmt->sql)>0;
   371         -}
   372         -
   373    367   /* Prepare a statement using text placed inside a Blob
   374    368   ** using blob_append_sql().
   375    369   */
   376    370   int db_prepare_blob(Stmt *pStmt, Blob *pSql){
   377    371     int rc;
   378    372     char *zSql;
   379    373     pStmt->sql = *pSql;

Deleted src/deltafunc.c.

     1         -/*
     2         -** Copyright (c) 2019 D. Richard Hipp
     3         -**
     4         -** This program is free software; you can redistribute it and/or
     5         -** modify it under the terms of the Simplified BSD License (also
     6         -** known as the "2-Clause License" or "FreeBSD License".)
     7         -**
     8         -** This program is distributed in the hope that it will be useful,
     9         -** but without any warranty; without even the implied warranty of
    10         -** merchantability or fitness for a particular purpose.
    11         -**
    12         -** Author contact information:
    13         -**   drh@hwaci.com
    14         -**   http://www.hwaci.com/drh/
    15         -**
    16         -*******************************************************************************
    17         -**
    18         -** This module implements SQL interfaces to the delta logic.  The code
    19         -** here is adapted from the ext/misc/fossildelta.c extension in SQLite.
    20         -*/
    21         -#include "config.h"
    22         -#include "deltafunc.h"
    23         -
    24         -/*
    25         -** SQL functions:  delta_create(X,Y)
    26         -**
    27         -** Return a delta that will transform X into Y.
    28         -*/
    29         -static void deltaCreateFunc(
    30         -  sqlite3_context *context,
    31         -  int argc,
    32         -  sqlite3_value **argv
    33         -){
    34         -  const char *aOrig; int nOrig;  /* old blob */
    35         -  const char *aNew;  int nNew;   /* new blob */
    36         -  char *aOut;        int nOut;   /* output delta */
    37         -
    38         -  assert( argc==2 );
    39         -  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
    40         -  if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return;
    41         -  nOrig = sqlite3_value_bytes(argv[0]);
    42         -  aOrig = (const char*)sqlite3_value_blob(argv[0]);
    43         -  nNew = sqlite3_value_bytes(argv[1]);
    44         -  aNew = (const char*)sqlite3_value_blob(argv[1]);
    45         -  aOut = sqlite3_malloc64(nNew+70);
    46         -  if( aOut==0 ){
    47         -    sqlite3_result_error_nomem(context);
    48         -  }else{
    49         -    nOut = delta_create(aOrig, nOrig, aNew, nNew, aOut);
    50         -    if( nOut<0 ){
    51         -      sqlite3_free(aOut);
    52         -      sqlite3_result_error(context, "cannot create fossil delta", -1);
    53         -    }else{
    54         -      sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
    55         -    }
    56         -  }
    57         -}
    58         -
    59         -/*
    60         -** SQL functions:  delta_apply(X,D)
    61         -**
    62         -** Return the result of applying delta D to input X.
    63         -*/
    64         -static void deltaApplyFunc(
    65         -  sqlite3_context *context,
    66         -  int argc,
    67         -  sqlite3_value **argv
    68         -){
    69         -  const char *aOrig;   int nOrig;        /* The X input */
    70         -  const char *aDelta;  int nDelta;       /* The input delta (D) */
    71         -  char *aOut;          int nOut, nOut2;  /* The output */
    72         -
    73         -  assert( argc==2 );
    74         -  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
    75         -  if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return;
    76         -  nOrig = sqlite3_value_bytes(argv[0]);
    77         -  aOrig = (const char*)sqlite3_value_blob(argv[0]);
    78         -  nDelta = sqlite3_value_bytes(argv[1]);
    79         -  aDelta = (const char*)sqlite3_value_blob(argv[1]);
    80         -
    81         -  /* Figure out the size of the output */
    82         -  nOut = delta_output_size(aDelta, nDelta);
    83         -  if( nOut<0 ){
    84         -    sqlite3_result_error(context, "corrupt fossil delta", -1);
    85         -    return;
    86         -  }
    87         -  aOut = sqlite3_malloc64((sqlite3_int64)nOut+1);
    88         -  if( aOut==0 ){
    89         -    sqlite3_result_error_nomem(context);
    90         -  }else{
    91         -    nOut2 = delta_apply(aOrig, nOrig, aDelta, nDelta, aOut);
    92         -    if( nOut2!=nOut ){
    93         -      sqlite3_free(aOut);
    94         -      sqlite3_result_error(context, "corrupt fossil delta", -1);
    95         -    }else{
    96         -      sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
    97         -    }
    98         -  }
    99         -}
   100         -
   101         -
   102         -/*
   103         -** SQL functions:  delta_output_size(D)
   104         -**
   105         -** Return the size of the output that results from applying delta D.
   106         -*/
   107         -static void deltaOutputSizeFunc(
   108         -  sqlite3_context *context,
   109         -  int argc,
   110         -  sqlite3_value **argv
   111         -){
   112         -  const char *aDelta;  int nDelta;       /* The input delta (D) */
   113         -  int nOut;                              /* Size of output */
   114         -  assert( argc==1 );
   115         -  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
   116         -  nDelta = sqlite3_value_bytes(argv[0]);
   117         -  aDelta = (const char*)sqlite3_value_blob(argv[0]);
   118         -
   119         -  /* Figure out the size of the output */
   120         -  nOut = delta_output_size(aDelta, nDelta);
   121         -  if( nOut<0 ){
   122         -    sqlite3_result_error(context, "corrupt fossil delta", -1);
   123         -    return;
   124         -  }else{
   125         -    sqlite3_result_int(context, nOut);
   126         -  }
   127         -}
   128         -
   129         -/*****************************************************************************
   130         -** Table-valued SQL function:   delta_parse(DELTA)
   131         -**
   132         -** Schema:
   133         -**
   134         -**     CREATE TABLE delta_parse(
   135         -**       op TEXT,
   136         -**       a1 INT,
   137         -**       a2 ANY,
   138         -**       delta HIDDEN BLOB
   139         -**     );
   140         -**
   141         -** Given an input DELTA, this function parses the delta and returns
   142         -** rows for each entry in the delta.  The op column has one of the
   143         -** values SIZE, COPY, INSERT, CHECKSUM, ERROR.
   144         -**
   145         -** Assuming no errors, the first row has op='SIZE'.  a1 is the size of
   146         -** the output in bytes and a2 is NULL.
   147         -**
   148         -** After the initial SIZE row, there are zero or more 'COPY' and/or 'INSERT'
   149         -** rows.  A COPY row means content is copied from the source into the
   150         -** output.  Column a1 is the number of bytes to copy and a2 is the offset
   151         -** into source from which to begin copying.  An INSERT row means to
   152         -** insert text into the output stream.  Column a1 is the number of bytes
   153         -** to insert and column is a BLOB that contains the text to be inserted.
   154         -**
   155         -** The last row of a well-formed delta will have an op value of 'CHECKSUM'.
   156         -** The a1 column will be the value of the checksum and a2 will be NULL.
   157         -**
   158         -** If the input delta is not well-formed, then a row with an op value
   159         -** of 'ERROR' is returned.  The a1 value of the ERROR row is the offset
   160         -** into the delta where the error was encountered and a2 is NULL.
   161         -*/
   162         -typedef struct deltaparsevtab_vtab deltaparsevtab_vtab;
   163         -typedef struct deltaparsevtab_cursor deltaparsevtab_cursor;
   164         -struct deltaparsevtab_vtab {
   165         -  sqlite3_vtab base;  /* Base class - must be first */
   166         -  /* No additional information needed */
   167         -};
   168         -struct deltaparsevtab_cursor {
   169         -  sqlite3_vtab_cursor base;  /* Base class - must be first */
   170         -  char *aDelta;              /* The delta being parsed */
   171         -  int nDelta;                /* Number of bytes in the delta */
   172         -  int iCursor;               /* Current cursor location */
   173         -  int eOp;                   /* Name of current operator */
   174         -  unsigned int a1, a2;       /* Arguments to current operator */
   175         -  int iNext;                 /* Next cursor value */
   176         -};
   177         -
   178         -/* Operator names:
   179         -*/
   180         -static const char *azOp[] = {
   181         -  "SIZE", "COPY", "INSERT", "CHECKSUM", "ERROR", "EOF"
   182         -};
   183         -#define DELTAPARSE_OP_SIZE         0
   184         -#define DELTAPARSE_OP_COPY         1
   185         -#define DELTAPARSE_OP_INSERT       2
   186         -#define DELTAPARSE_OP_CHECKSUM     3
   187         -#define DELTAPARSE_OP_ERROR        4
   188         -#define DELTAPARSE_OP_EOF          5
   189         -
   190         -/*
   191         -** Read bytes from *pz and convert them into a positive integer.  When
   192         -** finished, leave *pz pointing to the first character past the end of
   193         -** the integer.  The *pLen parameter holds the length of the string
   194         -** in *pz and is decremented once for each character in the integer.
   195         -*/
   196         -static unsigned int deltaGetInt(const char **pz, int *pLen){
   197         -  static const signed char zValue[] = {
   198         -    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
   199         -    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
   200         -    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
   201         -     0,  1,  2,  3,  4,  5,  6,  7,    8,  9, -1, -1, -1, -1, -1, -1,
   202         -    -1, 10, 11, 12, 13, 14, 15, 16,   17, 18, 19, 20, 21, 22, 23, 24,
   203         -    25, 26, 27, 28, 29, 30, 31, 32,   33, 34, 35, -1, -1, -1, -1, 36,
   204         -    -1, 37, 38, 39, 40, 41, 42, 43,   44, 45, 46, 47, 48, 49, 50, 51,
   205         -    52, 53, 54, 55, 56, 57, 58, 59,   60, 61, 62, -1, -1, -1, 63, -1,
   206         -  };
   207         -  unsigned int v = 0;
   208         -  int c;
   209         -  unsigned char *z = (unsigned char*)*pz;
   210         -  unsigned char *zStart = z;
   211         -  while( (c = zValue[0x7f&*(z++)])>=0 ){
   212         -     v = (v<<6) + c;
   213         -  }
   214         -  z--;
   215         -  *pLen -= z - zStart;
   216         -  *pz = (char*)z;
   217         -  return v;
   218         -}
   219         -
   220         -/*
   221         -** The deltaparsevtabConnect() method is invoked to create a new
   222         -** deltaparse virtual table.
   223         -**
   224         -** Think of this routine as the constructor for deltaparsevtab_vtab objects.
   225         -**
   226         -** All this routine needs to do is:
   227         -**
   228         -**    (1) Allocate the deltaparsevtab_vtab object and initialize all fields.
   229         -**
   230         -**    (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
   231         -**        result set of queries against the virtual table will look like.
   232         -*/
   233         -static int deltaparsevtabConnect(
   234         -  sqlite3 *db,
   235         -  void *pAux,
   236         -  int argc, const char *const*argv,
   237         -  sqlite3_vtab **ppVtab,
   238         -  char **pzErr
   239         -){
   240         -  deltaparsevtab_vtab *pNew;
   241         -  int rc;
   242         -
   243         -  rc = sqlite3_declare_vtab(db,
   244         -           "CREATE TABLE x(op,a1,a2,delta HIDDEN)"
   245         -       );
   246         -  /* For convenience, define symbolic names for the index to each column. */
   247         -#define DELTAPARSEVTAB_OP     0
   248         -#define DELTAPARSEVTAB_A1     1
   249         -#define DELTAPARSEVTAB_A2     2
   250         -#define DELTAPARSEVTAB_DELTA  3
   251         -  if( rc==SQLITE_OK ){
   252         -    pNew = sqlite3_malloc64( sizeof(*pNew) );
   253         -    *ppVtab = (sqlite3_vtab*)pNew;
   254         -    if( pNew==0 ) return SQLITE_NOMEM;
   255         -    memset(pNew, 0, sizeof(*pNew));
   256         -  }
   257         -  return rc;
   258         -}
   259         -
   260         -/*
   261         -** This method is the destructor for deltaparsevtab_vtab objects.
   262         -*/
   263         -static int deltaparsevtabDisconnect(sqlite3_vtab *pVtab){
   264         -  deltaparsevtab_vtab *p = (deltaparsevtab_vtab*)pVtab;
   265         -  sqlite3_free(p);
   266         -  return SQLITE_OK;
   267         -}
   268         -
   269         -/*
   270         -** Constructor for a new deltaparsevtab_cursor object.
   271         -*/
   272         -static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
   273         -  deltaparsevtab_cursor *pCur;
   274         -  pCur = sqlite3_malloc( sizeof(*pCur) );
   275         -  if( pCur==0 ) return SQLITE_NOMEM;
   276         -  memset(pCur, 0, sizeof(*pCur));
   277         -  *ppCursor = &pCur->base;
   278         -  return SQLITE_OK;
   279         -}
   280         -
   281         -/*
   282         -** Destructor for a deltaparsevtab_cursor.
   283         -*/
   284         -static int deltaparsevtabClose(sqlite3_vtab_cursor *cur){
   285         -  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
   286         -  sqlite3_free(pCur);
   287         -  return SQLITE_OK;
   288         -}
   289         -
   290         -
   291         -/*
   292         -** Advance a deltaparsevtab_cursor to its next row of output.
   293         -*/
   294         -static int deltaparsevtabNext(sqlite3_vtab_cursor *cur){
   295         -  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
   296         -  const char *z;
   297         -  int i = 0;
   298         -
   299         -  pCur->iCursor = pCur->iNext;
   300         -  z = pCur->aDelta + pCur->iCursor;
   301         -  pCur->a1 = deltaGetInt(&z, &i);
   302         -  switch( z[0] ){
   303         -    case '@': {
   304         -      z++;
   305         -      pCur->a2 = deltaGetInt(&z, &i);
   306         -      pCur->eOp = DELTAPARSE_OP_COPY;
   307         -      pCur->iNext = (int)(&z[1] - pCur->aDelta);
   308         -      break;
   309         -    }
   310         -    case ':': {
   311         -      z++;
   312         -      pCur->a2 = (unsigned int)(z - pCur->aDelta);
   313         -      pCur->eOp = DELTAPARSE_OP_INSERT;
   314         -      pCur->iNext = (int)(&z[pCur->a1] - pCur->aDelta);
   315         -      break;
   316         -    }
   317         -    case ';': {
   318         -      pCur->eOp = DELTAPARSE_OP_CHECKSUM;
   319         -      pCur->iNext = pCur->nDelta;
   320         -      break;
   321         -    }
   322         -    default: {
   323         -      if( pCur->iNext==pCur->nDelta ){
   324         -        pCur->eOp = DELTAPARSE_OP_EOF;
   325         -      }else{
   326         -        pCur->eOp = DELTAPARSE_OP_ERROR;
   327         -        pCur->iNext = pCur->nDelta;
   328         -      }
   329         -      break;
   330         -    }
   331         -  }
   332         -  return SQLITE_OK;
   333         -}
   334         -
   335         -/*
   336         -** Return values of columns for the row at which the deltaparsevtab_cursor
   337         -** is currently pointing.
   338         -*/
   339         -static int deltaparsevtabColumn(
   340         -  sqlite3_vtab_cursor *cur,   /* The cursor */
   341         -  sqlite3_context *ctx,       /* First argument to sqlite3_result_...() */
   342         -  int i                       /* Which column to return */
   343         -){
   344         -  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
   345         -  switch( i ){
   346         -    case DELTAPARSEVTAB_OP: {
   347         -      sqlite3_result_text(ctx, azOp[pCur->eOp], -1, SQLITE_STATIC);
   348         -      break;
   349         -    }
   350         -    case DELTAPARSEVTAB_A1: {
   351         -      sqlite3_result_int(ctx, pCur->a1);
   352         -      break;
   353         -    }
   354         -    case DELTAPARSEVTAB_A2: {
   355         -      if( pCur->eOp==DELTAPARSE_OP_COPY ){
   356         -        sqlite3_result_int(ctx, pCur->a2);
   357         -      }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){
   358         -        sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1,
   359         -                            SQLITE_TRANSIENT);
   360         -      }
   361         -      break;
   362         -    }
   363         -    case DELTAPARSEVTAB_DELTA: {
   364         -      sqlite3_result_blob(ctx, pCur->aDelta, pCur->nDelta, SQLITE_TRANSIENT);
   365         -      break;
   366         -    }
   367         -  }
   368         -  return SQLITE_OK;
   369         -}
   370         -
   371         -/*
   372         -** Return the rowid for the current row.  In this implementation, the
   373         -** rowid is the same as the output value.
   374         -*/
   375         -static int deltaparsevtabRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
   376         -  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
   377         -  *pRowid = pCur->iCursor;
   378         -  return SQLITE_OK;
   379         -}
   380         -
   381         -/*
   382         -** Return TRUE if the cursor has been moved off of the last
   383         -** row of output.
   384         -*/
   385         -static int deltaparsevtabEof(sqlite3_vtab_cursor *cur){
   386         -  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
   387         -  return pCur->eOp==DELTAPARSE_OP_EOF;
   388         -}
   389         -
   390         -/*
   391         -** This method is called to "rewind" the deltaparsevtab_cursor object back
   392         -** to the first row of output.  This method is always called at least
   393         -** once prior to any call to deltaparsevtabColumn() or deltaparsevtabRowid() or 
   394         -** deltaparsevtabEof().
   395         -*/
   396         -static int deltaparsevtabFilter(
   397         -  sqlite3_vtab_cursor *pVtabCursor, 
   398         -  int idxNum, const char *idxStr,
   399         -  int argc, sqlite3_value **argv
   400         -){
   401         -  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor *)pVtabCursor;
   402         -  const char *a;
   403         -  int i = 0;
   404         -  pCur->eOp = DELTAPARSE_OP_ERROR;
   405         -  if( idxNum!=1 ){
   406         -    return SQLITE_OK;
   407         -  }
   408         -  pCur->nDelta = sqlite3_value_bytes(argv[0]);
   409         -  a = (const char*)sqlite3_value_blob(argv[0]);
   410         -  if( pCur->nDelta==0 || a==0 ){
   411         -    return SQLITE_OK;
   412         -  }
   413         -  pCur->aDelta = sqlite3_malloc64( pCur->nDelta+1 );
   414         -  if( pCur->aDelta==0 ){
   415         -    pCur->nDelta = 0;
   416         -    return SQLITE_NOMEM;
   417         -  }
   418         -  memcpy(pCur->aDelta, a, pCur->nDelta);
   419         -  pCur->aDelta[pCur->nDelta] = 0;
   420         -  a = pCur->aDelta;
   421         -  pCur->eOp = DELTAPARSE_OP_SIZE;
   422         -  pCur->a1 = deltaGetInt(&a, &i);
   423         -  if( a[0]!='\n' ){
   424         -    pCur->eOp = DELTAPARSE_OP_ERROR;
   425         -    pCur->a1 = pCur->a2 = 0;
   426         -    pCur->iNext = pCur->nDelta;
   427         -    return SQLITE_OK;
   428         -  }
   429         -  a++;
   430         -  pCur->iNext = (unsigned int)(a - pCur->aDelta);
   431         -  return SQLITE_OK;
   432         -}
   433         -
   434         -/*
   435         -** SQLite will invoke this method one or more times while planning a query
   436         -** that uses the virtual table.  This routine needs to create
   437         -** a query plan for each invocation and compute an estimated cost for that
   438         -** plan.
   439         -*/
   440         -static int deltaparsevtabBestIndex(
   441         -  sqlite3_vtab *tab,
   442         -  sqlite3_index_info *pIdxInfo
   443         -){
   444         -  int i;
   445         -  for(i=0; i<pIdxInfo->nConstraint; i++){
   446         -    if( pIdxInfo->aConstraint[i].iColumn != DELTAPARSEVTAB_DELTA ) continue;
   447         -    if( pIdxInfo->aConstraint[i].usable==0 ) continue;
   448         -    if( pIdxInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
   449         -    pIdxInfo->aConstraintUsage[i].argvIndex = 1;
   450         -    pIdxInfo->aConstraintUsage[i].omit = 1;
   451         -    pIdxInfo->estimatedCost = (double)1;
   452         -    pIdxInfo->estimatedRows = 10;
   453         -    pIdxInfo->idxNum = 1;
   454         -    return SQLITE_OK;
   455         -  }
   456         -  pIdxInfo->idxNum = 0;
   457         -  pIdxInfo->estimatedCost = (double)0x7fffffff;
   458         -  pIdxInfo->estimatedRows = 0x7fffffff;
   459         -  return SQLITE_CONSTRAINT;
   460         -}
   461         -
   462         -/*
   463         -** This following structure defines all the methods for the 
   464         -** virtual table.
   465         -*/
   466         -static sqlite3_module deltaparsevtabModule = {
   467         -  /* iVersion    */ 0,
   468         -  /* xCreate     */ 0,
   469         -  /* xConnect    */ deltaparsevtabConnect,
   470         -  /* xBestIndex  */ deltaparsevtabBestIndex,
   471         -  /* xDisconnect */ deltaparsevtabDisconnect,
   472         -  /* xDestroy    */ 0,
   473         -  /* xOpen       */ deltaparsevtabOpen,
   474         -  /* xClose      */ deltaparsevtabClose,
   475         -  /* xFilter     */ deltaparsevtabFilter,
   476         -  /* xNext       */ deltaparsevtabNext,
   477         -  /* xEof        */ deltaparsevtabEof,
   478         -  /* xColumn     */ deltaparsevtabColumn,
   479         -  /* xRowid      */ deltaparsevtabRowid,
   480         -  /* xUpdate     */ 0,
   481         -  /* xBegin      */ 0,
   482         -  /* xSync       */ 0,
   483         -  /* xCommit     */ 0,
   484         -  /* xRollback   */ 0,
   485         -  /* xFindMethod */ 0,
   486         -  /* xRename     */ 0,
   487         -  /* xSavepoint  */ 0,
   488         -  /* xRelease    */ 0,
   489         -  /* xRollbackTo */ 0,
   490         -  /* xShadowName */ 0
   491         -};
   492         -
   493         -/*
   494         -** Invoke this routine to register the various delta functions.
   495         -*/
   496         -int deltafunc_init(sqlite3 *db){
   497         -  int rc = SQLITE_OK;
   498         -  rc = sqlite3_create_function(db, "delta_create", 2, SQLITE_UTF8, 0,
   499         -                               deltaCreateFunc, 0, 0);
   500         -  if( rc==SQLITE_OK ){
   501         -    rc = sqlite3_create_function(db, "delta_apply", 2, SQLITE_UTF8, 0,
   502         -                                 deltaApplyFunc, 0, 0);
   503         -  }
   504         -  if( rc==SQLITE_OK ){
   505         -    rc = sqlite3_create_function(db, "delta_output_size", 1, SQLITE_UTF8, 0,
   506         -                                 deltaOutputSizeFunc, 0, 0);
   507         -  }
   508         -  if( rc==SQLITE_OK ){
   509         -    rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0);
   510         -  }
   511         -  return rc;
   512         -}

Changes to src/export.c.

    26     26   */
    27     27   static struct {
    28     28     const char *zTrunkName;     /* Name of trunk branch */
    29     29   } gexport;
    30     30   
    31     31   #if INTERFACE
    32     32   /*
    33         -** Each line in a git-fast-export "marK" file is an instance of
    34         -** this object.
           33  +** struct mark_t
           34  +**   holds information for translating between git commits
           35  +**   and fossil commits.
           36  +**   -git_name: This is the mark name that identifies the commit to git.
           37  +**              It will always begin with a ':'.
           38  +**   -rid: The unique object ID that identifies this commit within the
           39  +**         repository database.
           40  +**   -uuid: The SHA-1/SHA-3 of artifact corresponding to rid.
    35     41   */
    36         -struct mark_t {
    37         -  char *name;       /* Name of the mark.  Also starts with ":" */
    38         -  int rid;          /* Corresponding object in the BLOB table */
    39         -  char uuid[65];    /* The GIT hash name for this object */
           42  +struct mark_t{
           43  +  char *name;
           44  +  int rid;
           45  +  char uuid[65];
    40     46   };
    41     47   #endif
    42     48   
    43         -#if defined(_WIN32) || defined(WIN32)
    44         -# undef popen
    45         -# define popen _popen
    46         -# undef pclose
    47         -# define pclose _pclose
    48         -#endif
    49         -
    50     49   /*
    51     50   ** Output a "committer" record for the given user.
    52     51   ** NOTE: the given user name may be an email itself.
    53     52   */
    54     53   static void print_person(const char *zUser){
    55     54     static Stmt q;
    56     55     const char *zContact;
................................................................................
   296    295         return NULL;
   297    296       }
   298    297     }
   299    298     return zMark;
   300    299   }
   301    300   
   302    301   /*
   303         -** Parse a single line of the mark file.  Store the result in the mark object.
   304         -**
   305         -** "line" is a single line of input.
   306         -** This function returns -1 in the case that the line is blank, malformed, or
   307         -** the rid/uuid named in 'line' does not match what is in the repository
   308         -** database.  Otherwise, 0 is returned.
   309         -**
   310         -** mark->name is dynamically allocated, and owned by the caller.
          302  +** parse_mark()
          303  +**   Create a new (mark,rid,uuid) entry in the 'xmark' table given a line
          304  +**   from a marks file.  Return the cross-ref information as a struct mark_t
          305  +**   in *mark.
          306  +**   This function returns -1 in the case that the line is blank, malformed, or
          307  +**   the rid/uuid named in 'line' does not match what is in the repository
          308  +**   database.  Otherwise, 0 is returned.
          309  +**   mark->name is dynamically allocated, and owned by the caller.
   311    310   */
   312    311   int parse_mark(char *line, struct mark_t *mark){
   313    312     char *cur_tok;
   314    313     char type_;
   315    314     cur_tok = strtok(line, " \t");
   316    315     if( !cur_tok || strlen(cur_tok)<2 ){
   317    316       return -1;
................................................................................
   360    359   
   361    360     /* insert a cross-ref into the 'xmark' table */
   362    361     insert_commit_xref(mark->rid, mark->name, mark->uuid);
   363    362     return 0;
   364    363   }
   365    364   
   366    365   /*
   367         -** Import the marks specified in file 'f';
   368         -** If 'blobs' is non-null, insert all blob marks into it.
   369         -** If 'vers' is non-null, insert all commit marks into it.
   370         -** If 'unused_marks' is non-null, upon return of this function, all values
   371         -** x >= *unused_marks are free to use as marks, i.e. they do not clash with
   372         -** any marks appearing in the marks file.
   373         -**
   374         -** Each line in the file must be at most 100 characters in length.  This
   375         -** seems like a reasonable maximum for a 40-character uuid, and 1-13
   376         -** character rid.
   377         -**
   378         -** The function returns -1 if any of the lines in file 'f' are malformed,
   379         -** or the rid/uuid information doesn't match what is in the repository
   380         -** database.  Otherwise, 0 is returned.
          366  +** import_marks()
          367  +**   Import the marks specified in file 'f' into the 'xmark' table.
          368  +**   If 'blobs' is non-null, insert all blob marks into it.
          369  +**   If 'vers' is non-null, insert all commit marks into it.
          370  +**   If 'unused_marks' is non-null, upon return of this function, all values
          371  +**   x >= *unused_marks are free to use as marks, i.e. they do not clash with
          372  +**   any marks appearing in the marks file.
          373  +**   Each line in the file must be at most 100 characters in length.  This
          374  +**   seems like a reasonable maximum for a 40-character uuid, and 1-13
          375  +**   character rid.
          376  +**   The function returns -1 if any of the lines in file 'f' are malformed,
          377  +**   or the rid/uuid information doesn't match what is in the repository
          378  +**   database.  Otherwise, 0 is returned.
   381    379   */
   382    380   int import_marks(FILE* f, Bag *blobs, Bag *vers, unsigned int *unused_mark){
   383    381     char line[101];
   384    382     while(fgets(line, sizeof(line), f)){
   385    383       struct mark_t mark;
   386    384       if( strlen(line)==100 && line[99]!='\n' ){
   387    385         /* line too long */
................................................................................
   452    450         do{
   453    451           export_mark(f, rid, 'c');
   454    452         }while( (rid = bag_next(vers, rid))!=0 );
   455    453       }
   456    454     }
   457    455   }
   458    456   
   459         -/* This is the original header command (and hence documentation) for
   460         -** the "fossil export" command:
   461         -** 
          457  +/*
          458  +** COMMAND: export
          459  +**
   462    460   ** Usage: %fossil export --git ?OPTIONS? ?REPOSITORY?
   463    461   **
   464    462   ** Write an export of all check-ins to standard output.  The export is
   465    463   ** written in the git-fast-export file format assuming the --git option is
   466    464   ** provided.  The git-fast-export format is currently the only VCS
   467    465   ** interchange format supported, though other formats may be added in
   468    466   ** the future.
................................................................................
   483    481   **   --export-marks FILE          export rids of exported data to FILE
   484    482   **   --import-marks FILE          read rids of data to ignore from FILE
   485    483   **   --rename-trunk NAME          use NAME as name of exported trunk branch
   486    484   **   --repository|-R REPOSITORY   export the given REPOSITORY
   487    485   **
   488    486   ** See also: import
   489    487   */
   490         -/*
   491         -** COMMAND: export*
   492         -**
   493         -** This command is deprecated.  Use "fossil git export" instead.
   494         -*/
   495    488   void export_cmd(void){
   496    489     Stmt q, q2, q3;
   497    490     Bag blobs, vers;
   498    491     unsigned int unused_mark = 1;
   499    492     const char *markfile_in;
   500    493     const char *markfile_out;
   501    494   
................................................................................
   512    505   
   513    506     db_find_and_open_repository(0, 2);
   514    507     verify_all_options();
   515    508     if( g.argc!=2 && g.argc!=3 ){ usage("--git ?REPOSITORY?"); }
   516    509   
   517    510     db_multi_exec("CREATE TEMPORARY TABLE oldblob(rid INTEGER PRIMARY KEY)");
   518    511     db_multi_exec("CREATE TEMPORARY TABLE oldcommit(rid INTEGER PRIMARY KEY)");
   519         -  db_multi_exec("CREATE TEMP TABLE xmark(tname TEXT UNIQUE, trid INT,"
   520         -                " tuuid TEXT)");
          512  +  db_multi_exec("CREATE TEMP TABLE xmark(tname TEXT UNIQUE, trid INT, tuuid TEXT)");
   521    513     db_multi_exec("CREATE INDEX xmark_trid ON xmark(trid)");
   522    514     if( markfile_in!=0 ){
   523    515       Stmt qb,qc;
   524    516       FILE *f;
   525    517       int rid;
   526    518   
   527    519       f = fossil_fopen(markfile_in, "r");
................................................................................
   760    752   **        tid INTEGER PRIMARY KEY,   -- Check-in id
   761    753   **        tseq INT                   -- integer total order on check-ins.
   762    754   **     );
   763    755   **
   764    756   ** This table contains all check-ins of the repository in topological
   765    757   ** order.  "Topological order" means that every parent check-in comes
   766    758   ** before all of its children.  Topological order is *almost* the same
   767         -** thing as "ORDER BY event.mtime".  Differences only arise when there
          759  +** thing as "ORDER BY event.mtime".  Differences only arrise when there
   768    760   ** are timewarps.  In as much as Git hates timewarps, we have to compute
   769    761   ** a correct topological order when doing an export.
   770    762   **
   771    763   ** Since mtime is a usually already nearly in topological order, the
   772    764   ** algorithm is to start with mtime, then make adjustments as necessary
   773    765   ** for timewarps.  This is not a great algorithm for the general case,
   774    766   ** but it is very fast for the overwhelmingly common case where there
................................................................................
   841    833   */
   842    834   void test_topological_sort(void){
   843    835     int n;
   844    836     db_find_and_open_repository(0, 0);
   845    837     n = topological_sort_checkins(1);
   846    838     fossil_print("%d reorderings required\n", n);
   847    839   }
   848         -
   849         -/***************************************************************************
   850         -** Implementation of the "fossil git" command follows.  We hope that the
   851         -** new code that follows will largely replace the legacy "fossil export"
   852         -** and "fossil import" code above.
   853         -*/
   854         -
   855         -/* Verbosity level.  Higher means more output.
   856         -**
   857         -**    0     print nothing at all
   858         -**    1     Errors only
   859         -**    2     Progress information (This is the default)
   860         -**    3     Extra details
   861         -*/
   862         -#define VERB_ERROR  1
   863         -#define VERB_NORMAL 2
   864         -#define VERB_EXTRA  3
   865         -static int gitmirror_verbosity = VERB_NORMAL;
   866         -
   867         -/*
   868         -** Output routine that depends on verbosity
   869         -*/
   870         -static void gitmirror_message(int iLevel, const char *zFormat, ...){
   871         -  va_list ap;
   872         -  if( iLevel>gitmirror_verbosity ) return;
   873         -  va_start(ap, zFormat);
   874         -  fossil_vprint(zFormat, ap);
   875         -  va_end(ap);
   876         -}
   877         -
   878         -/*
   879         -** Convert characters of z[] that are not allowed to be in branch or
   880         -** tag names into "_".
   881         -*/
   882         -static void gitmirror_sanitize_name(char *z){
   883         -  static unsigned char aSafe[] = {
   884         -     /* x0 x1 x2 x3 x4 x5 x6 x7 x8  x9 xA xB xC xD xE xF */
   885         -         0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,  /* 0x */
   886         -         0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,  /* 1x */
   887         -         0, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1,  /* 2x */
   888         -         1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 0, 1, 1, 1, 1, 0,  /* 3x */
   889         -         0, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1,  /* 4x */
   890         -         1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 0, 0, 1, 0, 1,  /* 5x */
   891         -         1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1,  /* 6x */
   892         -         1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 0, 0,  /* 7x */
   893         -  };
   894         -  unsigned char *zu = (unsigned char*)z;
   895         -  int i;
   896         -  for(i=0; zu[i]; i++){
   897         -    if( zu[i]>0x7f || !aSafe[zu[i]] ){
   898         -      zu[i] = '_';
   899         -    }else if( zu[i]=='/' && (i==0 || zu[i+1]==0 || zu[i+1]=='/') ){
   900         -      zu[i] = '_';
   901         -    }else if( zu[i]=='.' && (zu[i+1]==0 || zu[i+1]=='.'
   902         -                             || (i>0 && zu[i-1]=='.')) ){
   903         -      zu[i] = '_';
   904         -    }
   905         -  }
   906         -}
   907         -
   908         -/*
   909         -** Quote a filename as a C-style string using \\ and \" if necessary.
   910         -** If quoting is not necessary, just return a copy of the input string.
   911         -**
   912         -** The return value is a held in memory obtained from fossil_malloc()
   913         -** and must be freed by the caller.
   914         -*/
   915         -static char *gitmirror_quote_filename_if_needed(const char *zIn){
   916         -  int i, j;
   917         -  char c;
   918         -  int nSpecial = 0;
   919         -  char *zOut;
   920         -  for(i=0; (c = zIn[i])!=0; i++){
   921         -    if( c=='\\' || c=='"' || c=='\n' ){
   922         -      nSpecial++;
   923         -    }
   924         -  }
   925         -  if( nSpecial==0 ){
   926         -    return fossil_strdup(zIn);
   927         -  }
   928         -  zOut = fossil_malloc( i+nSpecial+3 );
   929         -  zOut[0] = '"';
   930         -  for(i=0, j=1; (c = zIn[i])!=0; i++){
   931         -    if( c=='\\' || c=='"' || c=='\n' ){
   932         -      zOut[j++] = '\\';
   933         -      if( c=='\n' ){
   934         -        zOut[j++] = 'n';
   935         -      }else{
   936         -        zOut[j++] = c;
   937         -      }
   938         -    }else{
   939         -      zOut[j++] = c;
   940         -    }
   941         -  }
   942         -  zOut[j++] = '"';
   943         -  zOut[j] = 0;
   944         -  return zOut;
   945         -}
   946         -
   947         -/*
   948         -** Find the Git-name corresponding to the Fossil-name zUuid.
   949         -**
   950         -** If the mark does not exist and if the bCreate flag is false, then
   951         -** return NULL.  If the mark does not exist and the bCreate flag is true,
   952         -** then create the mark.
   953         -**
   954         -** The string returned is obtained from fossil_malloc() and should
   955         -** be freed by the caller.
   956         -*/
   957         -static char *gitmirror_find_mark(const char *zUuid, int bCreate){
   958         -  static Stmt sFind, sIns;
   959         -  db_static_prepare(&sFind,
   960         -    "SELECT coalesce(githash,printf(':%%d',id))"
   961         -    " FROM mirror.mmark WHERE uuid=:uuid"
   962         -  );
   963         -  db_bind_text(&sFind, ":uuid", zUuid);
   964         -  if( db_step(&sFind)==SQLITE_ROW ){
   965         -    char *zMark = fossil_strdup(db_column_text(&sFind, 0));
   966         -    db_reset(&sFind);
   967         -    return zMark;
   968         -  }
   969         -  db_reset(&sFind);
   970         -  if( !bCreate ){
   971         -    return 0;
   972         -  }
   973         -  db_static_prepare(&sIns,
   974         -    "INSERT INTO mirror.mmark(uuid) VALUES(:uuid)"
   975         -  );
   976         -  db_bind_text(&sIns, ":uuid", zUuid);
   977         -  db_step(&sIns);
   978         -  db_reset(&sIns);
   979         -  return mprintf(":%d", db_last_insert_rowid());
   980         -}
   981         -
   982         -/* This is the SHA3-256 hash of an empty file */
   983         -static const char zEmptySha3[] = 
   984         -  "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a";
   985         -
   986         -/*
   987         -** Export a single file named by zUuid.
   988         -**
   989         -** Return 0 on success and non-zero on any failure.
   990         -**
   991         -** If zUuid is a shunned file, then treat it as if it were any empty file.
   992         -** But files that are missing from the repository but have not been officially
   993         -** shunned cause an error return.  Except, if bPhantomOk is true, then missing
   994         -** files are replaced by an empty file.
   995         -*/
   996         -static int gitmirror_send_file(FILE *xCmd, const char *zUuid, int bPhantomOk){
   997         -  char *zMark;
   998         -  int rid;
   999         -  int rc;
  1000         -  Blob data;
  1001         -  rid = fast_uuid_to_rid(zUuid);
  1002         -  if( rid<0 ){
  1003         -    if( bPhantomOk || uuid_is_shunned(zUuid) ){
  1004         -      gitmirror_message(VERB_EXTRA, "missing file: %s\n", zUuid);
  1005         -      zUuid = zEmptySha3;
  1006         -    }else{
  1007         -      return 1;
  1008         -    }
  1009         -  }else{
  1010         -    rc = content_get(rid, &data);
  1011         -    if( rc==0 ){
  1012         -      if( bPhantomOk ){
  1013         -        blob_init(&data, 0, 0);
  1014         -        gitmirror_message(VERB_EXTRA, "missing file: %s\n", zUuid);
  1015         -        zUuid = zEmptySha3;
  1016         -      }else{      
  1017         -        return 1;
  1018         -      }
  1019         -    }
  1020         -  }
  1021         -  zMark = gitmirror_find_mark(zUuid, 1);
  1022         -  if( zMark[0]==':' ){
  1023         -    fprintf(xCmd, "blob\nmark %s\ndata %d\n", zMark, blob_size(&data));
  1024         -    fwrite(blob_buffer(&data), 1, blob_size(&data), xCmd);
  1025         -    fprintf(xCmd, "\n");
  1026         -  }
  1027         -  fossil_free(zMark);
  1028         -  blob_reset(&data);
  1029         -  return 0;
  1030         -}
  1031         -
  1032         -/*
  1033         -** Transfer a check-in over to the mirror.  "rid" is the BLOB.RID for
  1034         -** the check-in to export.
  1035         -**
  1036         -** If any ancestor of the check-in has not yet been exported, then
  1037         -** invoke this routine recursively to export the ancestor first.
  1038         -** This can only happen on a timewarp, so deep nesting is unlikely.
  1039         -**
  1040         -** Before sending the check-in, first make sure all associated files
  1041         -** have already been exported, and send "blob" records for any that
  1042         -** have not been.  Update the MIRROR.MMARK table so that it holds the
  1043         -** marks for the exported files.
  1044         -**
  1045         -** Return zero on success and non-zero if the export should be stopped.
  1046         -*/
  1047         -static int gitmirror_send_checkin(
  1048         -  FILE *xCmd,           /* Write fast-import text on this pipe */
  1049         -  int rid,              /* BLOB.RID for the check-in to export */
  1050         -  const char *zUuid,    /* BLOB.UUID for the check-in to export */
  1051         -  int *pnLimit,         /* Stop when the counter reaches zero */
  1052         -  int fManifest         /* MFESTFLG_* values */
  1053         -){
  1054         -  Manifest *pMan;       /* The check-in to be output */
  1055         -  int i;                /* Loop counter */
  1056         -  int iParent;          /* Which immediate ancestor is primary.  -1 for none */
  1057         -  Stmt q;               /* An SQL query */
  1058         -  char *zBranch;        /* The branch of the check-in */
  1059         -  char *zMark;          /* The Git-name of the check-in */
  1060         -  Blob sql;             /* String of SQL for part of the query */
  1061         -  Blob comment;         /* The comment text for the check-in */
  1062         -  int nErr = 0;         /* Number of errors */
  1063         -  int bPhantomOk;       /* True if phantom files should be ignored */
  1064         -
  1065         -  pMan = manifest_get(rid, CFTYPE_MANIFEST, 0);
  1066         -  if( pMan==0 ){
  1067         -    /* Must be a phantom.  Return without doing anything, and in particular
  1068         -    ** without creating a mark for this check-in. */
  1069         -    gitmirror_message(VERB_NORMAL, "missing check-in: %s\n", zUuid);
  1070         -    return 0;
  1071         -  }
  1072         -
  1073         -  /* Check to see if any parent logins have not yet been processed, and
  1074         -  ** if so, create them */
  1075         -  for(i=0; i<pMan->nParent; i++){
  1076         -    char *zPMark = gitmirror_find_mark(pMan->azParent[i], 0);
  1077         -    if( zPMark==0 ){
  1078         -      int prid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q",
  1079         -                        pMan->azParent[i]);
  1080         -      int rc = gitmirror_send_checkin(xCmd, prid, pMan->azParent[i],
  1081         -                                      pnLimit, fManifest);
  1082         -      if( rc || *pnLimit<=0 ){
  1083         -        manifest_destroy(pMan);
  1084         -        return 1;
  1085         -      }
  1086         -    }
  1087         -    fossil_free(zPMark);
  1088         -  }
  1089         -
  1090         -  /* Ignore phantom files on check-ins that are over one year old */
  1091         -  bPhantomOk = db_int(0, "SELECT %.6f<julianday('now','-1 year')",
  1092         -                      pMan->rDate);
  1093         -
  1094         -  /* Make sure all necessary files have been exported */
  1095         -  db_prepare(&q,
  1096         -    "SELECT uuid FROM files_of_checkin(%Q)"
  1097         -    " WHERE uuid NOT IN (SELECT uuid FROM mirror.mmark)",
  1098         -    zUuid
  1099         -  );
  1100         -  while( db_step(&q)==SQLITE_ROW ){
  1101         -    const char *zFUuid = db_column_text(&q, 0);
  1102         -    int n = gitmirror_send_file(xCmd, zFUuid, bPhantomOk);
  1103         -    nErr += n;
  1104         -    if( n ) gitmirror_message(VERB_ERROR, "missing file: %s\n", zFUuid);
  1105         -  }
  1106         -  db_finalize(&q);
  1107         -
  1108         -  /* If some required files could not be exported, abandon the check-in
  1109         -  ** export */
  1110         -  if( nErr ){
  1111         -    gitmirror_message(VERB_ERROR,
  1112         -             "export of %s abandoned due to missing files\n", zUuid);
  1113         -    *pnLimit = 0;
  1114         -    return 1;
  1115         -  }
  1116         -
  1117         -  /* Figure out which branch this check-in is a member of */
  1118         -  zBranch = db_text(0,
  1119         -    "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=%d",
  1120         -    TAG_BRANCH, rid
  1121         -  );
  1122         -  if( fossil_strcmp(zBranch,"trunk")==0 ){
  1123         -    fossil_free(zBranch);
  1124         -    zBranch = mprintf("master");
  1125         -  }else if( zBranch==0 ){
  1126         -    zBranch = mprintf("unknown");
  1127         -  }else{
  1128         -    gitmirror_sanitize_name(zBranch);
  1129         -  }
  1130         -
  1131         -  /* Export the check-in */
  1132         -  fprintf(xCmd, "commit refs/heads/%s\n", zBranch);
  1133         -  fossil_free(zBranch);
  1134         -  zMark = gitmirror_find_mark(zUuid,1);
  1135         -  fprintf(xCmd, "mark %s\n", zMark);
  1136         -  fossil_free(zMark);
  1137         -  fprintf(xCmd, "committer %s <%s@noemail.net> %lld +0000\n",
  1138         -     pMan->zUser, pMan->zUser, 
  1139         -     (sqlite3_int64)((pMan->rDate-2440587.5)*86400.0)
  1140         -  );
  1141         -  blob_init(&comment, pMan->zComment, -1);
  1142         -  if( blob_size(&comment)==0 ){
  1143         -    blob_append(&comment, "(no comment)", -1);
  1144         -  }
  1145         -  blob_appendf(&comment, "\n\nFossilOrigin-Name: %s", zUuid);
  1146         -  fprintf(xCmd, "data %d\n%s\n", blob_size(&comment), blob_str(&comment));
  1147         -  blob_reset(&comment);
  1148         -  iParent = -1;  /* Which ancestor is the primary parent */
  1149         -  for(i=0; i<pMan->nParent; i++){
  1150         -    char *zOther = gitmirror_find_mark(pMan->azParent[i], 0);
  1151         -    if( zOther==0 ) continue;
  1152         -    if( iParent<0 ){
  1153         -      iParent = i;
  1154         -      fprintf(xCmd, "from %s\n", zOther);
  1155         -    }else{
  1156         -      fprintf(xCmd, "merge %s\n", zOther);
  1157         -    }
  1158         -    fossil_free(zOther);
  1159         -  }
  1160         -  if( iParent>=0 ){
  1161         -    db_prepare(&q,
  1162         -      "SELECT filename FROM files_of_checkin(%Q)"
  1163         -      " EXCEPT SELECT filename FROM files_of_checkin(%Q)",
  1164         -      pMan->azParent[iParent], zUuid
  1165         -    );
  1166         -    while( db_step(&q)==SQLITE_ROW ){
  1167         -      fprintf(xCmd, "D %s\n", db_column_text(&q,0));
  1168         -    }
  1169         -    db_finalize(&q);
  1170         -  }
  1171         -  blob_init(&sql, 0, 0);
  1172         -  blob_append_sql(&sql,
  1173         -    "SELECT filename, uuid, perm FROM files_of_checkin(%Q)",
  1174         -    zUuid
  1175         -  );
  1176         -  if( pMan->nParent ){
  1177         -    blob_append_sql(&sql,
  1178         -      " EXCEPT SELECT filename, uuid, perm FROM files_of_checkin(%Q)",
  1179         -      pMan->azParent[0]);
  1180         -  }
  1181         -  db_prepare(&q,
  1182         -     "SELECT x.filename, x.perm,"
  1183         -          "  coalesce(mmark.githash,printf(':%%d',mmark.id))"
  1184         -     "  FROM (%s) AS x, mirror.mmark"
  1185         -     " WHERE mmark.uuid=x.uuid",
  1186         -     blob_sql_text(&sql)
  1187         -  );
  1188         -  blob_reset(&sql);
  1189         -  while( db_step(&q)==SQLITE_ROW ){
  1190         -    const char *zFilename = db_column_text(&q,0);
  1191         -    const char *zMode = db_column_text(&q,1);
  1192         -    const char *zMark = db_column_text(&q,2);
  1193         -    const char *zGitMode = "100644";
  1194         -    char *zFNQuoted = 0;
  1195         -    if( zMode ){
  1196         -      if( strchr(zMode,'x') ) zGitMode = "100755";
  1197         -      if( strchr(zMode,'l') ) zGitMode = "120000";
  1198         -    }
  1199         -    zFNQuoted = gitmirror_quote_filename_if_needed(zFilename);
  1200         -    fprintf(xCmd,"M %s %s %s\n", zGitMode, zMark, zFNQuoted);
  1201         -    fossil_free(zFNQuoted);
  1202         -  }
  1203         -  db_finalize(&q);
  1204         -
  1205         -  /* Include Fossil-generated auxiliary files in the check-in */
  1206         -  if( fManifest & MFESTFLG_RAW ){
  1207         -    Blob manifest;
  1208         -    content_get(rid, &manifest);
  1209         -    fprintf(xCmd,"M 100644 inline manifest\ndata %d\n%s\n",
  1210         -      blob_size(&manifest), blob_str(&manifest));
  1211         -    blob_reset(&manifest);
  1212         -  }
  1213         -  if( fManifest & MFESTFLG_UUID ){
  1214         -    int n = (int)strlen(zUuid);
  1215         -    fprintf(xCmd,"M 100644 inline manifest.uuid\ndata %d\n%s\n", n, zUuid);
  1216         -  }
  1217         -  if( fManifest & MFESTFLG_TAGS ){
  1218         -    Blob tagslist;
  1219         -    blob_init(&tagslist, 0, 0);
  1220         -    get_checkin_taglist(rid, &tagslist);
  1221         -    fprintf(xCmd,"M 100644 inline manifest.tags\ndata %d\n%s\n",
  1222         -      blob_size(&tagslist), blob_str(&tagslist));
  1223         -    blob_reset(&tagslist);
  1224         -  }
  1225         -
  1226         -  /* The check-in is finished, so decrement the counter */
  1227         -  (*pnLimit)--;
  1228         -  return 0;
  1229         -}
  1230         -
  1231         -/*
  1232         -** Implementation of the "fossil git export" command.
  1233         -*/
  1234         -void gitmirror_export_command(void){
  1235         -  const char *zLimit;             /* Text of the --limit flag */
  1236         -  int nLimit = 0x7fffffff;        /* Numeric value of the --limit flag */
  1237         -  int nTotal = 0;                 /* Total number of check-ins to export */
  1238         -  char *zMirror;                  /* Name of the mirror */
  1239         -  char *z;                        /* Generic string */
  1240         -  char *zCmd;                     /* git command to run as a subprocess */
  1241         -  const char *zDebug = 0;         /* Value of the --debug flag */
  1242         -  const char *zAutoPush = 0;      /* Value of the --autopush flag */
  1243         -  char *zPushUrl;                 /* URL to sync the mirror to */
  1244         -  double rEnd;                    /* time of most recent export */
  1245         -  int rc;                         /* Result code */
  1246         -  int bForce;                     /* Do the export and sync even if no changes*/
  1247         -  int bNeedRepack = 0;            /* True if we should run repack at the end */
  1248         -  int fManifest;                  /* Current "manifest" setting */
  1249         -  FILE *xCmd;                     /* Pipe to the "git fast-import" command */
  1250         -  FILE *pMarks;                   /* Git mark files */
  1251         -  Stmt q;                         /* Queries */
  1252         -  char zLine[200];                /* One line of a mark file */
  1253         -
  1254         -  zDebug = find_option("debug",0,1);
  1255         -  db_find_and_open_repository(0, 0);
  1256         -  zLimit = find_option("limit", 0, 1);
  1257         -  if( zLimit ){
  1258         -    nLimit = (unsigned int)atoi(zLimit);
  1259         -    if( nLimit<=0 ) fossil_fatal("--limit must be positive");
  1260         -  }
  1261         -  zAutoPush = find_option("autopush",0,1);
  1262         -  bForce = find_option("force","f",0)!=0;
  1263         -  gitmirror_verbosity = VERB_NORMAL;
  1264         -  while( find_option("quiet","q",0)!=0 ){ gitmirror_verbosity--; }
  1265         -  while( find_option("verbose","v",0)!=0 ){ gitmirror_verbosity++; }
  1266         -  verify_all_options();
  1267         -  if( g.argc!=4 && g.argc!=3 ){ usage("export ?MIRROR?"); }
  1268         -  if( g.argc==4 ){
  1269         -    Blob mirror;
  1270         -    file_canonical_name(g.argv[3], &mirror, 0);
  1271         -    db_set("last-git-export-repo", blob_str(&mirror), 0);
  1272         -    blob_reset(&mirror);
  1273         -  }
  1274         -  zMirror = db_get("last-git-export-repo", 0);
  1275         -  if( zMirror==0 ){
  1276         -    fossil_fatal("no Git repository specified");
  1277         -  }
  1278         -
  1279         -  /* Make sure the GIT repository directory exists */
  1280         -  rc = file_mkdir(zMirror, ExtFILE, 0);
  1281         -  if( rc ) fossil_fatal("cannot create directory \"%s\"", zMirror);
  1282         -
  1283         -  /* Make sure GIT has been initialized */
  1284         -  z = mprintf("%s/.git", zMirror);
  1285         -  if( !file_isdir(z, ExtFILE) ){
  1286         -    zCmd = mprintf("git init '%s'",zMirror);
  1287         -    gitmirror_message(VERB_NORMAL, "%s\n", zCmd);
  1288         -    rc = fossil_system(zCmd);
  1289         -    if( rc ){
  1290         -      fossil_fatal("cannot initialize the git repository using: \"%s\"", zCmd);
  1291         -    }
  1292         -    fossil_free(zCmd);
  1293         -    bNeedRepack = 1;
  1294         -  }
  1295         -  fossil_free(z);
  1296         -  
  1297         -  /* Make sure the .mirror_state subdirectory exists */
  1298         -  z = mprintf("%s/.mirror_state", zMirror);
  1299         -  rc = file_mkdir(z, ExtFILE, 0);
  1300         -  if( rc ) fossil_fatal("cannot create directory \"%s\"", z);
  1301         -  fossil_free(z);
  1302         -
  1303         -  /* Attach the .mirror_state/db database */
  1304         -  db_multi_exec("ATTACH '%q/.mirror_state/db' AS mirror;", zMirror);
  1305         -  db_begin_write();
  1306         -  db_multi_exec(
  1307         -    "CREATE TABLE IF NOT EXISTS mirror.mconfig(\n"
  1308         -    "  key TEXT PRIMARY KEY,\n"
  1309         -    "  Value ANY\n"
  1310         -    ") WITHOUT ROWID;\n"
  1311         -    "CREATE TABLE IF NOT EXISTS mirror.mmark(\n"
  1312         -    "  id INTEGER PRIMARY KEY,\n"
  1313         -    "  uuid TEXT UNIQUE,\n"
  1314         -    "  githash TEXT\n"
  1315         -    ");"
  1316         -  );
  1317         -
  1318         -  /* Change the autopush setting if the --autopush flag is present */
  1319         -  if( zAutoPush ){
  1320         -    if( is_false(zAutoPush) ){
  1321         -      db_multi_exec("DELETE FROM mirror.mconfig WHERE key='autopush'");
  1322         -    }else{
  1323         -      db_multi_exec(
  1324         -         "REPLACE INTO mirror.mconfig(key,value)"
  1325         -         "VALUES('autopush',%Q)",
  1326         -         zAutoPush
  1327         -      );
  1328         -    }
  1329         -  }
  1330         -
  1331         -  /* See if there is any work to be done.  Exit early if not, before starting
  1332         -  ** the "git fast-import" command. */
  1333         -  if( !bForce
  1334         -   && !db_exists("SELECT 1 FROM event WHERE type IN ('ci','t')"
  1335         -                 " AND mtime>coalesce((SELECT value FROM mconfig"
  1336         -                                        " WHERE key='start'),0.0)")
  1337         -  ){
  1338         -    gitmirror_message(VERB_NORMAL, "no changes\n");
  1339         -    db_commit_transaction();
  1340         -    return;
  1341         -  }
  1342         -
  1343         -  /* Do we need to include manifest files in the clone? */
  1344         -  fManifest = db_get_manifest_setting();
  1345         -
  1346         -  /* Change to the MIRROR directory so that the Git commands will work */
  1347         -  rc = file_chdir(zMirror, 0);
  1348         -  if( rc ) fossil_fatal("cannot change the working directory to \"%s\"",
  1349         -                        zMirror);
  1350         -
  1351         -  /* Start up the git fast-import command */
  1352         -  if( zDebug ){
  1353         -    if( fossil_strcmp(zDebug,"stdout")==0 ){
  1354         -      xCmd = stdout;
  1355         -    }else{
  1356         -      xCmd = fopen(zDebug, "wb");
  1357         -      if( xCmd==0 ) fossil_fatal("cannot open file \"%s\" for writing", zDebug);
  1358         -    }
  1359         -  }else{
  1360         -    zCmd = mprintf("git fast-import"
  1361         -              " --export-marks=.mirror_state/marks.txt"
  1362         -              " --quiet --done");
  1363         -    gitmirror_message(VERB_NORMAL, "%s\n", zCmd);
  1364         -    xCmd = popen(zCmd, "w");
  1365         -    if( zCmd==0 ){
  1366         -      fossil_fatal("cannot start the \"git fast-import\" command");
  1367         -    }
  1368         -    fossil_free(zCmd);
  1369         -  }
  1370         -
  1371         -  /* Run the export */
  1372         -  rEnd = 0.0;
  1373         -  db_multi_exec(
  1374         -    "CREATE TEMP TABLE tomirror(objid,mtime,uuid);\n"
  1375         -    "INSERT INTO tomirror "
  1376         -    "SELECT objid, mtime, blob.uuid FROM event, blob\n"
  1377         -    " WHERE type='ci'"
  1378         -    "   AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
  1379         -    "   AND blob.rid=event.objid"
  1380         -    "   AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);"
  1381         -  );
  1382         -  nTotal = db_int(0, "SELECT count(*) FROM tomirror");
  1383         -  if( nLimit<nTotal ){
  1384         -    nTotal = nLimit;
  1385         -  }else if( nLimit>nTotal ){
  1386         -    nLimit = nTotal;
  1387         -  }
  1388         -  db_prepare(&q,
  1389         -    "SELECT objid, mtime, uuid FROM tomirror ORDER BY mtime"
  1390         -  );
  1391         -  while( nLimit && db_step(&q)==SQLITE_ROW ){
  1392         -    int rid = db_column_int(&q, 0);
  1393         -    double rMTime = db_column_double(&q, 1);
  1394         -    const char *zUuid = db_column_text(&q, 2);
  1395         -    if( rMTime>rEnd ) rEnd = rMTime;
  1396         -    rc = gitmirror_send_checkin(xCmd, rid, zUuid, &nLimit, fManifest);
  1397         -    if( rc ) break;
  1398         -    gitmirror_message(VERB_NORMAL,"%d/%d      \r", nTotal-nLimit, nTotal);
  1399         -    fflush(stdout);
  1400         -  }
  1401         -  db_finalize(&q);
  1402         -  fprintf(xCmd, "done\n");
  1403         -  if( zDebug ){
  1404         -    if( xCmd!=stdout ) fclose(xCmd);
  1405         -  }else{
  1406         -    pclose(xCmd);
  1407         -  }
  1408         -  gitmirror_message(VERB_NORMAL, "%d check-ins added to the %s\n",
  1409         -                    nTotal-nLimit, zMirror);
  1410         -
  1411         -  /* Read the export-marks file.  Transfer the new marks over into
  1412         -  ** the import-marks file.
  1413         -  */
  1414         -  pMarks = fopen(".mirror_state/marks.txt", "rb");
  1415         -  if( pMarks ){
  1416         -    db_prepare(&q, "UPDATE mirror.mmark SET githash=:githash WHERE id=:id");
  1417         -    while( fgets(zLine, sizeof(zLine), pMarks) ){
  1418         -      int j, k;
  1419         -      if( zLine[0]!=':' ) continue;
  1420         -      db_bind_int(&q, ":id", atoi(zLine+1));
  1421         -      for(j=1; zLine[j] && zLine[j]!=' '; j++){}
  1422         -      if( zLine[j]!=' ' ) continue;
  1423         -      j++;
  1424         -      if( zLine[j]==0 ) continue;
  1425         -      for(k=j; fossil_isalnum(zLine[k]); k++){}
  1426         -      zLine[k] = 0;
  1427         -      db_bind_text(&q, ":githash", &zLine[j]);
  1428         -      db_step(&q);
  1429         -      db_reset(&q);
  1430         -    }
  1431         -    db_finalize(&q);
  1432         -    fclose(pMarks);
  1433         -    file_delete(".mirror_state/marks.txt");
  1434         -  }else{
  1435         -    fossil_fatal("git fast-import didn't generate a marks file!");
  1436         -  }
  1437         -  db_multi_exec(
  1438         -    "CREATE INDEX IF NOT EXISTS mirror.mmarkx1 ON mmark(githash);"
  1439         -  );
  1440         -
  1441         -  /* Do any tags that have been created since the start time */
  1442         -  db_prepare(&q,
  1443         -    "SELECT substr(tagname,5), githash"
  1444         -    "  FROM (SELECT tagxref.tagid AS xtagid, tagname, rid, max(mtime) AS mtime"
  1445         -    "          FROM tagxref JOIN tag ON tag.tagid=tagxref.tagid"
  1446         -    "         WHERE tag.tagname GLOB 'sym-*'"
  1447         -    "           AND tagxref.tagtype=1"
  1448         -    "           AND tagxref.mtime > coalesce((SELECT value FROM mconfig"
  1449         -                                        " WHERE key='start'),0.0)"
  1450         -    "         GROUP BY tagxref.tagid) AS tx"
  1451         -    "       JOIN blob ON tx.rid=blob.rid"
  1452         -    "       JOIN mmark ON mmark.uuid=blob.uuid;"
  1453         -  );
  1454         -  while( db_step(&q)==SQLITE_ROW ){
  1455         -    char *zTagname = fossil_strdup(db_column_text(&q,0));
  1456         -    const char *zObj = db_column_text(&q,1);
  1457         -    char *zTagCmd;
  1458         -    gitmirror_sanitize_name(zTagname);
  1459         -    zTagCmd = mprintf("git tag -f \"%s\" %s", zTagname, zObj);
  1460         -    fossil_free(zTagname);
  1461         -    gitmirror_message(VERB_NORMAL, "%s\n", zTagCmd);
  1462         -    fossil_system(zTagCmd);
  1463         -    fossil_free(zTagCmd);
  1464         -  }
  1465         -  db_finalize(&q);
  1466         -
  1467         -  /* Update the start time */
  1468         -  if( rEnd>0.0 ){
  1469         -    db_prepare(&q, "REPLACE INTO mirror.mconfig(key,value) VALUES('start',:x)");
  1470         -    db_bind_double(&q, ":x", rEnd);
  1471         -    db_step(&q);
  1472         -    db_finalize(&q);
  1473         -  }
  1474         -  db_commit_transaction();
  1475         -
  1476         -  /* Maybe run a git repack */
  1477         -  if( bNeedRepack ){
  1478         -    const char *zRepack = "git repack -adf";
  1479         -    gitmirror_message(VERB_NORMAL, "%s\n", zRepack);
  1480         -    fossil_system(zRepack);
  1481         -  }
  1482         -
  1483         -  /* Optionally do a "git push" */
  1484         -  zPushUrl = db_text(0, "SELECT value FROM mconfig WHERE key='autopush'");
  1485         -  if( zPushUrl ){
  1486         -    char *zPushCmd;
  1487         -    UrlData url;
  1488         -    if( sqlite3_strglob("http*", zPushUrl)==0 ){
  1489         -      url_parse_local(zPushUrl, 0, &url);
  1490         -      zPushCmd = mprintf("git push --mirror %s", url.canonical);
  1491         -    }else{
  1492         -      zPushCmd = mprintf("git push --mirror %s", zPushUrl);
  1493         -    }
  1494         -    gitmirror_message(VERB_NORMAL, "%s\n", zPushCmd);
  1495         -    fossil_free(zPushCmd);
  1496         -    zPushCmd = mprintf("git push --mirror %s", zPushUrl);
  1497         -    fossil_system(zPushCmd);
  1498         -    fossil_free(zPushCmd);
  1499         -  }
  1500         -}
  1501         -
  1502         -/*
  1503         -** COMMAND: git
  1504         -**
  1505         -** Usage: %fossil git SUBCOMMAND
  1506         -**
  1507         -** Do incremental import or export operations between Fossil and Git.
  1508         -** Subcommands:
  1509         -**
  1510         -**   fossil git export [MIRROR] [OPTIONS]
  1511         -**
  1512         -**       Write content from the Fossil repository into the Git repository
  1513         -**       in directory MIRROR.  The Git repository is created if it does not
  1514         -**       already exist.  If the Git repository does already exist, then
  1515         -**       new content added to fossil since the previous export is appended.
  1516         -**
  1517         -**       Repeat this command whenever new checkins are added to the Fossil
  1518         -**       repository in order to reflect those changes into the mirror.  If
  1519         -**       the MIRROR option is omitted, the repository from the previous
  1520         -**       invocation is used.
  1521         -**
  1522         -**       The MIRROR directory will contain a subdirectory named
  1523         -**       ".mirror_state" that contains information that Fossil needs to
  1524         -**       do incremental exports.  Do not attempt to manage or edit the files
  1525         -**       in that directory since doing so can disrupt future incremental
  1526         -**       exports.
  1527         -**
  1528         -**       Options:
  1529         -**         --autopush URL      Automatically do a 'git push' to URL.  The
  1530         -**                             URL is remembered and used on subsequent exports
  1531         -**                             to the same repository.  Or if URL is "off" the
  1532         -**                             auto-push mechanism is disabled
  1533         -**         --debug FILE        Write fast-export text to FILE rather than
  1534         -**                             piping it into "git fast-import".
  1535         -**         --force|-f          Do the export even if nothing has changed
  1536         -**         --limit N           Add no more than N new check-ins to MIRROR.
  1537         -**                             Useful for debugging
  1538         -**         --quiet|-q          Reduce output. Repeat for even less output.
  1539         -**         --verbose|-v        More output.
  1540         -**
  1541         -**   fossil git import MIRROR
  1542         -**
  1543         -**       TBD...   
  1544         -*/
  1545         -void gitmirror_command(void){
  1546         -  char *zCmd;
  1547         -  int nCmd;
  1548         -  if( g.argc<3 ){
  1549         -    usage("export ARGS...");
  1550         -  }
  1551         -  zCmd =  g.argv[2];
  1552         -  nCmd = (int)strlen(zCmd);
  1553         -  if( nCmd>2 && strncmp(zCmd,"export",nCmd)==0 ){
  1554         -    gitmirror_export_command();
  1555         -  }else
  1556         -  if( nCmd>2 && strncmp(zCmd,"import",nCmd)==0 ){
  1557         -    fossil_fatal("not yet implemented - check back later");
  1558         -  }else
  1559         -  {
  1560         -    fossil_fatal("unknown subcommand \"%s\": should be one of "
  1561         -                 "\"export\", \"import\"",
  1562         -                 zCmd);
  1563         -  }
  1564         -}

Changes to src/file.c.

   435    435     const char *zTail = file_tail(z);
   436    436     if( zTail && zTail!=z ){
   437    437       return mprintf("%.*s", (int)(zTail-z-1), z);
   438    438     }else{
   439    439       return 0;
   440    440     }
   441    441   }
   442         -
   443         -/* SQL Function:  file_dirname(NAME)
   444         -**
   445         -** Return the directory for NAME
   446         -*/
   447         -void file_dirname_sql_function(
   448         -  sqlite3_context *context,
   449         -  int argc,
   450         -  sqlite3_value **argv
   451         -){
   452         -  const char *zName = (const char*)sqlite3_value_text(argv[0]);
   453         -  char *zDir;
   454         -  if( zName==0 ) return;
   455         -  zDir = file_dirname(zName);
   456         -  if( zDir ){
   457         -    sqlite3_result_text(context,zDir,-1,fossil_free);
   458         -  }
   459         -}
   460         -
   461    442   
   462    443   /*
   463    444   ** Rename a file or directory.
   464    445   ** Returns zero upon success.
   465    446   */
   466    447   int file_rename(
   467    448     const char *zFrom,
................................................................................
   612    593     char *z = fossil_utf8_to_path(zFilename, 0);
   613    594     rc = unlink(zFilename);
   614    595   #endif
   615    596     fossil_path_free(z);
   616    597     return rc;
   617    598   }
   618    599   
   619         -/* SQL Function:  file_delete(NAME)
   620         -**
   621         -** Remove file NAME.  Return zero on success and non-zero if anything goes
   622         -** wrong.
   623         -*/
   624         -void file_delete_sql_function(
   625         -  sqlite3_context *context,
   626         -  int argc,
   627         -  sqlite3_value **argv
   628         -){
   629         -  const char *zName = (const char*)sqlite3_value_text(argv[0]);
   630         -  int rc;
   631         -  if( zName==0 ){
   632         -    rc = 1;
   633         -  }else{
   634         -    rc = file_delete(zName);
   635         -  }
   636         -  sqlite3_result_int(context, rc);
   637         -}
   638         -
   639    600   /*
   640    601   ** Create a directory called zName, if it does not already exist.
   641    602   ** If forceFlag is 1, delete any prior non-directory object
   642    603   ** with the same name.
   643    604   **
   644    605   ** Return the number of errors.
   645    606   */
................................................................................
   722    683   #endif
   723    684       fossil_path_free(zMbcs);
   724    685       return rc;
   725    686     }
   726    687     return 0;
   727    688   }
   728    689   
   729         -/* SQL Function: rmdir(NAME)
   730         -**
   731         -** Try to remove the directory NAME.  Return zero on success and non-zero
   732         -** for failure.
   733         -*/
   734         -void file_rmdir_sql_function(
   735         -  sqlite3_context *context,
   736         -  int argc,
   737         -  sqlite3_value **argv
   738         -){
   739         -  const char *zName = (const char*)sqlite3_value_text(argv[0]);
   740         -  int rc;
   741         -  if( zName==0 ){
   742         -    rc = 1;
   743         -  }else{
   744         -    rc = file_rmdir(zName);
   745         -  }
   746         -  sqlite3_result_int(context, rc);
   747         -}
   748         -
   749    690   /*
   750    691   ** Return true if the filename given is a valid filename for
   751    692   ** a file in a repository.  Valid filenames follow all of the
   752    693   ** following rules:
   753    694   **
   754    695   **     *  Does not begin with "/"
   755    696   **     *  Does not contain any path element named "." or ".."
................................................................................
   947    888   
   948    889   /*
   949    890   ** Get the current working directory.
   950    891   **
   951    892   ** On windows, the name is converted from unicode to UTF8 and all '\\'
   952    893   ** characters are converted to '/'.  No conversions are needed on
   953    894   ** unix.
   954         -**
   955         -** Store the value of the CWD in zBuf which is nBuf bytes in size.
   956         -** or if zBuf==0, allocate space to hold the result using fossil_malloc().
   957    895   */
   958         -char *file_getcwd(char *zBuf, int nBuf){
   959         -  char zTemp[2000];
   960         -  if( zBuf==0 ){
   961         -    zBuf = zTemp;
   962         -    nBuf = sizeof(zTemp);
   963         -  }
          896  +void file_getcwd(char *zBuf, int nBuf){
   964    897   #ifdef _WIN32
   965    898     win32_getcwd(zBuf, nBuf);
   966    899   #else
   967    900     if( getcwd(zBuf, nBuf-1)==0 ){
   968    901       if( errno==ERANGE ){
   969    902         fossil_panic("pwd too big: max %d", nBuf-1);
   970    903       }else{
   971    904         fossil_panic("cannot find current working directory; %s",
   972    905                      strerror(errno));
   973    906       }
   974    907     }
   975    908   #endif
   976         -  return zBuf==zTemp ? fossil_strdup(zBuf) : zBuf;
   977    909   }
   978    910   
   979    911   /*
   980    912   ** Return true if zPath is an absolute pathname.  Return false
   981    913   ** if it is relative.
   982    914   */
   983    915   int file_is_absolute_path(const char *zPath){

Changes to src/info.c.

  1323   1323   #define OBJTYPE_FORUM      0x0200
  1324   1324   
  1325   1325   /*
  1326   1326   ** Possible flags for the second parameter to
  1327   1327   ** object_description()
  1328   1328   */
  1329   1329   #define OBJDESC_DETAIL      0x0001   /* more detail */
  1330         -#define OBJDESC_BASE        0x0002   /* Set <base> using this object */
  1331   1330   #endif
  1332   1331   
  1333   1332   /*
  1334   1333   ** Write a description of an object to the www reply.
  1335   1334   **
  1336   1335   ** If the object is a file then mention:
  1337   1336   **
................................................................................
  1353   1352     Stmt q;
  1354   1353     int cnt = 0;
  1355   1354     int nWiki = 0;
  1356   1355     int objType = 0;
  1357   1356     char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
  1358   1357     int showDetail = (objdescFlags & OBJDESC_DETAIL)!=0;
  1359   1358     char *prevName = 0;
  1360         -  int bNeedBase = (objdescFlags & OBJDESC_BASE)!=0;
  1361   1359   
  1362   1360     db_prepare(&q,
  1363   1361       "SELECT filename.name, datetime(event.mtime,toLocal()),"
  1364   1362       "       coalesce(event.ecomment,event.comment),"
  1365   1363       "       coalesce(event.euser,event.user),"
  1366   1364       "       b.uuid, mlink.mperm,"
  1367   1365       "       coalesce((SELECT value FROM tagxref"
................................................................................
  1402   1400           @ <li>Symbolic link
  1403   1401           objType |= OBJTYPE_SYMLINK;
  1404   1402         }else if( mPerm==PERM_EXE ){
  1405   1403           @ <li>Executable file
  1406   1404           objType |= OBJTYPE_EXE;
  1407   1405         }else{
  1408   1406           @ <li>File
  1409         -        if( bNeedBase ){
  1410         -          bNeedBase = 0;
  1411         -          style_set_current_page("doc/%S/%s",zVers,zName);
  1412         -        }
  1413   1407         }
  1414   1408         objType |= OBJTYPE_CONTENT;
  1415   1409         @ %z(href("%R/finfo?name=%T&m=%!S",zName,zUuid))%h(zName)</a>
  1416   1410         tag_private_status(rid);
  1417   1411         if( showDetail ){
  1418   1412           @ <ul>
  1419   1413         }
................................................................................
  1754   1748   **
  1755   1749   ** Return the uninterpreted content of an artifact.  Used primarily
  1756   1750   ** to view artifacts that are images.
  1757   1751   */
  1758   1752   void rawartifact_page(void){
  1759   1753     int rid = 0;
  1760   1754     char *zUuid;
         1755  +  const char *zMime;
         1756  +  Blob content;
  1761   1757   
  1762   1758     if( P("ci") && P("filename") ){
  1763   1759       rid = artifact_from_ci_and_filename(0, 0);
  1764   1760     }
  1765   1761     if( rid==0 ){
  1766   1762       rid = name_to_rid_www("name");
  1767   1763     }
................................................................................
  1769   1765     if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
  1770   1766     if( rid==0 ) fossil_redirect_home();
  1771   1767     zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
  1772   1768     if( fossil_strcmp(P("name"), zUuid)==0 && login_is_nobody() ){
  1773   1769       g.isConst = 1;
  1774   1770     }
  1775   1771     free(zUuid);
  1776         -  deliver_artifact(rid, P("m"));
  1777         -}
  1778         -
  1779         -
  1780         -/*
  1781         -** WEBPAGE: secureraw
  1782         -** URL: /secureraw/HASH?m=TYPE
  1783         -**
  1784         -** Return the uninterpreted content of an artifact.  This is similar
  1785         -** to /raw except in this case the only way to specify the artifact
  1786         -** is by the full-length SHA1 or SHA3 hash.  Abbreviations are not
  1787         -** accepted.
  1788         -*/
  1789         -void secure_rawartifact_page(void){
  1790         -  int rid = 0;
  1791         -  const char *zUuid = PD("name", "");
  1792         -
  1793         -  login_check_credentials();
  1794         -  if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
  1795         -  rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zUuid);
  1796         -  if( rid==0 ){
  1797         -    cgi_set_status(404, "Not Found");
  1798         -    @ Unknown artifact: "%h(zUuid)"
  1799         -    return;
  1800         -  }
  1801         -  g.isConst = 1;
  1802         -  deliver_artifact(rid, P("m"));
  1803         -}
  1804         -
  1805         -
  1806         -/*
  1807         -** Generate a verbatim artifact as the result of an HTTP request.
  1808         -** If zMime is not NULL, use it as the MIME-type.  If zMime is
  1809         -** NULL, guess at the MIME-type based on the filename
  1810         -** associated with the artifact.
  1811         -*/
  1812         -void deliver_artifact(int rid, const char *zMime){
  1813         -  Blob content;
         1772  +  zMime = P("m");
  1814   1773     if( zMime==0 ){
  1815   1774       char *zFName = db_text(0, "SELECT filename.name FROM mlink, filename"
  1816   1775                                 " WHERE mlink.fid=%d"
  1817   1776                                 "   AND filename.fnid=mlink.fnid", rid);
  1818   1777       if( !zFName ){
  1819   1778         /* Look also at the attachment table */
  1820   1779         zFName = db_text(0, "SELECT attachment.filename FROM attachment, blob"
................................................................................
  2107   2066     const char *zMime;
  2108   2067     Blob downloadName;
  2109   2068     int renderAsWiki = 0;
  2110   2069     int renderAsHtml = 0;
  2111   2070     int objType;
  2112   2071     int asText;
  2113   2072     const char *zUuid;
  2114         -  u32 objdescFlags = OBJDESC_BASE;
         2073  +  u32 objdescFlags = 0;
  2115   2074     int descOnly = fossil_strcmp(g.zPath,"whatis")==0;
  2116   2075     int isFile = fossil_strcmp(g.zPath,"file")==0;
  2117   2076     const char *zLn = P("ln");
  2118   2077     const char *zName = P("name");
  2119   2078     HQuery url;
  2120   2079   
  2121   2080     url_initialize(&url, g.zPath);
................................................................................
  2184   2143       style_submenu_element("Artifact", "%R/artifact/%S", zUuid);
  2185   2144     }else if( g.perm.Setup ){
  2186   2145       @ <h2>Artifact %s(zUuid) (%d(rid)):</h2>
  2187   2146     }else{
  2188   2147       @ <h2>Artifact %s(zUuid):</h2>
  2189   2148     }
  2190   2149     blob_zero(&downloadName);
  2191         -  asText = P("txt")!=0;
  2192         -  if( asText ) objdescFlags &= ~OBJDESC_BASE;
  2193   2150     objType = object_description(rid, objdescFlags, &downloadName);
  2194   2151     if( !descOnly && P("download")!=0 ){
  2195   2152       cgi_redirectf("%R/raw/%T?name=%s", blob_str(&downloadName),
  2196   2153             db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid));
  2197   2154       /*NOTREACHED*/
  2198   2155     }
  2199   2156     if( g.perm.Admin ){
................................................................................
  2224   2181       db_finalize(&q);
  2225   2182     }
  2226   2183     style_submenu_element("Download", "%R/raw/%T?name=%s",
  2227   2184                            blob_str(&downloadName), zUuid);
  2228   2185     if( db_exists("SELECT 1 FROM mlink WHERE fid=%d", rid) ){
  2229   2186       style_submenu_element("Check-ins Using", "%R/timeline?n=200&uf=%s", zUuid);
  2230   2187     }
         2188  +  asText = P("txt")!=0;
  2231   2189     zMime = mimetype_from_name(blob_str(&downloadName));
  2232   2190     if( zMime ){
  2233   2191       if( fossil_strcmp(zMime, "text/html")==0 ){
  2234   2192         if( asText ){
  2235   2193           style_submenu_element("Html", "%s", url_render(&url, "txt", 0, 0, 0));
  2236   2194         }else{
  2237   2195           renderAsHtml = 1;
................................................................................
  2284   2242             output_text_with_line_numbers(z, zLn);
  2285   2243           }else{
  2286   2244             @ <pre>
  2287   2245             @ %h(z)
  2288   2246             @ </pre>
  2289   2247           }
  2290   2248         }else if( strncmp(zMime, "image/", 6)==0 ){
  2291         -        @ <p>(file is %d(blob_size(&content)) bytes of image data)</i></p>
  2292         -        @ <p><img src="%R/raw/%s(zUuid)?m=%s(zMime)"></p>
         2249  +        @ <i>(file is %d(blob_size(&content)) bytes of image data)</i><br />
         2250  +        @ <img src="%R/raw/%s(zUuid)?m=%s(zMime)" />
  2293   2251           style_submenu_element("Image", "%R/raw/%s?m=%s", zUuid, zMime);
  2294   2252         }else{
  2295   2253           @ <i>(file is %d(blob_size(&content)) bytes of binary data)</i>
  2296   2254         }
  2297   2255         @ </blockquote>
  2298   2256       }
  2299   2257     }

Changes to src/login.c.

   695    695     }
   696    696     if( anonFlag ){
   697    697       @ <input type="hidden" name="anon" value="1" />
   698    698     }
   699    699     if( g.zLogin ){
   700    700       @ <p>Currently logged in as <b>%h(g.zLogin)</b>.
   701    701       @ <input type="submit" name="out" value="Logout"></p>
   702         -    @ </form>
   703    702     }else{
   704    703       @ <table class="login_out">
   705    704       @ <tr>
   706    705       @   <td class="form_label">User ID:</td>
   707    706       if( anonFlag ){
   708    707         @ <td><input type="text" id="u" name="u" value="anonymous" size="30"></td>
   709    708       }else{

Changes to src/main.c.

  2637   2637     }
  2638   2638     if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
  2639   2639     if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  2640   2640     db_close(1);
  2641   2641     if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
  2642   2642       fossil_fatal("unable to listen on TCP socket %d", iPort);
  2643   2643     }
  2644         -  /* For the parent process, the cgi_http_server() command above never
  2645         -  ** returns (except in the case of an error).  Instead, for each incoming
  2646         -  ** client connection, a child process is created, file descriptors 0
  2647         -  ** and 1 are bound to that connection, and the child returns.
  2648         -  **
  2649         -  ** So, when control reaches this point, we are running as a
  2650         -  ** child process, the HTTP or SCGI request is pending on file
  2651         -  ** descriptor 0 and the reply should be written to file descriptor 1.
  2652         -  */
  2653   2644     if( zMaxLatency ){
  2654   2645       signal(SIGALRM, sigalrm_handler);
  2655   2646       alarm(atoi(zMaxLatency));
  2656   2647     }
  2657   2648     g.httpIn = stdin;
  2658   2649     g.httpOut = stdout;
  2659   2650   

Changes to src/main.mk.

    39     39     $(SRCDIR)/comformat.c \
    40     40     $(SRCDIR)/configure.c \
    41     41     $(SRCDIR)/content.c \
    42     42     $(SRCDIR)/cookies.c \
    43     43     $(SRCDIR)/db.c \
    44     44     $(SRCDIR)/delta.c \
    45     45     $(SRCDIR)/deltacmd.c \
    46         -  $(SRCDIR)/deltafunc.c \
    47     46     $(SRCDIR)/descendants.c \
    48     47     $(SRCDIR)/diff.c \
    49     48     $(SRCDIR)/diffcmd.c \
    50     49     $(SRCDIR)/dispatch.c \
    51     50     $(SRCDIR)/doc.c \
    52     51     $(SRCDIR)/encode.c \
    53     52     $(SRCDIR)/etag.c \
................................................................................
   251    250     $(OBJDIR)/comformat_.c \
   252    251     $(OBJDIR)/configure_.c \
   253    252     $(OBJDIR)/content_.c \
   254    253     $(OBJDIR)/cookies_.c \
   255    254     $(OBJDIR)/db_.c \
   256    255     $(OBJDIR)/delta_.c \
   257    256     $(OBJDIR)/deltacmd_.c \
   258         -  $(OBJDIR)/deltafunc_.c \
   259    257     $(OBJDIR)/descendants_.c \
   260    258     $(OBJDIR)/diff_.c \
   261    259     $(OBJDIR)/diffcmd_.c \
   262    260     $(OBJDIR)/dispatch_.c \
   263    261     $(OBJDIR)/doc_.c \
   264    262     $(OBJDIR)/encode_.c \
   265    263     $(OBJDIR)/etag_.c \
................................................................................
   390    388    $(OBJDIR)/comformat.o \
   391    389    $(OBJDIR)/configure.o \
   392    390    $(OBJDIR)/content.o \
   393    391    $(OBJDIR)/cookies.o \
   394    392    $(OBJDIR)/db.o \
   395    393    $(OBJDIR)/delta.o \
   396    394    $(OBJDIR)/deltacmd.o \
   397         - $(OBJDIR)/deltafunc.o \
   398    395    $(OBJDIR)/descendants.o \
   399    396    $(OBJDIR)/diff.o \
   400    397    $(OBJDIR)/diffcmd.o \
   401    398    $(OBJDIR)/dispatch.o \
   402    399    $(OBJDIR)/doc.o \
   403    400    $(OBJDIR)/encode.o \
   404    401    $(OBJDIR)/etag.o \
................................................................................
   507    504   
   508    505   APPNAME = fossil$(E)
   509    506   
   510    507   
   511    508   
   512    509   all:	$(OBJDIR) $(APPNAME)
   513    510   
   514         -install:	all
          511  +install:	$(APPNAME)
   515    512   	mkdir -p $(INSTALLDIR)
   516    513   	cp $(APPNAME) $(INSTALLDIR)
   517    514   
   518    515   codecheck:	$(TRANS_SRC) $(OBJDIR)/codecheck1
   519    516   	$(OBJDIR)/codecheck1 $(TRANS_SRC)
   520    517   
   521    518   $(OBJDIR):
................................................................................
   725    722   	$(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h \
   726    723   	$(OBJDIR)/configure_.c:$(OBJDIR)/configure.h \
   727    724   	$(OBJDIR)/content_.c:$(OBJDIR)/content.h \
   728    725   	$(OBJDIR)/cookies_.c:$(OBJDIR)/cookies.h \
   729    726   	$(OBJDIR)/db_.c:$(OBJDIR)/db.h \
   730    727   	$(OBJDIR)/delta_.c:$(OBJDIR)/delta.h \
   731    728   	$(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h \
   732         -	$(OBJDIR)/deltafunc_.c:$(OBJDIR)/deltafunc.h \
   733    729   	$(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h \
   734    730   	$(OBJDIR)/diff_.c:$(OBJDIR)/diff.h \
   735    731   	$(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h \
   736    732   	$(OBJDIR)/dispatch_.c:$(OBJDIR)/dispatch.h \
   737    733   	$(OBJDIR)/doc_.c:$(OBJDIR)/doc.h \
   738    734   	$(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
   739    735   	$(OBJDIR)/etag_.c:$(OBJDIR)/etag.h \
................................................................................
  1058   1054   	$(OBJDIR)/translate $(SRCDIR)/deltacmd.c >$@
  1059   1055   
  1060   1056   $(OBJDIR)/deltacmd.o:	$(OBJDIR)/deltacmd_.c $(OBJDIR)/deltacmd.h $(SRCDIR)/config.h
  1061   1057   	$(XTCC) -o $(OBJDIR)/deltacmd.o -c $(OBJDIR)/deltacmd_.c
  1062   1058   
  1063   1059   $(OBJDIR)/deltacmd.h:	$(OBJDIR)/headers
  1064   1060   
  1065         -$(OBJDIR)/deltafunc_.c:	$(SRCDIR)/deltafunc.c $(OBJDIR)/translate
  1066         -	$(OBJDIR)/translate $(SRCDIR)/deltafunc.c >$@
  1067         -
  1068         -$(OBJDIR)/deltafunc.o:	$(OBJDIR)/deltafunc_.c $(OBJDIR)/deltafunc.h $(SRCDIR)/config.h
  1069         -	$(XTCC) -o $(OBJDIR)/deltafunc.o -c $(OBJDIR)/deltafunc_.c
  1070         -
  1071         -$(OBJDIR)/deltafunc.h:	$(OBJDIR)/headers
  1072         -
  1073   1061   $(OBJDIR)/descendants_.c:	$(SRCDIR)/descendants.c $(OBJDIR)/translate
  1074   1062   	$(OBJDIR)/translate $(SRCDIR)/descendants.c >$@
  1075   1063   
  1076   1064   $(OBJDIR)/descendants.o:	$(OBJDIR)/descendants_.c $(OBJDIR)/descendants.h $(SRCDIR)/config.h
  1077   1065   	$(XTCC) -o $(OBJDIR)/descendants.o -c $(OBJDIR)/descendants_.c
  1078   1066   
  1079   1067   $(OBJDIR)/descendants.h:	$(OBJDIR)/headers

Changes to src/makemake.tcl.

    50     50     comformat
    51     51     configure
    52     52     content
    53     53     cookies
    54     54     db
    55     55     delta
    56     56     deltacmd
    57         -  deltafunc
    58     57     descendants
    59     58     diff
    60     59     diffcmd
    61     60     dispatch
    62     61     doc
    63     62     encode
    64     63     etag
................................................................................
   316    315   
   317    316   writeln [string map [list \
   318    317       <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n                 "] \
   319    318       <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n                "] \
   320    319       <<<MINIZ_OPTIONS>>> [join $MINIZ_OPTIONS " \\\n                "]] {
   321    320   all:	$(OBJDIR) $(APPNAME)
   322    321   
   323         -install:	all
          322  +install:	$(APPNAME)
   324    323   	mkdir -p $(INSTALLDIR)
   325    324   	cp $(APPNAME) $(INSTALLDIR)
   326    325   
   327    326   codecheck:	$(TRANS_SRC) $(OBJDIR)/codecheck1
   328    327   	$(OBJDIR)/codecheck1 $(TRANS_SRC)
   329    328   
   330    329   $(OBJDIR):
................................................................................
   709    708   endif
   710    709   
   711    710   #### The directories where the OpenSSL include and library files are located.
   712    711   #    The recommended usage here is to use the Sysinternals junction tool
   713    712   #    to create a hard link between an "openssl-1.x" sub-directory of the
   714    713   #    Fossil source code directory and the target OpenSSL source directory.
   715    714   #
   716         -OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2r
          715  +OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2q
   717    716   OPENSSLINCDIR = $(OPENSSLDIR)/include
   718    717   OPENSSLLIBDIR = $(OPENSSLDIR)
   719    718   
   720    719   #### Either the directory where the Tcl library is installed or the Tcl
   721    720   #    source code directory resides (depending on the value of the macro
   722    721   #    FOSSIL_TCL_SOURCE).  If this points to the Tcl install directory,
   723    722   #    this directory must have "include" and "lib" sub-directories.  If
................................................................................
  1565   1564   
  1566   1565   # Enable support for the SQLite Encryption Extension?
  1567   1566   !ifndef USE_SEE
  1568   1567   USE_SEE = 0
  1569   1568   !endif
  1570   1569   
  1571   1570   !if $(FOSSIL_ENABLE_SSL)!=0
  1572         -SSLDIR    = $(B)\compat\openssl-1.0.2r
         1571  +SSLDIR    = $(B)\compat\openssl-1.0.2q
  1573   1572   SSLINCDIR = $(SSLDIR)\inc32
  1574   1573   !if $(FOSSIL_DYNAMIC_BUILD)!=0
  1575   1574   SSLLIBDIR = $(SSLDIR)\out32dll
  1576   1575   !else
  1577   1576   SSLLIBDIR = $(SSLDIR)\out32
  1578   1577   !endif
  1579   1578   SSLLFLAGS = /nologo /opt:ref /debug

Changes to src/printf.c.

   963    963       Blob b = empty_blob;
   964    964       vxprintf(&b, zFormat, ap);
   965    965       fossil_puts(blob_str(&b), 0);
   966    966       blob_reset(&b);
   967    967     }
   968    968     va_end(ap);
   969    969   }
   970         -void fossil_vprint(const char *zFormat, va_list ap){
   971         -  if( g.cgiOutput ){
   972         -    cgi_vprintf(zFormat, ap);
   973         -  }else{
   974         -    Blob b = empty_blob;
   975         -    vxprintf(&b, zFormat, ap);
   976         -    fossil_puts(blob_str(&b), 0);
   977         -    blob_reset(&b);
   978         -  }
   979         -}
   980    970   
   981    971   /*
   982    972   ** Print a trace message on standard error.
   983    973   */
   984    974   void fossil_trace(const char *zFormat, ...){
   985    975     va_list ap;
   986    976     Blob b;

Changes to src/regexp.c.

    11     11   **
    12     12   ** Author contact information:
    13     13   **   drh@hwaci.com
    14     14   **   http://www.hwaci.com/drh/
    15     15   **
    16     16   *******************************************************************************
    17     17   **
    18         -** This file was adapted from the ext/misc/regexp.c file in SQLite3.  That
           18  +** This file was adapted from the test_regexp.c file in SQLite3.  That
    19     19   ** file is in the public domain.
    20     20   **
    21     21   ** See ../www/grep.md for details of the algorithm and RE dialect.
    22     22   */
    23     23   #include "config.h"
    24     24   #include "regexp.h"
    25     25   
................................................................................
    85     85   };
    86     86   #endif
    87     87   
    88     88   /* Add a state to the given state set if it is not already there */
    89     89   static void re_add_state(ReStateSet *pSet, int newState){
    90     90     unsigned i;
    91     91     for(i=0; i<pSet->nState; i++) if( pSet->aState[i]==newState ) return;
    92         -  pSet->aState[pSet->nState++] = (ReStateNumber)newState;
           92  +  pSet->aState[pSet->nState++] = newState;
    93     93   }
    94     94   
    95     95   /* Extract the next unicode character from *pzIn and return it.  Advance
    96     96   ** *pzIn to the first byte past the end of the character returned.  To
    97     97   ** be clear:  this routine converts utf8 to unicode.  This routine is
    98     98   ** optimized for the common case where the next character is a single byte.
    99     99   */
................................................................................
   120    120         c = 0xfffd;
   121    121       }
   122    122     }
   123    123     return c;
   124    124   }
   125    125   static unsigned re_next_char_nocase(ReInput *p){
   126    126     unsigned c = re_next_char(p);
   127         -  return unicode_fold(c,2);
          127  +  return unicode_fold(c,1);
   128    128   }
   129    129   
   130    130   /* Return true if c is a perl "word" character:  [A-Za-z0-9_] */
   131    131   static int re_word_char(int c){
   132    132     return unicode_isalnum(c) || c=='_';
   133    133   }
   134    134   
................................................................................
   154    154     int c = RE_EOF+1;
   155    155     int cPrev = 0;
   156    156     int rc = 0;
   157    157     ReInput in;
   158    158   
   159    159     in.z = zIn;
   160    160     in.i = 0;
   161         -  in.mx = nIn>=0 ? nIn : (int)strlen((char const*)zIn);
          161  +  in.mx = nIn>=0 ? nIn : strlen((const char*)zIn);
   162    162   
   163    163     /* Look for the initial prefix match, if there is one. */
   164    164     if( pRe->nInit ){
   165    165       unsigned char x = pRe->zInit[0];
   166    166       while( in.i+pRe->nInit<=in.mx
   167    167        && (zIn[in.i]!=x ||
   168    168            strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
   169    169       ){
   170    170         in.i++;
   171    171       }
   172    172       if( in.i+pRe->nInit>in.mx ) return 0;
   173    173     }
   174    174   
   175         -  if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
          175  +  if( pRe->nState<=count(aSpace)*2 ){
   176    176       pToFree = 0;
   177    177       aStateSet[0].aState = aSpace;
   178    178     }else{
   179    179       pToFree = fossil_malloc( sizeof(ReStateNumber)*2*pRe->nState );
   180    180       if( pToFree==0 ) return -1;
   181    181       aStateSet[0].aState = pToFree;
   182    182     }
................................................................................
   305    305     int i;
   306    306     if( p->nAlloc<=p->nState && re_resize(p, p->nAlloc*2) ) return 0;
   307    307     for(i=p->nState; i>iBefore; i--){
   308    308       p->aOp[i] = p->aOp[i-1];
   309    309       p->aArg[i] = p->aArg[i-1];
   310    310     }
   311    311     p->nState++;
   312         -  p->aOp[iBefore] = (char)op;
          312  +  p->aOp[iBefore] = op;
   313    313     p->aArg[iBefore] = arg;
   314    314     return iBefore;
   315    315   }
   316    316   
   317    317   /* Append a new opcode and argument to the end of the RE under construction.
   318    318   */
   319    319   static int re_append(ReCompiled *p, int op, int arg){
................................................................................
   594    594     if( zIn[0]=='^' ){
   595    595       zIn++;
   596    596     }else{
   597    597       re_append(pRe, RE_OP_ANYSTAR, 0);
   598    598     }
   599    599     pRe->sIn.z = (unsigned char*)zIn;
   600    600     pRe->sIn.i = 0;
   601         -  pRe->sIn.mx = (int)strlen(zIn);
          601  +  pRe->sIn.mx = strlen(zIn);
   602    602     zErr = re_subcompile_re(pRe);
   603    603     if( zErr ){
   604    604       re_free(pRe);
   605    605       return zErr;
   606    606     }
   607    607     if( rePeek(pRe)=='$' && pRe->sIn.i+1>=pRe->sIn.mx ){
   608    608       re_append(pRe, RE_OP_MATCH, RE_EOF);
................................................................................
   624    624     ** regex engine over the string.  Do not worry able trying to match
   625    625     ** unicode characters beyond plane 0 - those are very rare and this is
   626    626     ** just an optimization. */
   627    627     if( pRe->aOp[0]==RE_OP_ANYSTAR ){
   628    628       for(j=0, i=1; j<sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){
   629    629         unsigned x = pRe->aArg[i];
   630    630         if( x<=127 ){
   631         -        pRe->zInit[j++] = (unsigned char)x;
          631  +        pRe->zInit[j++] = x;
   632    632         }else if( x<=0xfff ){
   633         -        pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6));
          633  +        pRe->zInit[j++] = 0xc0 | (x>>6);
   634    634           pRe->zInit[j++] = 0x80 | (x&0x3f);
   635    635         }else if( x<=0xffff ){
   636         -        pRe->zInit[j++] = (unsigned char)(0xd0 | (x>>12));
          636  +        pRe->zInit[j++] = 0xd0 | (x>>12);
   637    637           pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f);
   638    638           pRe->zInit[j++] = 0x80 | (x&0x3f);
   639    639         }else{
   640    640           break;
   641    641         }
   642    642       }
   643    643       if( j>0 && pRe->zInit[j-1]==0 ) j--;
................................................................................
   660    660     int argc,
   661    661     sqlite3_value **argv
   662    662   ){
   663    663     ReCompiled *pRe;          /* Compiled regular expression */
   664    664     const char *zPattern;     /* The regular expression */
   665    665     const unsigned char *zStr;/* String being searched */
   666    666     const char *zErr;         /* Compile error message */
   667         -  int setAux = 0;           /* True to invoke sqlite3_set_auxdata() */
   668    667   
   669    668     pRe = sqlite3_get_auxdata(context, 0);
   670    669     if( pRe==0 ){
   671    670       zPattern = (const char*)sqlite3_value_text(argv[0]);
   672    671       if( zPattern==0 ) return;
   673    672       zErr = re_compile(&pRe, zPattern, 0);
   674    673       if( zErr ){
   675         -      re_free(pRe);
   676    674         sqlite3_result_error(context, zErr, -1);
   677    675         return;
   678    676       }
   679    677       if( pRe==0 ){
   680    678         sqlite3_result_error_nomem(context);
   681    679         return;
   682    680       }
   683         -    setAux = 1;
          681  +    sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
   684    682     }
   685    683     zStr = (const unsigned char*)sqlite3_value_text(argv[1]);
   686    684     if( zStr!=0 ){
   687    685       sqlite3_result_int(context, re_match(pRe, zStr, -1));
   688    686     }
   689         -  if( setAux ){
   690         -    sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
   691         -  }
   692    687   }
   693    688   
   694    689   /*
   695         -** Invoke this routine to register the regexp() function with the
          690  +** Invoke this routine in order to install the REGEXP function in an
   696    691   ** SQLite database connection.
          692  +**
          693  +** Use:
          694  +**
          695  +**      sqlite3_auto_extension(sqlite3_add_regexp_func);
          696  +**
          697  +** to cause this extension to be automatically loaded into each new
          698  +** database connection.
   697    699   */
   698    700   int re_add_sql_func(sqlite3 *db){
   699    701     return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, 0,
   700    702                                    re_sql_func, 0, 0);
   701    703   }
   702    704   
   703    705   /*

Changes to src/shell.c.

  2173   2173     db = sqlite3_context_db_handle(ctx);
  2174   2174     mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
  2175   2175     if( nIn>mxBlob ){
  2176   2176       sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
  2177   2177       fclose(in);
  2178   2178       return;
  2179   2179     }
  2180         -  pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
         2180  +  pBuf = sqlite3_malloc64( nIn );
  2181   2181     if( pBuf==0 ){
  2182   2182       sqlite3_result_error_nomem(ctx);
  2183   2183       fclose(in);
  2184   2184       return;
  2185   2185     }
  2186         -  if( nIn==fread(pBuf, 1, nIn, in) ){
         2186  +  if( 1==fread(pBuf, nIn, 1, in) ){
  2187   2187       sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
  2188   2188     }else{
  2189   2189       sqlite3_result_error_code(ctx, SQLITE_IOERR);
  2190   2190       sqlite3_free(pBuf);
  2191   2191     }
  2192   2192     fclose(in);
  2193   2193   }
................................................................................
 10426  10426     sqlite3SelectTrace = savedSelectTrace;
 10427  10427   #endif
 10428  10428   #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
 10429  10429     sqlite3WhereTrace = savedWhereTrace;
 10430  10430   #endif
 10431  10431   }
 10432  10432   
 10433         -/* Name of the TEMP table that holds bind parameter values */
 10434         -#define BIND_PARAM_TABLE "$Parameters"
 10435         -
 10436         -/* Create the TEMP table used to store parameter bindings */
 10437         -static void bind_table_init(ShellState *p){
 10438         -  sqlite3_exec(p->db,
 10439         -    "CREATE TABLE IF NOT EXISTS temp.[" BIND_PARAM_TABLE "](\n"
 10440         -    "  key TEXT PRIMARY KEY,\n"
 10441         -    "  value ANY\n"
 10442         -    ") WITHOUT ROWID;",
 10443         -    0, 0, 0);
 10444         -}
 10445         -
 10446         -/*
 10447         -** Bind parameters on a prepared statement.
 10448         -**
 10449         -** Parameter bindings are taken from a TEMP table of the form:
 10450         -**
 10451         -**    CREATE TEMP TABLE "$Parameters"(key TEXT PRIMARY KEY, value)
 10452         -**    WITHOUT ROWID;
 10453         -**
 10454         -** No bindings occur if this table does not exist.  The special character '$'
 10455         -** is included in the table name to help prevent collisions with actual tables.
 10456         -** The table must be in the TEMP schema.
 10457         -*/
 10458         -static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
 10459         -  int nVar;
 10460         -  int i;
 10461         -  int rc;
 10462         -  sqlite3_stmt *pQ = 0;
 10463         -
 10464         -  nVar = sqlite3_bind_parameter_count(pStmt);
 10465         -  if( nVar==0 ) return;  /* Nothing to do */
 10466         -  if( sqlite3_table_column_metadata(pArg->db, "TEMP", BIND_PARAM_TABLE,
 10467         -                                    "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
 10468         -    return; /* Parameter table does not exist */
 10469         -  }
 10470         -  rc = sqlite3_prepare_v2(pArg->db,
 10471         -          "SELECT value FROM temp.\"" BIND_PARAM_TABLE "\""
 10472         -          " WHERE key=?1", -1, &pQ, 0);
 10473         -  if( rc || pQ==0 ) return;
 10474         -  for(i=1; i<=nVar; i++){
 10475         -    char zNum[30];
 10476         -    const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
 10477         -    if( zVar==0 ){
 10478         -      sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
 10479         -      zVar = zNum;
 10480         -    }
 10481         -    sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
 10482         -    if( sqlite3_step(pQ)==SQLITE_ROW ){
 10483         -      sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
 10484         -    }else{
 10485         -      sqlite3_bind_null(pStmt, i);
 10486         -    }
 10487         -    sqlite3_reset(pQ);
 10488         -  }
 10489         -  sqlite3_finalize(pQ);
 10490         -}
 10491         -
 10492  10433   /*
 10493  10434   ** Run a prepared statement
 10494  10435   */
 10495  10436   static void exec_prepared_stmt(
 10496  10437     ShellState *pArg,                                /* Pointer to ShellState */
 10497  10438     sqlite3_stmt *pStmt                              /* Statment to run */
 10498  10439   ){
................................................................................
 10737  10678   
 10738  10679         /* echo the sql statement if echo on */
 10739  10680         if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
 10740  10681           utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
 10741  10682         }
 10742  10683   
 10743  10684         /* Show the EXPLAIN QUERY PLAN if .eqp is on */
 10744         -      if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
        10685  +      if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
 10745  10686           sqlite3_stmt *pExplain;
 10746  10687           char *zEQP;
 10747  10688           int triggerEQP = 0;
 10748  10689           disable_debug_trace_modes();
 10749  10690           sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
 10750  10691           if( pArg->autoEQP>=AUTOEQP_trigger ){
 10751  10692             sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
................................................................................
 10786  10727           }
 10787  10728           restore_debug_trace_modes();
 10788  10729         }
 10789  10730   
 10790  10731         if( pArg ){
 10791  10732           pArg->cMode = pArg->mode;
 10792  10733           if( pArg->autoExplain ){
 10793         -          if( sqlite3_stmt_isexplain(pStmt)==1 ){
        10734  +          if( sqlite3_column_count(pStmt)==8
        10735  +           && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
        10736  +          ){
 10794  10737               pArg->cMode = MODE_Explain;
 10795  10738             }
 10796         -          if( sqlite3_stmt_isexplain(pStmt)==2 ){
        10739  +          if( sqlite3_column_count(pStmt)==4
        10740  +           && sqlite3_strlike("EXPLAIN QUERY PLAN%", zStmtSql,0)==0 ){
 10797  10741               pArg->cMode = MODE_EQP;
 10798  10742             }
 10799  10743           }
 10800  10744   
 10801  10745           /* If the shell is currently in ".explain" mode, gather the extra
 10802  10746           ** data required to add indents to the output.*/
 10803  10747           if( pArg->cMode==MODE_Explain ){
 10804  10748             explain_data_prepare(pArg, pStmt);
 10805  10749           }
 10806  10750         }
 10807  10751   
 10808         -      bind_prepared_stmt(pArg, pStmt);
 10809  10752         exec_prepared_stmt(pArg, pStmt);
 10810  10753         explain_data_delete(pArg);
 10811  10754         eqp_render(pArg);
 10812  10755   
 10813  10756         /* print usage stats if stats on */
 10814  10757         if( pArg && pArg->statsOn ){
 10815  10758           display_stats(db, pArg, 0);
................................................................................
 11233  11176     "        --maxsize N     Maximum size for --hexdb or --deserialized database",
 11234  11177   #endif
 11235  11178     "        --new           Initialize FILE to an empty database",
 11236  11179     "        --readonly      Open FILE readonly",
 11237  11180     "        --zip           FILE is a ZIP archive",
 11238  11181     ".output ?FILE?           Send output to FILE or stdout if FILE is omitted",
 11239  11182     "     If FILE begins with '|' then open it as a pipe.",
 11240         -  ".parameter CMD ...       Manage SQL parameter bindings",
 11241         -  "   clear                   Erase all bindings",
 11242         -  "   init                    Initialize the TEMP table that holds bindings",
 11243         -  "   list                    List the current parameter bindings",
 11244         -  "   set PARAMETER VALUE     Given SQL parameter PARAMETER a value of VALUE",
 11245         -  "                           PARAMETER should start with '$', ':', '@', or '?'",
 11246         -  "   unset PARAMETER         Remove PARAMETER from the binding table",
 11247  11183     ".print STRING...         Print literal STRING",
 11248  11184   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
 11249  11185     ".progress N              Invoke progress handler after every N opcodes",
 11250  11186     "   --limit N                 Interrupt after N progress callbacks",
 11251  11187     "   --once                    Do no more than one progress interrupt",
 11252  11188     "   --quiet|-q                No output except at interrupts",
 11253  11189     "   --reset                   Reset the count for each input and interrupt",
................................................................................
 14771  14707           rc = 1;
 14772  14708         } else {
 14773  14709           sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
 14774  14710         }
 14775  14711       }
 14776  14712     }else
 14777  14713   
 14778         -  if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
 14779         -    open_db(p,0);
 14780         -    if( nArg<=1 ) goto parameter_syntax_error;
 14781         -
 14782         -    /* .parameter clear
 14783         -    ** Clear all bind parameters by dropping the TEMP table that holds them.
 14784         -    */
 14785         -    if( nArg==2 && strcmp(azArg[1],"clear")==0 ){
 14786         -      sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.[" BIND_PARAM_TABLE "];",
 14787         -                   0, 0, 0);
 14788         -    }else
 14789         -
 14790         -    /* .parameter list
 14791         -    ** List all bind parameters.
 14792         -    */
 14793         -    if( nArg==2 && strcmp(azArg[1],"list")==0 ){
 14794         -      sqlite3_stmt *pStmt = 0;
 14795         -      int rx;
 14796         -      int len = 0;
 14797         -      rx = sqlite3_prepare_v2(p->db,
 14798         -             "SELECT max(length(key)) "
 14799         -             "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
 14800         -      if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
 14801         -        len = sqlite3_column_int(pStmt, 0);
 14802         -        if( len>40 ) len = 40;
 14803         -      }
 14804         -      sqlite3_finalize(pStmt);
 14805         -      pStmt = 0;
 14806         -      if( len ){
 14807         -        rx = sqlite3_prepare_v2(p->db,
 14808         -             "SELECT key, quote(value) "
 14809         -             "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
 14810         -        while( sqlite3_step(pStmt)==SQLITE_ROW ){
 14811         -          utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
 14812         -                      sqlite3_column_text(pStmt,1));
 14813         -        }
 14814         -        sqlite3_finalize(pStmt);
 14815         -      }
 14816         -    }else
 14817         -
 14818         -    /* .parameter init
 14819         -    ** Make sure the TEMP table used to hold bind parameters exists.
 14820         -    ** Create it if necessary.
 14821         -    */
 14822         -    if( nArg==2 && strcmp(azArg[1],"init")==0 ){
 14823         -      bind_table_init(p);
 14824         -    }else
 14825         -
 14826         -    /* .parameter set NAME VALUE
 14827         -    ** Set or reset a bind parameter.  NAME should be the full parameter
 14828         -    ** name exactly as it appears in the query.  (ex: $abc, @def).  The
 14829         -    ** VALUE can be in either SQL literal notation, or if not it will be
 14830         -    ** understood to be a text string.
 14831         -    */
 14832         -    if( nArg==4 && strcmp(azArg[1],"set")==0 ){
 14833         -      int rx;
 14834         -      char *zSql;
 14835         -      sqlite3_stmt *pStmt;
 14836         -      const char *zKey = azArg[2];
 14837         -      const char *zValue = azArg[3];
 14838         -      bind_table_init(p);
 14839         -      zSql = sqlite3_mprintf(
 14840         -                  "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
 14841         -                  "VALUES(%Q,%s);", zKey, zValue);
 14842         -      if( zSql==0 ) shell_out_of_memory();
 14843         -      pStmt = 0;
 14844         -      rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
 14845         -      sqlite3_free(zSql);
 14846         -      if( rx!=SQLITE_OK ){
 14847         -        sqlite3_finalize(pStmt);
 14848         -        pStmt = 0;
 14849         -        zSql = sqlite3_mprintf(
 14850         -                   "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
 14851         -                   "VALUES(%Q,%Q);", zKey, zValue);
 14852         -        if( zSql==0 ) shell_out_of_memory();
 14853         -        rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
 14854         -        sqlite3_free(zSql);
 14855         -        if( rx!=SQLITE_OK ){
 14856         -          utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
 14857         -          sqlite3_finalize(pStmt);
 14858         -          pStmt = 0;
 14859         -          rc = 1;
 14860         -        }
 14861         -      }
 14862         -      sqlite3_step(pStmt);
 14863         -      sqlite3_finalize(pStmt);
 14864         -    }else
 14865         -
 14866         -    /* .parameter unset NAME
 14867         -    ** Remove the NAME binding from the parameter binding table, if it
 14868         -    ** exists.
 14869         -    */
 14870         -    if( nArg==3 && strcmp(azArg[1],"unset")==0 ){
 14871         -      char *zSql = sqlite3_mprintf(
 14872         -          "DELETE FROM temp.[" BIND_PARAM_TABLE "] WHERE key=%Q", azArg[2]);
 14873         -      if( zSql==0 ) shell_out_of_memory();
 14874         -      sqlite3_exec(p->db, zSql, 0, 0, 0);
 14875         -      sqlite3_free(zSql);
 14876         -    }else
 14877         -    /* If no command name matches, show a syntax error */
 14878         -    parameter_syntax_error:
 14879         -    showHelp(p->out, "parameter");
 14880         -  }else
 14881         -
 14882  14714     if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
 14883  14715       int i;
 14884  14716       for(i=1; i<nArg; i++){
 14885  14717         if( i>1 ) raw_printf(p->out, " ");
 14886  14718         utf8_printf(p->out, "%s", azArg[i]);
 14887  14719       }
 14888  14720       raw_printf(p->out, "\n");

Changes to src/sitemap.c.

   191    191       @   <li>%z(href("%R/bloblist"))List of Artifacts</a></li>
   192    192       @   <li>%z(href("%R/timewarps"))List of "Timewarp" Check-ins</a></li>
   193    193       @   </ul>
   194    194       @ </li>
   195    195     }
   196    196     @ <li>Help
   197    197     @   <ul>
   198         -  if( g.perm.Admin || g.perm.Write ||
   199         -      g.perm.WrForum || g.perm.WrTForum ||
   200         -      g.perm.NewWiki || g.perm.ApndWiki || g.perm.WrWiki || g.perm.ModWiki ||
   201         -      g.perm.NewTkt  || g.perm.ApndTkt  || g.perm.WrTkt  || g.perm.ModTkt ){
   202         -    @   <li>%z(href("%R/wiki_rules"))Wiki Formatting Rules</a></li>
   203         -    @   <li>%z(href("%R/md_rules"))Markdown Formatting Rules</a></li>
   204         -  }
          198  +  @   <li>%z(href("%R/wiki_rules"))Wiki Formatting Rules</a></li>
          199  +  @   <li>%z(href("%R/md_rules"))Markdown Formatting Rules</a></li>
   205    200     @   <li>%z(href("%R/help"))List of All Commands and Web Pages</a></li>
   206    201     @   <li>%z(href("%R/test-all-help"))All "help" text on a single page</a></li>
   207         -  if( g.perm.Admin || g.perm.Write || g.perm.WrUnver ){
   208         -    @   <li>%z(href("%R/mimetype_list"))Filename suffix to MIME type map</a></li>
   209         -  }
          202  +  @   <li>%z(href("%R/mimetype_list"))Filename suffix to mimetype map</a></li>
   210    203     @   </ul></li>
   211    204     if( g.perm.Admin ){
   212    205       @ <li>%z(href("%R/setup"))Administration Pages</a>
   213    206       @   <ul>
   214    207       @   <li>%z(href("%R/modreq"))Pending Moderation Requests</a></li>
   215    208       @   <li>%z(href("%R/admin_log"))Admin log</a></li>
   216    209       @   <li>%z(href("%R/cachestat"))Status of the web-page cache</a></li>

Changes to src/sqlcmd.c.

   146    146     const void *notUsed
   147    147   ){
   148    148     add_content_sql_commands(db);
   149    149     db_add_aux_functions(db);
   150    150     re_add_sql_func(db);
   151    151     search_sql_setup(db);
   152    152     foci_register(db);
   153         -  deltafunc_init(db);
   154    153     g.repositoryOpen = 1;
   155    154     g.db = db;
   156    155     sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "repository");
   157    156     db_maybe_set_encryption_key(db, g.zRepositoryName);
   158    157     if( g.zLocalDbName ){
   159    158       char *zSql = sqlite3_mprintf("ATTACH %Q AS 'localdb' KEY ''",
   160    159                                    g.zLocalDbName);
................................................................................
   254    253   **
   255    254   ** WARNING:  Careless use of this command can corrupt a Fossil repository
   256    255   ** in ways that are unrecoverable.  Be sure you know what you are doing before
   257    256   ** running any SQL commands that modify the repository database.
   258    257   **
   259    258   ** The following extensions to the usual SQLite commands are provided:
   260    259   **
   261         -**    checkin_mtime(X,Y)        Return the mtime for the file Y (a BLOB.RID)
   262         -**                              found in check-in X (another BLOB.RID value).
          260  +**    content(X)                Return the content of artifact X.  X can be an
          261  +**                              artifact hash or prefix or a tag.
   263    262   **
   264    263   **    compress(X)               Compress text X.
   265    264   **
   266         -**    content(X)                Return the content of artifact X. X can be an
   267         -**                              artifact hash or hash prefix or a tag. Artifacts
   268         -**                              are stored compressed and deltaed. This function
   269         -**                              does all necessary decompression and undeltaing.
   270         -**
   271    265   **    decompress(X)             Decompress text X.  Undoes the work of
   272    266   **                              compress(X).
   273    267   **
   274         -**    delta_apply(X,D)          Apply delta D to source blob X and return
   275         -**                              the result.
          268  +**    checkin_mtime(X,Y)        Return the mtime for the file Y (a BLOB.RID)
          269  +**                              found in check-in X (another BLOB.RID value).
   276    270   **
   277         -**    delta_create(X,Y)         Create and return a delta that will convert
   278         -**                              X into Y.
   279         -**
   280         -**    delta_output_size(D)      Return the number of bytes of output to expect
   281         -**                              when applying delta D
   282         -**
   283         -**    delta_parse(D)            A table-valued function that deconstructs
   284         -**                              delta D and returns rows for each element of
   285         -**                              that delta.
   286         -**
   287         -**    files_of_checkin(X)       A table-valued function that returns info on
   288         -**                              all files contained in check-in X.  Example:
   289         -**                                SELECT * FROM files_of_checkin('trunk');
          271  +**    symbolic_name_to_rid(X)   Return the BLOB.RID corresponding to symbolic
          272  +**                              name X.
   290    273   **
   291    274   **    now()                     Return the number of seconds since 1970.
   292    275   **
   293    276   **    REGEXP                    The REGEXP operator works, unlike in
   294    277   **                              standard SQLite.
   295    278   **
   296         -**    symbolic_name_to_rid(X)   Return the BLOB.RID corresponding to symbolic
   297         -**                              name X.
          279  +**    files_of_checkin(X)       A table-valued function that returns info on
          280  +**                              all files contained in check-in X.  Example:
          281  +**                                SELECT * FROM files_of_checkin('trunk');
   298    282   */
   299    283   void cmd_sqlite3(void){
   300    284     int noRepository;
   301    285     const char *zConfigDb;
   302    286     extern int sqlite3_shell(int, char**);
   303    287   #ifdef FOSSIL_ENABLE_TH1_HOOKS
   304    288     g.fNoThHook = 1;

Changes to src/sqlite3.c.

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.28.0.  By combining all the individual C code files into this
            3  +** version 3.27.1.  By combining all the individual C code files into this
     4      4   ** single large file, the entire code can be compiled as a single translation
     5      5   ** unit.  This allows many compilers to do optimizations that would not be
     6      6   ** possible if the files were compiled separately.  Performance improvements
     7      7   ** of 5% or more are commonly seen when SQLite is compiled as a single
     8      8   ** translation unit.
     9      9   **
    10     10   ** This file is all you need to compile SQLite.  To use SQLite in other
................................................................................
  1158   1158   ** been edited in any way since it was last checked in, then the last
  1159   1159   ** four hexadecimal digits of the hash may be modified.
  1160   1160   **
  1161   1161   ** See also: [sqlite3_libversion()],
  1162   1162   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  1163   1163   ** [sqlite_version()] and [sqlite_source_id()].
  1164   1164   */
  1165         -#define SQLITE_VERSION        "3.28.0"
  1166         -#define SQLITE_VERSION_NUMBER 3028000
  1167         -#define SQLITE_SOURCE_ID      "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07e2f93"
         1165  +#define SQLITE_VERSION        "3.27.1"
         1166  +#define SQLITE_VERSION_NUMBER 3027001
         1167  +#define SQLITE_SOURCE_ID      "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd"
  1168   1168   
  1169   1169   /*
  1170   1170   ** CAPI3REF: Run-Time Library Version Numbers
  1171   1171   ** KEYWORDS: sqlite3_version sqlite3_sourceid
  1172   1172   **
  1173   1173   ** These interfaces provide the same information as the [SQLITE_VERSION],
  1174   1174   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  3121   3121   ** The second parameter is a pointer to an integer into which
  3122   3122   ** is written 0 or 1 to indicate whether triggers are disabled or enabled
  3123   3123   ** following this call.  The second parameter may be a NULL pointer, in
  3124   3124   ** which case the trigger setting is not reported back. </dd>
  3125   3125   **
  3126   3126   ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
  3127   3127   ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
  3128         -** <dd> ^This option is used to enable or disable the
  3129         -** [fts3_tokenizer()] function which is part of the
         3128  +** <dd> ^This option is used to enable or disable the two-argument
         3129  +** version of the [fts3_tokenizer()] function which is part of the
  3130   3130   ** [FTS3] full-text search engine extension.
  3131   3131   ** There should be two additional arguments.
  3132   3132   ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
  3133   3133   ** positive to enable fts3_tokenizer() or negative to leave the setting
  3134   3134   ** unchanged.
  3135   3135   ** The second parameter is a pointer to an integer into which
  3136   3136   ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
................................................................................
  3404   3404   ** does not affect the value returned by sqlite3_total_changes().
  3405   3405   ** 
  3406   3406   ** ^Changes made as part of [foreign key actions] are included in the
  3407   3407   ** count, but those made as part of REPLACE constraint resolution are
  3408   3408   ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers 
  3409   3409   ** are not counted.
  3410   3410   **
  3411         -** The [sqlite3_total_changes(D)] interface only reports the number
         3411  +** This the [sqlite3_total_changes(D)] interface only reports the number
  3412   3412   ** of rows that changed due to SQL statement run against database
  3413   3413   ** connection D.  Any changes by other database connections are ignored.
  3414   3414   ** To detect changes against a database file from other database
  3415   3415   ** connections use the [PRAGMA data_version] command or the
  3416   3416   ** [SQLITE_FCNTL_DATA_VERSION] [file control].
  3417   3417   ** 
  3418   3418   ** If a separate thread makes changes on the same database connection
................................................................................
  4929   4929   ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
  4930   4930   ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
  4931   4931   ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
  4932   4932   ** sqlite3_stmt_readonly() returns false for those commands.
  4933   4933   */
  4934   4934   SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  4935   4935   
  4936         -/*
  4937         -** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
  4938         -** METHOD: sqlite3_stmt
  4939         -**
  4940         -** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
  4941         -** prepared statement S is an EXPLAIN statement, or 2 if the
  4942         -** statement S is an EXPLAIN QUERY PLAN.
  4943         -** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
  4944         -** an ordinary statement or a NULL pointer.
  4945         -*/
  4946         -SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
  4947         -
  4948   4936   /*
  4949   4937   ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  4950   4938   ** METHOD: sqlite3_stmt
  4951   4939   **
  4952   4940   ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  4953   4941   ** [prepared statement] S has been stepped at least once using 
  4954   4942   ** [sqlite3_step(S)] but has neither run to completion (returned
................................................................................
  5080   5068   ** the value of the fourth parameter then the resulting string value will
  5081   5069   ** contain embedded NULs.  The result of expressions involving strings
  5082   5070   ** with embedded NULs is undefined.
  5083   5071   **
  5084   5072   ** ^The fifth argument to the BLOB and string binding interfaces
  5085   5073   ** is a destructor used to dispose of the BLOB or
  5086   5074   ** string after SQLite has finished with it.  ^The destructor is called
  5087         -** to dispose of the BLOB or string even if the call to the bind API fails,
  5088         -** except the destructor is not called if the third parameter is a NULL
  5089         -** pointer or the fourth parameter is negative.
         5075  +** to dispose of the BLOB or string even if the call to bind API fails.
  5090   5076   ** ^If the fifth argument is
  5091   5077   ** the special value [SQLITE_STATIC], then SQLite assumes that the
  5092   5078   ** information is in static, unmanaged space and does not need to be freed.
  5093   5079   ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
  5094   5080   ** SQLite makes its own private copy of the data immediately, before
  5095   5081   ** the sqlite3_bind_*() routine returns.
  5096   5082   **
................................................................................
  6840   6826   ** CAPI3REF: Return The Filename For A Database Connection
  6841   6827   ** METHOD: sqlite3
  6842   6828   **
  6843   6829   ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
  6844   6830   ** associated with database N of connection D.  ^The main database file
  6845   6831   ** has the name "main".  If there is no attached database N on the database
  6846   6832   ** connection D, or if database N is a temporary or in-memory database, then
  6847         -** this function will return either a NULL pointer or an empty string.
         6833  +** a NULL pointer is returned.
  6848   6834   **
  6849   6835   ** ^The filename returned by this function is the output of the
  6850   6836   ** xFullPathname method of the [VFS].  ^In other words, the filename
  6851   6837   ** will be an absolute pathname, even if the filename used
  6852   6838   ** to open the database originally was a URI or relative pathname.
  6853   6839   */
  6854   6840   SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
................................................................................
 12350  12336   **
 12351  12337   **
 12352  12338   ** xSetAuxdata(pFts5, pAux, xDelete)
 12353  12339   **
 12354  12340   **   Save the pointer passed as the second argument as the extension functions 
 12355  12341   **   "auxiliary data". The pointer may then be retrieved by the current or any
 12356  12342   **   future invocation of the same fts5 extension function made as part of
 12357         -**   the same MATCH query using the xGetAuxdata() API.
        12343  +**   of the same MATCH query using the xGetAuxdata() API.
 12358  12344   **
 12359  12345   **   Each extension function is allocated a single auxiliary data slot for
 12360  12346   **   each FTS query (MATCH expression). If the extension function is invoked 
 12361  12347   **   more than once for a single FTS query, then all invocations share a 
 12362  12348   **   single auxiliary data context.
 12363  12349   **
 12364  12350   **   If there is already an auxiliary data pointer when this function is
................................................................................
 12365  12351   **   invoked, then it is replaced by the new pointer. If an xDelete callback
 12366  12352   **   was specified along with the original pointer, it is invoked at this
 12367  12353   **   point.
 12368  12354   **
 12369  12355   **   The xDelete callback, if one is specified, is also invoked on the
 12370  12356   **   auxiliary data pointer after the FTS5 query has finished.
 12371  12357   **
 12372         -**   If an error (e.g. an OOM condition) occurs within this function,
        12358  +**   If an error (e.g. an OOM condition) occurs within this function, an
 12373  12359   **   the auxiliary data is set to NULL and an error code returned. If the
 12374  12360   **   xDelete parameter was not NULL, it is invoked on the auxiliary data
 12375  12361   **   pointer before returning.
 12376  12362   **
 12377  12363   **
 12378  12364   ** xGetAuxdata(pFts5, bClear)
 12379  12365   **
................................................................................
 14947  14933   #define OP_OpenPseudo    116 /* synopsis: P3 columns in r[P2]              */
 14948  14934   #define OP_Close         117
 14949  14935   #define OP_ColumnsUsed   118
 14950  14936   #define OP_SeekHit       119 /* synopsis: seekHit=P2                       */
 14951  14937   #define OP_Sequence      120 /* synopsis: r[P2]=cursor[P1].ctr++           */
 14952  14938   #define OP_NewRowid      121 /* synopsis: r[P2]=rowid                      */
 14953  14939   #define OP_Insert        122 /* synopsis: intkey=r[P3] data=r[P2]          */
 14954         -#define OP_Delete        123
 14955         -#define OP_ResetCount    124
 14956         -#define OP_SorterCompare 125 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 14957         -#define OP_SorterData    126 /* synopsis: r[P2]=data                       */
 14958         -#define OP_RowData       127 /* synopsis: r[P2]=data                       */
 14959         -#define OP_Rowid         128 /* synopsis: r[P2]=rowid                      */
 14960         -#define OP_NullRow       129
 14961         -#define OP_SeekEnd       130
 14962         -#define OP_SorterInsert  131 /* synopsis: key=r[P2]                        */
 14963         -#define OP_IdxInsert     132 /* synopsis: key=r[P2]                        */
 14964         -#define OP_IdxDelete     133 /* synopsis: key=r[P2@P3]                     */
 14965         -#define OP_DeferredSeek  134 /* synopsis: Move P3 to P1.rowid if needed    */
 14966         -#define OP_IdxRowid      135 /* synopsis: r[P2]=rowid                      */
 14967         -#define OP_Destroy       136
 14968         -#define OP_Clear         137
 14969         -#define OP_ResetSorter   138
 14970         -#define OP_CreateBtree   139 /* synopsis: r[P2]=root iDb=P1 flags=P3       */
 14971         -#define OP_SqlExec       140
        14940  +#define OP_InsertInt     123 /* synopsis: intkey=P3 data=r[P2]             */
        14941  +#define OP_Delete        124
        14942  +#define OP_ResetCount    125
        14943  +#define OP_SorterCompare 126 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
        14944  +#define OP_SorterData    127 /* synopsis: r[P2]=data                       */
        14945  +#define OP_RowData       128 /* synopsis: r[P2]=data                       */
        14946  +#define OP_Rowid         129 /* synopsis: r[P2]=rowid                      */
        14947  +#define OP_NullRow       130
        14948  +#define OP_SeekEnd       131
        14949  +#define OP_SorterInsert  132 /* synopsis: key=r[P2]                        */
        14950  +#define OP_IdxInsert     133 /* synopsis: key=r[P2]                        */
        14951  +#define OP_IdxDelete     134 /* synopsis: key=r[P2@P3]                     */
        14952  +#define OP_DeferredSeek  135 /* synopsis: Move P3 to P1.rowid if needed    */
        14953  +#define OP_IdxRowid      136 /* synopsis: r[P2]=rowid                      */
        14954  +#define OP_Destroy       137
        14955  +#define OP_Clear         138
        14956  +#define OP_ResetSorter   139
        14957  +#define OP_CreateBtree   140 /* synopsis: r[P2]=root iDb=P1 flags=P3       */
 14972  14958   #define OP_Real          141 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
 14973         -#define OP_ParseSchema   142
 14974         -#define OP_LoadAnalysis  143
 14975         -#define OP_DropTable     144
 14976         -#define OP_DropIndex     145
 14977         -#define OP_DropTrigger   146
 14978         -#define OP_IntegrityCk   147
 14979         -#define OP_RowSetAdd     148 /* synopsis: rowset(P1)=r[P2]                 */
 14980         -#define OP_Param         149
 14981         -#define OP_FkCounter     150 /* synopsis: fkctr[P1]+=P2                    */
 14982         -#define OP_MemMax        151 /* synopsis: r[P1]=max(r[P1],r[P2])           */
 14983         -#define OP_OffsetLimit   152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 14984         -#define OP_AggInverse    153 /* synopsis: accum=r[P3] inverse(r[P2@P5])    */
 14985         -#define OP_AggStep       154 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 14986         -#define OP_AggStep1      155 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 14987         -#define OP_AggValue      156 /* synopsis: r[P3]=value N=P2                 */
 14988         -#define OP_AggFinal      157 /* synopsis: accum=r[P1] N=P2                 */
 14989         -#define OP_Expire        158
 14990         -#define OP_TableLock     159 /* synopsis: iDb=P1 root=P2 write=P3          */
 14991         -#define OP_VBegin        160
 14992         -#define OP_VCreate       161
 14993         -#define OP_VDestroy      162
 14994         -#define OP_VOpen         163
 14995         -#define OP_VColumn       164 /* synopsis: r[P3]=vcolumn(P2)                */
 14996         -#define OP_VRename       165
 14997         -#define OP_Pagecount     166
 14998         -#define OP_MaxPgcnt      167
 14999         -#define OP_Trace         168
 15000         -#define OP_CursorHint    169
 15001         -#define OP_Noop          170
 15002         -#define OP_Explain       171
 15003         -#define OP_Abortable     172
        14959  +#define OP_SqlExec       142
        14960  +#define OP_ParseSchema   143
        14961  +#define OP_LoadAnalysis  144
        14962  +#define OP_DropTable     145
        14963  +#define OP_DropIndex     146
        14964  +#define OP_DropTrigger   147
        14965  +#define OP_IntegrityCk   148
        14966  +#define OP_RowSetAdd     149 /* synopsis: rowset(P1)=r[P2]                 */
        14967  +#define OP_Param         150
        14968  +#define OP_FkCounter     151 /* synopsis: fkctr[P1]+=P2                    */
        14969  +#define OP_MemMax        152 /* synopsis: r[P1]=max(r[P1],r[P2])           */
        14970  +#define OP_OffsetLimit   153 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
        14971  +#define OP_AggInverse    154 /* synopsis: accum=r[P3] inverse(r[P2@P5])    */
        14972  +#define OP_AggStep       155 /* synopsis: accum=r[P3] step(r[P2@P5])       */
        14973  +#define OP_AggStep1      156 /* synopsis: accum=r[P3] step(r[P2@P5])       */
        14974  +#define OP_AggValue      157 /* synopsis: r[P3]=value N=P2                 */
        14975  +#define OP_AggFinal      158 /* synopsis: accum=r[P1] N=P2                 */
        14976  +#define OP_Expire        159
        14977  +#define OP_TableLock     160 /* synopsis: iDb=P1 root=P2 write=P3          */
        14978  +#define OP_VBegin        161
        14979  +#define OP_VCreate       162
        14980  +#define OP_VDestroy      163
        14981  +#define OP_VOpen         164
        14982  +#define OP_VColumn       165 /* synopsis: r[P3]=vcolumn(P2)                */
        14983  +#define OP_VRename       166
        14984  +#define OP_Pagecount     167
        14985  +#define OP_MaxPgcnt      168
        14986  +#define OP_Trace         169
        14987  +#define OP_CursorHint    170
        14988  +#define OP_Noop          171
        14989  +#define OP_Explain       172
        14990  +#define OP_Abortable     173
 15004  14991   
 15005  14992   /* Properties such as "out2" or "jump" that are specified in
 15006  14993   ** comments following the "case" for each opcode in the vdbe.c
 15007  14994   ** are encoded into bitvectors as follows:
 15008  14995   */
 15009  14996   #define OPFLG_JUMP        0x01  /* jump:  P2 holds jmp target */
 15010  14997   #define OPFLG_IN1         0x02  /* in1:   P1 is an input */
................................................................................
 15025  15012   /*  72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
 15026  15013   /*  80 */ 0x10, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
 15027  15014   /*  88 */ 0x12, 0x20, 0x00, 0x00, 0x26, 0x26, 0x26, 0x26,\
 15028  15015   /*  96 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
 15029  15016   /* 104 */ 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15030  15017   /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15031  15018   /* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15032         -/* 128 */ 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
 15033         -/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00,\
 15034         -/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
 15035         -/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15036         -/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
 15037         -/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00,}
        15019  +/* 128 */ 0x00, 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00,\
        15020  +/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
        15021  +/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\
        15022  +/* 152 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
        15023  +/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
        15024  +/* 168 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,}
 15038  15025   
 15039  15026   /* The sqlite3P2Values() routine is able to run faster if it knows
 15040  15027   ** the value of the largest JUMP opcode.  The smaller the maximum
 15041  15028   ** JUMP opcode the better, so the mkopcodeh.tcl script that
 15042  15029   ** generated this include file strives to group all JUMP opcodes
 15043  15030   ** together near the beginning of the list.
 15044  15031   */
................................................................................
 16335  16322   #endif
 16336  16323     void *pCommitArg;                 /* Argument to xCommitCallback() */
 16337  16324     int (*xCommitCallback)(void*);    /* Invoked at every commit. */
 16338  16325     void *pRollbackArg;               /* Argument to xRollbackCallback() */
 16339  16326     void (*xRollbackCallback)(void*); /* Invoked at every commit. */
 16340  16327     void *pUpdateArg;
 16341  16328     void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
 16342         -  Parse *pParse;                /* Current parse */
 16343  16329   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 16344  16330     void *pPreUpdateArg;          /* First argument to xPreUpdateCallback */
 16345  16331     void (*xPreUpdateCallback)(   /* Registered using sqlite3_preupdate_hook() */
 16346  16332       void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
 16347  16333     );
 16348  16334     PreUpdate *pPreUpdate;        /* Context for active pre-update callback */
 16349  16335   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
................................................................................
 17999  17985   #ifndef SQLITE_OMIT_SHARED_CACHE
 18000  17986     int nTableLock;        /* Number of locks in aTableLock */
 18001  17987     TableLock *aTableLock; /* Required table locks for shared-cache mode */
 18002  17988   #endif
 18003  17989     AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
 18004  17990     Parse *pToplevel;    /* Parse structure for main program (or NULL) */
 18005  17991     Table *pTriggerTab;  /* Table triggers are being coded for */
 18006         -  Parse *pParentParse; /* Parent parser if this parser is nested */
 18007  17992     int addrCrTab;       /* Address of OP_CreateBtree opcode on CREATE TABLE */
 18008  17993     u32 nQueryLoop;      /* Est number of iterations of a query (10*log2(N)) */
 18009  17994     u32 oldmask;         /* Mask of old.* columns referenced */
 18010  17995     u32 newmask;         /* Mask of new.* columns referenced */
 18011  17996     u8 eTriggerOp;       /* TK_UPDATE, TK_INSERT or TK_DELETE */
 18012  17997     u8 eOrconf;          /* Default ON CONFLICT policy for trigger steps */
 18013  17998     u8 disableTriggers;  /* True to disable triggers */
................................................................................
 19185  19170   SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
 19186  19171   SQLITE_PRIVATE void sqlite3AlterFunctions(void);
 19187  19172   SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
 19188  19173   SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
 19189  19174   SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
 19190  19175   SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
 19191  19176   SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
 19192         -SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
        19177  +SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
 19193  19178   SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
 19194  19179   SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
 19195  19180   SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
 19196  19181   SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
 19197  19182   SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
 19198  19183   SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
 19199  19184   SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
................................................................................
 27132  27117   SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
 27133  27118     if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
 27134  27119       db->mallocFailed = 1;
 27135  27120       if( db->nVdbeExec>0 ){
 27136  27121         db->u1.isInterrupted = 1;
 27137  27122       }
 27138  27123       db->lookaside.bDisable++;
 27139         -    if( db->pParse ){
 27140         -      db->pParse->rc = SQLITE_NOMEM_BKPT;
 27141         -    }
 27142  27124     }
 27143  27125   }
 27144  27126   
 27145  27127   /*
 27146  27128   ** This routine reactivates the memory allocator and clears the
 27147  27129   ** db->mallocFailed flag as necessary.
 27148  27130   **
................................................................................
 27328  27310   
 27329  27311   /*
 27330  27312   ** Set the StrAccum object to an error mode.
 27331  27313   */
 27332  27314   static void setStrAccumError(StrAccum *p, u8 eError){
 27333  27315     assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
 27334  27316     p->accError = eError;
 27335         -  if( p->mxAlloc ) sqlite3_str_reset(p);
        27317  +  p->nAlloc = 0;
 27336  27318   }
 27337  27319   
 27338  27320   /*
 27339  27321   ** Extra argument values from a PrintfArguments object
 27340  27322   */
 27341  27323   static sqlite3_int64 getIntArg(PrintfArguments *p){
 27342  27324     if( p->nArg<=p->nUsed ) return 0;
................................................................................
 27358  27340   ** of the output buffer in pAccum, then cause an SQLITE_TOOBIG error.
 27359  27341   ** Do the size check before the memory allocation to prevent rogue
 27360  27342   ** SQL from requesting large allocations using the precision or width
 27361  27343   ** field of the printf() function.
 27362  27344   */
 27363  27345   static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
 27364  27346     char *z;
 27365         -  if( pAccum->accError ) return 0;
 27366  27347     if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
 27367  27348       setStrAccumError(pAccum, SQLITE_TOOBIG);
 27368  27349       return 0;
 27369  27350     }
 27370  27351     z = sqlite3DbMallocRaw(pAccum->db, n);
 27371  27352     if( z==0 ){
 27372  27353       setStrAccumError(pAccum, SQLITE_NOMEM);
................................................................................
 28078  28059     assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
 28079  28060     if( p->accError ){
 28080  28061       testcase(p->accError==SQLITE_TOOBIG);
 28081  28062       testcase(p->accError==SQLITE_NOMEM);
 28082  28063       return 0;
 28083  28064     }
 28084  28065     if( p->mxAlloc==0 ){
        28066  +    N = p->nAlloc - p->nChar - 1;
 28085  28067       setStrAccumError(p, SQLITE_TOOBIG);
 28086         -    return p->nAlloc - p->nChar - 1;
        28068  +    return N;
 28087  28069     }else{
 28088  28070       char *zOld = isMalloced(p) ? p->zText : 0;
 28089  28071       i64 szNew = p->nChar;
 28090  28072       szNew += N + 1;
 28091  28073       if( szNew+p->nChar<=p->mxAlloc ){
 28092  28074         /* Force exponential buffer size growth as long as it does not overflow,
 28093  28075         ** to avoid having to call this routine too often */
................................................................................
 28151  28133   ** Append N bytes of text from z to the StrAccum object.  Increase the
 28152  28134   ** size of the memory allocation for StrAccum if necessary.
 28153  28135   */
 28154  28136   SQLITE_API void sqlite3_str_append(sqlite3_str *p, const char *z, int N){
 28155  28137     assert( z!=0 || N==0 );
 28156  28138     assert( p->zText!=0 || p->nChar==0 || p->accError );
 28157  28139     assert( N>=0 );
 28158         -  assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 );
        28140  +  assert( p->accError==0 || p->nAlloc==0 );
 28159  28141     if( p->nChar+N >= p->nAlloc ){
 28160  28142       enlargeAndAppend(p,z,N);
 28161  28143     }else if( N ){
 28162  28144       assert( p->zText );
 28163  28145       p->nChar += N;
 28164  28146       memcpy(&p->zText[p->nChar-N], z, N);
 28165  28147     }
................................................................................
 32153  32135       /* 116 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
 32154  32136       /* 117 */ "Close"            OpHelp(""),
 32155  32137       /* 118 */ "ColumnsUsed"      OpHelp(""),
 32156  32138       /* 119 */ "SeekHit"          OpHelp("seekHit=P2"),
 32157  32139       /* 120 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
 32158  32140       /* 121 */ "NewRowid"         OpHelp("r[P2]=rowid"),
 32159  32141       /* 122 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
 32160         -    /* 123 */ "Delete"           OpHelp(""),
 32161         -    /* 124 */ "ResetCount"       OpHelp(""),
 32162         -    /* 125 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
 32163         -    /* 126 */ "SorterData"       OpHelp("r[P2]=data"),
 32164         -    /* 127 */ "RowData"          OpHelp("r[P2]=data"),
 32165         -    /* 128 */ "Rowid"            OpHelp("r[P2]=rowid"),
 32166         -    /* 129 */ "NullRow"          OpHelp(""),
 32167         -    /* 130 */ "SeekEnd"          OpHelp(""),
 32168         -    /* 131 */ "SorterInsert"     OpHelp("key=r[P2]"),
 32169         -    /* 132 */ "IdxInsert"        OpHelp("key=r[P2]"),
 32170         -    /* 133 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
 32171         -    /* 134 */ "DeferredSeek"     OpHelp("Move P3 to P1.rowid if needed"),
 32172         -    /* 135 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 32173         -    /* 136 */ "Destroy"          OpHelp(""),
 32174         -    /* 137 */ "Clear"            OpHelp(""),
 32175         -    /* 138 */ "ResetSorter"      OpHelp(""),
 32176         -    /* 139 */ "CreateBtree"      OpHelp("r[P2]=root iDb=P1 flags=P3"),
 32177         -    /* 140 */ "SqlExec"          OpHelp(""),
        32142  +    /* 123 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
        32143  +    /* 124 */ "Delete"           OpHelp(""),
        32144  +    /* 125 */ "ResetCount"       OpHelp(""),
        32145  +    /* 126 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
        32146  +    /* 127 */ "SorterData"       OpHelp("r[P2]=data"),
        32147  +    /* 128 */ "RowData"          OpHelp("r[P2]=data"),
        32148  +    /* 129 */ "Rowid"            OpHelp("r[P2]=rowid"),
        32149  +    /* 130 */ "NullRow"          OpHelp(""),
        32150  +    /* 131 */ "SeekEnd"          OpHelp(""),
        32151  +    /* 132 */ "SorterInsert"     OpHelp("key=r[P2]"),
        32152  +    /* 133 */ "IdxInsert"        OpHelp("key=r[P2]"),
        32153  +    /* 134 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
        32154  +    /* 135 */ "DeferredSeek"     OpHelp("Move P3 to P1.rowid if needed"),
        32155  +    /* 136 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
        32156  +    /* 137 */ "Destroy"          OpHelp(""),
        32157  +    /* 138 */ "Clear"            OpHelp(""),
        32158  +    /* 139 */ "ResetSorter"      OpHelp(""),
        32159  +    /* 140 */ "CreateBtree"      OpHelp("r[P2]=root iDb=P1 flags=P3"),
 32178  32160       /* 141 */ "Real"             OpHelp("r[P2]=P4"),
 32179         -    /* 142 */ "ParseSchema"      OpHelp(""),
 32180         -    /* 143 */ "LoadAnalysis"     OpHelp(""),
 32181         -    /* 144 */ "DropTable"        OpHelp(""),
 32182         -    /* 145 */ "DropIndex"        OpHelp(""),
 32183         -    /* 146 */ "DropTrigger"      OpHelp(""),
 32184         -    /* 147 */ "IntegrityCk"      OpHelp(""),
 32185         -    /* 148 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
 32186         -    /* 149 */ "Param"            OpHelp(""),
 32187         -    /* 150 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
 32188         -    /* 151 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
 32189         -    /* 152 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
 32190         -    /* 153 */ "AggInverse"       OpHelp("accum=r[P3] inverse(r[P2@P5])"),
 32191         -    /* 154 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
 32192         -    /* 155 */ "AggStep1"         OpHelp("accum=r[P3] step(r[P2@P5])"),
 32193         -    /* 156 */ "AggValue"         OpHelp("r[P3]=value N=P2"),
 32194         -    /* 157 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
 32195         -    /* 158 */ "Expire"           OpHelp(""),
 32196         -    /* 159 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
 32197         -    /* 160 */ "VBegin"           OpHelp(""),
 32198         -    /* 161 */ "VCreate"          OpHelp(""),
 32199         -    /* 162 */ "VDestroy"         OpHelp(""),
 32200         -    /* 163 */ "VOpen"            OpHelp(""),
 32201         -    /* 164 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
 32202         -    /* 165 */ "VRename"          OpHelp(""),
 32203         -    /* 166 */ "Pagecount"        OpHelp(""),
 32204         -    /* 167 */ "MaxPgcnt"         OpHelp(""),
 32205         -    /* 168 */ "Trace"            OpHelp(""),
 32206         -    /* 169 */ "CursorHint"       OpHelp(""),
 32207         -    /* 170 */ "Noop"             OpHelp(""),
 32208         -    /* 171 */ "Explain"          OpHelp(""),
 32209         -    /* 172 */ "Abortable"        OpHelp(""),
        32161  +    /* 142 */ "SqlExec"          OpHelp(""),
        32162  +    /* 143 */ "ParseSchema"      OpHelp(""),
        32163  +    /* 144 */ "LoadAnalysis"     OpHelp(""),
        32164  +    /* 145 */ "DropTable"        OpHelp(""),
        32165  +    /* 146 */ "DropIndex"        OpHelp(""),
        32166  +    /* 147 */ "DropTrigger"      OpHelp(""),
        32167  +    /* 148 */ "IntegrityCk"      OpHelp(""),
        32168  +    /* 149 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
        32169  +    /* 150 */ "Param"            OpHelp(""),
        32170  +    /* 151 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
        32171  +    /* 152 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
        32172  +    /* 153 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
        32173  +    /* 154 */ "AggInverse"       OpHelp("accum=r[P3] inverse(r[P2@P5])"),
        32174  +    /* 155 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
        32175  +    /* 156 */ "AggStep1"         OpHelp("accum=r[P3] step(r[P2@P5])"),
        32176  +    /* 157 */ "AggValue"         OpHelp("r[P3]=value N=P2"),
        32177  +    /* 158 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
        32178  +    /* 159 */ "Expire"           OpHelp(""),
        32179  +    /* 160 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
        32180  +    /* 161 */ "VBegin"           OpHelp(""),
        32181  +    /* 162 */ "VCreate"          OpHelp(""),
        32182  +    /* 163 */ "VDestroy"         OpHelp(""),
        32183  +    /* 164 */ "VOpen"            OpHelp(""),
        32184  +    /* 165 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
        32185  +    /* 166 */ "VRename"          OpHelp(""),
        32186  +    /* 167 */ "Pagecount"        OpHelp(""),
        32187  +    /* 168 */ "MaxPgcnt"         OpHelp(""),
        32188  +    /* 169 */ "Trace"            OpHelp(""),
        32189  +    /* 170 */ "CursorHint"       OpHelp(""),
        32190  +    /* 171 */ "Noop"             OpHelp(""),
        32191  +    /* 172 */ "Explain"          OpHelp(""),
        32192  +    /* 173 */ "Abortable"        OpHelp(""),
 32210  32193     };
 32211  32194     return azName[i];
 32212  32195   }
 32213  32196   #endif
 32214  32197   
 32215  32198   /************** End of opcodes.c *********************************************/
 32216  32199   /************** Begin file os_unix.c *****************************************/
................................................................................
 51317  51300   **   * the database file is open,
 51318  51301   **   * there are no dirty pages in the cache, and
 51319  51302   **   * the desired page is not currently in the wal file.
 51320  51303   */
 51321  51304   SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
 51322  51305     if( pPager->fd->pMethods==0 ) return 0;
 51323  51306     if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
 51324         -#ifdef SQLITE_HAS_CODEC
 51325         -  if( pPager->xCodec!=0 ) return 0;
 51326         -#endif
 51327  51307   #ifndef SQLITE_OMIT_WAL
 51328  51308     if( pPager->pWal ){
 51329  51309       u32 iRead = 0;
 51330  51310       int rc;
 51331  51311       rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
 51332  51312       return (rc==SQLITE_OK && iRead==0);
 51333  51313     }
................................................................................
 54269  54249       char *pNew = NULL;             /* New temp space */
 54270  54250       i64 nByte = 0;
 54271  54251   
 54272  54252       if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
 54273  54253         rc = sqlite3OsFileSize(pPager->fd, &nByte);
 54274  54254       }
 54275  54255       if( rc==SQLITE_OK ){
 54276         -      /* 8 bytes of zeroed overrun space is sufficient so that the b-tree
 54277         -      * cell header parser will never run off the end of the allocation */
 54278         -      pNew = (char *)sqlite3PageMalloc(pageSize+8);
 54279         -      if( !pNew ){
 54280         -        rc = SQLITE_NOMEM_BKPT;
 54281         -      }else{
 54282         -        memset(pNew+pageSize, 0, 8);
 54283         -      }
        54256  +      pNew = (char *)sqlite3PageMalloc(pageSize);
        54257  +      if( !pNew ) rc = SQLITE_NOMEM_BKPT;
 54284  54258       }
 54285  54259   
 54286  54260       if( rc==SQLITE_OK ){
 54287  54261         pager_reset(pPager);
 54288  54262         rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
 54289  54263       }
 54290  54264       if( rc==SQLITE_OK ){
................................................................................
 57657  57631     /* If the cache contains a page with page-number pgno, remove it
 57658  57632     ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for 
 57659  57633     ** page pgno before the 'move' operation, it needs to be retained 
 57660  57634     ** for the page moved there.
 57661  57635     */
 57662  57636     pPg->flags &= ~PGHDR_NEED_SYNC;
 57663  57637     pPgOld = sqlite3PagerLookup(pPager, pgno);
 57664         -  assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
        57638  +  assert( !pPgOld || pPgOld->nRef==1 );
 57665  57639     if( pPgOld ){
 57666         -    if( pPgOld->nRef>1 ){
 57667         -      sqlite3PagerUnrefNotNull(pPgOld);
 57668         -      return SQLITE_CORRUPT_BKPT;
 57669         -    }
 57670  57640       pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
 57671  57641       if( pPager->tempFile ){
 57672  57642         /* Do not discard pages from an in-memory database since we might
 57673  57643         ** need to rollback later.  Just move the page out of the way. */
 57674  57644         sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
 57675  57645       }else{
 57676  57646         sqlite3PcacheDrop(pPgOld);
................................................................................
 58190  58160   
 58191  58161   /*
 58192  58162   ** Release a lock obtained by an earlier successful call to
 58193  58163   ** sqlite3PagerSnapshotCheck().
 58194  58164   */
 58195  58165   SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager){
 58196  58166     assert( pPager->pWal );
 58197         -  sqlite3WalSnapshotUnlock(pPager->pWal);
        58167  +  return sqlite3WalSnapshotUnlock(pPager->pWal);
 58198  58168   }
 58199  58169   
 58200  58170   #endif /* SQLITE_ENABLE_SNAPSHOT */
 58201  58171   #endif /* !SQLITE_OMIT_WAL */
 58202  58172   
 58203  58173   #ifdef SQLITE_ENABLE_ZIPVFS
 58204  58174   /*
................................................................................
 62366  62336     u8 hdrOffset;        /* 100 for page 1.  0 otherwise */
 62367  62337     u8 childPtrSize;     /* 0 if leaf==1.  4 if leaf==0 */
 62368  62338     u8 max1bytePayload;  /* min(maxLocal,127) */
 62369  62339     u8 nOverflow;        /* Number of overflow cell bodies in aCell[] */
 62370  62340     u16 maxLocal;        /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
 62371  62341     u16 minLocal;        /* Copy of BtShared.minLocal or BtShared.minLeaf */
 62372  62342     u16 cellOffset;      /* Index in aData of first cell pointer */
 62373         -  int nFree;           /* Number of free bytes on the page. -1 for unknown */
        62343  +  u16 nFree;           /* Number of free bytes on the page */
 62374  62344     u16 nCell;           /* Number of cells on this page, local and ovfl */
 62375  62345     u16 maskPage;        /* Mask for page offset */
 62376  62346     u16 aiOvfl[4];       /* Insert the i-th overflow cell before the aiOvfl-th
 62377  62347                          ** non-overflow cell */
 62378  62348     u8 *apOvfl[4];       /* Pointers to the body of overflow cells */
 62379  62349     BtShared *pBt;       /* Pointer to BtShared that this page is part of */
 62380  62350     u8 *aData;           /* Pointer to disk image of the page data */
................................................................................
 64508  64478     assert( pPage->nOverflow==0 );
 64509  64479     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 64510  64480     temp = 0;
 64511  64481     src = data = pPage->aData;
 64512  64482     hdr = pPage->hdrOffset;
 64513  64483     cellOffset = pPage->cellOffset;
 64514  64484     nCell = pPage->nCell;
 64515         -  assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
        64485  +  assert( nCell==get2byte(&data[hdr+3]) );
 64516  64486     iCellFirst = cellOffset + 2*nCell;
 64517  64487     usableSize = pPage->pBt->usableSize;
 64518  64488   
 64519  64489     /* This block handles pages with two or fewer free blocks and nMaxFrag
 64520  64490     ** or fewer fragmented bytes. In this case it is faster to move the
 64521  64491     ** two (or one) blocks of cells using memmove() and add the required
 64522  64492     ** offsets to each pointer in the cell-pointer array than it is to 
 64523  64493     ** reconstruct the entire page.  */
 64524  64494     if( (int)data[hdr+7]<=nMaxFrag ){
 64525  64495       int iFree = get2byte(&data[hdr+1]);
 64526  64496   
 64527         -    /* If the initial freeblock offset were out of bounds, that would have
 64528         -    ** been detected by btreeComputeFreeSpace() when it was computing the
        64497  +    /* If the initial freeblock offset were out of bounds, that would
        64498  +    ** have been detected by btreeInitPage() when it was computing the
 64529  64499       ** number of free bytes on the page. */
 64530  64500       assert( iFree<=usableSize-4 );
 64531  64501       if( iFree ){
 64532  64502         int iFree2 = get2byte(&data[iFree]);
 64533  64503         if( iFree2>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
 64534  64504         if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
 64535  64505           u8 *pEnd = &data[cellOffset + nCell*2];
................................................................................
 64593  64563         src = temp;
 64594  64564       }
 64595  64565       memcpy(&data[cbrk], &src[pc], size);
 64596  64566     }
 64597  64567     data[hdr+7] = 0;
 64598  64568   
 64599  64569    defragment_out:
 64600         -  assert( pPage->nFree>=0 );
 64601  64570     if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
 64602  64571       return SQLITE_CORRUPT_PAGE(pPage);
 64603  64572     }
 64604  64573     assert( cbrk>=iCellFirst );
 64605  64574     put2byte(&data[hdr+5], cbrk);
 64606  64575     data[hdr+1] = 0;
 64607  64576     data[hdr+2] = 0;
................................................................................
 64621  64590   ** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
 64622  64591   **
 64623  64592   ** Slots on the free list that are between 1 and 3 bytes larger than nByte
 64624  64593   ** will be ignored if adding the extra space to the fragmentation count
 64625  64594   ** causes the fragmentation count to exceed 60.
 64626  64595   */
 64627  64596   static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
 64628         -  const int hdr = pPg->hdrOffset;            /* Offset to page header */
 64629         -  u8 * const aData = pPg->aData;             /* Page data */
 64630         -  int iAddr = hdr + 1;                       /* Address of ptr to pc */
 64631         -  int pc = get2byte(&aData[iAddr]);          /* Address of a free slot */
 64632         -  int x;                                     /* Excess size of the slot */
 64633         -  int maxPC = pPg->pBt->usableSize - nByte;  /* Max address for a usable slot */
 64634         -  int size;                                  /* Size of the free slot */
        64597  +  const int hdr = pPg->hdrOffset;
        64598  +  u8 * const aData = pPg->aData;
        64599  +  int iAddr = hdr + 1;
        64600  +  int pc = get2byte(&aData[iAddr]);
        64601  +  int x;
        64602  +  int usableSize = pPg->pBt->usableSize;
        64603  +  int size;            /* Size of the free slot */
 64635  64604   
 64636  64605     assert( pc>0 );
 64637         -  while( pc<=maxPC ){
        64606  +  while( pc<=usableSize-4 ){
 64638  64607       /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
 64639  64608       ** freeblock form a big-endian integer which is the size of the freeblock
 64640  64609       ** in bytes, including the 4-byte header. */
 64641  64610       size = get2byte(&aData[pc+2]);
 64642  64611       if( (x = size - nByte)>=0 ){
 64643  64612         testcase( x==4 );
 64644  64613         testcase( x==3 );
 64645         -      if( x<4 ){
        64614  +      if( size+pc > usableSize ){
        64615  +        *pRc = SQLITE_CORRUPT_PAGE(pPg);
        64616  +        return 0;
        64617  +      }else if( x<4 ){
 64646  64618           /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
 64647  64619           ** number of bytes in fragments may not exceed 60. */
 64648  64620           if( aData[hdr+7]>57 ) return 0;
 64649  64621   
 64650  64622           /* Remove the slot from the free-list. Update the number of
 64651  64623           ** fragmented bytes within the page. */
 64652  64624           memcpy(&aData[iAddr], &aData[pc], 2);
 64653  64625           aData[hdr+7] += (u8)x;
 64654         -      }else if( x+pc > maxPC ){
 64655         -        /* This slot extends off the end of the usable part of the page */
 64656         -        *pRc = SQLITE_CORRUPT_PAGE(pPg);
 64657         -        return 0;
 64658  64626         }else{
 64659  64627           /* The slot remains on the free-list. Reduce its size to account
 64660         -        ** for the portion used by the new allocation. */
        64628  +         ** for the portion used by the new allocation. */
 64661  64629           put2byte(&aData[pc+2], x);
 64662  64630         }
 64663  64631         return &aData[pc + x];
 64664  64632       }
 64665  64633       iAddr = pc;
 64666  64634       pc = get2byte(&aData[pc]);
 64667         -    if( pc<=iAddr+size ){
 64668         -      if( pc ){
 64669         -        /* The next slot in the chain is not past the end of the current slot */
 64670         -        *pRc = SQLITE_CORRUPT_PAGE(pPg);
 64671         -      }
 64672         -      return 0;
 64673         -    }
        64635  +    if( pc<iAddr+size ) break;
 64674  64636     }
 64675         -  if( pc>maxPC+nByte-4 ){
 64676         -    /* The free slot chain extends off the end of the page */
        64637  +  if( pc ){
 64677  64638       *pRc = SQLITE_CORRUPT_PAGE(pPg);
 64678  64639     }
        64640  +
 64679  64641     return 0;
 64680  64642   }
 64681  64643   
 64682  64644   /*
 64683  64645   ** Allocate nByte bytes of space from within the B-Tree page passed
 64684  64646   ** as the first argument. Write into *pIdx the index into pPage->aData[]
 64685  64647   ** of the first byte of allocated space. Return either SQLITE_OK or
................................................................................
 64721  64683       if( top==0 && pPage->pBt->usableSize==65536 ){
 64722  64684         top = 65536;
 64723  64685       }else{
 64724  64686         return SQLITE_CORRUPT_PAGE(pPage);
 64725  64687       }
 64726  64688     }
 64727  64689   
 64728         -  /* If there is enough space between gap and top for one more cell pointer,
 64729         -  ** and if the freelist is not empty, then search the
 64730         -  ** freelist looking for a slot big enough to satisfy the request.
        64690  +  /* If there is enough space between gap and top for one more cell pointer
        64691  +  ** array entry offset, and if the freelist is not empty, then search the
        64692  +  ** freelist looking for a free slot big enough to satisfy the request.
 64731  64693     */
 64732  64694     testcase( gap+2==top );
 64733  64695     testcase( gap+1==top );
 64734  64696     testcase( gap==top );
 64735  64697     if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
 64736  64698       u8 *pSpace = pageFindSlot(pPage, nByte, &rc);
 64737  64699       if( pSpace ){
................................................................................
 64745  64707   
 64746  64708     /* The request could not be fulfilled using a freelist slot.  Check
 64747  64709     ** to see if defragmentation is necessary.
 64748  64710     */
 64749  64711     testcase( gap+2+nByte==top );
 64750  64712     if( gap+2+nByte>top ){
 64751  64713       assert( pPage->nCell>0 || CORRUPT_DB );
 64752         -    assert( pPage->nFree>=0 );
 64753  64714       rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
 64754  64715       if( rc ) return rc;
 64755  64716       top = get2byteNotZero(&data[hdr+5]);
 64756  64717       assert( gap+2+nByte<=top );
 64757  64718     }
 64758  64719   
 64759  64720   
 64760  64721     /* Allocate memory from the gap in between the cell pointer array
 64761         -  ** and the cell content area.  The btreeComputeFreeSpace() call has already
        64722  +  ** and the cell content area.  The btreeInitPage() call has already
 64762  64723     ** validated the freelist.  Given that the freelist is valid, there
 64763  64724     ** is no way that the allocation can extend off the end of the page.
 64764  64725     ** The assert() below verifies the previous sentence.
 64765  64726     */
 64766  64727     top -= nByte;
 64767  64728     put2byte(&data[hdr+5], top);
 64768  64729     assert( top+nByte <= (int)pPage->pBt->usableSize );
................................................................................
 64773  64734   /*
 64774  64735   ** Return a section of the pPage->aData to the freelist.
 64775  64736   ** The first byte of the new free block is pPage->aData[iStart]
 64776  64737   ** and the size of the block is iSize bytes.
 64777  64738   **
 64778  64739   ** Adjacent freeblocks are coalesced.
 64779  64740   **
 64780         -** Even though the freeblock list was checked by btreeComputeFreeSpace(),
        64741  +** Note that even though the freeblock list was checked by btreeInitPage(),
 64781  64742   ** that routine will not detect overlap between cells or freeblocks.  Nor
 64782  64743   ** does it detect cells or freeblocks that encrouch into the reserved bytes
 64783  64744   ** at the end of the page.  So do additional corruption checks inside this
 64784  64745   ** routine and return SQLITE_CORRUPT if any problems are found.
 64785  64746   */
 64786  64747   static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
 64787  64748     u16 iPtr;                             /* Address of ptr to next freeblock */
................................................................................
 64935  64896       return SQLITE_CORRUPT_PAGE(pPage);
 64936  64897     }
 64937  64898     pPage->max1bytePayload = pBt->max1bytePayload;
 64938  64899     return SQLITE_OK;
 64939  64900   }
 64940  64901   
 64941  64902   /*
 64942         -** Compute the amount of freespace on the page.  In other words, fill
 64943         -** in the pPage->nFree field.
        64903  +** Initialize the auxiliary information for a disk block.
        64904  +**
        64905  +** Return SQLITE_OK on success.  If we see that the page does
        64906  +** not contain a well-formed database page, then return 
        64907  +** SQLITE_CORRUPT.  Note that a return of SQLITE_OK does not
        64908  +** guarantee that the page is well-formed.  It only shows that
        64909  +** we failed to detect any corruption.
 64944  64910   */
 64945         -static int btreeComputeFreeSpace(MemPage *pPage){
        64911  +static int btreeInitPage(MemPage *pPage){
 64946  64912     int pc;            /* Address of a freeblock within pPage->aData[] */
 64947  64913     u8 hdr;            /* Offset to beginning of page header */
 64948  64914     u8 *data;          /* Equal to pPage->aData */
        64915  +  BtShared *pBt;        /* The main btree structure */
 64949  64916     int usableSize;    /* Amount of usable space on each page */
        64917  +  u16 cellOffset;    /* Offset from start of page to first cell pointer */
 64950  64918     int nFree;         /* Number of unused bytes on the page */
 64951  64919     int top;           /* First byte of the cell content area */
 64952  64920     int iCellFirst;    /* First allowable cell or freeblock offset */
 64953  64921     int iCellLast;     /* Last possible cell or freeblock offset */
 64954  64922   
 64955  64923     assert( pPage->pBt!=0 );
 64956  64924     assert( pPage->pBt->db!=0 );
 64957  64925     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 64958  64926     assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
 64959  64927     assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
 64960  64928     assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
 64961         -  assert( pPage->isInit==1 );
 64962         -  assert( pPage->nFree<0 );
        64929  +  assert( pPage->isInit==0 );
 64963  64930   
 64964         -  usableSize = pPage->pBt->usableSize;
        64931  +  pBt = pPage->pBt;
 64965  64932     hdr = pPage->hdrOffset;
 64966  64933     data = pPage->aData;
        64934  +  /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
        64935  +  ** the b-tree page type. */
        64936  +  if( decodeFlags(pPage, data[hdr]) ){
        64937  +    return SQLITE_CORRUPT_PAGE(pPage);
        64938  +  }
        64939  +  assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
        64940  +  pPage->maskPage = (u16)(pBt->pageSize - 1);
        64941  +  pPage->nOverflow = 0;
        64942  +  usableSize = pBt->usableSize;
        64943  +  pPage->cellOffset = cellOffset = hdr + 8 + pPage->childPtrSize;
        64944  +  pPage->aDataEnd = &data[usableSize];
        64945  +  pPage->aCellIdx = &data[cellOffset];
        64946  +  pPage->aDataOfst = &data[pPage->childPtrSize];
 64967  64947     /* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
 64968  64948     ** the start of the cell content area. A zero value for this integer is
 64969  64949     ** interpreted as 65536. */
 64970  64950     top = get2byteNotZero(&data[hdr+5]);
 64971         -  iCellFirst = hdr + 8 + pPage->childPtrSize + 2*pPage->nCell;
        64951  +  /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
        64952  +  ** number of cells on the page. */
        64953  +  pPage->nCell = get2byte(&data[hdr+3]);
        64954  +  if( pPage->nCell>MX_CELL(pBt) ){
        64955  +    /* To many cells for a single page.  The page must be corrupt */
        64956  +    return SQLITE_CORRUPT_PAGE(pPage);
        64957  +  }
        64958  +  testcase( pPage->nCell==MX_CELL(pBt) );
        64959  +  /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
        64960  +  ** possible for a root page of a table that contains no rows) then the
        64961  +  ** offset to the cell content area will equal the page size minus the
        64962  +  ** bytes of reserved space. */
        64963  +  assert( pPage->nCell>0 || top==usableSize || CORRUPT_DB );
        64964  +
        64965  +  /* A malformed database page might cause us to read past the end
        64966  +  ** of page when parsing a cell.  
        64967  +  **
        64968  +  ** The following block of code checks early to see if a cell extends
        64969  +  ** past the end of a page boundary and causes SQLITE_CORRUPT to be 
        64970  +  ** returned if it does.
        64971  +  */
        64972  +  iCellFirst = cellOffset + 2*pPage->nCell;
 64972  64973     iCellLast = usableSize - 4;
        64974  +  if( pBt->db->flags & SQLITE_CellSizeCk ){
        64975  +    int i;            /* Index into the cell pointer array */
        64976  +    int sz;           /* Size of a cell */
        64977  +
        64978  +    if( !pPage->leaf ) iCellLast--;
        64979  +    for(i=0; i<pPage->nCell; i++){
        64980  +      pc = get2byteAligned(&data[cellOffset+i*2]);
        64981  +      testcase( pc==iCellFirst );
        64982  +      testcase( pc==iCellLast );
        64983  +      if( pc<iCellFirst || pc>iCellLast ){
        64984  +        return SQLITE_CORRUPT_PAGE(pPage);
        64985  +      }
        64986  +      sz = pPage->xCellSize(pPage, &data[pc]);
        64987  +      testcase( pc+sz==usableSize );
        64988  +      if( pc+sz>usableSize ){
        64989  +        return SQLITE_CORRUPT_PAGE(pPage);
        64990  +      }
        64991  +    }
        64992  +    if( !pPage->leaf ) iCellLast++;
        64993  +  }  
 64973  64994   
 64974  64995     /* Compute the total free space on the page
 64975  64996     ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
 64976  64997     ** start of the first freeblock on the page, or is zero if there are no
 64977  64998     ** freeblocks. */
 64978  64999     pc = get2byte(&data[hdr+1]);
 64979  65000     nFree = data[hdr+7] + top;  /* Init nFree to non-freeblock free space */
................................................................................
 65013  65034     ** serves to verify that the offset to the start of the cell-content
 65014  65035     ** area, according to the page header, lies within the page.
 65015  65036     */
 65016  65037     if( nFree>usableSize ){
 65017  65038       return SQLITE_CORRUPT_PAGE(pPage);
 65018  65039     }
 65019  65040     pPage->nFree = (u16)(nFree - iCellFirst);
 65020         -  return SQLITE_OK;
 65021         -}
 65022         -
 65023         -/*
 65024         -** Do additional sanity check after btreeInitPage() if
 65025         -** PRAGMA cell_size_check=ON 
 65026         -*/
 65027         -static SQLITE_NOINLINE int btreeCellSizeCheck(MemPage *pPage){
 65028         -  int iCellFirst;    /* First allowable cell or freeblock offset */
 65029         -  int iCellLast;     /* Last possible cell or freeblock offset */
 65030         -  int i;             /* Index into the cell pointer array */
 65031         -  int sz;            /* Size of a cell */
 65032         -  int pc;            /* Address of a freeblock within pPage->aData[] */
 65033         -  u8 *data;          /* Equal to pPage->aData */
 65034         -  int usableSize;    /* Maximum usable space on the page */
 65035         -  int cellOffset;    /* Start of cell content area */
 65036         -
 65037         -  iCellFirst = pPage->cellOffset + 2*pPage->nCell;
 65038         -  usableSize = pPage->pBt->usableSize;
 65039         -  iCellLast = usableSize - 4;
 65040         -  data = pPage->aData;
 65041         -  cellOffset = pPage->cellOffset;
 65042         -  if( !pPage->leaf ) iCellLast--;
 65043         -  for(i=0; i<pPage->nCell; i++){
 65044         -    pc = get2byteAligned(&data[cellOffset+i*2]);
 65045         -    testcase( pc==iCellFirst );
 65046         -    testcase( pc==iCellLast );
 65047         -    if( pc<iCellFirst || pc>iCellLast ){
 65048         -      return SQLITE_CORRUPT_PAGE(pPage);
 65049         -    }
 65050         -    sz = pPage->xCellSize(pPage, &data[pc]);
 65051         -    testcase( pc+sz==usableSize );
 65052         -    if( pc+sz>usableSize ){
 65053         -      return SQLITE_CORRUPT_PAGE(pPage);
 65054         -    }
 65055         -  }
 65056         -  return SQLITE_OK;
 65057         -}
 65058         -
 65059         -/*
 65060         -** Initialize the auxiliary information for a disk block.
 65061         -**
 65062         -** Return SQLITE_OK on success.  If we see that the page does
 65063         -** not contain a well-formed database page, then return 
 65064         -** SQLITE_CORRUPT.  Note that a return of SQLITE_OK does not
 65065         -** guarantee that the page is well-formed.  It only shows that
 65066         -** we failed to detect any corruption.
 65067         -*/
 65068         -static int btreeInitPage(MemPage *pPage){
 65069         -  u8 *data;          /* Equal to pPage->aData */
 65070         -  BtShared *pBt;        /* The main btree structure */
 65071         -
 65072         -  assert( pPage->pBt!=0 );
 65073         -  assert( pPage->pBt->db!=0 );
 65074         -  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 65075         -  assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
 65076         -  assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
 65077         -  assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
 65078         -  assert( pPage->isInit==0 );
 65079         -
 65080         -  pBt = pPage->pBt;
 65081         -  data = pPage->aData + pPage->hdrOffset;
 65082         -  /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
 65083         -  ** the b-tree page type. */
 65084         -  if( decodeFlags(pPage, data[0]) ){
 65085         -    return SQLITE_CORRUPT_PAGE(pPage);
 65086         -  }
 65087         -  assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
 65088         -  pPage->maskPage = (u16)(pBt->pageSize - 1);
 65089         -  pPage->nOverflow = 0;
 65090         -  pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize;
 65091         -  pPage->aCellIdx = data + pPage->childPtrSize + 8;
 65092         -  pPage->aDataEnd = pPage->aData + pBt->usableSize;
 65093         -  pPage->aDataOfst = pPage->aData + pPage->childPtrSize;
 65094         -  /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
 65095         -  ** number of cells on the page. */
 65096         -  pPage->nCell = get2byte(&data[3]);
 65097         -  if( pPage->nCell>MX_CELL(pBt) ){
 65098         -    /* To many cells for a single page.  The page must be corrupt */
 65099         -    return SQLITE_CORRUPT_PAGE(pPage);
 65100         -  }
 65101         -  testcase( pPage->nCell==MX_CELL(pBt) );
 65102         -  /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
 65103         -  ** possible for a root page of a table that contains no rows) then the
 65104         -  ** offset to the cell content area will equal the page size minus the
 65105         -  ** bytes of reserved space. */
 65106         -  assert( pPage->nCell>0
 65107         -       || get2byteNotZero(&data[5])==pBt->usableSize
 65108         -       || CORRUPT_DB );
 65109         -  pPage->nFree = -1;  /* Indicate that this value is yet uncomputed */
 65110  65041     pPage->isInit = 1;
 65111         -  if( pBt->db->flags & SQLITE_CellSizeCk ){
 65112         -    return btreeCellSizeCheck(pPage);
 65113         -  }
 65114  65042     return SQLITE_OK;
 65115  65043   }
 65116  65044   
 65117  65045   /*
 65118  65046   ** Set up a raw page so that it looks like a database page holding
 65119  65047   ** no entries.
 65120  65048   */
................................................................................
 65249  65177     assert( sqlite3_mutex_held(pBt->mutex) );
 65250  65178     assert( pCur==0 || ppPage==&pCur->pPage );
 65251  65179     assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
 65252  65180     assert( pCur==0 || pCur->iPage>0 );
 65253  65181   
 65254  65182     if( pgno>btreePagecount(pBt) ){
 65255  65183       rc = SQLITE_CORRUPT_BKPT;
 65256         -    goto getAndInitPage_error1;
        65184  +    goto getAndInitPage_error;
 65257  65185     }
 65258  65186     rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
 65259  65187     if( rc ){
 65260         -    goto getAndInitPage_error1;
        65188  +    goto getAndInitPage_error;
 65261  65189     }
 65262  65190     *ppPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
 65263  65191     if( (*ppPage)->isInit==0 ){
 65264  65192       btreePageFromDbPage(pDbPage, pgno, pBt);
 65265  65193       rc = btreeInitPage(*ppPage);
 65266  65194       if( rc!=SQLITE_OK ){
 65267         -      goto getAndInitPage_error2;
        65195  +      releasePage(*ppPage);
        65196  +      goto getAndInitPage_error;
 65268  65197       }
 65269  65198     }
 65270  65199     assert( (*ppPage)->pgno==pgno );
 65271  65200     assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
 65272  65201   
 65273  65202     /* If obtaining a child page for a cursor, we must verify that the page is
 65274  65203     ** compatible with the root page. */
 65275  65204     if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){
 65276  65205       rc = SQLITE_CORRUPT_PGNO(pgno);
 65277         -    goto getAndInitPage_error2;
        65206  +    releasePage(*ppPage);
        65207  +    goto getAndInitPage_error;
 65278  65208     }
 65279  65209     return SQLITE_OK;
 65280  65210   
 65281         -getAndInitPage_error2:
 65282         -  releasePage(*ppPage);
 65283         -getAndInitPage_error1:
        65211  +getAndInitPage_error:
 65284  65212     if( pCur ){
 65285  65213       pCur->iPage--;
 65286  65214       pCur->pPage = pCur->apPage[pCur->iPage];
 65287  65215     }
 65288  65216     testcase( pgno==0 );
 65289  65217     assert( pgno!=0 || rc==SQLITE_CORRUPT );
 65290  65218     return rc;
................................................................................
 68639  68567             pCur->ix = (u16)idx;
 68640  68568             rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
 68641  68569             pCur->curFlags &= ~BTCF_ValidOvfl;
 68642  68570             if( rc ){
 68643  68571               sqlite3_free(pCellKey);
 68644  68572               goto moveto_finish;
 68645  68573             }
 68646         -          c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
        68574  +          c = xRecordCompare(nCell, pCellKey, pIdxKey);
 68647  68575             sqlite3_free(pCellKey);
 68648  68576           }
 68649  68577           assert( 
 68650  68578               (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
 68651  68579            && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
 68652  68580           );
 68653  68581           if( c<0 ){
................................................................................
 69688  69616     int hdr;        /* Beginning of the header.  0 most pages.  100 page 1 */
 69689  69617   
 69690  69618     if( *pRC ) return;
 69691  69619     assert( idx>=0 && idx<pPage->nCell );
 69692  69620     assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
 69693  69621     assert( sqlite3PagerIswriteable(pPage->pDbPage) );
 69694  69622     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 69695         -  assert( pPage->nFree>=0 );
 69696  69623     data = pPage->aData;
 69697  69624     ptr = &pPage->aCellIdx[2*idx];
 69698  69625     pc = get2byte(ptr);
 69699  69626     hdr = pPage->hdrOffset;
 69700  69627     testcase( pc==get2byte(&data[hdr+5]) );
 69701  69628     testcase( pc+sz==pPage->pBt->usableSize );
 69702  69629     if( pc+sz > pPage->pBt->usableSize ){
................................................................................
 69759  69686     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 69760  69687     /* The cell should normally be sized correctly.  However, when moving a
 69761  69688     ** malformed cell from a leaf page to an interior page, if the cell size
 69762  69689     ** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
 69763  69690     ** might be less than 8 (leaf-size + pointer) on the interior node.  Hence
 69764  69691     ** the term after the || in the following assert(). */
 69765  69692     assert( sz==pPage->xCellSize(pPage, pCell) || (sz==8 && iChild>0) );
 69766         -  assert( pPage->nFree>=0 );
 69767  69693     if( pPage->nOverflow || sz+2>pPage->nFree ){
 69768  69694       if( pTemp ){
 69769  69695         memcpy(pTemp, pCell, sz);
 69770  69696         pCell = pTemp;
 69771  69697       }
 69772  69698       if( iChild ){
 69773  69699         put4byte(pCell, iChild);
................................................................................
 69817  69743       }
 69818  69744       pIns = pPage->aCellIdx + i*2;
 69819  69745       memmove(pIns+2, pIns, 2*(pPage->nCell - i));
 69820  69746       put2byte(pIns, idx);
 69821  69747       pPage->nCell++;
 69822  69748       /* increment the cell count */
 69823  69749       if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
 69824         -    assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
        69750  +    assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell );
 69825  69751   #ifndef SQLITE_OMIT_AUTOVACUUM
 69826  69752       if( pPage->pBt->autoVacuum ){
 69827  69753         /* The cell may contain a pointer to an overflow page. If so, write
 69828  69754         ** the entry for the overflow page into the pointer map.
 69829  69755         */
 69830  69756         ptrmapPutOvflPtr(pPage, pPage, pCell, pRC);
 69831  69757       }
................................................................................
 69904  69830   **    ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
 69905  69831   **    ixNx[4] = Total number of cells.
 69906  69832   **
 69907  69833   ** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
 69908  69834   ** are used and they point to the leaf pages only, and the ixNx value are:
 69909  69835   **
 69910  69836   **    ixNx[0] = Number of cells in Child-1.
 69911         -**    ixNx[1] = Number of cells in Child-1 and Child-2.
 69912         -**    ixNx[2] = Total number of cells.
 69913         -**
 69914         -** Sometimes when deleting, a child page can have zero cells.  In those
 69915         -** cases, ixNx[] entries with higher indexes, and the corresponding apEnd[]
 69916         -** entries, shift down.  The end result is that each ixNx[] entry should
 69917         -** be larger than the previous
        69837  +**    ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
        69838  +**    ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells
 69918  69839   */
 69919  69840   typedef struct CellArray CellArray;
 69920  69841   struct CellArray {
 69921  69842     int nCell;              /* Number of cells in apCell[] */
 69922  69843     MemPage *pRef;          /* Reference page */
 69923  69844     u8 **apCell;            /* All cells begin balanced */
 69924  69845     u16 *szCell;            /* Local size of all cells in apCell[] */
................................................................................
 70239  70160     }
 70240  70161   
 70241  70162     /* Add any overflow cells */
 70242  70163     for(i=0; i<pPg->nOverflow; i++){
 70243  70164       int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
 70244  70165       if( iCell>=0 && iCell<nNew ){
 70245  70166         pCellptr = &pPg->aCellIdx[iCell * 2];
 70246         -      if( nCell>iCell ){
 70247         -        memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
 70248         -      }
        70167  +      assert( nCell>=iCell );
        70168  +      memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
 70249  70169         nCell++;
 70250  70170         if( pageInsertArray(
 70251  70171               pPg, pBegin, &pData, pCellptr,
 70252  70172               iCell+iNew, 1, pCArray
 70253  70173         ) ) goto editpage_fail;
 70254  70174       }
 70255  70175     }
................................................................................
 70317  70237     MemPage *pNew;                       /* Newly allocated page */
 70318  70238     int rc;                              /* Return Code */
 70319  70239     Pgno pgnoNew;                        /* Page number of pNew */
 70320  70240   
 70321  70241     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 70322  70242     assert( sqlite3PagerIswriteable(pParent->pDbPage) );
 70323  70243     assert( pPage->nOverflow==1 );
 70324         -  
        70244  +
 70325  70245     if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT;  /* dbfuzz001.test */
 70326         -  assert( pPage->nFree>=0 );
 70327         -  assert( pParent->nFree>=0 );
 70328  70246   
 70329  70247     /* Allocate a new page. This page will become the right-sibling of 
 70330  70248     ** pPage. Make the parent page writable, so that the new divider cell
 70331  70249     ** may be inserted. If both these operations are successful, proceed.
 70332  70250     */
 70333  70251     rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
 70334  70252   
................................................................................
 70490  70408       /* Reinitialize page pTo so that the contents of the MemPage structure
 70491  70409       ** match the new data. The initialization of pTo can actually fail under
 70492  70410       ** fairly obscure circumstances, even though it is a copy of initialized 
 70493  70411       ** page pFrom.
 70494  70412       */
 70495  70413       pTo->isInit = 0;
 70496  70414       rc = btreeInitPage(pTo);
 70497         -    if( rc==SQLITE_OK ) rc = btreeComputeFreeSpace(pTo);
 70498  70415       if( rc!=SQLITE_OK ){
 70499  70416         *pRC = rc;
 70500  70417         return;
 70501  70418       }
 70502  70419     
 70503  70420       /* If this is an auto-vacuum database, update the pointer-map entries
 70504  70421       ** for any b-tree or overflow pages that pTo now contains the pointers to.
................................................................................
 70599  70516     */
 70600  70517     assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
 70601  70518     assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
 70602  70519   
 70603  70520     if( !aOvflSpace ){
 70604  70521       return SQLITE_NOMEM_BKPT;
 70605  70522     }
 70606         -  assert( pParent->nFree>=0 );
 70607  70523   
 70608  70524     /* Find the sibling pages to balance. Also locate the cells in pParent 
 70609  70525     ** that divide the siblings. An attempt is made to find NN siblings on 
 70610  70526     ** either side of pPage. More siblings are taken from one side, however, 
 70611  70527     ** if there are fewer than NN siblings on the other side. If pParent
 70612  70528     ** has NB or fewer children then all children of pParent are taken.  
 70613  70529     **
................................................................................
 70639  70555     pgno = get4byte(pRight);
 70640  70556     while( 1 ){
 70641  70557       rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
 70642  70558       if( rc ){
 70643  70559         memset(apOld, 0, (i+1)*sizeof(MemPage*));
 70644  70560         goto balance_cleanup;
 70645  70561       }
 70646         -    if( apOld[i]->nFree<0 ){
 70647         -      rc = btreeComputeFreeSpace(apOld[i]);
 70648         -      if( rc ){
 70649         -        memset(apOld, 0, (i)*sizeof(MemPage*));
 70650         -        goto balance_cleanup;
 70651         -      }
 70652         -    }
 70653  70562       nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
 70654  70563       if( (i--)==0 ) break;
 70655  70564   
 70656  70565       if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
 70657  70566         apDiv[i] = pParent->apOvfl[0];
 70658  70567         pgno = get4byte(apDiv[i]);
 70659  70568         szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
................................................................................
 70840  70749     ** 
 70841  70750     */
 70842  70751     usableSpace = pBt->usableSize - 12 + leafCorrection;
 70843  70752     for(i=k=0; i<nOld; i++, k++){
 70844  70753       MemPage *p = apOld[i];
 70845  70754       b.apEnd[k] = p->aDataEnd;
 70846  70755       b.ixNx[k] = cntOld[i];
 70847         -    if( k && b.ixNx[k]==b.ixNx[k-1] ){
 70848         -      k--;  /* Omit b.ixNx[] entry for child pages with no cells */
 70849         -    }
 70850  70756       if( !leafData ){
 70851  70757         k++;
 70852  70758         b.apEnd[k] = pParent->aDataEnd;
 70853  70759         b.ixNx[k] = cntOld[i]+1;
 70854  70760       }
 70855         -    assert( p->nFree>=0 );
 70856  70761       szNew[i] = usableSpace - p->nFree;
 70857  70762       for(j=0; j<p->nOverflow; j++){
 70858  70763         szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
 70859  70764       }
 70860  70765       cntNew[i] = cntOld[i];
 70861  70766     }
 70862  70767     k = nOld;
................................................................................
 71074  70979     ** associated with the right-child of each sibling may also need to be 
 71075  70980     ** updated. This happens below, after the sibling pages have been 
 71076  70981     ** populated, not here.
 71077  70982     */
 71078  70983     if( ISAUTOVACUUM ){
 71079  70984       MemPage *pOld;
 71080  70985       MemPage *pNew = pOld = apNew[0];
        70986  +    u8 *aOld = pNew->aData;
 71081  70987       int cntOldNext = pNew->nCell + pNew->nOverflow;
        70988  +    int usableSize = pBt->usableSize;
 71082  70989       int iNew = 0;
 71083  70990       int iOld = 0;
 71084  70991   
 71085  70992       for(i=0; i<b.nCell; i++){
 71086  70993         u8 *pCell = b.apCell[i];
 71087         -      while( i==cntOldNext ){
 71088         -        iOld++;
 71089         -        assert( iOld<nNew || iOld<nOld );
 71090         -        pOld = iOld<nNew ? apNew[iOld] : apOld[iOld];
        70994  +      if( i==cntOldNext ){
        70995  +        pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld];
 71091  70996           cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
        70997  +        aOld = pOld->aData;
 71092  70998         }
 71093  70999         if( i==cntNew[iNew] ){
 71094  71000           pNew = apNew[++iNew];
 71095  71001           if( !leafData ) continue;
 71096  71002         }
 71097  71003   
 71098  71004         /* Cell pCell is destined for new sibling page pNew. Originally, it
................................................................................
 71099  71005         ** was either part of sibling page iOld (possibly an overflow cell), 
 71100  71006         ** or else the divider cell to the left of sibling page iOld. So,
 71101  71007         ** if sibling page iOld had the same page number as pNew, and if
 71102  71008         ** pCell really was a part of sibling page iOld (not a divider or
 71103  71009         ** overflow cell), we can skip updating the pointer map entries.  */
 71104  71010         if( iOld>=nNew
 71105  71011          || pNew->pgno!=aPgno[iOld]
 71106         -       || !SQLITE_WITHIN(pCell,pOld->aData,pOld->aDataEnd)
        71012  +       || !SQLITE_WITHIN(pCell,aOld,&aOld[usableSize])
 71107  71013         ){
 71108  71014           if( !leafCorrection ){
 71109  71015             ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
 71110  71016           }
 71111  71017           if( cachedCellSize(&b,i)>pNew->minLocal ){
 71112  71018             ptrmapPutOvflPtr(pNew, pOld, pCell, &rc);
 71113  71019           }
................................................................................
 71349  71255     if( rc ){
 71350  71256       *ppChild = 0;
 71351  71257       releasePage(pChild);
 71352  71258       return rc;
 71353  71259     }
 71354  71260     assert( sqlite3PagerIswriteable(pChild->pDbPage) );
 71355  71261     assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
 71356         -  assert( pChild->nCell==pRoot->nCell || CORRUPT_DB );
        71262  +  assert( pChild->nCell==pRoot->nCell );
 71357  71263   
 71358  71264     TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));
 71359  71265   
 71360  71266     /* Copy the overflow cells from pRoot to pChild */
 71361  71267     memcpy(pChild->aiOvfl, pRoot->aiOvfl,
 71362  71268            pRoot->nOverflow*sizeof(pRoot->aiOvfl[0]));
 71363  71269     memcpy(pChild->apOvfl, pRoot->apOvfl,
................................................................................
 71391  71297     VVA_ONLY( int balance_quick_called = 0 );
 71392  71298     VVA_ONLY( int balance_deeper_called = 0 );
 71393  71299   
 71394  71300     do {
 71395  71301       int iPage = pCur->iPage;
 71396  71302       MemPage *pPage = pCur->pPage;
 71397  71303   
 71398         -    if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
 71399  71304       if( iPage==0 ){
 71400  71305         if( pPage->nOverflow ){
 71401  71306           /* The root page of the b-tree is overfull. In this case call the
 71402  71307           ** balance_deeper() function to create a new child for the root-page
 71403  71308           ** and copy the current contents of the root-page to it. The
 71404  71309           ** next iteration of the do-loop will balance the child page.
 71405  71310           */ 
................................................................................
 71420  71325       }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
 71421  71326         break;
 71422  71327       }else{
 71423  71328         MemPage * const pParent = pCur->apPage[iPage-1];
 71424  71329         int const iIdx = pCur->aiIdx[iPage-1];
 71425  71330   
 71426  71331         rc = sqlite3PagerWrite(pParent->pDbPage);
 71427         -      if( rc==SQLITE_OK && pParent->nFree<0 ){
 71428         -        rc = btreeComputeFreeSpace(pParent);
 71429         -      }
 71430  71332         if( rc==SQLITE_OK ){
 71431  71333   #ifndef SQLITE_OMIT_QUICKBALANCE
 71432  71334           if( pPage->intKeyLeaf
 71433  71335            && pPage->nOverflow==1
 71434  71336            && pPage->aiOvfl[0]==pPage->nCell
 71435  71337            && pParent->pgno!=1
 71436  71338            && pParent->nCell==iIdx
................................................................................
 71769  71671   
 71770  71672     }
 71771  71673     assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
 71772  71674   
 71773  71675     pPage = pCur->pPage;
 71774  71676     assert( pPage->intKey || pX->nKey>=0 );
 71775  71677     assert( pPage->leaf || !pPage->intKey );
 71776         -  if( pPage->nFree<0 ){
 71777         -    rc = btreeComputeFreeSpace(pPage);
 71778         -    if( rc ) return rc;
 71779         -  }
 71780  71678   
 71781  71679     TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
 71782  71680             pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
 71783  71681             loc==0 ? "overwrite" : "new entry"));
 71784  71682     assert( pPage->isInit );
 71785  71683     newCell = pBt->pTmpSpace;
 71786  71684     assert( newCell!=0 );
................................................................................
 71923  71821     assert( pCur->eState==CURSOR_VALID );
 71924  71822     assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
 71925  71823   
 71926  71824     iCellDepth = pCur->iPage;
 71927  71825     iCellIdx = pCur->ix;
 71928  71826     pPage = pCur->pPage;
 71929  71827     pCell = findCell(pPage, iCellIdx);
 71930         -  if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;
 71931  71828   
 71932  71829     /* If the bPreserve flag is set to true, then the cursor position must
 71933  71830     ** be preserved following this delete operation. If the current delete
 71934  71831     ** will cause a b-tree rebalance, then this is done by saving the cursor
 71935  71832     ** key and leaving the cursor in CURSOR_REQUIRESEEK state before 
 71936  71833     ** returning. 
 71937  71834     **
................................................................................
 71994  71891     ** node to replace the deleted cell.  */
 71995  71892     if( !pPage->leaf ){
 71996  71893       MemPage *pLeaf = pCur->pPage;
 71997  71894       int nCell;
 71998  71895       Pgno n;
 71999  71896       unsigned char *pTmp;
 72000  71897   
 72001         -    if( pLeaf->nFree<0 ){
 72002         -      rc = btreeComputeFreeSpace(pLeaf);
 72003         -      if( rc ) return rc;
 72004         -    }
 72005  71898       if( iCellDepth<pCur->iPage-1 ){
 72006  71899         n = pCur->apPage[iCellDepth+1]->pgno;
 72007  71900       }else{
 72008  71901         n = pCur->pPage->pgno;
 72009  71902       }
 72010  71903       pCell = findCell(pLeaf, pLeaf->nCell-1);
 72011  71904       if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
................................................................................
 72356  72249     int rc;
 72357  72250     MemPage *pPage = 0;
 72358  72251     BtShared *pBt = p->pBt;
 72359  72252   
 72360  72253     assert( sqlite3BtreeHoldsMutex(p) );
 72361  72254     assert( p->inTrans==TRANS_WRITE );
 72362  72255     assert( iTable>=2 );
 72363         -  if( iTable>btreePagecount(pBt) ){
 72364         -    return SQLITE_CORRUPT_BKPT;
 72365         -  }
 72366  72256   
 72367  72257     rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
 72368  72258     if( rc ) return rc;
 72369  72259     rc = sqlite3BtreeClearTable(p, iTable, 0);
 72370  72260     if( rc ){
 72371  72261       releasePage(pPage);
 72372  72262       return rc;
................................................................................
 72707  72597   ** Check the integrity of the freelist or of an overflow page list.
 72708  72598   ** Verify that the number of pages on the list is N.
 72709  72599   */
 72710  72600   static void checkList(
 72711  72601     IntegrityCk *pCheck,  /* Integrity checking context */
 72712  72602     int isFreeList,       /* True for a freelist.  False for overflow page list */
 72713  72603     int iPage,            /* Page number for first page in the list */
 72714         -  u32 N                 /* Expected number of pages in the list */
        72604  +  int N                 /* Expected number of pages in the list */
 72715  72605   ){
 72716  72606     int i;
 72717         -  u32 expected = N;
        72607  +  int expected = N;
 72718  72608     int nErrAtStart = pCheck->nErr;
 72719  72609     while( iPage!=0 && pCheck->mxErr ){
 72720  72610       DbPage *pOvflPage;
 72721  72611       unsigned char *pOvflData;
 72722  72612       if( checkRef(pCheck, iPage) ) break;
 72723  72613       N--;
 72724  72614       if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){
................................................................................
 72892  72782     pPage->isInit = 0;
 72893  72783     if( (rc = btreeInitPage(pPage))!=0 ){
 72894  72784       assert( rc==SQLITE_CORRUPT );  /* The only possible error from InitPage */
 72895  72785       checkAppendMsg(pCheck,
 72896  72786                      "btreeInitPage() returns error code %d", rc);
 72897  72787       goto end_of_check;
 72898  72788     }
 72899         -  if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
 72900         -    assert( rc==SQLITE_CORRUPT );
 72901         -    checkAppendMsg(pCheck, "free space corruption", rc);
 72902         -    goto end_of_check;
 72903         -  }
 72904  72789     data = pPage->aData;
 72905  72790     hdr = pPage->hdrOffset;
 72906  72791   
 72907  72792     /* Set up for cell analysis */
 72908  72793     pCheck->zPfx = "On tree page %d cell %d: ";
 72909  72794     contentOffset = get2byteNotZero(&data[hdr+5]);
 72910  72795     assert( contentOffset<=usableSize );  /* Enforced by btreeInitPage() */
................................................................................
 72969  72854         }
 72970  72855         maxKey = info.nKey;
 72971  72856         keyCanBeEqual = 0;     /* Only the first key on the page may ==maxKey */
 72972  72857       }
 72973  72858   
 72974  72859       /* Check the content overflow list */
 72975  72860       if( info.nPayload>info.nLocal ){
 72976         -      u32 nPage;       /* Number of pages on the overflow chain */
        72861  +      int nPage;       /* Number of pages on the overflow chain */
 72977  72862         Pgno pgnoOvfl;   /* First page of the overflow chain */
 72978  72863         assert( pc + info.nSize - 4 <= usableSize );
 72979  72864         nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
 72980  72865         pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
 72981  72866   #ifndef SQLITE_OMIT_AUTOVACUUM
 72982  72867         if( pBt->autoVacuum ){
 72983  72868           checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage);
................................................................................
 73029  72914       ** EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
 73030  72915       ** is the offset of the first freeblock, or zero if there are no
 73031  72916       ** freeblocks on the page. 
 73032  72917       */
 73033  72918       i = get2byte(&data[hdr+1]);
 73034  72919       while( i>0 ){
 73035  72920         int size, j;
 73036         -      assert( (u32)i<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
        72921  +      assert( (u32)i<=usableSize-4 );     /* Enforced by btreeInitPage() */
 73037  72922         size = get2byte(&data[i+2]);
 73038         -      assert( (u32)(i+size)<=usableSize ); /* due to btreeComputeFreeSpace() */
        72923  +      assert( (u32)(i+size)<=usableSize );  /* Enforced by btreeInitPage() */
 73039  72924         btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
 73040  72925         /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
 73041  72926         ** big-endian integer which is the offset in the b-tree page of the next
 73042  72927         ** freeblock in the chain, or zero if the freeblock is the last on the
 73043  72928         ** chain. */
 73044  72929         j = get2byte(&data[i]);
 73045  72930         /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
 73046  72931         ** increasing offset. */
 73047         -      assert( j==0 || j>i+size );     /* Enforced by btreeComputeFreeSpace() */
 73048         -      assert( (u32)j<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
        72932  +      assert( j==0 || j>i+size );  /* Enforced by btreeInitPage() */
        72933  +      assert( (u32)j<=usableSize-4 );   /* Enforced by btreeInitPage() */
 73049  72934         i = j;
 73050  72935       }
 73051  72936       /* Analyze the min-heap looking for overlap between cells and/or 
 73052  72937       ** freeblocks, and counting the number of untracked bytes in nFrag.
 73053  72938       ** 
 73054  72939       ** Each min-heap entry is of the form:    (start_address<<16)|end_address.
 73055  72940       ** There is an implied first entry the covers the page header, the cell
................................................................................
 74506  74391     assert(rc==SQLITE_OK    || pMem->enc!=desiredEnc);
 74507  74392     assert(rc==SQLITE_NOMEM || pMem->enc==desiredEnc);
 74508  74393     return rc;
 74509  74394   #endif
 74510  74395   }
 74511  74396   
 74512  74397   /*
 74513         -** Make sure pMem->z points to a writable allocation of at least n bytes.
        74398  +** Make sure pMem->z points to a writable allocation of at least 
        74399  +** min(n,32) bytes.
 74514  74400   **
 74515  74401   ** If the bPreserve argument is true, then copy of the content of
 74516  74402   ** pMem->z into the new allocation.  pMem must be either a string or
 74517  74403   ** blob if bPreserve is true.  If bPreserve is false, any prior content
 74518  74404   ** in pMem->z is discarded.
 74519  74405   */
 74520  74406   SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
................................................................................
 74525  74411     /* If the bPreserve flag is set to true, then the memory cell must already
 74526  74412     ** contain a valid string or blob value.  */
 74527  74413     assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
 74528  74414     testcase( bPreserve && pMem->z==0 );
 74529  74415   
 74530  74416     assert( pMem->szMalloc==0
 74531  74417          || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
        74418  +  if( n<32 ) n = 32;
 74532  74419     if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
 74533  74420       pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
 74534  74421       bPreserve = 0;
 74535  74422     }else{
 74536  74423       if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
 74537  74424       pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
 74538  74425     }
................................................................................
 75373  75260       iLimit = SQLITE_MAX_LENGTH;
 75374  75261     }
 75375  75262     flags = (enc==0?MEM_Blob:MEM_Str);
 75376  75263     if( nByte<0 ){
 75377  75264       assert( enc!=0 );
 75378  75265       if( enc==SQLITE_UTF8 ){
 75379  75266         nByte = 0x7fffffff & (int)strlen(z);
        75267  +      if( nByte>iLimit ) nByte = iLimit+1;
 75380  75268       }else{
 75381  75269         for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
 75382  75270       }
 75383  75271       flags |= MEM_Term;
 75384  75272     }
 75385  75273   
 75386  75274     /* The following block sets the new values of Mem.z and Mem.xDel. It
 75387  75275     ** also sets a flag in local variable "flags" to indicate the memory
 75388  75276     ** management (one of MEM_Dyn or MEM_Static).
 75389  75277     */
 75390  75278     if( xDel==SQLITE_TRANSIENT ){
 75391         -    u32 nAlloc = nByte;
        75279  +    int nAlloc = nByte;
 75392  75280       if( flags&MEM_Term ){
 75393  75281         nAlloc += (enc==SQLITE_UTF8?1:2);
 75394  75282       }
 75395  75283       if( nByte>iLimit ){
 75396  75284         return SQLITE_TOOBIG;
 75397  75285       }
 75398  75286       testcase( nAlloc==0 );
 75399  75287       testcase( nAlloc==31 );
 75400  75288       testcase( nAlloc==32 );
 75401         -    if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
        75289  +    if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
 75402  75290         return SQLITE_NOMEM_BKPT;
 75403  75291       }
 75404  75292       memcpy(pMem->z, z, nAlloc);
        75293  +  }else if( xDel==SQLITE_DYNAMIC ){
        75294  +    sqlite3VdbeMemRelease(pMem);
        75295  +    pMem->zMalloc = pMem->z = (char *)z;
        75296  +    pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
 75405  75297     }else{
 75406  75298       sqlite3VdbeMemRelease(pMem);
 75407  75299       pMem->z = (char *)z;
 75408         -    if( xDel==SQLITE_DYNAMIC ){
 75409         -      pMem->zMalloc = pMem->z;
 75410         -      pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
 75411         -    }else{
 75412         -      pMem->xDel = xDel;
 75413         -      flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
 75414         -    }
        75300  +    pMem->xDel = xDel;
        75301  +    flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
 75415  75302     }
 75416  75303   
 75417  75304     pMem->n = nByte;
 75418  75305     pMem->flags = flags;
 75419  75306     pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
 75420  75307   
 75421  75308   #ifndef SQLITE_OMIT_UTF16
................................................................................
 76857  76744     memset(&sIter, 0, sizeof(sIter));
 76858  76745     sIter.v = v;
 76859  76746   
 76860  76747     while( (pOp = opIterNext(&sIter))!=0 ){
 76861  76748       int opcode = pOp->opcode;
 76862  76749       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
 76863  76750        || opcode==OP_VDestroy
 76864         -     || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
 76865  76751        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
 76866  76752         && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
 76867  76753       ){
 76868  76754         hasAbort = 1;
 76869  76755         break;
 76870  76756       }
 76871  76757       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
................................................................................
 82318  82204   **    3      The name of the table that the column derives from
 82319  82205   **    4      The name of the table column that the result column derives from
 82320  82206   **
 82321  82207   ** If the result is not a simple column reference (if it is an expression
 82322  82208   ** or a constant) then useTypes 2, 3, and 4 return NULL.
 82323  82209   */
 82324  82210   static const void *columnName(
 82325         -  sqlite3_stmt *pStmt,     /* The statement */
 82326         -  int N,                   /* Which column to get the name for */
 82327         -  int useUtf16,            /* True to return the name as UTF16 */
 82328         -  int useType              /* What type of name */
        82211  +  sqlite3_stmt *pStmt,
        82212  +  int N,
        82213  +  const void *(*xFunc)(Mem*),
        82214  +  int useType
 82329  82215   ){
 82330  82216     const void *ret;
 82331  82217     Vdbe *p;
 82332  82218     int n;
 82333  82219     sqlite3 *db;
 82334  82220   #ifdef SQLITE_ENABLE_API_ARMOR
 82335  82221     if( pStmt==0 ){
................................................................................
 82342  82228     db = p->db;
 82343  82229     assert( db!=0 );
 82344  82230     n = sqlite3_column_count(pStmt);
 82345  82231     if( N<n && N>=0 ){
 82346  82232       N += useType*n;
 82347  82233       sqlite3_mutex_enter(db->mutex);
 82348  82234       assert( db->mallocFailed==0 );
 82349         -#ifndef SQLITE_OMIT_UTF16
 82350         -    if( useUtf16 ){
 82351         -      ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
 82352         -    }else
 82353         -#endif
 82354         -    {
 82355         -      ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
 82356         -    }
 82357         -    /* A malloc may have failed inside of the _text() call. If this
        82235  +    ret = xFunc(&p->aColName[N]);
        82236  +     /* A malloc may have failed inside of the xFunc() call. If this
 82358  82237       ** is the case, clear the mallocFailed flag and return NULL.
 82359  82238       */
 82360  82239       if( db->mallocFailed ){
 82361  82240         sqlite3OomClear(db);
 82362  82241         ret = 0;
 82363  82242       }
 82364  82243       sqlite3_mutex_leave(db->mutex);
................................................................................
 82367  82246   }
 82368  82247   
 82369  82248   /*
 82370  82249   ** Return the name of the Nth column of the result set returned by SQL
 82371  82250   ** statement pStmt.
 82372  82251   */
 82373  82252   SQLITE_API const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
 82374         -  return columnName(pStmt, N, 0, COLNAME_NAME);
        82253  +  return columnName(
        82254  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
 82375  82255   }
 82376  82256   #ifndef SQLITE_OMIT_UTF16
 82377  82257   SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
 82378         -  return columnName(pStmt, N, 1, COLNAME_NAME);
        82258  +  return columnName(
        82259  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
 82379  82260   }
 82380  82261   #endif
 82381  82262   
 82382  82263   /*
 82383  82264   ** Constraint:  If you have ENABLE_COLUMN_METADATA then you must
 82384  82265   ** not define OMIT_DECLTYPE.
 82385  82266   */
................................................................................
 82390  82271   
 82391  82272   #ifndef SQLITE_OMIT_DECLTYPE
 82392  82273   /*
 82393  82274   ** Return the column declaration type (if applicable) of the 'i'th column
 82394  82275   ** of the result set of SQL statement pStmt.
 82395  82276   */
 82396  82277   SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
 82397         -  return columnName(pStmt, N, 0, COLNAME_DECLTYPE);
        82278  +  return columnName(
        82279  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
 82398  82280   }
 82399  82281   #ifndef SQLITE_OMIT_UTF16
 82400  82282   SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
 82401         -  return columnName(pStmt, N, 1, COLNAME_DECLTYPE);
        82283  +  return columnName(
        82284  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
 82402  82285   }
 82403  82286   #endif /* SQLITE_OMIT_UTF16 */
 82404  82287   #endif /* SQLITE_OMIT_DECLTYPE */
 82405  82288   
 82406  82289   #ifdef SQLITE_ENABLE_COLUMN_METADATA
 82407  82290   /*
 82408  82291   ** Return the name of the database from which a result column derives.
 82409  82292   ** NULL is returned if the result column is an expression or constant or
 82410  82293   ** anything else which is not an unambiguous reference to a database column.
 82411  82294   */
 82412  82295   SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
 82413         -  return columnName(pStmt, N, 0, COLNAME_DATABASE);
        82296  +  return columnName(
        82297  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
 82414  82298   }
 82415  82299   #ifndef SQLITE_OMIT_UTF16
 82416  82300   SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
 82417         -  return columnName(pStmt, N, 1, COLNAME_DATABASE);
        82301  +  return columnName(
        82302  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
 82418  82303   }
 82419  82304   #endif /* SQLITE_OMIT_UTF16 */
 82420  82305   
 82421  82306   /*
 82422  82307   ** Return the name of the table from which a result column derives.
 82423  82308   ** NULL is returned if the result column is an expression or constant or
 82424  82309   ** anything else which is not an unambiguous reference to a database column.
 82425  82310   */
 82426  82311   SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
 82427         -  return columnName(pStmt, N, 0, COLNAME_TABLE);
        82312  +  return columnName(
        82313  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
 82428  82314   }
 82429  82315   #ifndef SQLITE_OMIT_UTF16
 82430  82316   SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
 82431         -  return columnName(pStmt, N, 1, COLNAME_TABLE);
        82317  +  return columnName(
        82318  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
 82432  82319   }
 82433  82320   #endif /* SQLITE_OMIT_UTF16 */
 82434  82321   
 82435  82322   /*
 82436  82323   ** Return the name of the table column from which a result column derives.
 82437  82324   ** NULL is returned if the result column is an expression or constant or
 82438  82325   ** anything else which is not an unambiguous reference to a database column.
 82439  82326   */
 82440  82327   SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
 82441         -  return columnName(pStmt, N, 0, COLNAME_COLUMN);
        82328  +  return columnName(
        82329  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
 82442  82330   }
 82443  82331   #ifndef SQLITE_OMIT_UTF16
 82444  82332   SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
 82445         -  return columnName(pStmt, N, 1, COLNAME_COLUMN);
        82333  +  return columnName(
        82334  +      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
 82446  82335   }
 82447  82336   #endif /* SQLITE_OMIT_UTF16 */
 82448  82337   #endif /* SQLITE_ENABLE_COLUMN_METADATA */
 82449  82338   
 82450  82339   
 82451  82340   /******************************* sqlite3_bind_  ***************************
 82452  82341   ** 
................................................................................
 82806  82695   ** Return true if the prepared statement is guaranteed to not modify the
 82807  82696   ** database.
 82808  82697   */
 82809  82698   SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
 82810  82699     return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
 82811  82700   }
 82812  82701   
 82813         -/*
 82814         -** Return 1 if the statement is an EXPLAIN and return 2 if the
 82815         -** statement is an EXPLAIN QUERY PLAN
 82816         -*/
 82817         -SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
 82818         -  return pStmt ? ((Vdbe*)pStmt)->explain : 0;
 82819         -}
 82820         -
 82821  82702   /*
 82822  82703   ** Return true if the prepared statement is in need of being reset.
 82823  82704   */
 82824  82705   SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
 82825  82706     Vdbe *v = (Vdbe*)pStmt;
 82826  82707     return v!=0 && v->magic==VDBE_MAGIC_RUN && v->pc>=0;
 82827  82708   }
................................................................................
 84092  83973   #ifdef VDBE_PROFILE
 84093  83974     u64 start;                 /* CPU clock count at start of opcode */
 84094  83975   #endif
 84095  83976     /*** INSERT STACK UNION HERE ***/
 84096  83977   
 84097  83978     assert( p->magic==VDBE_MAGIC_RUN );  /* sqlite3_step() verifies this */
 84098  83979     sqlite3VdbeEnter(p);
 84099         -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
 84100         -  if( db->xProgress ){
 84101         -    u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
 84102         -    assert( 0 < db->nProgressOps );
 84103         -    nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
 84104         -  }else{
 84105         -    nProgressLimit = 0xffffffff;
 84106         -  }
 84107         -#endif
 84108  83980     if( p->rc==SQLITE_NOMEM ){
 84109  83981       /* This happens if a malloc() inside a call to sqlite3_column_text() or
 84110  83982       ** sqlite3_column_text16() failed.  */
 84111  83983       goto no_mem;
 84112  83984     }
 84113  83985     assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
 84114  83986     assert( p->bIsReader || p->readOnly!=0 );
 84115  83987     p->iCurrentTime = 0;
 84116  83988     assert( p->explain==0 );
 84117  83989     p->pResultSet = 0;
 84118  83990     db->busyHandler.nBusy = 0;
 84119  83991     if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
 84120  83992     sqlite3VdbeIOTraceSql(p);
        83993  +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
        83994  +  if( db->xProgress ){
        83995  +    u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
        83996  +    assert( 0 < db->nProgressOps );
        83997  +    nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
        83998  +  }else{
        83999  +    nProgressLimit = 0xffffffff;
        84000  +  }
        84001  +#endif
 84121  84002   #ifdef SQLITE_DEBUG
 84122  84003     sqlite3BeginBenignMalloc();
 84123  84004     if( p->pc==0
 84124  84005      && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
 84125  84006     ){
 84126  84007       int i;
 84127  84008       int once = 1;
................................................................................
 84289  84170   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
 84290  84171     /* Call the progress callback if it is configured and the required number
 84291  84172     ** of VDBE ops have been executed (either since this invocation of
 84292  84173     ** sqlite3VdbeExec() or since last time the progress callback was called).
 84293  84174     ** If the progress callback returns non-zero, exit the virtual machine with
 84294  84175     ** a return code SQLITE_ABORT.
 84295  84176     */
 84296         -  while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
        84177  +  if( nVmStep>=nProgressLimit && db->xProgress!=0 ){
 84297  84178       assert( db->nProgressOps!=0 );
 84298         -    nProgressLimit += db->nProgressOps;
        84179  +    nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
 84299  84180       if( db->xProgress(db->pProgressArg) ){
 84300         -      nProgressLimit = 0xffffffff;
 84301  84181         rc = SQLITE_INTERRUPT;
 84302  84182         goto abort_due_to_error;
 84303  84183       }
 84304  84184     }
 84305  84185   #endif
 84306  84186     
 84307  84187     break;
................................................................................
 84572  84452     pOp->opcode = OP_String;
 84573  84453     pOp->p1 = sqlite3Strlen30(pOp->p4.z);
 84574  84454   
 84575  84455   #ifndef SQLITE_OMIT_UTF16
 84576  84456     if( encoding!=SQLITE_UTF8 ){
 84577  84457       rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
 84578  84458       assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
 84579         -    if( rc ) goto too_big;
 84580  84459       if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
 84581  84460       assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
 84582  84461       assert( VdbeMemDynamic(pOut)==0 );
 84583  84462       pOut->szMalloc = 0;
 84584  84463       pOut->flags |= MEM_Static;
 84585  84464       if( pOp->p4type==P4_DYNAMIC ){
 84586  84465         sqlite3DbFree(db, pOp->p4.z);
 84587  84466       }
 84588  84467       pOp->p4type = P4_DYNAMIC;
 84589  84468       pOp->p4.z = pOut->z;
 84590  84469       pOp->p1 = pOut->n;
 84591  84470     }
        84471  +  testcase( rc==SQLITE_TOOBIG );
 84592  84472   #endif
 84593  84473     if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
 84594  84474       goto too_big;
 84595  84475     }
 84596  84476     assert( rc==SQLITE_OK );
 84597  84477     /* Fall through to the next case, OP_String */
 84598  84478   }
................................................................................
 84838  84718   */
 84839  84719   case OP_ResultRow: {
 84840  84720     Mem *pMem;
 84841  84721     int i;
 84842  84722     assert( p->nResColumn==pOp->p2 );
 84843  84723     assert( pOp->p1>0 );
 84844  84724     assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
        84725  +
        84726  +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
        84727  +  /* Run the progress counter just before returning.
        84728  +  */
        84729  +  if( db->xProgress!=0
        84730  +   && nVmStep>=nProgressLimit 
        84731  +   && db->xProgress(db->pProgressArg)!=0
        84732  +  ){
        84733  +    rc = SQLITE_INTERRUPT;
        84734  +    goto abort_due_to_error;
        84735  +  }
        84736  +#endif
 84845  84737   
 84846  84738     /* If this statement has violated immediate foreign key constraints, do
 84847  84739     ** not return the number of rows modified. And do not RELEASE the statement
 84848  84740     ** transaction. It needs to be rolled back.  */
 84849  84741     if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
 84850  84742       assert( db->flags&SQLITE_CountRows );
 84851  84743       assert( p->usesStmtJournal );
................................................................................
 86065  85957       op_column_read_header:
 86066  85958         i = pC->nHdrParsed;
 86067  85959         offset64 = aOffset[i];
 86068  85960         zHdr = zData + pC->iHdrOffset;
 86069  85961         zEndHdr = zData + aOffset[0];
 86070  85962         testcase( zHdr>=zEndHdr );
 86071  85963         do{
 86072         -        if( (pC->aType[i] = t = zHdr[0])<0x80 ){
        85964  +        if( (t = zHdr[0])<0x80 ){
 86073  85965             zHdr++;
 86074  85966             offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
 86075  85967           }else{
 86076  85968             zHdr += sqlite3GetVarint32(zHdr, &t);
 86077         -          pC->aType[i] = t;
 86078  85969             offset64 += sqlite3VdbeSerialTypeLen(t);
 86079  85970           }
 86080         -        aOffset[++i] = (u32)(offset64 & 0xffffffff);
        85971  +        pC->aType[i++] = t;
        85972  +        aOffset[i] = (u32)(offset64 & 0xffffffff);
 86081  85973         }while( i<=p2 && zHdr<zEndHdr );
 86082  85974   
 86083  85975         /* The record is corrupt if any of the following are true:
 86084  85976         ** (1) the bytes of the header extend past the declared header size
 86085  85977         ** (2) the entire header was used but not all data was used
 86086  85978         ** (3) the end of the data extends beyond the end of the record.
 86087  85979         */
................................................................................
 88039  87931   ** and register P2 becomes ephemeral.  If the cursor is changed, the
 88040  87932   ** value of register P2 will then change.  Make sure this does not
 88041  87933   ** cause any problems.)
 88042  87934   **
 88043  87935   ** This instruction only works on tables.  The equivalent instruction
 88044  87936   ** for indices is OP_IdxInsert.
 88045  87937   */
 88046         -case OP_Insert: {
        87938  +/* Opcode: InsertInt P1 P2 P3 P4 P5
        87939  +** Synopsis: intkey=P3 data=r[P2]
        87940  +**
        87941  +** This works exactly like OP_Insert except that the key is the
        87942  +** integer value P3, not the value of the integer stored in register P3.
        87943  +*/
        87944  +case OP_Insert: 
        87945  +case OP_InsertInt: {
 88047  87946     Mem *pData;       /* MEM cell holding data for the record to be inserted */
 88048  87947     Mem *pKey;        /* MEM cell holding key  for the record */
 88049  87948     VdbeCursor *pC;   /* Cursor to table into which insert is written */
 88050  87949     int seekResult;   /* Result of prior seek or 0 if no USESEEKRESULT flag */
 88051  87950     const char *zDb;  /* database name - used by the update hook */
 88052  87951     Table *pTab;      /* Table structure - used by update and pre-update hooks */
 88053  87952     BtreePayload x;   /* Payload to be inserted */
................................................................................
 88060  87959     assert( pC->eCurType==CURTYPE_BTREE );
 88061  87960     assert( pC->uc.pCursor!=0 );
 88062  87961     assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
 88063  87962     assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
 88064  87963     REGISTER_TRACE(pOp->p2, pData);
 88065  87964     sqlite3VdbeIncrWriteCounter(p, pC);
 88066  87965   
 88067         -  pKey = &aMem[pOp->p3];
 88068         -  assert( pKey->flags & MEM_Int );
 88069         -  assert( memIsValid(pKey) );
 88070         -  REGISTER_TRACE(pOp->p3, pKey);
 88071         -  x.nKey = pKey->u.i;
        87966  +  if( pOp->opcode==OP_Insert ){
        87967  +    pKey = &aMem[pOp->p3];
        87968  +    assert( pKey->flags & MEM_Int );
        87969  +    assert( memIsValid(pKey) );
        87970  +    REGISTER_TRACE(pOp->p3, pKey);
        87971  +    x.nKey = pKey->u.i;
        87972  +  }else{
        87973  +    assert( pOp->opcode==OP_InsertInt );
        87974  +    x.nKey = pOp->p3;
        87975  +  }
 88072  87976   
 88073  87977     if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
 88074  87978       assert( pC->iDb>=0 );
 88075  87979       zDb = db->aDb[pC->iDb].zDbSName;
 88076  87980       pTab = pOp->p4.pTab;
 88077  87981       assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
 88078  87982     }else{
................................................................................
 89632  89536       for(i=0; i<p->nMem; i++){
 89633  89537         aMem[i].pScopyFrom = 0;  /* Prevent false-positive AboutToChange() errs */
 89634  89538         aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
 89635  89539       }
 89636  89540     }
 89637  89541   #endif
 89638  89542     pOp = &aOp[-1];
 89639         -  goto check_for_interrupt;
        89543  +
        89544  +  break;
 89640  89545   }
 89641  89546   
 89642  89547   /* Opcode: Param P1 P2 * * *
 89643  89548   **
 89644  89549   ** This opcode is only ever present in sub-programs called via the 
 89645  89550   ** OP_Program instruction. Copy a value currently stored in a memory 
 89646  89551   ** cell of the calling (parent) frame to cell P2 in the current frames 
................................................................................
 91041  90946       sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
 91042  90947     }
 91043  90948   
 91044  90949     /* This is the only way out of this procedure.  We have to
 91045  90950     ** release the mutexes on btrees that were acquired at the
 91046  90951     ** top. */
 91047  90952   vdbe_return:
 91048         -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
 91049         -  while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
 91050         -    nProgressLimit += db->nProgressOps;
 91051         -    if( db->xProgress(db->pProgressArg) ){
 91052         -      nProgressLimit = 0xffffffff;
 91053         -      rc = SQLITE_INTERRUPT;
 91054         -      goto abort_due_to_error;
 91055         -    }
 91056         -  }
 91057         -#endif
        90953  +  testcase( nVmStep>0 );
 91058  90954     p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
 91059  90955     sqlite3VdbeLeave(p);
 91060  90956     assert( rc!=SQLITE_OK || nExtraDelete==0 
 91061  90957          || sqlite3_strlike("DELETE%",p->zSql,0)!=0 
 91062  90958     );
 91063  90959     return rc;
 91064  90960   
................................................................................
 96231  96127         resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,
 96232  96128                      zType,0);
 96233  96129       }
 96234  96130     }
 96235  96131     return 0;
 96236  96132   }
 96237  96133   
 96238         -#ifndef SQLITE_OMIT_WINDOWFUNC
 96239         -/*
 96240         -** Walker callback for resolveRemoveWindows().
 96241         -*/
 96242         -static int resolveRemoveWindowsCb(Walker *pWalker, Expr *pExpr){
 96243         -  if( ExprHasProperty(pExpr, EP_WinFunc) ){
 96244         -    Window **pp;
 96245         -    for(pp=&pWalker->u.pSelect->pWin; *pp; pp=&(*pp)->pNextWin){
 96246         -      if( *pp==pExpr->y.pWin ){
 96247         -        *pp = (*pp)->pNextWin;
 96248         -        break;
 96249         -      }    
 96250         -    }
 96251         -  }
 96252         -  return WRC_Continue;
 96253         -}
 96254         -
 96255         -/*
 96256         -** Remove any Window objects owned by the expression pExpr from the
 96257         -** Select.pWin list of Select object pSelect.
 96258         -*/
 96259         -static void resolveRemoveWindows(Select *pSelect, Expr *pExpr){
 96260         -  Walker sWalker;
 96261         -  memset(&sWalker, 0, sizeof(Walker));
 96262         -  sWalker.xExprCallback = resolveRemoveWindowsCb;
 96263         -  sWalker.u.pSelect = pSelect;
 96264         -  sqlite3WalkExpr(&sWalker, pExpr);
 96265         -}
 96266         -#else
 96267         -# define resolveRemoveWindows(x,y)
 96268         -#endif
 96269         -
 96270  96134   /*
 96271  96135   ** pOrderBy is an ORDER BY or GROUP BY clause in SELECT statement pSelect.
 96272  96136   ** The Name context of the SELECT statement is pNC.  zType is either
 96273  96137   ** "ORDER" or "GROUP" depending on which type of clause pOrderBy is.
 96274  96138   **
 96275  96139   ** This routine resolves each term of the clause into an expression.
 96276  96140   ** If the order-by term is an integer I between 1 and N (where N is the
................................................................................
 96329  96193       /* Otherwise, treat the ORDER BY term as an ordinary expression */
 96330  96194       pItem->u.x.iOrderByCol = 0;
 96331  96195       if( sqlite3ResolveExprNames(pNC, pE) ){
 96332  96196         return 1;
 96333  96197       }
 96334  96198       for(j=0; j<pSelect->pEList->nExpr; j++){
 96335  96199         if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
 96336         -        /* Since this expresion is being changed into a reference
 96337         -        ** to an identical expression in the result set, remove all Window
 96338         -        ** objects belonging to the expression from the Select.pWin list. */
 96339         -        resolveRemoveWindows(pSelect, pE);
        96200  +#ifndef SQLITE_OMIT_WINDOWFUNC
        96201  +        if( ExprHasProperty(pE, EP_WinFunc) ){
        96202  +          /* Since this window function is being changed into a reference
        96203  +          ** to the same window function the result set, remove the instance
        96204  +          ** of this window function from the Select.pWin list. */
        96205  +          Window **pp;
        96206  +          for(pp=&pSelect->pWin; *pp; pp=&(*pp)->pNextWin){
        96207  +            if( *pp==pE->y.pWin ){
        96208  +              *pp = (*pp)->pNextWin;
        96209  +            }    
        96210  +          }
        96211  +        }
        96212  +#endif
 96340  96213           pItem->u.x.iOrderByCol = j+1;
 96341  96214         }
 96342  96215       }
 96343  96216     }
 96344  96217     return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
 96345  96218   }
 96346  96219   
................................................................................
 96544  96417             sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
 96545  96418                 "the GROUP BY clause");
 96546  96419             return WRC_Abort;
 96547  96420           }
 96548  96421         }
 96549  96422       }
 96550  96423   
 96551         -#ifndef SQLITE_OMIT_WINDOWFUNC
 96552  96424       if( IN_RENAME_OBJECT ){
 96553  96425         Window *pWin;
 96554  96426         for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
 96555  96427           if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
 96556  96428            || sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
 96557  96429           ){
 96558  96430             return WRC_Abort;
 96559  96431           }
 96560  96432         }
 96561  96433       }
 96562         -#endif
 96563  96434   
 96564  96435       /* If this is part of a compound SELECT, check that it has the right
 96565  96436       ** number of expressions in the select list. */
 96566  96437       if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
 96567  96438         sqlite3SelectWrongNumTermsError(pParse, p->pNext);
 96568  96439         return WRC_Abort;
 96569  96440       }
................................................................................
 99306  99177       ** We will have to generate an ephemeral table to do the job.
 99307  99178       */
 99308  99179       u32 savedNQueryLoop = pParse->nQueryLoop;
 99309  99180       int rMayHaveNull = 0;
 99310  99181       eType = IN_INDEX_EPH;
 99311  99182       if( inFlags & IN_INDEX_LOOP ){
 99312  99183         pParse->nQueryLoop = 0;
        99184  +      if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
        99185  +        eType = IN_INDEX_ROWID;
        99186  +      }
 99313  99187       }else if( prRhsHasNull ){
 99314  99188         *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
 99315  99189       }
 99316  99190       assert( pX->op==TK_IN );
 99317         -    sqlite3CodeRhsOfIN(pParse, pX, iTab);
        99191  +    sqlite3CodeRhsOfIN(pParse, pX, iTab, eType==IN_INDEX_ROWID);
 99318  99192       if( rMayHaveNull ){
 99319  99193         sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
 99320  99194       }
 99321  99195       pParse->nQueryLoop = savedNQueryLoop;
 99322  99196     }
 99323  99197   
 99324  99198     if( aiMap && eType!=IN_INDEX_INDEX_ASC && eType!=IN_INDEX_INDEX_DESC ){
................................................................................
 99410  99284   **     x IN (SELECT a FROM b)     -- IN operator with subquery on the right
 99411  99285   **
 99412  99286   ** The pExpr parameter is the IN operator.  The cursor number for the
 99413  99287   ** constructed ephermeral table is returned.  The first time the ephemeral
 99414  99288   ** table is computed, the cursor number is also stored in pExpr->iTable,
 99415  99289   ** however the cursor number returned might not be the same, as it might
 99416  99290   ** have been duplicated using OP_OpenDup.
        99291  +**
        99292  +** If parameter isRowid is non-zero, then LHS of the IN operator is guaranteed
        99293  +** to be a non-null integer. In this case, the ephemeral table can be an
        99294  +** table B-Tree that keyed by only integers.  The more general cases uses
        99295  +** an index B-Tree which can have arbitrary keys, but is slower to both
        99296  +** read and write.
 99417  99297   **
 99418  99298   ** If the LHS expression ("x" in the examples) is a column value, or
 99419  99299   ** the SELECT statement returns a column value, then the affinity of that
 99420  99300   ** column is used to build the index keys. If both 'x' and the
 99421  99301   ** SELECT... statement are columns, then numeric affinity is used
 99422  99302   ** if either column has NUMERIC or INTEGER affinity. If neither
 99423  99303   ** 'x' nor the SELECT... statement are columns, then numeric affinity
 99424  99304   ** is used.
 99425  99305   */
 99426  99306   SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
 99427  99307     Parse *pParse,          /* Parsing context */
 99428  99308     Expr *pExpr,            /* The IN operator */
 99429         -  int iTab                /* Use this cursor number */
        99309  +  int iTab,               /* Use this cursor number */
        99310  +  int isRowid             /* If true, LHS is a rowid */
 99430  99311   ){
 99431  99312     int addrOnce = 0;           /* Address of the OP_Once instruction at top */
 99432  99313     int addr;                   /* Address of OP_OpenEphemeral instruction */
 99433  99314     Expr *pLeft;                /* the LHS of the IN operator */
 99434  99315     KeyInfo *pKeyInfo = 0;      /* Key information */
 99435  99316     int nVal;                   /* Size of vector pLeft */
 99436  99317     Vdbe *v;                    /* The prepared statement under construction */
................................................................................
 99475  99356   
 99476  99357       addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
 99477  99358     }
 99478  99359   
 99479  99360     /* Check to see if this is a vector IN operator */
 99480  99361     pLeft = pExpr->pLeft;
 99481  99362     nVal = sqlite3ExprVectorSize(pLeft);
        99363  +  assert( !isRowid || nVal==1 );
 99482  99364   
 99483  99365     /* Construct the ephemeral table that will contain the content of
 99484  99366     ** RHS of the IN operator.
 99485  99367     */
 99486  99368     pExpr->iTable = iTab;
 99487         -  addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
        99369  +  addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, 
        99370  +      pExpr->iTable, (isRowid?0:nVal));
 99488  99371   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
 99489  99372     if( ExprHasProperty(pExpr, EP_xIsSelect) ){
 99490  99373       VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
 99491  99374     }else{
 99492  99375       VdbeComment((v, "RHS of IN operator"));
 99493  99376     }
 99494  99377   #endif
 99495         -  pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
        99378  +  pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
 99496  99379   
 99497  99380     if( ExprHasProperty(pExpr, EP_xIsSelect) ){
 99498  99381       /* Case 1:     expr IN (SELECT ...)
 99499  99382       **
 99500  99383       ** Generate code to write the results of the select into the temporary
 99501  99384       ** table allocated and opened above.
 99502  99385       */
 99503  99386       Select *pSelect = pExpr->x.pSelect;
 99504  99387       ExprList *pEList = pSelect->pEList;
 99505  99388   
 99506  99389       ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY %d",
 99507  99390           addrOnce?"":"CORRELATED ", pSelect->selId
 99508  99391       ));
        99392  +    assert( !isRowid );
 99509  99393       /* If the LHS and RHS of the IN operator do not match, that
 99510  99394       ** error will have been caught long before we reach this point. */
 99511  99395       if( ALWAYS(pEList->nExpr==nVal) ){
 99512  99396         SelectDest dest;
 99513  99397         int i;
 99514  99398         sqlite3SelectDestInit(&dest, SRT_Set, iTab);
 99515  99399         dest.zAffSdst = exprINAffinity(pParse, pExpr);
................................................................................
 99554  99438         assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
 99555  99439         pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
 99556  99440       }
 99557  99441   
 99558  99442       /* Loop through each expression in <exprlist>. */
 99559  99443       r1 = sqlite3GetTempReg(pParse);
 99560  99444       r2 = sqlite3GetTempReg(pParse);
        99445  +    if( isRowid ) sqlite3VdbeAddOp4(v, OP_Blob, 0, r2, 0, "", P4_STATIC);
 99561  99446       for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
 99562  99447         Expr *pE2 = pItem->pExpr;
        99448  +      int iValToIns;
 99563  99449   
 99564  99450         /* If the expression is not constant then we will need to
 99565  99451         ** disable the test that was generated above that makes sure
 99566  99452         ** this code only executes once.  Because for a non-constant
 99567  99453         ** expression we need to rerun this code each time.
 99568  99454         */
 99569  99455         if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
 99570  99456           sqlite3VdbeChangeToNoop(v, addrOnce);
 99571  99457           addrOnce = 0;
 99572  99458         }
 99573  99459   
 99574  99460         /* Evaluate the expression and insert it into the temp table */
 99575         -      r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
 99576         -      sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
 99577         -      sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
        99461  +      if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
        99462  +        sqlite3VdbeAddOp3(v, OP_InsertInt, iTab, r2, iValToIns);
        99463  +      }else{
        99464  +        r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
        99465  +        if( isRowid ){
        99466  +          sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
        99467  +                            sqlite3VdbeCurrentAddr(v)+2);
        99468  +          VdbeCoverage(v);
        99469  +          sqlite3VdbeAddOp3(v, OP_Insert, iTab, r2, r3);
        99470  +        }else{
        99471  +          sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
        99472  +          sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
        99473  +        }
        99474  +      }
 99578  99475       }
 99579  99476       sqlite3ReleaseTempReg(pParse, r1);
 99580  99477       sqlite3ReleaseTempReg(pParse, r2);
 99581  99478     }
 99582  99479     if( pKeyInfo ){
 99583  99480       sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
 99584  99481     }
................................................................................
102367 102264       pVTab = sqlite3GetVTable(db, pTab);
102368 102265       if( pVTab->pVtab->pModule->xRename==0 ){
102369 102266         pVTab = 0;
102370 102267       }
102371 102268     }
102372 102269   #endif
102373 102270   
102374         -  /* Begin a transaction for database iDb. Then modify the schema cookie
102375         -  ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
102376         -  ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the 
102377         -  ** nested SQL may raise an exception.  */
       102271  +  /* Begin a transaction for database iDb. 
       102272  +  ** Then modify the schema cookie (since the ALTER TABLE modifies the
       102273  +  ** schema). Open a statement transaction if the table is a virtual
       102274  +  ** table.
       102275  +  */
102378 102276     v = sqlite3GetVdbe(pParse);
102379 102277     if( v==0 ){
102380 102278       goto exit_rename_table;
102381 102279     }
102382         -  sqlite3MayAbort(pParse);
102383 102280   
102384 102281     /* figure out how many UTF-8 characters are in zName */
102385 102282     zTabName = pTab->zName;
102386 102283     nTabName = sqlite3Utf8CharLen(zTabName, -1);
102387 102284   
102388 102285     /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
102389 102286     ** the schema to use the new table name.  */
................................................................................
102444 102341     ** SQLite tables) that are identified by the name of the virtual table.
102445 102342     */
102446 102343   #ifndef SQLITE_OMIT_VIRTUALTABLE
102447 102344     if( pVTab ){
102448 102345       int i = ++pParse->nMem;
102449 102346       sqlite3VdbeLoadString(v, i, zName);
102450 102347       sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
       102348  +    sqlite3MayAbort(pParse);
102451 102349     }
102452 102350   #endif
102453 102351   
102454 102352     renameReloadSchema(pParse, iDb);
102455 102353     renameTestSchema(pParse, zDb, iDb==1);
102456 102354   
102457 102355   exit_rename_table:
................................................................................
102764 102662       goto exit_rename_column;
102765 102663     }
102766 102664   
102767 102665     /* Do the rename operation using a recursive UPDATE statement that
102768 102666     ** uses the sqlite_rename_column() SQL function to compute the new
102769 102667     ** CREATE statement text for the sqlite_master table.
102770 102668     */
102771         -  sqlite3MayAbort(pParse);
102772 102669     zNew = sqlite3NameFromToken(db, pNew);
102773 102670     if( !zNew ) goto exit_rename_column;
102774 102671     assert( pNew->n>0 );
102775 102672     bQuote = sqlite3Isquote(pNew->z[0]);
102776 102673     sqlite3NestedParse(pParse, 
102777 102674         "UPDATE \"%w\".%s SET "
102778 102675         "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
................................................................................
106019 105916     ** remove the entry from the db->aDb[] array. i.e. put everything back the
106020 105917     ** way we found it.
106021 105918     */
106022 105919     if( rc==SQLITE_OK ){
106023 105920       sqlite3BtreeEnterAll(db);
106024 105921       db->init.iDb = 0;
106025 105922       db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
106026         -    if( !REOPEN_AS_MEMDB(db) ){
106027         -      rc = sqlite3Init(db, &zErrDyn);
106028         -    }
       105923  +    rc = sqlite3Init(db, &zErrDyn);
106029 105924       sqlite3BtreeLeaveAll(db);
106030 105925       assert( zErrDyn==0 || rc!=SQLITE_OK );
106031 105926     }
106032 105927   #ifdef SQLITE_USER_AUTHENTICATION
106033 105928     if( rc==SQLITE_OK ){
106034 105929       u8 newAuth = 0;
106035 105930       rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
................................................................................
106955 106850   
106956 106851     if( pParse->nErr ) return;
106957 106852     assert( pParse->nested<10 );  /* Nesting should only be of limited depth */
106958 106853     va_start(ap, zFormat);
106959 106854     zSql = sqlite3VMPrintf(db, zFormat, ap);
106960 106855     va_end(ap);
106961 106856     if( zSql==0 ){
106962         -    /* This can result either from an OOM or because the formatted string
106963         -    ** exceeds SQLITE_LIMIT_LENGTH.  In the latter case, we need to set
106964         -    ** an error */
106965         -    if( !db->mallocFailed ) pParse->rc = SQLITE_TOOBIG;
106966         -    return;
       106857  +    return;   /* A malloc must have failed */
106967 106858     }
106968 106859     pParse->nested++;
106969 106860     memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
106970 106861     memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
106971 106862     sqlite3RunParser(pParse, zSql, &zErrMsg);
106972 106863     sqlite3DbFree(db, zErrMsg);
106973 106864     sqlite3DbFree(db, zSql);
................................................................................
108520 108411       sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
108521 108412                          SQLITE_IDXTYPE_PRIMARYKEY);
108522 108413       if( db->mallocFailed || pParse->nErr ) return;
108523 108414       pPk = sqlite3PrimaryKeyIndex(pTab);
108524 108415       pTab->iPKey = -1;
108525 108416     }else{
108526 108417       pPk = sqlite3PrimaryKeyIndex(pTab);
108527         -    assert( pPk!=0 );
108528 108418   
108529 108419       /*
108530 108420       ** Remove all redundant columns from the PRIMARY KEY.  For example, change
108531 108421       ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
108532 108422       ** code assumes the PRIMARY KEY contains no repeated columns.
108533 108423       */
108534 108424       for(i=j=1; i<pPk->nKeyCol; i++){
................................................................................
108690 108580         sqlite3ErrorMsg(pParse, "");
108691 108581         return;
108692 108582       }
108693 108583       p->tnum = db->init.newTnum;
108694 108584       if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
108695 108585     }
108696 108586   
108697         -  assert( (p->tabFlags & TF_HasPrimaryKey)==0
108698         -       || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
108699         -  assert( (p->tabFlags & TF_HasPrimaryKey)!=0
108700         -       || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
108701         -
108702 108587     /* Special processing for WITHOUT ROWID Tables */
108703 108588     if( tabOpts & TF_WithoutRowid ){
108704 108589       if( (p->tabFlags & TF_Autoincrement) ){
108705 108590         sqlite3ErrorMsg(pParse,
108706 108591             "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
108707 108592         return;
108708 108593       }
................................................................................
114646 114531   */
114647 114532   static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
114648 114533     FuncDef *pDef;
114649 114534     pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
114650 114535     if( ALWAYS(pDef) ){
114651 114536       pDef->funcFlags |= flagVal;
114652 114537     }
114653         -  pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0);
114654         -  if( pDef ){
114655         -    pDef->funcFlags |= flagVal;
114656         -  }
114657 114538   }
114658 114539   
114659 114540   /*
114660 114541   ** Register the built-in LIKE and GLOB functions.  The caseSensitive
114661 114542   ** parameter determines whether or not the LIKE operator is case
114662 114543   ** sensitive.  GLOB is always case sensitive.
114663 114544   */
................................................................................
117972 117853           sqlite3VdbeAddOp2(v, iField<0 ? OP_IntCopy : OP_SCopy, x, regIdx+i);
117973 117854           VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
117974 117855         }
117975 117856       }
117976 117857       sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
117977 117858       VdbeComment((v, "for %s", pIdx->zName));
117978 117859   #ifdef SQLITE_ENABLE_NULL_TRIM
117979         -    if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
117980         -      sqlite3SetMakeRecordP5(v, pIdx->pTable);
117981         -    }
       117860  +    if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable);
117982 117861   #endif
117983 117862   
117984 117863       /* In an UPDATE operation, if this index is the PRIMARY KEY index 
117985 117864       ** of a WITHOUT ROWID table and there has been no change the
117986 117865       ** primary key, then no collision is possible.  The collision detection
117987 117866       ** logic below can all be skipped. */
117988 117867       if( isUpdate && pPk==pIdx && pkChng==0 ){
................................................................................
118224 118103       pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
118225 118104       if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
118226 118105         assert( pParse->nested==0 );
118227 118106         pik_flags |= OPFLAG_NCHANGE;
118228 118107         pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
118229 118108   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
118230 118109         if( update_flags==0 ){
118231         -        int r = sqlite3GetTempReg(pParse);
118232         -        sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
118233         -        sqlite3VdbeAddOp4(v, OP_Insert, 
118234         -            iIdxCur+i, aRegIdx[i], r, (char*)pTab, P4_TABLE
       118110  +        sqlite3VdbeAddOp4(v, OP_InsertInt, 
       118111  +            iIdxCur+i, aRegIdx[i], 0, (char*)pTab, P4_TABLE
118235 118112           );
118236 118113           sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP);
118237         -        sqlite3ReleaseTempReg(pParse, r);
118238 118114         }
118239 118115   #endif
118240 118116       }
118241 118117       sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
118242 118118                            aRegIdx[i]+1,
118243 118119                            pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
118244 118120       sqlite3VdbeChangeP5(v, pik_flags);
................................................................................
118655 118531         addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
118656 118532         sqlite3VdbeVerifyAbortable(v, onError);
118657 118533         addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
118658 118534         VdbeCoverage(v);
118659 118535         sqlite3RowidConstraint(pParse, onError, pDest);
118660 118536         sqlite3VdbeJumpHere(v, addr2);
118661 118537         autoIncStep(pParse, regAutoinc, regRowid);
118662         -    }else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_Vacuum) ){
       118538  +    }else if( pDest->pIndex==0 ){
118663 118539         addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
118664 118540       }else{
118665 118541         addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
118666 118542         assert( (pDest->tabFlags & TF_Autoincrement)==0 );
118667 118543       }
118668 118544       sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
118669 118545       if( db->mDbFlags & DBFLAG_Vacuum ){
................................................................................
118718 118594           if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
118719 118595         }
118720 118596         if( i==pSrcIdx->nColumn ){
118721 118597           idxInsFlags = OPFLAG_USESEEKRESULT;
118722 118598           sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
118723 118599         }
118724 118600       }
118725         -    if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
       118601  +    if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
118726 118602         idxInsFlags |= OPFLAG_NCHANGE;
118727 118603       }
118728 118604       sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
118729 118605       sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
118730 118606       sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
118731 118607       sqlite3VdbeJumpHere(v, addr1);
118732 118608       sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
................................................................................
129761 129637   
129762 129638   /*
129763 129639   ** Update the accumulator memory cells for an aggregate based on
129764 129640   ** the current cursor position.
129765 129641   **
129766 129642   ** If regAcc is non-zero and there are no min() or max() aggregates
129767 129643   ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
129768         -** registers if register regAcc contains 0. The caller will take care
       129644  +** registers i register regAcc contains 0. The caller will take care
129769 129645   ** of setting and clearing regAcc.
129770 129646   */
129771 129647   static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
129772 129648     Vdbe *v = pParse->pVdbe;
129773 129649     int i;
129774 129650     int regHit = 0;
129775 129651     int addrHitTest = 0;
................................................................................
136547 136423       if( pIn ){
136548 136424         int iMap = 0;               /* Index in aiMap[] */
136549 136425         pIn += i;
136550 136426         for(i=iEq;i<pLoop->nLTerm; i++){
136551 136427           if( pLoop->aLTerm[i]->pExpr==pX ){
136552 136428             int iOut = iReg + i - iEq;
136553 136429             if( eType==IN_INDEX_ROWID ){
       136430  +            testcase( nEq>1 );  /* Happens with a UNIQUE index on ROWID */
136554 136431               pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iOut);
136555 136432             }else{
136556 136433               int iCol = aiMap ? aiMap[iMap++] : 0;
136557 136434               pIn->addrInTop = sqlite3VdbeAddOp3(v,OP_Column,iTab, iCol, iOut);
136558 136435             }
136559 136436             sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v);
136560 136437             if( i==iEq ){
................................................................................
137124 137001       x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
137125 137002       sqlite3WalkExpr(&w, pWInfo->pWhere);
137126 137003       sqlite3WalkExprList(&w, pWInfo->pOrderBy);
137127 137004       sqlite3WalkExprList(&w, pWInfo->pResultSet);
137128 137005     }
137129 137006   }
137130 137007   
137131         -/*
137132         -** The pTruth expression is always true because it is the WHERE clause
137133         -** a partial index that is driving a query loop.  Look through all of the
137134         -** WHERE clause terms on the query, and if any of those terms must be
137135         -** true because pTruth is true, then mark those WHERE clause terms as
137136         -** coded.
137137         -*/
137138         -static void whereApplyPartialIndexConstraints(
137139         -  Expr *pTruth,
137140         -  int iTabCur,
137141         -  WhereClause *pWC
137142         -){
137143         -  int i;
137144         -  WhereTerm *pTerm;
137145         -  while( pTruth->op==TK_AND ){
137146         -    whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC);
137147         -    pTruth = pTruth->pRight;
137148         -  }
137149         -  for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
137150         -    Expr *pExpr;
137151         -    if( pTerm->wtFlags & TERM_CODED ) continue;
137152         -    pExpr = pTerm->pExpr;
137153         -    if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
137154         -      pTerm->wtFlags |= TERM_CODED;
137155         -    }
137156         -  }
137157         -}
137158         -
137159 137008   /*
137160 137009   ** Generate code for the start of the iLevel-th loop in the WHERE clause
137161 137010   ** implementation described by pWInfo.
137162 137011   */
137163 137012   SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
137164 137013     Parse *pParse,       /* Parsing context */
137165 137014     Vdbe *v,             /* Prepared statement under construction */
................................................................................
137336 137185       iReleaseReg = ++pParse->nMem;
137337 137186       iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
137338 137187       if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
137339 137188       addrNxt = pLevel->addrNxt;
137340 137189       sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg);
137341 137190       VdbeCoverage(v);
137342 137191       pLevel->op = OP_Noop;
137343         -    if( (pTerm->prereqAll & pLevel->notReady)==0 ){
137344         -      pTerm->wtFlags |= TERM_CODED;
137345         -    }
137346 137192     }else if( (pLoop->wsFlags & WHERE_IPK)!=0
137347 137193            && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
137348 137194     ){
137349 137195       /* Case 3:  We have an inequality comparison against the ROWID field.
137350 137196       */
137351 137197       int testOp = OP_Noop;
137352 137198       int start;
................................................................................
137761 137607       ** move forward to the next index.
137762 137608       ** https://sqlite.org/src/info/4e8e4857d32d401f
137763 137609       */
137764 137610       if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137765 137611         whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137766 137612       }
137767 137613   
137768         -    /* If a partial index is driving the loop, try to eliminate WHERE clause
137769         -    ** terms from the query that must be true due to the WHERE clause of
137770         -    ** the partial index
137771         -    */
137772         -    if( pIdx->pPartIdxWhere ){
137773         -      whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
137774         -    }
137775         -
137776 137614       /* Record the instruction used to terminate the loop. */
137777 137615       if( pLoop->wsFlags & WHERE_ONEROW ){
137778 137616         pLevel->op = OP_Noop;
137779 137617       }else if( bRev ){
137780 137618         pLevel->op = OP_Prev;
137781 137619       }else{
137782 137620         pLevel->op = OP_Next;
................................................................................
139765 139603       assert( p->x.pList==0 );
139766 139604     }else if( ExprHasProperty(p, EP_xIsSelect) ){
139767 139605       if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
139768 139606       mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
139769 139607     }else if( p->x.pList ){
139770 139608       mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
139771 139609     }
139772         -#ifndef SQLITE_OMIT_WINDOWFUNC
139773         -  if( p->op==TK_FUNCTION && p->y.pWin ){
139774         -    mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
139775         -    mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
139776         -  }
139777         -#endif
139778 139610     return mask;
139779 139611   }
139780 139612   SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
139781 139613     return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
139782 139614   }
139783 139615   SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
139784 139616     int i;
................................................................................
153178 153010     int tokenType;                  /* type of the next token */
153179 153011     int lastTokenParsed = -1;       /* type of the previous token */
153180 153012     sqlite3 *db = pParse->db;       /* The database connection */
153181 153013     int mxSqlLen;                   /* Max length of an SQL string */
153182 153014   #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
153183 153015     yyParser sEngine;    /* Space to hold the Lemon-generated Parser object */
153184 153016   #endif
153185         -  VVA_ONLY( u8 startedWithOom = db->mallocFailed );
153186 153017   
153187 153018     assert( zSql!=0 );
153188 153019     mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
153189 153020     if( db->nVdbeActive==0 ){
153190 153021       db->u1.isInterrupted = 0;
153191 153022     }
153192 153023     pParse->rc = SQLITE_OK;
................................................................................
153210 153041       return SQLITE_NOMEM_BKPT;
153211 153042     }
153212 153043   #endif
153213 153044     assert( pParse->pNewTable==0 );
153214 153045     assert( pParse->pNewTrigger==0 );
153215 153046     assert( pParse->nVar==0 );
153216 153047     assert( pParse->pVList==0 );
153217         -  pParse->pParentParse = db->pParse;
153218         -  db->pParse = pParse;
153219 153048     while( 1 ){
153220 153049       n = sqlite3GetToken((u8*)zSql, &tokenType);
153221 153050       mxSqlLen -= n;
153222 153051       if( mxSqlLen<0 ){
153223 153052         pParse->rc = SQLITE_TOOBIG;
153224 153053         break;
153225 153054       }
................................................................................
153268 153097         }
153269 153098       }
153270 153099       pParse->sLastToken.z = zSql;
153271 153100       pParse->sLastToken.n = n;
153272 153101       sqlite3Parser(pEngine, tokenType, pParse->sLastToken);
153273 153102       lastTokenParsed = tokenType;
153274 153103       zSql += n;
153275         -    assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
153276         -    if( pParse->rc!=SQLITE_OK ) break;
       153104  +    if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
153277 153105     }
153278 153106     assert( nErr==0 );
153279 153107   #ifdef YYTRACKMAXSTACKDEPTH
153280 153108     sqlite3_mutex_enter(sqlite3MallocMutex());
153281 153109     sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
153282 153110         sqlite3ParserStackPeak(pEngine)
153283 153111     );
................................................................................
153337 153165       sqlite3DbFreeNN(db, p);
153338 153166     }
153339 153167     while( pParse->pZombieTab ){
153340 153168       Table *p = pParse->pZombieTab;
153341 153169       pParse->pZombieTab = p->pNextZombie;
153342 153170       sqlite3DeleteTable(db, p);
153343 153171     }
153344         -  db->pParse = pParse->pParentParse;
153345         -  pParse->pParentParse = 0;
153346 153172     assert( nErr==0 || pParse->rc!=SQLITE_OK );
153347 153173     return nErr;
153348 153174   }
153349 153175   
153350 153176   
153351 153177   #ifdef SQLITE_ENABLE_NORMALIZE
153352 153178   /*
................................................................................
161381 161207       if( !isFirstTerm ){
161382 161208         zCsr += fts3GetVarint32(zCsr, &nPrefix);
161383 161209       }
161384 161210       isFirstTerm = 0;
161385 161211       zCsr += fts3GetVarint32(zCsr, &nSuffix);
161386 161212       
161387 161213       assert( nPrefix>=0 && nSuffix>=0 );
161388         -    if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
       161214  +    if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
161389 161215         rc = FTS_CORRUPT_VTAB;
161390 161216         goto finish_scan;
161391 161217       }
161392 161218       if( (i64)nPrefix+nSuffix>nAlloc ){
161393 161219         char *zNew;
161394 161220         nAlloc = ((i64)nPrefix+nSuffix) * 2;
161395 161221         zNew = (char *)sqlite3_realloc64(zBuffer, nAlloc);
................................................................................
168521 168347       if( !pPtr ){
168522 168348         char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
168523 168349         sqlite3_result_error(context, zErr, -1);
168524 168350         sqlite3_free(zErr);
168525 168351         return;
168526 168352       }
168527 168353     }
168528         -  if( fts3TokenizerEnabled(context) ){
168529         -    sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
168530         -  }
       168354  +  sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
168531 168355   }
168532 168356   
168533 168357   SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){
168534 168358     static const char isFtsIdChar[] = {
168535 168359         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 0x */
168536 168360         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 1x */
168537 168361         0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 2x */
................................................................................
170979 170803         return SQLITE_OK;
170980 170804       }
170981 170805   
170982 170806       fts3SegReaderSetEof(pReader);
170983 170807   
170984 170808       /* If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf 
170985 170809       ** blocks have already been traversed.  */
170986         -#ifdef CORRUPT_DB
170987         -    assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock || CORRUPT_DB );
170988         -#endif
       170810  +    assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock );
170989 170811       if( pReader->iCurrentBlock>=pReader->iLeafEndBlock ){
170990 170812         return SQLITE_OK;
170991 170813       }
170992 170814   
170993 170815       rc = sqlite3Fts3ReadBlock(
170994 170816           p, ++pReader->iCurrentBlock, &pReader->aNode, &pReader->nNode, 
170995 170817           (bIncr ? &pReader->nPopulate : 0)
................................................................................
172868 172690       iNewLevel = getAbsoluteLevel(p, iLangid, iIndex, iLevel+1);
172869 172691       rc = fts3AllocateSegdirIdx(p, iLangid, iIndex, iLevel+1, &iIdx);
172870 172692       bIgnoreEmpty = (iLevel!=FTS3_SEGCURSOR_PENDING) && (iNewLevel>iMaxLevel);
172871 172693     }
172872 172694     if( rc!=SQLITE_OK ) goto finished;
172873 172695   
172874 172696     assert( csr.nSegment>0 );
172875         -  assert_fts3_nc( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
172876         -  assert_fts3_nc( 
172877         -    iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) 
172878         -  );
       172697  +  assert( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
       172698  +  assert( iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) );
172879 172699   
172880 172700     memset(&filter, 0, sizeof(Fts3SegFilter));
172881 172701     filter.flags = FTS3_SEGMENT_REQUIRE_POS;
172882 172702     filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);
172883 172703   
172884 172704     rc = sqlite3Fts3SegReaderStart(p, &csr, &filter);
172885 172705     while( SQLITE_OK==rc ){
................................................................................
175776 175596   
175777 175597     for(i=0; i<pIter->nPhrase; i++){
175778 175598       SnippetPhrase *pPhrase = &pIter->aPhrase[i];
175779 175599       if( pPhrase->pTail ){
175780 175600         char *pCsr = pPhrase->pTail;
175781 175601         int iCsr = pPhrase->iTail;
175782 175602   
175783         -      while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
       175603  +      while( iCsr<(iStart+pIter->nSnippet) ){
175784 175604           int j;
175785 175605           u64 mPhrase = (u64)1 << i;
175786 175606           u64 mPos = (u64)1 << (iCsr - iStart);
175787 175607           assert( iCsr>=iStart && (iCsr - iStart)<=64 );
175788 175608           assert( i>=0 && i<=64 );
175789 175609           if( (mCover|mCovered)&mPhrase ){
175790 175610             iScore++;
................................................................................
176890 176710     int rc;
176891 176711   
176892 176712     UNUSED_PARAMETER(iPhrase);
176893 176713     rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
176894 176714     nTerm = pExpr->pPhrase->nToken;
176895 176715     if( pList ){
176896 176716       fts3GetDeltaPosition(&pList, &iPos);
176897         -    assert_fts3_nc( iPos>=0 );
       176717  +    assert( iPos>=0 );
176898 176718     }
176899 176719   
176900 176720     for(iTerm=0; iTerm<nTerm; iTerm++){
176901 176721       TermOffset *pT = &p->aTerm[p->iTerm++];
176902 176722       pT->iOff = nTerm-iTerm-1;
176903 176723       pT->pList = pList;
176904 176724       pT->iPos = iPos;
................................................................................
177000 176820           }
177001 176821         }
177002 176822   
177003 176823         if( !pTerm ){
177004 176824           /* All offsets for this column have been gathered. */
177005 176825           rc = SQLITE_DONE;
177006 176826         }else{
177007         -        assert_fts3_nc( iCurrent<=iMinPos );
       176827  +        assert( iCurrent<=iMinPos );
177008 176828           if( 0==(0xFE&*pTerm->pList) ){
177009 176829             pTerm->pList = 0;
177010 176830           }else{
177011 176831             fts3GetDeltaPosition(&pTerm->pList, &pTerm->iPos);
177012 176832           }
177013 176833           while( rc==SQLITE_OK && iCurrent<iMinPos ){
177014 176834             rc = pMod->xNext(pC, &ZDUMMY, &NDUMMY, &iStart, &iEnd, &iCurrent);
................................................................................
188800 188620   
188801 188621     aOut = sqlite3_malloc(nOut+1);
188802 188622     if( aOut==0 ){
188803 188623       sqlite3_result_error_nomem(context);
188804 188624     }else{
188805 188625       nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
188806 188626       if( nOut2!=nOut ){
188807         -      sqlite3_free(aOut);
188808 188627         sqlite3_result_error(context, "corrupt fossil delta", -1);
188809 188628       }else{
188810 188629         sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
188811 188630       }
188812 188631     }
188813 188632   }
188814 188633   
................................................................................
199860 199679   **
199861 199680   **
199862 199681   ** xSetAuxdata(pFts5, pAux, xDelete)
199863 199682   **
199864 199683   **   Save the pointer passed as the second argument as the extension functions 
199865 199684   **   "auxiliary data". The pointer may then be retrieved by the current or any
199866 199685   **   future invocation of the same fts5 extension function made as part of
199867         -**   the same MATCH query using the xGetAuxdata() API.
       199686  +**   of the same MATCH query using the xGetAuxdata() API.
199868 199687   **
199869 199688   **   Each extension function is allocated a single auxiliary data slot for
199870 199689   **   each FTS query (MATCH expression). If the extension function is invoked 
199871 199690   **   more than once for a single FTS query, then all invocations share a 
199872 199691   **   single auxiliary data context.
199873 199692   **
199874 199693   **   If there is already an auxiliary data pointer when this function is
................................................................................
199875 199694   **   invoked, then it is replaced by the new pointer. If an xDelete callback
199876 199695   **   was specified along with the original pointer, it is invoked at this
199877 199696   **   point.
199878 199697   **
199879 199698   **   The xDelete callback, if one is specified, is also invoked on the
199880 199699   **   auxiliary data pointer after the FTS5 query has finished.
199881 199700   **
199882         -**   If an error (e.g. an OOM condition) occurs within this function,
       199701  +**   If an error (e.g. an OOM condition) occurs within this function, an
199883 199702   **   the auxiliary data is set to NULL and an error code returned. If the
199884 199703   **   xDelete parameter was not NULL, it is invoked on the auxiliary data
199885 199704   **   pointer before returning.
199886 199705   **
199887 199706   **
199888 199707   ** xGetAuxdata(pFts5, bClear)
199889 199708   **
................................................................................
212210 212029               /* Set the szLeaf field */
212211 212030               fts5PutU16(&buf.p[2], (u16)buf.n);
212212 212031             }
212213 212032   
212214 212033             /* Set up the new page-index array */
212215 212034             fts5BufferAppendVarint(&p->rc, &buf, 4);
212216 212035             if( pSeg->iLeafPgno==pSeg->iTermLeafPgno 
212217         -           && pSeg->iEndofDoclist<pData->szLeaf
212218         -           && pSeg->iPgidxOff<=pData->nn
212219         -          ){
       212036  +              && pSeg->iEndofDoclist<pData->szLeaf 
       212037  +            ){
212220 212038               int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
212221 212039               fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
212222 212040               fts5BufferAppendBlob(&p->rc, &buf, 
212223 212041                   pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
212224         -            );
       212042  +                );
212225 212043             }
212226 212044   
212227 212045             pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
212228 212046             fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
212229 212047             fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
212230 212048           }
212231 212049           fts5DataRelease(pData);
................................................................................
217254 217072   static void fts5SourceIdFunc(
217255 217073     sqlite3_context *pCtx,          /* Function call context */
217256 217074     int nArg,                       /* Number of args */
217257 217075     sqlite3_value **apUnused        /* Function arguments */
217258 217076   ){
217259 217077     assert( nArg==0 );
217260 217078     UNUSED_PARAM2(nArg, apUnused);
217261         -  sqlite3_result_text(pCtx, "fts5: 2019-03-15 16:17:32 0f2129f59f7df929106e2af876c2976dea6528c1dc1850d64cddb256f20e121a", -1, SQLITE_TRANSIENT);
       217079  +  sqlite3_result_text(pCtx, "fts5: 2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd", -1, SQLITE_TRANSIENT);
217262 217080   }
217263 217081   
217264 217082   /*
217265 217083   ** Return true if zName is the extension on one of the shadow tables used
217266 217084   ** by this module.
217267 217085   */
217268 217086   static int fts5ShadowName(const char *zName){
................................................................................
222018 221836   #endif
222019 221837     return rc;
222020 221838   }
222021 221839   #endif /* SQLITE_CORE */
222022 221840   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
222023 221841   
222024 221842   /************** End of stmt.c ************************************************/
222025         -#if __LINE__!=222025
       221843  +#if __LINE__!=221843
222026 221844   #undef SQLITE_SOURCE_ID
222027         -#define SQLITE_SOURCE_ID      "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07ealt2"
       221845  +#define SQLITE_SOURCE_ID      "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959alt2"
222028 221846   #endif
222029 221847   /* Return the source-id for this library */
222030 221848   SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
222031 221849   /************************** End of sqlite3.c ******************************/

Changes to src/sqlite3.h.

   119    119   ** been edited in any way since it was last checked in, then the last
   120    120   ** four hexadecimal digits of the hash may be modified.
   121    121   **
   122    122   ** See also: [sqlite3_libversion()],
   123    123   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   124    124   ** [sqlite_version()] and [sqlite_source_id()].
   125    125   */
   126         -#define SQLITE_VERSION        "3.28.0"
   127         -#define SQLITE_VERSION_NUMBER 3028000
   128         -#define SQLITE_SOURCE_ID      "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07e2f93"
          126  +#define SQLITE_VERSION        "3.27.1"
          127  +#define SQLITE_VERSION_NUMBER 3027001
          128  +#define SQLITE_SOURCE_ID      "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd"
   129    129   
   130    130   /*
   131    131   ** CAPI3REF: Run-Time Library Version Numbers
   132    132   ** KEYWORDS: sqlite3_version sqlite3_sourceid
   133    133   **
   134    134   ** These interfaces provide the same information as the [SQLITE_VERSION],
   135    135   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  2082   2082   ** The second parameter is a pointer to an integer into which
  2083   2083   ** is written 0 or 1 to indicate whether triggers are disabled or enabled
  2084   2084   ** following this call.  The second parameter may be a NULL pointer, in
  2085   2085   ** which case the trigger setting is not reported back. </dd>
  2086   2086   **
  2087   2087   ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
  2088   2088   ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
  2089         -** <dd> ^This option is used to enable or disable the
  2090         -** [fts3_tokenizer()] function which is part of the
         2089  +** <dd> ^This option is used to enable or disable the two-argument
         2090  +** version of the [fts3_tokenizer()] function which is part of the
  2091   2091   ** [FTS3] full-text search engine extension.
  2092   2092   ** There should be two additional arguments.
  2093   2093   ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
  2094   2094   ** positive to enable fts3_tokenizer() or negative to leave the setting
  2095   2095   ** unchanged.
  2096   2096   ** The second parameter is a pointer to an integer into which
  2097   2097   ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
................................................................................
  2365   2365   ** does not affect the value returned by sqlite3_total_changes().
  2366   2366   ** 
  2367   2367   ** ^Changes made as part of [foreign key actions] are included in the
  2368   2368   ** count, but those made as part of REPLACE constraint resolution are
  2369   2369   ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers 
  2370   2370   ** are not counted.
  2371   2371   **
  2372         -** The [sqlite3_total_changes(D)] interface only reports the number
         2372  +** This the [sqlite3_total_changes(D)] interface only reports the number
  2373   2373   ** of rows that changed due to SQL statement run against database
  2374   2374   ** connection D.  Any changes by other database connections are ignored.
  2375   2375   ** To detect changes against a database file from other database
  2376   2376   ** connections use the [PRAGMA data_version] command or the
  2377   2377   ** [SQLITE_FCNTL_DATA_VERSION] [file control].
  2378   2378   ** 
  2379   2379   ** If a separate thread makes changes on the same database connection
................................................................................
  3890   3890   ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
  3891   3891   ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
  3892   3892   ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
  3893   3893   ** sqlite3_stmt_readonly() returns false for those commands.
  3894   3894   */
  3895   3895   SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  3896   3896   
  3897         -/*
  3898         -** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
  3899         -** METHOD: sqlite3_stmt
  3900         -**
  3901         -** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
  3902         -** prepared statement S is an EXPLAIN statement, or 2 if the
  3903         -** statement S is an EXPLAIN QUERY PLAN.
  3904         -** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
  3905         -** an ordinary statement or a NULL pointer.
  3906         -*/
  3907         -SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
  3908         -
  3909   3897   /*
  3910   3898   ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  3911   3899   ** METHOD: sqlite3_stmt
  3912   3900   **
  3913   3901   ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  3914   3902   ** [prepared statement] S has been stepped at least once using 
  3915   3903   ** [sqlite3_step(S)] but has neither run to completion (returned
................................................................................
  4041   4029   ** the value of the fourth parameter then the resulting string value will
  4042   4030   ** contain embedded NULs.  The result of expressions involving strings
  4043   4031   ** with embedded NULs is undefined.
  4044   4032   **
  4045   4033   ** ^The fifth argument to the BLOB and string binding interfaces
  4046   4034   ** is a destructor used to dispose of the BLOB or
  4047   4035   ** string after SQLite has finished with it.  ^The destructor is called
  4048         -** to dispose of the BLOB or string even if the call to the bind API fails,
  4049         -** except the destructor is not called if the third parameter is a NULL
  4050         -** pointer or the fourth parameter is negative.
         4036  +** to dispose of the BLOB or string even if the call to bind API fails.
  4051   4037   ** ^If the fifth argument is
  4052   4038   ** the special value [SQLITE_STATIC], then SQLite assumes that the
  4053   4039   ** information is in static, unmanaged space and does not need to be freed.
  4054   4040   ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
  4055   4041   ** SQLite makes its own private copy of the data immediately, before
  4056   4042   ** the sqlite3_bind_*() routine returns.
  4057   4043   **
................................................................................
  5801   5787   ** CAPI3REF: Return The Filename For A Database Connection
  5802   5788   ** METHOD: sqlite3
  5803   5789   **
  5804   5790   ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
  5805   5791   ** associated with database N of connection D.  ^The main database file
  5806   5792   ** has the name "main".  If there is no attached database N on the database
  5807   5793   ** connection D, or if database N is a temporary or in-memory database, then
  5808         -** this function will return either a NULL pointer or an empty string.
         5794  +** a NULL pointer is returned.
  5809   5795   **
  5810   5796   ** ^The filename returned by this function is the output of the
  5811   5797   ** xFullPathname method of the [VFS].  ^In other words, the filename
  5812   5798   ** will be an absolute pathname, even if the filename used
  5813   5799   ** to open the database originally was a URI or relative pathname.
  5814   5800   */
  5815   5801   SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
................................................................................
 11311  11297   **
 11312  11298   **
 11313  11299   ** xSetAuxdata(pFts5, pAux, xDelete)
 11314  11300   **
 11315  11301   **   Save the pointer passed as the second argument as the extension functions 
 11316  11302   **   "auxiliary data". The pointer may then be retrieved by the current or any
 11317  11303   **   future invocation of the same fts5 extension function made as part of
 11318         -**   the same MATCH query using the xGetAuxdata() API.
        11304  +**   of the same MATCH query using the xGetAuxdata() API.
 11319  11305   **
 11320  11306   **   Each extension function is allocated a single auxiliary data slot for
 11321  11307   **   each FTS query (MATCH expression). If the extension function is invoked 
 11322  11308   **   more than once for a single FTS query, then all invocations share a 
 11323  11309   **   single auxiliary data context.
 11324  11310   **
 11325  11311   **   If there is already an auxiliary data pointer when this function is
................................................................................
 11326  11312   **   invoked, then it is replaced by the new pointer. If an xDelete callback
 11327  11313   **   was specified along with the original pointer, it is invoked at this
 11328  11314   **   point.
 11329  11315   **
 11330  11316   **   The xDelete callback, if one is specified, is also invoked on the
 11331  11317   **   auxiliary data pointer after the FTS5 query has finished.
 11332  11318   **
 11333         -**   If an error (e.g. an OOM condition) occurs within this function,
        11319  +**   If an error (e.g. an OOM condition) occurs within this function, an
 11334  11320   **   the auxiliary data is set to NULL and an error code returned. If the
 11335  11321   **   xDelete parameter was not NULL, it is invoked on the auxiliary data
 11336  11322   **   pointer before returning.
 11337  11323   **
 11338  11324   **
 11339  11325   ** xGetAuxdata(pFts5, bClear)
 11340  11326   **

Changes to src/stash.c.

   534    534   **     Show the contents of a stash as a diff against its baseline.
   535    535   **     With gshow and gcat, gdiff-command is used instead of internal
   536    536   **     diff logic.
   537    537   **
   538    538   **  fossil stash pop
   539    539   **  fossil stash apply ?STASHID?
   540    540   **
   541         -**     Apply STASHID or the most recently created stash to the current
          541  +**     Apply STASHID or the most recently create stash to the current
   542    542   **     working checkout.  The "pop" command deletes that changeset from
   543    543   **     the stash after applying it but the "apply" command retains the
   544    544   **     changeset.
   545    545   **
   546    546   **  fossil stash goto ?STASHID?
   547    547   **
   548    548   **     Update to the baseline checkout for STASHID then apply the
................................................................................
   606    606         db_finalize(&q);
   607    607         newArgv[0] = g.argv[0];
   608    608         newArgv[1] = 0;
   609    609         g.argv = newArgv;
   610    610         g.argc = nFile+2;
   611    611         if( nFile==0 ) return;
   612    612       }
   613         -    /* Make sure the stash has committed before running the revert, so that
   614         -    ** we have a copy of the changes before deleting them. */
   615         -    db_commit_transaction();
   616    613       g.argv[1] = "revert";
   617    614       revert_cmd();
   618    615     }else
   619    616     if( memcmp(zCmd, "snapshot", nCmd)==0 ){
   620    617       stash_create();
   621    618     }else
   622    619     if( memcmp(zCmd, "list", nCmd)==0 || memcmp(zCmd, "ls", nCmd)==0 ){

Changes to src/sync.c.

   153    153     }
   154    154     if( find_option("verbose","v",0)!=0 ){
   155    155       *pSyncFlags |= SYNC_VERBOSE;
   156    156     }
   157    157     url_proxy_options();
   158    158     clone_ssh_find_options();
   159    159     if( !uvOnly ) db_find_and_open_repository(0, 0);
   160         -  db_open_config(0, 1);
          160  +  db_open_config(0, 0);
   161    161     if( g.argc==2 ){
   162    162       if( db_get_boolean("auto-shun",1) ) configSync = CONFIGSET_SHUN;
   163    163     }else if( g.argc==3 ){
   164    164       zUrl = g.argv[2];
   165    165     }
   166    166     if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL)
   167    167      && db_get_boolean("uv-sync",0)

Changes to src/th_tcl.c.

    96     96   #      define _WIN32_WINNT 0x0502 /* SetDllDirectory, Windows XP SP2 */
    97     97   #    endif
    98     98   #    include <windows.h>
    99     99   #    ifndef TCL_DIRECTORY_SEP
   100    100   #      define TCL_DIRECTORY_SEP '\\'
   101    101   #    endif
   102    102   #    ifndef TCL_LIBRARY_NAME
   103         -#      define TCL_LIBRARY_NAME "tcl87.dll\0"
          103  +#      define TCL_LIBRARY_NAME "tcl86.dll\0"
   104    104   #    endif
   105    105   #    ifndef TCL_MINOR_OFFSET
   106    106   #      define TCL_MINOR_OFFSET (4)
   107    107   #    endif
   108    108   #    ifndef dlopen
   109    109   #      define dlopen(a,b) (void *)LoadLibrary((a))
   110    110   #    endif
................................................................................
   117    117   #  else
   118    118   #    include <dlfcn.h>
   119    119   #    ifndef TCL_DIRECTORY_SEP
   120    120   #      define TCL_DIRECTORY_SEP '/'
   121    121   #    endif
   122    122   #    if defined(__CYGWIN__)
   123    123   #      ifndef TCL_LIBRARY_NAME
   124         -#        define TCL_LIBRARY_NAME "libtcl8.7.dll\0"
          124  +#        define TCL_LIBRARY_NAME "libtcl8.6.dll\0"
   125    125   #      endif
   126    126   #      ifndef TCL_MINOR_OFFSET
   127    127   #        define TCL_MINOR_OFFSET (8)
   128    128   #      endif
   129    129   #    elif defined(__APPLE__)
   130    130   #      ifndef TCL_LIBRARY_NAME
   131         -#        define TCL_LIBRARY_NAME "libtcl8.7.dylib\0"
          131  +#        define TCL_LIBRARY_NAME "libtcl8.6.dylib\0"
   132    132   #      endif
   133    133   #      ifndef TCL_MINOR_OFFSET
   134    134   #        define TCL_MINOR_OFFSET (8)
   135    135   #      endif
   136    136   #    elif defined(__FreeBSD__)
   137    137   #      ifndef TCL_LIBRARY_NAME
   138         -#        define TCL_LIBRARY_NAME "libtcl87.so\0"
          138  +#        define TCL_LIBRARY_NAME "libtcl86.so\0"
   139    139   #      endif
   140    140   #      ifndef TCL_MINOR_OFFSET
   141    141   #        define TCL_MINOR_OFFSET (7)
   142    142   #      endif
   143    143   #    else
   144    144   #      ifndef TCL_LIBRARY_NAME
   145         -#        define TCL_LIBRARY_NAME "libtcl8.7.so\0"
          145  +#        define TCL_LIBRARY_NAME "libtcl8.6.so\0"
   146    146   #      endif
   147    147   #      ifndef TCL_MINOR_OFFSET
   148    148   #        define TCL_MINOR_OFFSET (8)
   149    149   #      endif
   150    150   #    endif /* defined(__CYGWIN__) */
   151    151   #  endif /* defined(_WIN32) */
   152    152   #  ifndef TCL_FINDEXECUTABLE_NAME
................................................................................
   970    970         *pxDeleteInterp = xDeleteInterp;
   971    971         *pxFinalize = xFinalize;
   972    972         return TH_OK;
   973    973       }
   974    974     } while( --aFileName[TCL_MINOR_OFFSET]>'3' ); /* Tcl 8.4+ */
   975    975     aFileName[TCL_MINOR_OFFSET] = 'x';
   976    976     Th_ErrorMessage(interp,
   977         -      "could not load any supported Tcl 8.x shared library \"",
          977  +      "could not load any supported Tcl 8.6, 8.5, or 8.4 shared library \"",
   978    978         aFileName, -1);
   979    979     return TH_ERROR;
   980    980   #else
   981    981     *phLibrary = 0;
   982    982     *pxFindExecutable = Tcl_FindExecutable;
   983    983     *pxCreateInterp = Tcl_CreateInterp;
   984    984     *pxDeleteInterp = Tcl_DeleteInterp;
................................................................................
  1008   1008     Tcl_IncrRefCount(objPtr);
  1009   1009     resultObjPtr = Tcl_SetVar2Ex(pInterp, "argv0", NULL, objPtr,
  1010   1010         TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
  1011   1011     Tcl_DecrRefCount(objPtr); objPtr = 0;
  1012   1012     if( !resultObjPtr ){
  1013   1013       return TCL_ERROR;
  1014   1014     }
  1015         -  objPtr = Tcl_NewWideIntObj(argc - 1);
         1015  +  objPtr = Tcl_NewIntObj(argc - 1);
  1016   1016     Tcl_IncrRefCount(objPtr);
  1017   1017     resultObjPtr = Tcl_SetVar2Ex(pInterp, "argc", NULL, objPtr,
  1018   1018         TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
  1019   1019     Tcl_DecrRefCount(objPtr); objPtr = 0;
  1020   1020     if( !resultObjPtr ){
  1021   1021       return TCL_ERROR;
  1022   1022     }
................................................................................
  1190   1190     tclContext->useTip285 = canUseTip285();
  1191   1191     /* Add the TH1 integration commands to Tcl. */
  1192   1192     Tcl_CallWhenDeleted(tclInterp, Th1DeleteProc, interp);
  1193   1193     Tcl_CreateObjCommand(tclInterp, "th1Eval", Th1EvalObjCmd, interp, NULL);
  1194   1194     Tcl_CreateObjCommand(tclInterp, "th1Expr", Th1ExprObjCmd, interp, NULL);
  1195   1195     /* If necessary, evaluate the custom Tcl setup script. */
  1196   1196     setup = tclContext->setup;
  1197         -  if( setup && Tcl_EvalEx(tclInterp, setup, -1, 0)!=TCL_OK ){
         1197  +  if( setup && Tcl_Eval(tclInterp, setup)!=TCL_OK ){
  1198   1198       Th_ErrorMessage(interp,
  1199   1199           "Tcl setup script error:", Tcl_GetStringResult(tclInterp), -1);
  1200   1200       Tcl_DeleteInterp(tclInterp);
  1201   1201       tclContext->interp = tclInterp = 0;
  1202   1202       return TH_ERROR;
  1203   1203     }
  1204   1204     return TH_OK;

Changes to src/unicode.c.

    57     57       0x0027E802, 0x0027F402, 0x00280403, 0x0028F001, 0x0028F805,
    58     58       0x00291C02, 0x00292C03, 0x00294401, 0x0029C002, 0x0029D402,
    59     59       0x002A0403, 0x002AF001, 0x002AF808, 0x002B1C03, 0x002B2C03,
    60     60       0x002B8802, 0x002BC002, 0x002BE806, 0x002C0403, 0x002CF001,
    61     61       0x002CF807, 0x002D1C02, 0x002D2C03, 0x002D5802, 0x002D8802,
    62     62       0x002DC001, 0x002E0801, 0x002EF805, 0x002F1803, 0x002F2804,
    63     63       0x002F5C01, 0x002FCC08, 0x00300005, 0x0030F807, 0x00311803,
    64         -    0x00312804, 0x00315402, 0x00318802, 0x0031DC01, 0x0031FC01,
    65         -    0x00320404, 0x0032F001, 0x0032F807, 0x00331803, 0x00332804,
    66         -    0x00335402, 0x00338802, 0x00340004, 0x0034EC02, 0x0034F807,
    67         -    0x00351803, 0x00352804, 0x00353C01, 0x00355C01, 0x00358802,
    68         -    0x0035E401, 0x00360802, 0x00372801, 0x00373C06, 0x00375801,
    69         -    0x00376008, 0x0037C803, 0x0038C401, 0x0038D007, 0x0038FC01,
    70         -    0x00391C09, 0x00396802, 0x003AC401, 0x003AD009, 0x003B2006,
           64  +    0x00312804, 0x00315402, 0x00318802, 0x0031FC01, 0x00320404,
           65  +    0x0032F001, 0x0032F807, 0x00331803, 0x00332804, 0x00335402,
           66  +    0x00338802, 0x00340004, 0x0034EC02, 0x0034F807, 0x00351803,
           67  +    0x00352804, 0x00353C01, 0x00355C01, 0x00358802, 0x0035E401,
           68  +    0x00360802, 0x00372801, 0x00373C06, 0x00375801, 0x00376008,
           69  +    0x0037C803, 0x0038C401, 0x0038D007, 0x0038FC01, 0x00391C09,
           70  +    0x00396802, 0x003AC401, 0x003AD006, 0x003AEC02, 0x003B2006,
    71     71       0x003C041F, 0x003CD00C, 0x003DC417, 0x003E340B, 0x003E6424,
    72     72       0x003EF80F, 0x003F380D, 0x0040AC14, 0x00412806, 0x00415804,
    73     73       0x00417803, 0x00418803, 0x00419C07, 0x0041C404, 0x0042080C,
    74     74       0x00423C01, 0x00426806, 0x0043EC01, 0x004D740C, 0x004E400A,
    75     75       0x00500001, 0x0059B402, 0x005A0001, 0x005A6C02, 0x005BAC03,
    76     76       0x005C4803, 0x005CC805, 0x005D4802, 0x005DC802, 0x005ED023,
    77     77       0x005F6004, 0x005F7401, 0x0060000F, 0x00621402, 0x0062A401,
    78     78       0x0064800C, 0x0064C00C, 0x00650001, 0x00651002, 0x00677822,
    79     79       0x00685C05, 0x00687802, 0x0069540A, 0x0069801D, 0x0069FC01,
    80     80       0x006A8007, 0x006AA006, 0x006AC00F, 0x006C0005, 0x006CD011,
    81     81       0x006D6823, 0x006E0003, 0x006E840D, 0x006F980E, 0x006FF004,
    82     82       0x00709014, 0x0070EC05, 0x0071F802, 0x00730008, 0x00734019,
    83         -    0x0073B401, 0x0073D001, 0x0073DC03, 0x0077003A, 0x0077EC05,
           83  +    0x0073B401, 0x0073C803, 0x0073DC03, 0x0077003A, 0x0077EC05,
    84     84       0x007EF401, 0x007EFC03, 0x007F3403, 0x007F7403, 0x007FB403,
    85     85       0x007FF402, 0x00800065, 0x0081980A, 0x0081E805, 0x00822805,
    86     86       0x00828020, 0x00834021, 0x00840002, 0x00840C04, 0x00842002,
    87     87       0x00845001, 0x00845803, 0x00847806, 0x00849401, 0x00849C01,
    88     88       0x0084A401, 0x0084B801, 0x0084E802, 0x00850005, 0x00852804,
    89     89       0x00853C01, 0x00862802, 0x00864297, 0x0091000B, 0x0092704E,
    90         -    0x00940276, 0x009E53E0, 0x00ADD820, 0x00AE6068, 0x00B39406,
    91         -    0x00B3BC03, 0x00B3E404, 0x00B3F802, 0x00B5C001, 0x00B5FC01,
    92         -    0x00B7804F, 0x00B8C020, 0x00BA001A, 0x00BA6C59, 0x00BC00D6,
    93         -    0x00BFC00C, 0x00C00005, 0x00C02019, 0x00C0A807, 0x00C0D802,
    94         -    0x00C0F403, 0x00C26404, 0x00C28001, 0x00C3EC01, 0x00C64002,
    95         -    0x00C6580A, 0x00C70024, 0x00C8001F, 0x00C8A81E, 0x00C94001,
    96         -    0x00C98020, 0x00CA2827, 0x00CB0140, 0x01370040, 0x02924037,
    97         -    0x0293F802, 0x02983403, 0x0299BC10, 0x029A7802, 0x029BC008,
    98         -    0x029C0017, 0x029C8002, 0x029E2402, 0x02A00801, 0x02A01801,
    99         -    0x02A02C01, 0x02A08C09, 0x02A0D804, 0x02A1D004, 0x02A20002,
   100         -    0x02A2D012, 0x02A33802, 0x02A38012, 0x02A3E003, 0x02A3F001,
   101         -    0x02A3FC01, 0x02A4980A, 0x02A51C0D, 0x02A57C01, 0x02A60004,
   102         -    0x02A6CC1B, 0x02A77802, 0x02A79401, 0x02A8A40E, 0x02A90C01,
   103         -    0x02A93002, 0x02A97004, 0x02A9DC03, 0x02A9EC03, 0x02AAC001,
   104         -    0x02AAC803, 0x02AADC02, 0x02AAF802, 0x02AB0401, 0x02AB7802,
   105         -    0x02ABAC07, 0x02ABD402, 0x02AD6C01, 0x02AF8C0B, 0x03600001,
   106         -    0x036DFC02, 0x036FFC02, 0x037FFC01, 0x03EC7801, 0x03ECA401,
   107         -    0x03EEC810, 0x03F4F802, 0x03F7F002, 0x03F8001A, 0x03F88033,
   108         -    0x03F95013, 0x03F9A004, 0x03FBFC01, 0x03FC040F, 0x03FC6807,
   109         -    0x03FCEC06, 0x03FD6C0B, 0x03FF8007, 0x03FFA007, 0x03FFE405,
   110         -    0x04040003, 0x0404DC09, 0x0405E411, 0x04063003, 0x0406400C,
   111         -    0x04068001, 0x0407402E, 0x040B8001, 0x040DD805, 0x040E7C01,
   112         -    0x040F4001, 0x0415BC01, 0x04215C01, 0x0421DC02, 0x04247C01,
   113         -    0x0424FC01, 0x04280403, 0x04281402, 0x04283004, 0x0428E003,
   114         -    0x0428FC01, 0x04294009, 0x0429FC01, 0x042B2001, 0x042B9402,
   115         -    0x042BC007, 0x042CE407, 0x042E6404, 0x04349004, 0x043D180B,
   116         -    0x043D5405, 0x04400003, 0x0440E016, 0x0441FC04, 0x0442C012,
   117         -    0x04433401, 0x04440003, 0x04449C0E, 0x04450004, 0x04451402,
   118         -    0x0445CC03, 0x04460003, 0x0446CC0E, 0x04471409, 0x04476C01,
   119         -    0x04477403, 0x0448B013, 0x044AA401, 0x044B7C0C, 0x044C0004,
   120         -    0x044CEC02, 0x044CF807, 0x044D1C02, 0x044D2C03, 0x044D5C01,
   121         -    0x044D8802, 0x044D9807, 0x044DC005, 0x0450D412, 0x04512C05,
   122         -    0x04516C01, 0x04517402, 0x0452C014, 0x04531801, 0x0456BC07,
   123         -    0x0456E020, 0x04577002, 0x0458C014, 0x0459800D, 0x045AAC0D,
   124         -    0x045C740F, 0x045CF004, 0x0460B010, 0x04674407, 0x04676807,
   125         -    0x04678801, 0x04679001, 0x0468040A, 0x0468CC07, 0x0468EC0D,
   126         -    0x0469440B, 0x046A2813, 0x046A7805, 0x0470BC08, 0x0470E008,
   127         -    0x04710405, 0x0471C002, 0x04724816, 0x0472A40E, 0x0474C406,
   128         -    0x0474E801, 0x0474F002, 0x0474FC07, 0x04751C01, 0x04762805,
   129         -    0x04764002, 0x04764C05, 0x047BCC06, 0x047F541D, 0x047FFC01,
   130         -    0x0491C005, 0x04D0C009, 0x05A9B802, 0x05ABC006, 0x05ACC010,
   131         -    0x05AD1002, 0x05BA5C04, 0x05BD3C01, 0x05BD4437, 0x05BE3C04,
   132         -    0x05BF8801, 0x06F27008, 0x074000F6, 0x07440027, 0x0744A4C0,
   133         -    0x07480046, 0x074C0057, 0x075B0401, 0x075B6C01, 0x075BEC01,
   134         -    0x075C5401, 0x075CD401, 0x075D3C01, 0x075DBC01, 0x075E2401,
   135         -    0x075EA401, 0x075F0C01, 0x0760028C, 0x076A6C05, 0x076A840F,
   136         -    0x07800007, 0x07802011, 0x07806C07, 0x07808C02, 0x07809805,
   137         -    0x0784C007, 0x07853C01, 0x078BB004, 0x078BFC01, 0x07A34007,
   138         -    0x07A51007, 0x07A57802, 0x07B2B001, 0x07B2C001, 0x07B4B801,
   139         -    0x07BBC002, 0x07C0002C, 0x07C0C064, 0x07C2800F, 0x07C2C40F,
   140         -    0x07C3040F, 0x07C34425, 0x07C4405D, 0x07C5C03D, 0x07C7981D,
   141         -    0x07C8402C, 0x07C90009, 0x07C94002, 0x07C98006, 0x07CC03D6,
   142         -    0x07DB800D, 0x07DBC00B, 0x07DC0074, 0x07DE0059, 0x07DF800C,
   143         -    0x07E0000C, 0x07E04038, 0x07E1400A, 0x07E18028, 0x07E2401E,
   144         -    0x07E4000C, 0x07E43465, 0x07E5CC04, 0x07E5E829, 0x07E69406,
   145         -    0x07E6B81D, 0x07E73487, 0x07E9800E, 0x07E9C004, 0x07E9E003,
   146         -    0x07EA0003, 0x07EA4006, 0x38000401, 0x38008060, 0x380400F0,
           90  +    0x00940276, 0x009E53E0, 0x00ADD820, 0x00AE6031, 0x00AF2835,
           91  +    0x00B39406, 0x00B3BC03, 0x00B3E404, 0x00B3F802, 0x00B5C001,
           92  +    0x00B5FC01, 0x00B7804F, 0x00B8C01F, 0x00BA001A, 0x00BA6C59,
           93  +    0x00BC00D6, 0x00BFC00C, 0x00C00005, 0x00C02019, 0x00C0A807,
           94  +    0x00C0D802, 0x00C0F403, 0x00C26404, 0x00C28001, 0x00C3EC01,
           95  +    0x00C64002, 0x00C6580A, 0x00C70024, 0x00C8001F, 0x00C8A81E,
           96  +    0x00C94001, 0x00C98020, 0x00CA2827, 0x00CB003F, 0x00CC0100,
           97  +    0x01370040, 0x02924037, 0x0293F802, 0x02983403, 0x0299BC10,
           98  +    0x029A7802, 0x029BC008, 0x029C0017, 0x029C8002, 0x029E2402,
           99  +    0x02A00801, 0x02A01801, 0x02A02C01, 0x02A08C09, 0x02A0D804,
          100  +    0x02A1D004, 0x02A20002, 0x02A2D012, 0x02A33802, 0x02A38012,
          101  +    0x02A3E003, 0x02A3F001, 0x02A3FC01, 0x02A4980A, 0x02A51C0D,
          102  +    0x02A57C01, 0x02A60004, 0x02A6CC1B, 0x02A77802, 0x02A79401,
          103  +    0x02A8A40E, 0x02A90C01, 0x02A93002, 0x02A97004, 0x02A9DC03,
          104  +    0x02A9EC03, 0x02AAC001, 0x02AAC803, 0x02AADC02, 0x02AAF802,
          105  +    0x02AB0401, 0x02AB7802, 0x02ABAC07, 0x02ABD402, 0x02AD6C01,
          106  +    0x02AF8C0B, 0x03600001, 0x036DFC02, 0x036FFC02, 0x037FFC01,
          107  +    0x03EC7801, 0x03ECA401, 0x03EEC810, 0x03F4F802, 0x03F7F002,
          108  +    0x03F8001A, 0x03F88033, 0x03F95013, 0x03F9A004, 0x03FBFC01,
          109  +    0x03FC040F, 0x03FC6807, 0x03FCEC06, 0x03FD6C0B, 0x03FF8007,
          110  +    0x03FFA007, 0x03FFE405, 0x04040003, 0x0404DC09, 0x0405E411,
          111  +    0x04063003, 0x0406400C, 0x04068001, 0x0407402E, 0x040B8001,
          112  +    0x040DD805, 0x040E7C01, 0x040F4001, 0x0415BC01, 0x04215C01,
          113  +    0x0421DC02, 0x04247C01, 0x0424FC01, 0x04280403, 0x04281402,
          114  +    0x04283004, 0x0428E003, 0x0428FC01, 0x04294009, 0x0429FC01,
          115  +    0x042B2001, 0x042B9402, 0x042BC007, 0x042CE407, 0x042E6404,
          116  +    0x04349004, 0x043D180B, 0x043D5405, 0x04400003, 0x0440E016,
          117  +    0x0441FC04, 0x0442C012, 0x04433401, 0x04440003, 0x04449C0E,
          118  +    0x04450004, 0x04451402, 0x0445CC03, 0x04460003, 0x0446CC0E,
          119  +    0x04471409, 0x04476C01, 0x04477403, 0x0448B013, 0x044AA401,
          120  +    0x044B7C0C, 0x044C0004, 0x044CEC02, 0x044CF807, 0x044D1C02,
          121  +    0x044D2C03, 0x044D5C01, 0x044D8802, 0x044D9807, 0x044DC005,
          122  +    0x0450D412, 0x04512C05, 0x04516C01, 0x04517402, 0x0452C014,
          123  +    0x04531801, 0x0456BC07, 0x0456E020, 0x04577002, 0x0458C014,
          124  +    0x0459800D, 0x045AAC0D, 0x045C740F, 0x045CF004, 0x0460B010,
          125  +    0x0468040A, 0x0468CC07, 0x0468EC0D, 0x0469440B, 0x046A2813,
          126  +    0x046A7805, 0x0470BC08, 0x0470E008, 0x04710405, 0x0471C002,
          127  +    0x04724816, 0x0472A40E, 0x0474C406, 0x0474E801, 0x0474F002,
          128  +    0x0474FC07, 0x04751C01, 0x04762805, 0x04764002, 0x04764C05,
          129  +    0x047BCC06, 0x0491C005, 0x05A9B802, 0x05ABC006, 0x05ACC010,
          130  +    0x05AD1002, 0x05BA5C04, 0x05BD442E, 0x05BE3C04, 0x06F27008,
          131  +    0x074000F6, 0x07440027, 0x0744A4C0, 0x07480046, 0x074C0057,
          132  +    0x075B0401, 0x075B6C01, 0x075BEC01, 0x075C5401, 0x075CD401,
          133  +    0x075D3C01, 0x075DBC01, 0x075E2401, 0x075EA401, 0x075F0C01,
          134  +    0x0760028C, 0x076A6C05, 0x076A840F, 0x07800007, 0x07802011,
          135  +    0x07806C07, 0x07808C02, 0x07809805, 0x07A34007, 0x07A51007,
          136  +    0x07A57802, 0x07B2B001, 0x07B2C001, 0x07BBC002, 0x07C0002C,
          137  +    0x07C0C064, 0x07C2800F, 0x07C2C40F, 0x07C3040F, 0x07C34425,
          138  +    0x07C4405C, 0x07C5C03D, 0x07C7981D, 0x07C8402C, 0x07C90009,
          139  +    0x07C94002, 0x07C98006, 0x07CC03D5, 0x07DB800D, 0x07DBC00A,
          140  +    0x07DC0074, 0x07DE0059, 0x07E0000C, 0x07E04038, 0x07E1400A,
          141  +    0x07E18028, 0x07E2401E, 0x07E4000C, 0x07E4402F, 0x07E50031,
          142  +    0x07E5CC04, 0x07E5E801, 0x07E5F027, 0x07E6C00A, 0x07E70003,
          143  +    0x07E74030, 0x07E9800E, 0x38000401, 0x38008060, 0x380400F0,
   147    144     };
   148    145     static const unsigned int aAscii[4] = {
   149    146       0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001,
   150    147     };
   151    148   
   152    149     if( (unsigned int)c<128 ){
   153    150       return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 );
................................................................................
   177    174   ** If the argument is a codepoint corresponding to a lowercase letter
   178    175   ** in the ASCII range with a diacritic added, return the codepoint
   179    176   ** of the ASCII letter only. For example, if passed 235 - "LATIN
   180    177   ** SMALL LETTER E WITH DIAERESIS" - return 65 ("LATIN SMALL LETTER
   181    178   ** E"). The resuls of passing a codepoint that corresponds to an
   182    179   ** uppercase letter are undefined.
   183    180   */
   184         -static int unicode_remove_diacritic(int c, int bComplex){
          181  +static int unicode_remove_diacritic(int c){
   185    182     static const unsigned short aDia[] = {
   186    183           0,  1797,  1848,  1859,  1891,  1928,  1940,  1995,
   187    184        2024,  2040,  2060,  2110,  2168,  2206,  2264,  2286,
   188    185        2344,  2383,  2472,  2488,  2516,  2596,  2668,  2732,
   189    186        2782,  2842,  2894,  2954,  2984,  3000,  3028,  3336,
   190         -     3456,  3696,  3712,  3728,  3744,  3766,  3832,  3896,
   191         -     3912,  3928,  3944,  3968,  4008,  4040,  4056,  4106,
   192         -     4138,  4170,  4202,  4234,  4266,  4296,  4312,  4344,
   193         -     4408,  4424,  4442,  4472,  4488,  4504,  6148,  6198,
   194         -     6264,  6280,  6360,  6429,  6505,  6529, 61448, 61468,
   195         -    61512, 61534, 61592, 61610, 61642, 61672, 61688, 61704,
   196         -    61726, 61784, 61800, 61816, 61836, 61880, 61896, 61914,
   197         -    61948, 61998, 62062, 62122, 62154, 62184, 62200, 62218,
   198         -    62252, 62302, 62364, 62410, 62442, 62478, 62536, 62554,
   199         -    62584, 62604, 62640, 62648, 62656, 62664, 62730, 62766,
   200         -    62830, 62890, 62924, 62974, 63032, 63050, 63082, 63118,
   201         -    63182, 63242, 63274, 63310, 63368, 63390,
          187  +     3456,  3696,  3712,  3728,  3744,  3896,  3912,  3928,
          188  +     3968,  4008,  4040,  4106,  4138,  4170,  4202,  4234,
          189  +     4266,  4296,  4312,  4344,  4408,  4424,  4472,  4504,
          190  +     6148,  6198,  6264,  6280,  6360,  6429,  6505,  6529,
          191  +    61448, 61468, 61534, 61592, 61642, 61688, 61704, 61726,
          192  +    61784, 61800, 61836, 61880, 61914, 61948, 61998, 62122,
          193  +    62154, 62200, 62218, 62302, 62364, 62442, 62478, 62536,
          194  +    62554, 62584, 62604, 62640, 62648, 62656, 62664, 62730,
          195  +    62924, 63050, 63082, 63274, 63390,
   202    196     };
   203         -#define HIBIT ((unsigned char)0x80)
   204         -  static const unsigned char aChar[] = {
   205         -    '\0',      'a',       'c',       'e',       'i',       'n',
   206         -    'o',       'u',       'y',       'y',       'a',       'c',
   207         -    'd',       'e',       'e',       'g',       'h',       'i',
   208         -    'j',       'k',       'l',       'n',       'o',       'r',
   209         -    's',       't',       'u',       'u',       'w',       'y',
   210         -    'z',       'o',       'u',       'a',       'i',       'o',
   211         -    'u',       'u'|HIBIT, 'a'|HIBIT, 'g',       'k',       'o',
   212         -    'o'|HIBIT, 'j',       'g',       'n',       'a'|HIBIT, 'a',
   213         -    'e',       'i',       'o',       'r',       'u',       's',
   214         -    't',       'h',       'a',       'e',       'o'|HIBIT, 'o',
   215         -    'o'|HIBIT, 'y',       '\0',      '\0',      '\0',      '\0',
   216         -    '\0',      '\0',      '\0',      '\0',      'a',       'b',
   217         -    'c'|HIBIT, 'd',       'd',       'e'|HIBIT, 'e',       'e'|HIBIT,
   218         -    'f',       'g',       'h',       'h',       'i',       'i'|HIBIT,
   219         -    'k',       'l',       'l'|HIBIT, 'l',       'm',       'n',
   220         -    'o'|HIBIT, 'p',       'r',       'r'|HIBIT, 'r',       's',
   221         -    's'|HIBIT, 't',       'u',       'u'|HIBIT, 'v',       'w',
   222         -    'w',       'x',       'y',       'z',       'h',       't',
   223         -    'w',       'y',       'a',       'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT,
   224         -    'e',       'e'|HIBIT, 'e'|HIBIT, 'i',       'o',       'o'|HIBIT,
   225         -    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',
          197  +  static const char aChar[] = {
          198  +    '\0', 'a',  'c',  'e',  'i',  'n',  'o',  'u',  'y',  'y',  'a',  'c',
          199  +    'd',  'e',  'e',  'g',  'h',  'i',  'j',  'k',  'l',  'n',  'o',  'r',
          200  +    's',  't',  'u',  'u',  'w',  'y',  'z',  'o',  'u',  'a',  'i',  'o',
          201  +    'u',  'g',  'k',  'o',  'j',  'g',  'n',  'a',  'e',  'i',  'o',  'r',
          202  +    'u',  's',  't',  'h',  'a',  'e',  'o',  'y',  '\0', '\0', '\0', '\0',
          203  +    '\0', '\0', '\0', '\0', 'a',  'b',  'd',  'd',  'e',  'f',  'g',  'h',
          204  +    'h',  'i',  'k',  'l',  'l',  'm',  'n',  'p',  'r',  'r',  's',  't',
          205  +    'u',  'v',  'w',  'w',  'x',  'y',  'z',  'h',  't',  'w',  'y',  'a',
          206  +    'e',  'i',  'o',  'u',  'y',
   226    207     };
   227    208   
   228    209     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
   229    210     int iRes = 0;
   230    211     int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
   231    212     int iLo = 0;
   232    213     while( iHi>=iLo ){
................................................................................
   235    216         iRes = iTest;
   236    217         iLo = iTest+1;
   237    218       }else{
   238    219         iHi = iTest-1;
   239    220       }
   240    221     }
   241    222     assert( key>=aDia[iRes] );
   242         -  if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
   243         -  return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
          223  +  return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]);
   244    224   }
   245    225   
   246    226   
   247    227   /*
   248    228   ** Return true if the argument interpreted as a unicode codepoint
   249    229   ** is a diacritical modifier character.
   250    230   */
   251    231   int unicode_is_diacritic(int c){
   252    232     unsigned int mask0 = 0x08029FDF;
   253    233     unsigned int mask1 = 0x000361F8;
   254    234     if( c<768 || c>817 ) return 0;
   255    235     return (c < 768+32) ?
   256         -      (mask0 & ((unsigned int)1 << (c-768))) :
   257         -      (mask1 & ((unsigned int)1 << (c-768-32)));
          236  +      (mask0 & (1 << (c-768))) :
          237  +      (mask1 & (1 << (c-768-32)));
   258    238   }
   259    239   
   260    240   
   261    241   /*
   262    242   ** Interpret the argument as a unicode codepoint. If the codepoint
   263    243   ** is an upper case character that has a lower case equivalent,
   264    244   ** return the codepoint corresponding to the lower case version.
   265    245   ** Otherwise, return a copy of the argument.
   266    246   **
   267    247   ** The results are undefined if the value passed to this function
   268    248   ** is less than zero.
   269    249   */
   270         -int unicode_fold(int c, int eRemoveDiacritic){
          250  +int unicode_fold(int c, int bRemoveDiacritic){
   271    251     /* Each entry in the following array defines a rule for folding a range
   272    252     ** of codepoints to lower case. The rule applies to a range of nRange
   273    253     ** codepoints starting at codepoint iCode.
   274    254     **
   275    255     ** If the least significant bit in flags is clear, then the rule applies
   276    256     ** to all nRange codepoints (i.e. all nRange codepoints are upper case and
   277    257     ** need to be folded). Or, if it is set, then the rule only applies to
................................................................................
   288    268     static const struct TableEntry {
   289    269       unsigned short iCode;
   290    270       unsigned char flags;
   291    271       unsigned char nRange;
   292    272     } aEntry[] = {
   293    273       {65, 14, 26},          {181, 66, 1},          {192, 14, 23},
   294    274       {216, 14, 7},          {256, 1, 48},          {306, 1, 6},
   295         -    {313, 1, 16},          {330, 1, 46},          {376, 156, 1},
   296         -    {377, 1, 6},           {383, 144, 1},         {385, 52, 1},
          275  +    {313, 1, 16},          {330, 1, 46},          {376, 152, 1},
          276  +    {377, 1, 6},           {383, 140, 1},         {385, 52, 1},
   297    277       {386, 1, 4},           {390, 46, 1},          {391, 0, 1},
   298    278       {393, 44, 2},          {395, 0, 1},           {398, 34, 1},
   299    279       {399, 40, 1},          {400, 42, 1},          {401, 0, 1},
   300    280       {403, 44, 1},          {404, 48, 1},          {406, 54, 1},
   301    281       {407, 50, 1},          {408, 0, 1},           {412, 54, 1},
   302    282       {413, 56, 1},          {415, 58, 1},          {416, 1, 6},
   303    283       {422, 62, 1},          {423, 0, 1},           {425, 62, 1},
   304    284       {428, 0, 1},           {430, 62, 1},          {431, 0, 1},
   305    285       {433, 60, 2},          {435, 1, 4},           {439, 64, 1},
   306    286       {440, 0, 1},           {444, 0, 1},           {452, 2, 1},
   307    287       {453, 0, 1},           {455, 2, 1},           {456, 0, 1},
   308    288       {458, 2, 1},           {459, 1, 18},          {478, 1, 18},
   309         -    {497, 2, 1},           {498, 1, 4},           {502, 162, 1},
   310         -    {503, 174, 1},         {504, 1, 40},          {544, 150, 1},
          289  +    {497, 2, 1},           {498, 1, 4},           {502, 158, 1},
          290  +    {503, 170, 1},         {504, 1, 40},          {544, 146, 1},
   311    291       {546, 1, 18},          {570, 74, 1},          {571, 0, 1},
   312         -    {573, 148, 1},         {574, 72, 1},          {577, 0, 1},
   313         -    {579, 146, 1},         {580, 30, 1},          {581, 32, 1},
          292  +    {573, 144, 1},         {574, 72, 1},          {577, 0, 1},
          293  +    {579, 142, 1},         {580, 30, 1},          {581, 32, 1},
   314    294       {582, 1, 10},          {837, 38, 1},          {880, 1, 4},
   315    295       {886, 0, 1},           {895, 38, 1},          {902, 20, 1},
   316    296       {904, 18, 3},          {908, 28, 1},          {910, 26, 2},
   317    297       {913, 14, 17},         {931, 14, 9},          {962, 0, 1},
   318         -    {975, 4, 1},           {976, 180, 1},         {977, 182, 1},
   319         -    {981, 186, 1},         {982, 184, 1},         {984, 1, 24},
   320         -    {1008, 176, 1},        {1009, 178, 1},        {1012, 170, 1},
   321         -    {1013, 168, 1},        {1015, 0, 1},          {1017, 192, 1},
   322         -    {1018, 0, 1},          {1021, 150, 3},        {1024, 36, 16},
          298  +    {975, 4, 1},           {976, 176, 1},         {977, 178, 1},
          299  +    {981, 182, 1},         {982, 180, 1},         {984, 1, 24},
          300  +    {1008, 172, 1},        {1009, 174, 1},        {1012, 166, 1},
          301  +    {1013, 164, 1},        {1015, 0, 1},          {1017, 188, 1},
          302  +    {1018, 0, 1},          {1021, 146, 3},        {1024, 36, 16},
   323    303       {1040, 14, 32},        {1120, 1, 34},         {1162, 1, 54},
   324    304       {1216, 6, 1},          {1217, 1, 14},         {1232, 1, 96},
   325    305       {1329, 24, 38},        {4256, 70, 38},        {4295, 70, 1},
   326         -    {4301, 70, 1},         {5112, 190, 6},        {7296, 126, 1},
   327         -    {7297, 128, 1},        {7298, 130, 1},        {7299, 134, 2},
   328         -    {7301, 132, 1},        {7302, 136, 1},        {7303, 138, 1},
   329         -    {7304, 100, 1},        {7312, 142, 43},       {7357, 142, 3},
   330         -    {7680, 1, 150},        {7835, 172, 1},        {7838, 120, 1},
   331         -    {7840, 1, 96},         {7944, 190, 8},        {7960, 190, 6},
   332         -    {7976, 190, 8},        {7992, 190, 8},        {8008, 190, 6},
   333         -    {8025, 191, 8},        {8040, 190, 8},        {8072, 190, 8},
   334         -    {8088, 190, 8},        {8104, 190, 8},        {8120, 190, 2},
   335         -    {8122, 166, 2},        {8124, 188, 1},        {8126, 124, 1},
   336         -    {8136, 164, 4},        {8140, 188, 1},        {8152, 190, 2},
   337         -    {8154, 160, 2},        {8168, 190, 2},        {8170, 158, 2},
   338         -    {8172, 192, 1},        {8184, 152, 2},        {8186, 154, 2},
   339         -    {8188, 188, 1},        {8486, 122, 1},        {8490, 116, 1},
   340         -    {8491, 118, 1},        {8498, 12, 1},         {8544, 8, 16},
          306  +    {4301, 70, 1},         {5112, 186, 6},        {7296, 122, 1},
          307  +    {7297, 124, 1},        {7298, 126, 1},        {7299, 130, 2},
          308  +    {7301, 128, 1},        {7302, 132, 1},        {7303, 134, 1},
          309  +    {7304, 96, 1},         {7312, 138, 43},       {7357, 138, 3},
          310  +    {7680, 1, 150},        {7835, 168, 1},        {7838, 116, 1},
          311  +    {7840, 1, 96},         {7944, 186, 8},        {7960, 186, 6},
          312  +    {7976, 186, 8},        {7992, 186, 8},        {8008, 186, 6},
          313  +    {8025, 187, 8},        {8040, 186, 8},        {8072, 186, 8},
          314  +    {8088, 186, 8},        {8104, 186, 8},        {8120, 186, 2},
          315  +    {8122, 162, 2},        {8124, 184, 1},        {8126, 120, 1},
          316  +    {8136, 160, 4},        {8140, 184, 1},        {8152, 186, 2},
          317  +    {8154, 156, 2},        {8168, 186, 2},        {8170, 154, 2},
          318  +    {8172, 188, 1},        {8184, 148, 2},        {8186, 150, 2},
          319  +    {8188, 184, 1},        {8486, 118, 1},        {8490, 112, 1},
          320  +    {8491, 114, 1},        {8498, 12, 1},         {8544, 8, 16},
   341    321       {8579, 0, 1},          {9398, 10, 26},        {11264, 24, 47},
   342         -    {11360, 0, 1},         {11362, 112, 1},       {11363, 140, 1},
   343         -    {11364, 114, 1},       {11367, 1, 6},         {11373, 108, 1},
   344         -    {11374, 110, 1},       {11375, 104, 1},       {11376, 106, 1},
   345         -    {11378, 0, 1},         {11381, 0, 1},         {11390, 102, 2},
          322  +    {11360, 0, 1},         {11362, 108, 1},       {11363, 136, 1},
          323  +    {11364, 110, 1},       {11367, 1, 6},         {11373, 104, 1},
          324  +    {11374, 106, 1},       {11375, 100, 1},       {11376, 102, 1},
          325  +    {11378, 0, 1},         {11381, 0, 1},         {11390, 98, 2},
   346    326       {11392, 1, 100},       {11499, 1, 4},         {11506, 0, 1},
   347    327       {42560, 1, 46},        {42624, 1, 28},        {42786, 1, 14},
   348         -    {42802, 1, 62},        {42873, 1, 4},         {42877, 98, 1},
   349         -    {42878, 1, 10},        {42891, 0, 1},         {42893, 88, 1},
          328  +    {42802, 1, 62},        {42873, 1, 4},         {42877, 94, 1},
          329  +    {42878, 1, 10},        {42891, 0, 1},         {42893, 86, 1},
   350    330       {42896, 1, 4},         {42902, 1, 20},        {42922, 80, 1},
   351         -    {42923, 76, 1},        {42924, 78, 1},        {42925, 84, 1},
   352         -    {42926, 80, 1},        {42928, 92, 1},        {42929, 86, 1},
   353         -    {42930, 90, 1},        {42931, 68, 1},        {42932, 1, 12},
   354         -    {42946, 0, 1},         {42948, 178, 1},       {42949, 82, 1},
   355         -    {42950, 96, 1},        {43888, 94, 80},       {65313, 14, 26},
          331  +    {42923, 76, 1},        {42924, 78, 1},        {42925, 82, 1},
          332  +    {42926, 80, 1},        {42928, 90, 1},        {42929, 84, 1},
          333  +    {42930, 88, 1},        {42931, 68, 1},        {42932, 1, 6},
          334  +    {43888, 92, 80},       {65313, 14, 26},
   356    335     };
   357    336     static const unsigned short aiOff[] = {
   358    337      1,     2,     8,     15,    16,    26,    28,    32,
   359    338      34,    37,    38,    40,    48,    63,    64,    69,
   360    339      71,    79,    80,    116,   202,   203,   205,   206,
   361    340      207,   209,   210,   211,   213,   214,   217,   218,
   362    341      219,   775,   928,   7264,  10792, 10795, 23217, 23221,
   363         -   23228, 23229, 23231, 23254, 23256, 23275, 23278, 26672,
   364         -   30152, 30204, 35267, 54721, 54753, 54754, 54756, 54787,
   365         -   54793, 54809, 57153, 57274, 57921, 58019, 58363, 59314,
   366         -   59315, 59324, 59325, 59326, 59332, 59356, 61722, 62528,
   367         -   65268, 65341, 65373, 65406, 65408, 65410, 65415, 65424,
   368         -   65436, 65439, 65450, 65462, 65472, 65476, 65478, 65480,
   369         -   65482, 65488, 65506, 65511, 65514, 65521, 65527, 65528,
   370         -   65529,
          342  +   23228, 23231, 23254, 23256, 23275, 23278, 26672, 30204,
          343  +   35267, 54721, 54753, 54754, 54756, 54787, 54793, 54809,
          344  +   57153, 57274, 57921, 58019, 58363, 59314, 59315, 59324,
          345  +   59325, 59326, 59332, 59356, 61722, 62528, 65268, 65341,
          346  +   65373, 65406, 65408, 65410, 65415, 65424, 65436, 65439,
          347  +   65450, 65462, 65472, 65476, 65478, 65480, 65482, 65488,
          348  +   65506, 65511, 65514, 65521, 65527, 65528, 65529,
   371    349     };
   372    350   
   373    351     int ret = c;
   374    352   
   375    353     assert( sizeof(unsigned short)==2 && sizeof(unsigned char)==1 );
   376    354   
   377    355     if( c<128 ){
................................................................................
   397    375       assert( iRes>=0 && c>=aEntry[iRes].iCode );
   398    376       p = &aEntry[iRes];
   399    377       if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
   400    378         ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
   401    379         assert( ret>0 );
   402    380       }
   403    381   
   404         -    if( eRemoveDiacritic ){
   405         -      ret = unicode_remove_diacritic(ret, eRemoveDiacritic==2);
   406         -    }
          382  +    if( bRemoveDiacritic ) ret = unicode_remove_diacritic(ret);
   407    383     }
   408    384   
   409    385     else if( c>=66560 && c<66600 ){
   410    386       ret = c + 40;
   411    387     }
   412    388     else if( c>=66736 && c<66772 ){
   413    389       ret = c + 40;

Changes to src/update.c.

   158    158                         db_get_int("autosync-tries", 1), 1) ){
   159    159         fossil_fatal("update abandoned due to sync failure");
   160    160       }
   161    161     }
   162    162   
   163    163     /* Create any empty directories now, as well as after the update,
   164    164     ** so changes in settings are reflected now */
   165         -  if( !dryRunFlag ) ensure_empty_dirs_created(0);
          165  +  if( !dryRunFlag ) ensure_empty_dirs_created();
   166    166   
   167    167     if( internalUpdate ){
   168    168       tid = internalUpdate;
   169    169     }else if( g.argc>=3 ){
   170    170       if( fossil_strcmp(g.argv[2], "current")==0 ){
   171    171         /* If VERSION is "current", then use the same algorithm to find the
   172    172         ** target as if VERSION were omitted. */
................................................................................
   225    225     }
   226    226   
   227    227     if( tid==0 ){
   228    228       return;
   229    229     }
   230    230   
   231    231     db_begin_transaction();
   232         -  db_multi_exec(
   233         -     "CREATE TEMP TABLE dir_to_delete(name TEXT %s PRIMARY KEY)WITHOUT ROWID",
   234         -     filename_collation()
   235         -  );
   236    232     vfile_check_signature(vid, CKSIG_ENOTFILE);
   237    233     if( !dryRunFlag && !internalUpdate ) undo_begin();
   238    234     if( load_vfile_from_rid(tid) && !forceMissingFlag ){
   239    235       fossil_fatal("missing content, unable to update");
   240    236     };
   241    237   
   242    238     /*
................................................................................
   457    453           ** file but keep the edited version around. */
   458    454           fossil_print("CONFLICT %s - edited locally but deleted by update\n",
   459    455                        zName);
   460    456           nConflict++;
   461    457         }else{
   462    458           fossil_print("REMOVE %s\n", zName);
   463    459           if( !dryRunFlag && !internalUpdate ) undo_save(zName);
   464         -        if( !dryRunFlag ){
   465         -          char *zDir;
   466         -          file_delete(zFullPath);
   467         -          zDir = file_dirname(zName);
   468         -          while( zDir!=0 ){
   469         -            char *zNext;
   470         -            db_multi_exec("INSERT OR IGNORE INTO dir_to_delete(name)"
   471         -                          "VALUES(%Q)", zDir);
   472         -            zNext = db_changes() ? file_dirname(zDir) : 0;
   473         -            fossil_free(zDir);
   474         -            zDir = zNext;
   475         -          }
   476         -        }
          460  +        if( !dryRunFlag ) file_delete(zFullPath);
   477    461         }
   478    462       }else if( idt>0 && idv>0 && ridt!=ridv && chnged ){
   479    463         /* Merge the changes in the current tree into the target version */
   480    464         Blob r, t, v;
   481    465         int rc;
   482    466         if( nameChng ){
   483    467           fossil_print("MERGE %s -> %s\n", zName, zNewName);
................................................................................
   580    564   
   581    565     /*
   582    566     ** Clean up the mid and pid VFILE entries.  Then commit the changes.
   583    567     */
   584    568     if( dryRunFlag ){
   585    569       db_end_transaction(1);  /* With --dry-run, rollback changes */
   586    570     }else{
   587         -    char *zPwd;
   588         -    ensure_empty_dirs_created(1);
   589         -    sqlite3_create_function(g.db, "rmdir", 1, SQLITE_UTF8, 0,
   590         -                            file_rmdir_sql_function, 0, 0);
   591         -    zPwd = file_getcwd(0,0);
   592         -    db_multi_exec(
   593         -      "SELECT rmdir(%Q||name) FROM dir_to_delete"
   594         -      " WHERE (%Q||name)<>%Q ORDER BY name DESC",
   595         -      g.zLocalRoot, g.zLocalRoot, zPwd
   596         -    );
   597         -    fossil_free(zPwd);
          571  +    ensure_empty_dirs_created();
   598    572       if( g.argc<=3 ){
   599    573         /* All files updated.  Shift the current checkout to the target. */
   600    574         db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid);
   601    575         checkout_set_all_exe(tid);
   602    576         manifest_to_disk(tid);
   603    577         db_set_checkout(tid);
   604    578       }else{
................................................................................
   611    585       db_end_transaction(0);
   612    586     }
   613    587   }
   614    588   
   615    589   /*
   616    590   ** Create empty directories specified by the empty-dirs setting.
   617    591   */
   618         -void ensure_empty_dirs_created(int clearDirTable){
          592  +void ensure_empty_dirs_created(void){
   619    593     char *zEmptyDirs = db_get("empty-dirs", 0);
   620    594     if( zEmptyDirs!=0 ){
   621    595       int i;
   622    596       Blob dirName;
   623    597       Blob dirsList;
   624    598   
   625    599       zEmptyDirs = fossil_strdup(zEmptyDirs);
................................................................................
   637    611             if( file_mkfolder(zPath, RepoFILE, 0, 1)!=0 ) {
   638    612               fossil_warning("couldn't create directory %s as "
   639    613                              "required by empty-dirs setting", zDir);
   640    614             }
   641    615             break;
   642    616           }
   643    617           case 1: { /* exists, and is a directory */
   644         -          /* make sure this directory is not on the delete list */
   645         -          if( clearDirTable ){
   646         -            db_multi_exec(
   647         -              "DELETE FROM dir_to_delete WHERE name=%Q", zDir
   648         -            );
   649         -          }
          618  +          /* do nothing - required directory exists already */
   650    619             break;
   651    620           }
   652    621           case 2: { /* exists, but isn't a directory */
   653    622             fossil_warning("file %s found, but a directory is required "
   654    623                            "by empty-dirs setting", zDir);
   655    624           }
   656    625         }

Changes to src/vfile.c.

   357    357       blob_reset(&content);
   358    358       db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
   359    359                     file_mtime(zName, RepoFILE), id);
   360    360     }
   361    361     db_finalize(&q);
   362    362   }
   363    363   
          364  +
          365  +/*
          366  +** Delete from the disk every file in VFILE vid.
          367  +*/
          368  +void vfile_unlink(int vid){
          369  +  Stmt q;
          370  +  db_prepare(&q, "SELECT %Q || pathname FROM vfile"
          371  +                 " WHERE vid=%d AND mrid>0", g.zLocalRoot, vid);
          372  +  while( db_step(&q)==SQLITE_ROW ){
          373  +    const char *zName;
          374  +
          375  +    zName = db_column_text(&q, 0);
          376  +    file_delete(zName);
          377  +  }
          378  +  db_finalize(&q);
          379  +  db_multi_exec("UPDATE vfile SET mtime=NULL WHERE vid=%d AND mrid>0", vid);
          380  +}
          381  +
   364    382   /*
   365    383   ** Check to see if the directory named in zPath is the top of a checkout.
   366    384   ** In other words, check to see if directory pPath contains a file named
   367    385   ** "_FOSSIL_" or ".fslckout".  Return true or false.
   368    386   */
   369    387   int vfile_top_of_checkout(const char *zPath){
   370    388     char *zFile;

Changes to src/wiki.c.

   488    488     }
   489    489     zMimetype = wiki_filter_mimetypes(zMimetype);
   490    490     if( !g.isHome ){
   491    491       if( ((rid && g.perm.WrWiki) || (!rid && g.perm.NewWiki))
   492    492        && wiki_special_permission(zPageName)
   493    493       ){
   494    494         if( db_get_boolean("wysiwyg-wiki", 0) ){
   495         -        style_submenu_element("Edit", "%R/wikiedit?name=%T&wysiwyg=1",
   496         -                              zPageName);
          495  +        style_submenu_element("Edit", "%s/wikiedit?name=%T&wysiwyg=1",
          496  +             g.zTop, zPageName);
   497    497         }else{
   498         -        style_submenu_element("Edit", "%R/wikiedit?name=%T", zPageName);
          498  +        style_submenu_element("Edit", "%s/wikiedit?name=%T", g.zTop, zPageName);
   499    499         }
   500         -    }else if( rid && g.perm.ApndWiki ){
   501         -      style_submenu_element("Edit", "%R/wikiappend?name=%T", zPageName);
   502    500       }
   503    501       if( g.perm.Hyperlink ){
   504         -      style_submenu_element("History", "%R/whistory?name=%T", zPageName);
          502  +      style_submenu_element("History", "%s/whistory?name=%T",
          503  +           g.zTop, zPageName);
   505    504       }
   506    505     }
   507    506     style_set_current_page("%T?name=%T", g.zPath, zPageName);
   508    507     wiki_page_header(WIKITYPE_UNKNOWN, zPageName, "");
   509    508     wiki_standard_submenu(submenuFlags);
   510    509     if( zBody[0]==0 ){
   511    510       @ <i>This page has been deleted</i>
................................................................................
   683    682     eType = wiki_page_header(WIKITYPE_UNKNOWN, zPageName, "Edit: ");
   684    683     if( rid && !isSandbox && g.perm.ApndWiki ){
   685    684       if( g.perm.Attach ){
   686    685         style_submenu_element("Attach",
   687    686              "%s/attachadd?page=%T&from=%s/wiki%%3fname=%T",
   688    687              g.zTop, zPageName, g.zTop, zPageName);
   689    688       }
          689  +    style_submenu_element("Append", "%s/wikiappend?name=%T&mimetype=%s",
          690  +         g.zTop, zPageName, zMimetype);
   690    691     }
   691    692     if( !goodCaptcha ){
   692    693       @ <p class="generalError">Error:  Incorrect security code.</p>
   693    694     }
   694    695     blob_zero(&wiki);
   695    696     while( fossil_isspace(zBody[0]) ) zBody++;
   696    697     blob_append(&wiki, zBody, -1);
................................................................................
   758    759       blob_reset(&html);
   759    760       @ <br />
   760    761       @ <input type="submit" name="edit-markup" value="Markup Editor"
   761    762       @  onclick='return confirm("Switching to markup-mode\nwill erase your WYSIWYG\nedits. Continue?")' />
   762    763     }
   763    764     login_insert_csrf_secret();
   764    765     if( havePreview ){
   765         -    if( isWysiwyg || zBody[0] ){
          766  +    if( zBody[0] ){
   766    767         @ <input type="submit" name="submit" value="Apply These Changes" />
   767    768       }else{
   768    769         @ <input type="submit" name="submit" value="Delete This Wiki Page" />
   769    770       }
   770    771     }
   771    772     @ <input type="hidden" name="name" value="%h(zPageName)" />
   772    773     @ <input type="submit" name="cancel" value="Cancel"

Changes to src/wikiformat.c.

  1106   1106   ** is not the UUID of a ticket, return false.
  1107   1107   */
  1108   1108   static int is_ticket(
  1109   1109     const char *zTarget,    /* Ticket UUID */
  1110   1110     int *pClosed            /* True if the ticket is closed */
  1111   1111   ){
  1112   1112     static Stmt q;
         1113  +  static int once = 1;
  1113   1114     int n;
  1114   1115     int rc;
  1115   1116     char zLower[HNAME_MAX+1];
  1116   1117     char zUpper[HNAME_MAX+1];
  1117   1118     n = strlen(zTarget);
  1118   1119     memcpy(zLower, zTarget, n+1);
  1119   1120     canonical16(zLower, n+1);
  1120   1121     memcpy(zUpper, zLower, n+1);
  1121   1122     zUpper[n-1]++;
  1122         -  if( !db_static_stmt_is_init(&q) ){
         1123  +  if( once ){
  1123   1124       const char *zClosedExpr = db_get("ticket-closed-expr", "status='Closed'");
  1124   1125       db_static_prepare(&q,
  1125   1126         "SELECT %s FROM ticket "
  1126   1127         " WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr",
  1127   1128         zClosedExpr /*safe-for-%s*/
  1128   1129       );
         1130  +    once = 0;
  1129   1131     }
  1130   1132     db_bind_text(&q, ":lwr", zLower);
  1131   1133     db_bind_text(&q, ":upr", zUpper);
  1132   1134     if( db_step(&q)==SQLITE_ROW ){
  1133   1135       rc = 1;
  1134   1136       *pClosed = db_column_int(&q, 0);
  1135   1137     }else{

Changes to win/Makefile.dmc.

    26     26   TCC    = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
    27     27   LIBS   = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
    28     28   
    29     29   SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_INTROSPECTION_PRAGMAS -DSQLITE_ENABLE_DBPAGE_VTAB
    30     30   
    31     31   SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_GET_TABLE -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_USE_ALLOCA -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_INTROSPECTION_PRAGMAS -DSQLITE_ENABLE_DBPAGE_VTAB -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
    32     32   
    33         -SRC   = add_.c alerts_.c allrepo_.c attach_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c file_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c glob_.c graph_.c gzip_.c hname_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c piechart_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c webmail_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
           33  +SRC   = add_.c alerts_.c allrepo_.c attach_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c file_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c glob_.c graph_.c gzip_.c hname_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c piechart_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c webmail_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
    34     34   
    35         -OBJ   = $(OBJDIR)\add$O $(OBJDIR)\alerts$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\backoffice$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\bundle$O $(OBJDIR)\cache$O $(OBJDIR)\capabilities$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\cookies$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\deltafunc$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\dispatch$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\etag$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\foci$O $(OBJDIR)\forum$O $(OBJDIR)\fshell$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\hname$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\piechart$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\publish$O $(OBJDIR)\purge$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\repolist$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\security_audit$O $(OBJDIR)\setup$O $(OBJDIR)\setupuser$O $(OBJDIR)\sha1$O $(OBJDIR)\sha1hard$O $(OBJDIR)\sha3$O $(OBJDIR)\shun$O $(OBJDIR)\sitemap$O $(OBJDIR)\skins$O $(OBJDIR)\smtp$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\statrep$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\unversioned$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\webmail$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
           35  +OBJ   = $(OBJDIR)\add$O $(OBJDIR)\alerts$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\backoffice$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\bundle$O $(OBJDIR)\cache$O $(OBJDIR)\capabilities$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\cookies$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\dispatch$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\etag$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\foci$O $(OBJDIR)\forum$O $(OBJDIR)\fshell$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\hname$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\piechart$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\publish$O $(OBJDIR)\purge$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\repolist$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\security_audit$O $(OBJDIR)\setup$O $(OBJDIR)\setupuser$O $(OBJDIR)\sha1$O $(OBJDIR)\sha1hard$O $(OBJDIR)\sha3$O $(OBJDIR)\shun$O $(OBJDIR)\sitemap$O $(OBJDIR)\skins$O $(OBJDIR)\smtp$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\statrep$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\unversioned$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\webmail$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
    36     36   
    37     37   
    38     38   RC=$(DMDIR)\bin\rcc
    39     39   RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
    40     40   
    41     41   APPNAME = $(OBJDIR)\fossil$(E)
    42     42   
................................................................................
    47     47   	codecheck1$E $(SRC)
    48     48   	$(DMDIR)\bin\link @link
    49     49   
    50     50   $(OBJDIR)\fossil.res:	$B\win\fossil.rc
    51     51   	$(RC) $(RCFLAGS) -o$@ $**
    52     52   
    53     53   $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res
    54         -	+echo add alerts allrepo attach backoffice bag bisect blob branch browse builtin bundle cache capabilities captcha cgi checkin checkout clearsign clone comformat configure content cookies db delta deltacmd deltafunc descendants diff diffcmd dispatch doc encode etag event export file finfo foci forum fshell fusefs glob graph gzip hname http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path piechart pivot popen pqueue printf publish purge rebuild regexp repolist report rss schema search security_audit setup setupuser sha1 sha1hard sha3 shun sitemap skins smtp sqlcmd stash stat statrep style sync tag tar th_main timeline tkt tktsetup undo unicode unversioned update url user utf8 util verify vfile webmail wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
           54  +	+echo add alerts allrepo attach backoffice bag bisect blob branch browse builtin bundle cache capabilities captcha cgi checkin checkout clearsign clone comformat configure content cookies db delta deltacmd descendants diff diffcmd dispatch doc encode etag event export file finfo foci forum fshell fusefs glob graph gzip hname http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path piechart pivot popen pqueue printf publish purge rebuild regexp repolist report rss schema search security_audit setup setupuser sha1 sha1hard sha3 shun sitemap skins smtp sqlcmd stash stat statrep style sync tag tar th_main timeline tkt tktsetup undo unicode unversioned update url user utf8 util verify vfile webmail wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
    55     55   	+echo fossil >> $@
    56     56   	+echo fossil >> $@
    57     57   	+echo $(LIBS) >> $@
    58     58   	+echo. >> $@
    59     59   	+echo fossil >> $@
    60     60   
    61     61   translate$E: $(SRCDIR)\translate.c
................................................................................
   289    289   
   290    290   $(OBJDIR)\deltacmd$O : deltacmd_.c deltacmd.h
   291    291   	$(TCC) -o$@ -c deltacmd_.c
   292    292   
   293    293   deltacmd_.c : $(SRCDIR)\deltacmd.c
   294    294   	+translate$E $** > $@
   295    295   
   296         -$(OBJDIR)\deltafunc$O : deltafunc_.c deltafunc.h
   297         -	$(TCC) -o$@ -c deltafunc_.c
   298         -
   299         -deltafunc_.c : $(SRCDIR)\deltafunc.c
   300         -	+translate$E $** > $@
   301         -
   302    296   $(OBJDIR)\descendants$O : descendants_.c descendants.h
   303    297   	$(TCC) -o$@ -c descendants_.c
   304    298   
   305    299   descendants_.c : $(SRCDIR)\descendants.c
   306    300   	+translate$E $** > $@
   307    301   
   308    302   $(OBJDIR)\diff$O : diff_.c diff.h
................................................................................
   950    944   $(OBJDIR)\zip$O : zip_.c zip.h
   951    945   	$(TCC) -o$@ -c zip_.c
   952    946   
   953    947   zip_.c : $(SRCDIR)\zip.c
   954    948   	+translate$E $** > $@
   955    949   
   956    950   headers: makeheaders$E page_index.h builtin_data.h default_css.h VERSION.h
   957         -	 +makeheaders$E add_.c:add.h alerts_.c:alerts.h allrepo_.c:allrepo.h attach_.c:attach.h backoffice_.c:backoffice.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.h capabilities_.c:capabilities.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h cookies_.c:cookies.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h deltafunc_.c:deltafunc.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h dispatch_.c:dispatch.h doc_.c:doc.h encode_.c:encode.h etag_.c:etag.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h foci_.c:foci.h forum_.c:forum.h fshell_.c:fshell.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h hname_.c:hname.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h piechart_.c:piechart.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.h repolist_.c:repolist.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h security_audit_.c:security_audit.h setup_.c:setup.h setupuser_.c:setupuser.h sha1_.c:sha1.h sha1hard_.c:sha1hard.h sha3_.c:sha3.h shun_.c:shun.h sitemap_.c:sitemap.h skins_.c:skins.h smtp_.c:smtp.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h unversioned_.c:unversioned.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h webmail_.c:webmail.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
          951  +	 +makeheaders$E add_.c:add.h alerts_.c:alerts.h allrepo_.c:allrepo.h attach_.c:attach.h backoffice_.c:backoffice.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.h capabilities_.c:capabilities.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h cookies_.c:cookies.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h dispatch_.c:dispatch.h doc_.c:doc.h encode_.c:encode.h etag_.c:etag.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h foci_.c:foci.h forum_.c:forum.h fshell_.c:fshell.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h hname_.c:hname.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h piechart_.c:piechart.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.h repolist_.c:repolist.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h security_audit_.c:security_audit.h setup_.c:setup.h setupuser_.c:setupuser.h sha1_.c:sha1.h sha1hard_.c:sha1hard.h sha3_.c:sha3.h shun_.c:shun.h sitemap_.c:sitemap.h skins_.c:skins.h smtp_.c:smtp.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h statrep_.c:statrep.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h unversioned_.c:unversioned.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h webmail_.c:webmail.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
   958    952   	@copy /Y nul: headers

Changes to win/Makefile.mingw.

   172    172   endif
   173    173   
   174    174   #### The directories where the OpenSSL include and library files are located.
   175    175   #    The recommended usage here is to use the Sysinternals junction tool
   176    176   #    to create a hard link between an "openssl-1.x" sub-directory of the
   177    177   #    Fossil source code directory and the target OpenSSL source directory.
   178    178   #
   179         -OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2r
          179  +OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2q
   180    180   OPENSSLINCDIR = $(OPENSSLDIR)/include
   181    181   OPENSSLLIBDIR = $(OPENSSLDIR)
   182    182   
   183    183   #### Either the directory where the Tcl library is installed or the Tcl
   184    184   #    source code directory resides (depending on the value of the macro
   185    185   #    FOSSIL_TCL_SOURCE).  If this points to the Tcl install directory,
   186    186   #    this directory must have "include" and "lib" sub-directories.  If
................................................................................
   461    461     $(SRCDIR)/comformat.c \
   462    462     $(SRCDIR)/configure.c \
   463    463     $(SRCDIR)/content.c \
   464    464     $(SRCDIR)/cookies.c \
   465    465     $(SRCDIR)/db.c \
   466    466     $(SRCDIR)/delta.c \
   467    467     $(SRCDIR)/deltacmd.c \
   468         -  $(SRCDIR)/deltafunc.c \
   469    468     $(SRCDIR)/descendants.c \
   470    469     $(SRCDIR)/diff.c \
   471    470     $(SRCDIR)/diffcmd.c \
   472    471     $(SRCDIR)/dispatch.c \
   473    472     $(SRCDIR)/doc.c \
   474    473     $(SRCDIR)/encode.c \
   475    474     $(SRCDIR)/etag.c \
................................................................................
   673    672     $(OBJDIR)/comformat_.c \
   674    673     $(OBJDIR)/configure_.c \
   675    674     $(OBJDIR)/content_.c \
   676    675     $(OBJDIR)/cookies_.c \
   677    676     $(OBJDIR)/db_.c \
   678    677     $(OBJDIR)/delta_.c \
   679    678     $(OBJDIR)/deltacmd_.c \
   680         -  $(OBJDIR)/deltafunc_.c \
   681    679     $(OBJDIR)/descendants_.c \
   682    680     $(OBJDIR)/diff_.c \
   683    681     $(OBJDIR)/diffcmd_.c \
   684    682     $(OBJDIR)/dispatch_.c \
   685    683     $(OBJDIR)/doc_.c \
   686    684     $(OBJDIR)/encode_.c \
   687    685     $(OBJDIR)/etag_.c \
................................................................................
   812    810    $(OBJDIR)/comformat.o \
   813    811    $(OBJDIR)/configure.o \
   814    812    $(OBJDIR)/content.o \
   815    813    $(OBJDIR)/cookies.o \
   816    814    $(OBJDIR)/db.o \
   817    815    $(OBJDIR)/delta.o \
   818    816    $(OBJDIR)/deltacmd.o \
   819         - $(OBJDIR)/deltafunc.o \
   820    817    $(OBJDIR)/descendants.o \
   821    818    $(OBJDIR)/diff.o \
   822    819    $(OBJDIR)/diffcmd.o \
   823    820    $(OBJDIR)/dispatch.o \
   824    821    $(OBJDIR)/doc.o \
   825    822    $(OBJDIR)/encode.o \
   826    823    $(OBJDIR)/etag.o \
................................................................................
  1170   1167   		$(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h \
  1171   1168   		$(OBJDIR)/configure_.c:$(OBJDIR)/configure.h \
  1172   1169   		$(OBJDIR)/content_.c:$(OBJDIR)/content.h \
  1173   1170   		$(OBJDIR)/cookies_.c:$(OBJDIR)/cookies.h \
  1174   1171   		$(OBJDIR)/db_.c:$(OBJDIR)/db.h \
  1175   1172   		$(OBJDIR)/delta_.c:$(OBJDIR)/delta.h \
  1176   1173   		$(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h \
  1177         -		$(OBJDIR)/deltafunc_.c:$(OBJDIR)/deltafunc.h \
  1178   1174   		$(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h \
  1179   1175   		$(OBJDIR)/diff_.c:$(OBJDIR)/diff.h \
  1180   1176   		$(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h \
  1181   1177   		$(OBJDIR)/dispatch_.c:$(OBJDIR)/dispatch.h \
  1182   1178   		$(OBJDIR)/doc_.c:$(OBJDIR)/doc.h \
  1183   1179   		$(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
  1184   1180   		$(OBJDIR)/etag_.c:$(OBJDIR)/etag.h \
................................................................................
  1505   1501   	$(TRANSLATE) $(SRCDIR)/deltacmd.c >$@
  1506   1502   
  1507   1503   $(OBJDIR)/deltacmd.o:	$(OBJDIR)/deltacmd_.c $(OBJDIR)/deltacmd.h $(SRCDIR)/config.h
  1508   1504   	$(XTCC) -o $(OBJDIR)/deltacmd.o -c $(OBJDIR)/deltacmd_.c
  1509   1505   
  1510   1506   $(OBJDIR)/deltacmd.h:	$(OBJDIR)/headers
  1511   1507   
  1512         -$(OBJDIR)/deltafunc_.c:	$(SRCDIR)/deltafunc.c $(TRANSLATE)
  1513         -	$(TRANSLATE) $(SRCDIR)/deltafunc.c >$@
  1514         -
  1515         -$(OBJDIR)/deltafunc.o:	$(OBJDIR)/deltafunc_.c $(OBJDIR)/deltafunc.h $(SRCDIR)/config.h
  1516         -	$(XTCC) -o $(OBJDIR)/deltafunc.o -c $(OBJDIR)/deltafunc_.c
  1517         -
  1518         -$(OBJDIR)/deltafunc.h:	$(OBJDIR)/headers
  1519         -
  1520   1508   $(OBJDIR)/descendants_.c:	$(SRCDIR)/descendants.c $(TRANSLATE)
  1521   1509   	$(TRANSLATE) $(SRCDIR)/descendants.c >$@
  1522   1510   
  1523   1511   $(OBJDIR)/descendants.o:	$(OBJDIR)/descendants_.c $(OBJDIR)/descendants.h $(SRCDIR)/config.h
  1524   1512   	$(XTCC) -o $(OBJDIR)/descendants.o -c $(OBJDIR)/descendants_.c
  1525   1513   
  1526   1514   $(OBJDIR)/descendants.h:	$(OBJDIR)/headers

Changes to win/Makefile.mingw.mistachkin.

   172    172   endif
   173    173   
   174    174   #### The directories where the OpenSSL include and library files are located.
   175    175   #    The recommended usage here is to use the Sysinternals junction tool
   176    176   #    to create a hard link between an "openssl-1.x" sub-directory of the
   177    177   #    Fossil source code directory and the target OpenSSL source directory.
   178    178   #
   179         -OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2r
          179  +OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2q
   180    180   OPENSSLINCDIR = $(OPENSSLDIR)/include
   181    181   OPENSSLLIBDIR = $(OPENSSLDIR)
   182    182   
   183    183   #### Either the directory where the Tcl library is installed or the Tcl
   184    184   #    source code directory resides (depending on the value of the macro
   185    185   #    FOSSIL_TCL_SOURCE).  If this points to the Tcl install directory,
   186    186   #    this directory must have "include" and "lib" sub-directories.  If
................................................................................
   461    461     $(SRCDIR)/comformat.c \
   462    462     $(SRCDIR)/configure.c \
   463    463     $(SRCDIR)/content.c \
   464    464     $(SRCDIR)/cookies.c \
   465    465     $(SRCDIR)/db.c \
   466    466     $(SRCDIR)/delta.c \
   467    467     $(SRCDIR)/deltacmd.c \
   468         -  $(SRCDIR)/deltafunc.c \
   469    468     $(SRCDIR)/descendants.c \
   470    469     $(SRCDIR)/diff.c \
   471    470     $(SRCDIR)/diffcmd.c \
   472    471     $(SRCDIR)/dispatch.c \
   473    472     $(SRCDIR)/doc.c \
   474    473     $(SRCDIR)/encode.c \
   475    474     $(SRCDIR)/etag.c \
................................................................................
   673    672     $(OBJDIR)/comformat_.c \
   674    673     $(OBJDIR)/configure_.c \
   675    674     $(OBJDIR)/content_.c \
   676    675     $(OBJDIR)/cookies_.c \
   677    676     $(OBJDIR)/db_.c \
   678    677     $(OBJDIR)/delta_.c \
   679    678     $(OBJDIR)/deltacmd_.c \
   680         -  $(OBJDIR)/deltafunc_.c \
   681    679     $(OBJDIR)/descendants_.c \
   682    680     $(OBJDIR)/diff_.c \
   683    681     $(OBJDIR)/diffcmd_.c \
   684    682     $(OBJDIR)/dispatch_.c \
   685    683     $(OBJDIR)/doc_.c \
   686    684     $(OBJDIR)/encode_.c \
   687    685     $(OBJDIR)/etag_.c \
................................................................................
   812    810    $(OBJDIR)/comformat.o \
   813    811    $(OBJDIR)/configure.o \
   814    812    $(OBJDIR)/content.o \
   815    813    $(OBJDIR)/cookies.o \
   816    814    $(OBJDIR)/db.o \
   817    815    $(OBJDIR)/delta.o \
   818    816    $(OBJDIR)/deltacmd.o \
   819         - $(OBJDIR)/deltafunc.o \
   820    817    $(OBJDIR)/descendants.o \
   821    818    $(OBJDIR)/diff.o \
   822    819    $(OBJDIR)/diffcmd.o \
   823    820    $(OBJDIR)/dispatch.o \
   824    821    $(OBJDIR)/doc.o \
   825    822    $(OBJDIR)/encode.o \
   826    823    $(OBJDIR)/etag.o \
................................................................................
  1170   1167   		$(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h \
  1171   1168   		$(OBJDIR)/configure_.c:$(OBJDIR)/configure.h \
  1172   1169   		$(OBJDIR)/content_.c:$(OBJDIR)/content.h \
  1173   1170   		$(OBJDIR)/cookies_.c:$(OBJDIR)/cookies.h \
  1174   1171   		$(OBJDIR)/db_.c:$(OBJDIR)/db.h \
  1175   1172   		$(OBJDIR)/delta_.c:$(OBJDIR)/delta.h \
  1176   1173   		$(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h \
  1177         -		$(OBJDIR)/deltafunc_.c:$(OBJDIR)/deltafunc.h \
  1178   1174   		$(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h \
  1179   1175   		$(OBJDIR)/diff_.c:$(OBJDIR)/diff.h \
  1180   1176   		$(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h \
  1181   1177   		$(OBJDIR)/dispatch_.c:$(OBJDIR)/dispatch.h \
  1182   1178   		$(OBJDIR)/doc_.c:$(OBJDIR)/doc.h \
  1183   1179   		$(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
  1184   1180   		$(OBJDIR)/etag_.c:$(OBJDIR)/etag.h \
................................................................................
  1505   1501   	$(TRANSLATE) $(SRCDIR)/deltacmd.c >$@
  1506   1502   
  1507   1503   $(OBJDIR)/deltacmd.o:	$(OBJDIR)/deltacmd_.c $(OBJDIR)/deltacmd.h $(SRCDIR)/config.h
  1508   1504   	$(XTCC) -o $(OBJDIR)/deltacmd.o -c $(OBJDIR)/deltacmd_.c
  1509   1505   
  1510   1506   $(OBJDIR)/deltacmd.h:	$(OBJDIR)/headers
  1511   1507   
  1512         -$(OBJDIR)/deltafunc_.c:	$(SRCDIR)/deltafunc.c $(TRANSLATE)
  1513         -	$(TRANSLATE) $(SRCDIR)/deltafunc.c >$@
  1514         -
  1515         -$(OBJDIR)/deltafunc.o:	$(OBJDIR)/deltafunc_.c $(OBJDIR)/deltafunc.h $(SRCDIR)/config.h
  1516         -	$(XTCC) -o $(OBJDIR)/deltafunc.o -c $(OBJDIR)/deltafunc_.c
  1517         -
  1518         -$(OBJDIR)/deltafunc.h:	$(OBJDIR)/headers
  1519         -
  1520   1508   $(OBJDIR)/descendants_.c:	$(SRCDIR)/descendants.c $(TRANSLATE)
  1521   1509   	$(TRANSLATE) $(SRCDIR)/descendants.c >$@
  1522   1510   
  1523   1511   $(OBJDIR)/descendants.o:	$(OBJDIR)/descendants_.c $(OBJDIR)/descendants.h $(SRCDIR)/config.h
  1524   1512   	$(XTCC) -o $(OBJDIR)/descendants.o -c $(OBJDIR)/descendants_.c
  1525   1513   
  1526   1514   $(OBJDIR)/descendants.h:	$(OBJDIR)/headers

Changes to win/Makefile.msc.

    96     96   
    97     97   # Enable support for the SQLite Encryption Extension?
    98     98   !ifndef USE_SEE
    99     99   USE_SEE = 0
   100    100   !endif
   101    101   
   102    102   !if $(FOSSIL_ENABLE_SSL)!=0
   103         -SSLDIR    = $(B)\compat\openssl-1.0.2r
          103  +SSLDIR    = $(B)\compat\openssl-1.0.2q
   104    104   SSLINCDIR = $(SSLDIR)\inc32
   105    105   !if $(FOSSIL_DYNAMIC_BUILD)!=0
   106    106   SSLLIBDIR = $(SSLDIR)\out32dll
   107    107   !else
   108    108   SSLLIBDIR = $(SSLDIR)\out32
   109    109   !endif
   110    110   SSLLFLAGS = /nologo /opt:ref /debug
................................................................................
   401    401           comformat_.c \
   402    402           configure_.c \
   403    403           content_.c \
   404    404           cookies_.c \
   405    405           db_.c \
   406    406           delta_.c \
   407    407           deltacmd_.c \
   408         -        deltafunc_.c \
   409    408           descendants_.c \
   410    409           diff_.c \
   411    410           diffcmd_.c \
   412    411           dispatch_.c \
   413    412           doc_.c \
   414    413           encode_.c \
   415    414           etag_.c \
................................................................................
   612    611           $(OX)\configure$O \
   613    612           $(OX)\content$O \
   614    613           $(OX)\cookies$O \
   615    614           $(OX)\cson_amalgamation$O \
   616    615           $(OX)\db$O \
   617    616           $(OX)\delta$O \
   618    617           $(OX)\deltacmd$O \
   619         -        $(OX)\deltafunc$O \
   620    618           $(OX)\descendants$O \
   621    619           $(OX)\diff$O \
   622    620           $(OX)\diffcmd$O \
   623    621           $(OX)\dispatch$O \
   624    622           $(OX)\doc$O \
   625    623           $(OX)\encode$O \
   626    624           $(OX)\etag$O \
................................................................................
   814    812   	echo $(OX)\configure.obj >> $@
   815    813   	echo $(OX)\content.obj >> $@
   816    814   	echo $(OX)\cookies.obj >> $@
   817    815   	echo $(OX)\cson_amalgamation.obj >> $@
   818    816   	echo $(OX)\db.obj >> $@
   819    817   	echo $(OX)\delta.obj >> $@
   820    818   	echo $(OX)\deltacmd.obj >> $@
   821         -	echo $(OX)\deltafunc.obj >> $@
   822    819   	echo $(OX)\descendants.obj >> $@
   823    820   	echo $(OX)\diff.obj >> $@
   824    821   	echo $(OX)\diffcmd.obj >> $@
   825    822   	echo $(OX)\dispatch.obj >> $@
   826    823   	echo $(OX)\doc.obj >> $@
   827    824   	echo $(OX)\encode.obj >> $@
   828    825   	echo $(OX)\etag.obj >> $@
................................................................................
  1209   1206   
  1210   1207   $(OX)\deltacmd$O : deltacmd_.c deltacmd.h
  1211   1208   	$(TCC) /Fo$@ -c deltacmd_.c
  1212   1209   
  1213   1210   deltacmd_.c : $(SRCDIR)\deltacmd.c
  1214   1211   	translate$E $** > $@
  1215   1212   
  1216         -$(OX)\deltafunc$O : deltafunc_.c deltafunc.h
  1217         -	$(TCC) /Fo$@ -c deltafunc_.c
  1218         -
  1219         -deltafunc_.c : $(SRCDIR)\deltafunc.c
  1220         -	translate$E $** > $@
  1221         -
  1222   1213   $(OX)\descendants$O : descendants_.c descendants.h
  1223   1214   	$(TCC) /Fo$@ -c descendants_.c
  1224   1215   
  1225   1216   descendants_.c : $(SRCDIR)\descendants.c
  1226   1217   	translate$E $** > $@
  1227   1218   
  1228   1219   $(OX)\diff$O : diff_.c diff.h
................................................................................
  1900   1891   			comformat_.c:comformat.h \
  1901   1892   			configure_.c:configure.h \
  1902   1893   			content_.c:content.h \
  1903   1894   			cookies_.c:cookies.h \
  1904   1895   			db_.c:db.h \
  1905   1896   			delta_.c:delta.h \
  1906   1897   			deltacmd_.c:deltacmd.h \
  1907         -			deltafunc_.c:deltafunc.h \
  1908   1898   			descendants_.c:descendants.h \
  1909   1899   			diff_.c:diff.h \
  1910   1900   			diffcmd_.c:diffcmd.h \
  1911   1901   			dispatch_.c:dispatch.h \
  1912   1902   			doc_.c:doc.h \
  1913   1903   			encode_.c:encode.h \
  1914   1904   			etag_.c:etag.h \

Changes to www/admin-v-setup.md.

     1      1   # The Differences Between the Setup and Admin User Capabilities
     2      2   
     3      3   Several of the Fossil user capabilities form a clear power hierarchy.
     4      4   Mathematically speaking:
     5      5   
     6      6   > *Setup > Admin > Moderator > User > Subscriber > Anonymous > Nobody*
     7         -
            7  +    
     8      8   This document explains the distinction between the first two. For the
     9      9   others, see:
    10     10   
    11     11   * [How Moderation Works](./forum.wiki#moderation)
    12     12   
    13     13   * [Users vs Subscribers](./alerts.md#uvs)
    14     14   
................................................................................
   283    283           to 0 to Setup only while allowing Admin-only users to change it
   284    284           from 0 to 1. Fossil doesn't currently allow that.</p>
   285    285   
   286    286       *   <p><b>Risky</b>: The <tt>https-login</tt> setting falls under
   287    287           the "Security" section above, but it should probably never be
   288    288           adjusted by Admin-only users. Sites that want it on will never
   289    289           want it to be disabled without a very good reason.</p>
   290         -
          290  +        
   291    291           <p>There is also an inverse risk: if the site has a front-end
   292    292           HTTPS proxy that uses HTTP to communicate over localhost to
   293    293           Fossil, enabling this setting will create an infinite redirect
   294    294           loop! (Ask me how I know.)</p>
   295    295   
   296    296       *   <p><b>Dangerous</b>: The <tt>email-send-command</tt> setting
   297    297           could allow a rogue Admin to run arbitrary commands on the host

Changes to www/backoffice.md.

     1      1   Backoffice
     2      2   ==========
     3      3   
     4      4   This is technical documentation about the internal workings of Fossil.
     5      5   Ordinary Fossil users do not need to know about anything covered by this
     6      6   document.  The information here is intended for people who want to enhance
     7         -or extend the Fossil code, or who just want a deeper understanding of
            7  +or extend the Fossil code, or who just want a deeper understanding of 
     8      8   the internal workings of Fossil.
     9      9   
    10     10   What Is The Backoffice
    11     11   ----------------------
    12     12   
    13         -The backoffice is a mechanism used by a
           13  +The backoffice is a mechanism used by a 
    14     14   [Fossil server](/doc/trunk/www/server.wiki) to do low-priority
    15     15   background work that is not directly related to the user interface.  Here
    16     16   are some examples of the kinds of work that backoffice performs:
    17     17   
    18     18     1.  Sending email alerts and notifications
    19     19     2.  Sending out daily digests of email notifications
    20     20     3.  Other background email handling chores
................................................................................
    47     47   request.
    48     48   
    49     49   The backoffice is not a daemon.  Each backoffice process runs for a short
    50     50   while and then exits.  This helps keep Fossil easy to manage, since there
    51     51   are no daemons to start and stop.  To upgrade Fossil to a new version,
    52     52   you simply replace the older "fossil" executable with the newer one, and
    53     53   the backoffice processes will (within a minute or so) start using the new
    54         -one.  (Upgrading the executable on Windows is more complicated, since on
    55         -Windows it is not possible to replace an executable file that is in active
           54  +one.  (Upgrading the executable on Windows is more complicated, since on 
           55  +Windows it is not possible to replace an executable file that is in active 
    56     56   use.  But Windows users probably already know this.)
    57     57   
    58     58   The backoffice is serialized and rate limited.  No more than a single
    59     59   backoffice process will be running at once, and backoffice runs will not
    60     60   occur more frequently than once every 60 seconds.
    61     61   
    62     62   If a Fossil server is idle, then no backoffice processes will be running.
    63         -That means there are no extra processes sitting around taking up memory
           63  +That means there are no extra processes sitting around taking up memory 
    64     64   and process table slots for seldom accessed repositories.
    65     65   The backoffice is an on-demand system.
    66     66   A busy repository will usually have a backoffice
    67     67   running at all times.  But an infrequently accessed repository will only have
    68     68   backoffice processes running for a minute or two following the most recent
    69     69   access.
    70     70   
................................................................................
    75     75   However, the daily digest of email notifications is handled by the
    76     76   backoffice.  If a Fossil server can sometimes go more than a day without
    77     77   being accessed, then the automatic backoffice will never run, and the
    78     78   daily digest might not go out until somebody does visit a webpage.
    79     79   If this is a problem, an adminstrator can set up a cron job to
    80     80   periodically run:
    81     81   
    82         ->   fossil backoffice _REPOSITORY_
           82  +>   fossil backoffice -R _REPOSITORY_
    83     83   
    84     84   That command will cause backoffice processing to occur immediately.
    85     85   Note that this is almost never necessary for an internet-facing
    86     86   Fossil repository, since most repositories will get multiple accesses
    87     87   per day from random robots, which will be sufficient to kick off the
    88     88   daily digest emails.  And even for a private server, if there is very
    89     89   little traffic, then the daily digests are probably a no-op anyhow
................................................................................
   116    116   >  fossil test-backoffice-lease -R _REPOSITORY_
   117    117   
   118    118   If a system has been idle for a long time, then there will be no
   119    119   backoffice processes.  (Either the process id entries in the lease
   120    120   will be zero, or there will exist no process associated with the
   121    121   process id.) When a new web request comes in, the system
   122    122   sees that no backoffice process is active and so it kicks off a separate
   123         -process to run backoffice.
          123  +process to run backoffice.  
   124    124   
   125         -The new backoffice process becomes the "current" process.  It sets a
          125  +The new backoffice process becomes the "current" process.  It sets a 
   126    126   lease expiration time for itself to be 60 seconds in the future.
   127    127   Then it does the backoffice processing and exits.  Note that usually
   128    128   the backoffice process will exit long before its lease expires.  That
   129    129   is ok.  The lease is there to limit the rate at which backoffice processes
   130    130   run.
   131    131   
   132    132   If a new backoffice process starts up and sees that the "current" lease has
................................................................................
   178    178   can be fixed.  The "backoffice-logfile" setting is the name of a log
   179    179   file onto which is appended a short message everything a backoffice
   180    180   process actually starts to do the backoffice work.  This log file can
   181    181   be used to verify that backoffice really is running, if there is any
   182    182   doubt.  The "backoffice-disable" setting prevents automatic backoffice
   183    183   processing, if true.  Use this to completely disable backoffice processing
   184    184   that occurs automatically after each HTTP request.  The "backoffice-disable"
   185         -setting does not affect the operation of the manual
          185  +setting does not affect the operation of the manual 
   186    186   "fossil backoffice" command.
   187    187   Most installations should leave "backoffice-nodelay" and "backoffice-disable"
   188    188   set to their default values of off and
   189    189   leave "backoffice-logfile" unset or set to an empty string.

Changes to www/blockchain.md.

    18     18   
    19     19   Some people have come to associate blockchain with cryptocurrency, however,
    20     20   and since Fossil has nothing to do with cryptocurrency, the claim that
    21     21   Fossil is build around blockchain is met with skepticism.  The key thing
    22     22   to note here is that cryptocurrency implementations like BitCoin are
    23     23   built around blockchain, but they are not synonymous with blockchain.
    24     24   Blockchain is a much broader concept.  Blockchain is a mechanism for
    25         -constructed a distributed ledger of transactions.
           25  +constructed a distributed ledger of transactions.  
    26     26   Yes, you can use a distributed
    27     27   ledger to implement a cryptocurrency, but you can also use a distributed
    28     28   ledger to implement a version control system, and probably many other kinds
    29     29   of applications as well.  Blockchain is a much broader idea than
    30     30   cryptocurrency.
    31     31   
    32     32   [(1)]: https://en.wikipedia.org/wiki/Blockchain

Changes to www/build.wiki.

    71     71   <h2>2.0 Compiling</h2>
    72     72   
    73     73   <ol>
    74     74   <li value="5">
    75     75   <p>Unpack the ZIP or tarball you downloaded then
    76     76   <b>cd</b> into the directory created.</p></li>
    77     77   
    78         -<li><i>(Optional, Debian-compatible Linux only)</i>
    79         -Make sure you have all the necessary tools and libraries at hand by running:
    80         -<b>sudo apt install tcl-dev tk libssl-dev</b>.
    81         -
    82     78   <li><i>(Optional, Unix only)</i>
    83     79   Run <b>./configure</b> to construct a makefile.
    84     80   
    85     81   <ol type="a">
    86     82   <li><p>
    87     83   The build system for Fossil on Unix-like systems assumes that the
    88     84   OpenSSL development and runtime files are available on your system,
................................................................................
   159    155   file "<b>win\buildmsvc.bat</b>" may be used and it will attempt to
   160    156   detect and use the latest installed version of MSVC.<br><br>To enable
   161    157   the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
   162    158   first <a href="https://www.openssl.org/source/">download the official
   163    159   source code for OpenSSL</a> and extract it to an appropriately named
   164    160   "<b>openssl-X.Y.ZA</b>" subdirectory within the local
   165    161   [/tree?ci=trunk&name=compat | compat] directory (e.g.
   166         -"<b>compat/openssl-1.0.2r</b>"), then make sure that some recent
          162  +"<b>compat/openssl-1.0.2q</b>"), then make sure that some recent
   167    163   <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
   168    164   and finally run one of the following commands:
   169    165   <blockquote><pre>
   170    166   nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
   171    167   </pre></blockquote>
   172    168   <blockquote><pre>
   173    169   buildmsvc.bat FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
................................................................................
   188    184   "openssl-devel" packages installed first.
   189    185   </ol>
   190    186   </ol>
   191    187   
   192    188   <h2>3.0 Installing</h2>
   193    189   
   194    190   <ol>
   195         -<li value="9">
          191  +<li value="8">
   196    192   <p>The finished binary is named "fossil" (or "fossil.exe" on Windows).
   197    193   Put this binary in a
   198    194   directory that is somewhere on your PATH environment variable.
   199    195   It does not matter where.</p>
   200    196   
   201    197   <li>
   202    198   <p><b>(Optional:)</b>

Changes to www/changes.wiki.

     1      1   <title>Change Log</title>
     2      2   
     3         -<a name='v2_9'></a>
     4         -<h2>Changes for Version 2.9 (pending)</h2>
     5         -
     6         -  *  Added the [/help?cmd=git|fossil git export] command and instructions
     7         -     for [./mirrortogithub.md|creating a GitHub mirror of a Fossil project].
     8         -  *  Improved handling of relative hyperlinks on the
     9         -     [/help?cmd=/artifact|/artifact] pages for wiki. For example,
    10         -     hyperlinks and the lizard &lt;img&gt; now work correctly
    11         -     for both [/artifact/2ff24ab0887cf522] and
    12         -     [/doc/0d7ac90d575004c2415/www/index.wiki].
    13         -  *  For the "[/help?cmd=update|fossil update]" and
    14         -     "[/help?cmd=checkout|fossil checkout]" commands, if a
    15         -     managed file is removed because it is no longer part of the target
    16         -     check-in and the directory containing the file is empty after the
    17         -     file is removed and the directory is not the current working
    18         -     directory and is not on the [/help?cmd=empty-dirs|empty-dirs]
    19         -     list, then also remove the directory.
    20         -  *  Update internal Unicode character tables, used in regular expression
    21         -     handling, from version 11.0 to 12.0.
    22         -  *  In "[/help?cmd=regexp|fossil regexp]", "[/help?cmd=grep|fossil grep]"
    23         -     and the TH1 "regexp" command, the -nocase option now removes multiple
    24         -     diacritics from the same character (derived from SQLite's
    25         -     remove_diacritics=2)
    26         -
    27      3   <a name='v2_8'></a>
    28      4   <h2>Changes for Version 2.8 (2019-02-20)</h2>
    29      5   
    30      6     *  Show cherry-pick merges as dotted lines on the timeline graph.
    31      7        &rarr; The "fossil rebuild" command must be run to create and
    32         -     populate the new "cherrypick" table in the repository in order
            8  +     populate the new "cherrypick" table in the repository in order 
    33      9        for this feature to operate.
    34     10     *  Add the ability to associate branches, check-ins, and tags with
    35     11        specially-named Wiki pages. This gives the ability to better
    36     12        document branches and tags, and provide more documentation on
    37     13        check-ins beyond the check-in comment.  The associated Wiki is
    38     14        automatically displayed on /info pages for check-ins, and on
    39         -     /timeline?r=BRANCH and /timeline?t=TAG pages for branches and
           15  +     /timeline?r=BRANCH and /timeline?t=TAG pages for branches and 
    40     16        tags. This feature is on by default, but can be disabled in on
    41     17        the Admin/Wiki page.
    42     18     *  Enhance the repository list page (shown for example by
    43     19        "fossil all ui") so that it shows the name and last check-in
    44     20        time for each project.  The implementation of the repository
    45     21        list page is now broken out into a separate source file (repolist.c).
    46     22     *  Allow users with Forum Supervisor permission ('6') to add Forum
................................................................................
    68     44        version of the Wiki page named in the timeline, not to the latest
    69     45        version.
    70     46     *  Enhancements to the "amend", "tag", and "reparent" commands, including
    71     47        adding options --override-date, --override-user, and --dry-run.
    72     48     *  Add the global --comment-format command-line option and the
    73     49        comment-format setting to control the display of the command-line
    74     50        timeline.
    75         -  *  Change the "fossil reparent" command so that it only works from
           51  +  *  Change the "fossil reparent" command so that it only works from 
    76     52        within an active checkout.
    77     53     *  On the /setup_ucap_list, show administrators how many users have
    78     54        each capability.  The counts are a hyperlink to the /setup_ulist
    79     55        page showing the subset of users that have that capability.
    80     56     *  Provide the ability to redirect all HTTP pages to HTTPS.  Formerly
    81     57        one could cause this to occur for the /login page only.  That option
    82     58        still exists, but the redirect can now also be done for all pages.
................................................................................
   103     79        Formerly, user capabilities were letters from &#91;a-z&#93;, but with the
   104     80        enhancements, the supply of lower case letters was exhausted.
   105     81        User capabilities are now letters in &#91;a-zA-Z0-9&#93;.
   106     82     *  The built-in skins are now responsive, providing better layout on
   107     83        small screens, including mobile devices.
   108     84     *  The default skin now includes a hamburger menu that is generated
   109     85        by the [/sitemap] page.
   110         -  *  All of the built-in skins now use a
           86  +  *  All of the built-in skins now use a 
   111     87        [https://en.wikipedia.org/wiki/Content_Security_Policy|Content Security Policy (CSP)]
   112     88        to help prevent cross-site injection and forgery attacks.  There are no known
   113     89        vulnerabilities in Fossil.  The added CSP does not fix anything; it merely adds
   114     90        another layer of defense.
   115     91     *  The [/sitemap] and other list pages show as multiple columns if
   116     92        the viewing window is wide enough.
   117     93     *  There is an optional "js" file for each skin that can be used to

Changes to www/delta_format.wiki.

     1      1   <title>Fossil Delta Format</title>
     2         -<h1>1.0 Overview</h1>
            2  +<nowiki>
            3  +<h2>Abstract</h2>
     3      4   
     4      5   <p>Fossil achieves efficient storage and low-bandwidth synchronization
     5      6   through the use of delta-compression.  Instead of storing
     6         -or transmitting the complete content of an artifact, Fossil stores or
            7  +or transmitting the complete content of an artifact, fossil stores or
     7      8   transmits only the changes relative to a related artifact.
     8      9   </p>
     9     10   
    10         -<p>This document describes the delta-encoding format used by Fossil.
           11  +<p>This document describes the delta-encoding format used by fossil.
    11     12   The intended audience is developers working on either
    12         -<a href="index.wiki">Fossil</a> itself, or on tools compatible with
    13         -Fossil. Understanding of this document is <em>not</em> required for
    14         -ordinary users of Fossil.  This document is an implementation detail.</p>
    15         -
    16         -<p>This document only describes the delta file format.  A 
    17         -[./delta_encoder_algorithm.wiki|separate document] describes one possible
    18         -algorithm for generating deltas in this format.</p>
    19         -
    20         -<h2>1.1 Sample Software And Analysis Tools</h2>
    21         -
    22         -<p>The core routines used to generate and apply deltas in this format
    23         -are contained in the [../src/delta.c|delta.c] source file.  Interface
    24         -logic, including "test-*" commands to directly manipulate deltas are
    25         -contained in the [../src/deltacmd.c|deltacmd.c] source file.  SQL functions
    26         -to create, apply, and analyze deltas are implemented by code in the
    27         -[../src/deltafunc.c|deltafunc.c] source file.
    28         -
    29         -<p>The following command-line tools are available to create and apply
    30         -deltas and to test the delta logic:
    31         -
    32         -   *   [/help?cmd=test-delta|fossil test-delta] &rarr; Run self-tests of
    33         -       the delta logic
    34         -
    35         -   *   [/help?cmd=test-delta-create|fossil test-delta-create X Y] &rarr; compute
    36         -       a delta that converts file X into file Y.  Output that delta.
    37         -
    38         -   *   [/help?cmd=test-delta-apply|fossil test-delta-apply X D] &rarr; apply
    39         -       delta D to input file X and output the result.
    40         -
    41         -   *   [/help?cmd=test-delta-analyze|fossil test-delta-analyze X Y] &rarr; compute
    42         -       and delta that converts file X into file Y but instead of writing the
    43         -       delta to output, write performance information about the delta.
    44         -
    45         -<p>When running the [/help?cmd=sqlite3|fossil sql] command to get an
    46         -interactive SQL session connected to the repository, the following
    47         -additional SQL functions are provided:
    48         -
    49         -   *   <b>delta_create(</b><i>X</i><b>,</b><i>Y</i><b>)</b> &rarr;
    50         -       Compute a data that carries blob X into blob Y and return that delta
    51         -       as a blob.
    52         -
    53         -   *   <b>delta_apply(</b><i>X</i><b>,</b><i>D</i><b>)</b> &rarr;
    54         -       Apply delta D to input blob X return a new blob which is the result.
    55         -
    56         -
    57         -   *   <b>delta_output_size(</b><i>D</i>)</b> &rarr;
    58         -       Return the size of the output that would result from applying delta D.
    59         -
    60         -   *   <b>delta_parse(</b><i>D</i>)</b> &rarr; This is a table-valued function
    61         -       that returns one row for the header, for the trailer, and for each segment
    62         -       in delta D.
    63         -
    64         -
    65         -<a name="structure"></a><h1>2.0 Structure</h1>
           13  +<a href="index.wiki">fossil</a> itself, or on tools compatible with
           14  +fossil.</p>
           15  +
           16  +<p>Note that the delta-encoding is not a fundamental element of the
           17  +state of a fossil repository.  A state of a fossil repository is
           18  +defined by the uncompressed and undeltaed content of all artifacts.
           19  +The fact the artifacts
           20  +are stored on disk using this delta-encoding format is merely an
           21  +optimization.  One could, in theory, create an entirely new and
           22  +compatible implementation of fossil that used a different delta-encoding
           23  +or did no delta-encoding at all.  However, experience has shown that
           24  +the delta-encoding described here is both efficient to compute and
           25  +results in very small deltas, so its continued use is recommended.</p>
           26  +
           27  +<a name="structure"></a><h2>1.0 Structure</h2>
    66     28   <img src="delta1.gif" align="left" hspace="10">
    67     29   
    68     30   <p>A delta consists of three parts, a "header", a "trailer", and a
    69     31   "segment-list" between them.</p>
    70     32   
    71     33   <p>Both header and trailer provide information about the target
    72     34   helping the decoder, and the segment-list describes how the target can
    73     35   be constructed from the original.</p>
    74     36   
    75         -<a name="header"></a><h2>2.1 Header</h2>
           37  +<a name="header"></a><h3>1.1 Header</h3>
    76     38   <img src="delta6.gif" align="left" hspace="10">
    77     39   
    78     40   <p>The header consists of a single number followed by a newline
    79     41   character (ASCII 0x0a). The number is the length of the target in
    80     42   bytes.</p>
    81     43   
    82     44   <p>This means that, given a delta, the decoder can compute the size of
    83     45   the target (and allocate any necessary memory based on that) by simply
    84     46   reading the first line of the delta and decoding the number found
    85     47   there. In other words, before it has to decode everything else.</p>
    86     48   
    87         -<a name="trailer"></a><h2>2.2 Trailer</h2>
           49  +<a name="trailer"></a><h3>1.2 Trailer</h3>
    88     50   <img src="delta5.gif" align="left" hspace="10">
    89     51   
    90     52   <p>The trailer consists of a single number followed by a semicolon (ASCII
    91     53   0x3b). This number is a checksum of the target and can be used by a
    92     54   decoder to verify that the delta applied correctly, reconstructing the
    93     55   target from the original.</p>
    94     56   
................................................................................
    97     59   2^32-1. A target whose length is not a multiple of 4 is padded with
    98     60   0-bytes (ASCII 0x00) at the end.</p>
    99     61   
   100     62   <p>By putting this information at the end of the delta a decoder has
   101     63   it available immediately after the target has been reconstructed
   102     64   fully.</p>
   103     65   
   104         -<a name="slist"></a><h2>2.3 Segment-List</h2>
           66  +<a name="slist"></a><h3>1.3 Segment-List</h3>
   105     67   <img src="delta2.gif" align="left" hspace="10">
   106     68   
   107     69   <p>The segment-list of a delta describes how to create the target from
   108     70   the original by a combination of inserting literal byte-sequences and
   109     71   copying ranges of bytes from the original. This is where the
   110     72   compression takes place, by encoding the large common parts of
   111     73   original and target in small copy instructions.</p>
   112     74   
   113     75   <p>The target is constructed from beginning to end, with the data
   114     76   generated by each instruction appended after the data of all previous
   115     77   instructions, with no gaps.</p>
   116     78   
   117         -<a name="insertlit"></a><h3>2.3.1 Insert Literal</h3>
           79  +<a name="insertlit"></a><h4>1.3.1 Insert Literal</h4>
   118     80   
   119     81   <p>A literal is specified by two elements, the size of the literal in
   120     82   bytes, and the bytes of the literal itself.</p>
   121     83   
   122     84   <img src="delta4.gif" align="left" hspace="10">
   123     85   <p>The length is written first, followed by a colon character (ASCII
   124     86   0x3a), followed by the bytes of the literal.</p>
   125     87   
   126         -<a name="copyrange"></a><h3>2.3.2 Copy Range</h3>
           88  +<a name="copyrange"></a><h4>1.3.2 Copy Range</h4>
   127     89   
   128     90   <p>A range to copy is specified by two numbers, the offset of the
   129     91   first byte in the original to copy, and the size of the range, in
   130     92   bytes. The size zero is special, its usage indicates that the range
   131     93   extends to the end of the original.</p>
   132     94   
   133     95   <img src="delta3.gif" align="left" hspace="10">
   134     96   <p>The length is written first, followed by an "at" character (ASCII
   135     97   0x40), then the offset, followed by a comma (ASCII 0x2c).</p>
   136     98   
   137         -<a name="intcoding"></a><h1>3.0 Encoding of integers</h1>
           99  +<a name="intcoding"></a><h2>2.0 Encoding of integers</h2>
   138    100   
   139    101   <p>
   140    102   The format currently handles only 32 bit integer numbers. They are
   141    103   written base-64 encoded, MSB first, and without leading
   142    104   "0"-characters, except if they are significant (i.e. 0 => "0").
   143    105   </p>
   144    106   
   145    107   <p>
   146    108   The base-64 coding is described in
   147    109   <a href="http://www.ietf.org/rfc/rfc3548.txt">RFC 3548</a>.
   148    110   </p>
   149    111   
   150         -<a name="examples"></a><h1>4.0 Examples</h1>
          112  +<a name="examples"></a><h2>3.0 Examples</h2>
   151    113   
   152         -<a name="examplesint"></a><h2>4.1 Integer encoding</h2>
          114  +<a name="examplesint"></a><h3>3.1 Integer encoding</h3>
   153    115   
   154    116   <table border=1>
   155    117   <tr>
   156    118   <th>Value</th>
   157    119   <th>Encoding</th>
   158    120   </tr>
   159    121   <tr>
................................................................................
   166    128   </tr>
   167    129   <tr>
   168    130   <td>-1101438770</td>
   169    131   <td>2zMM3E</td>
   170    132   </tr>
   171    133   </table>
   172    134   
   173         -<a name="examplesdelta"></a><h2>4.2 Delta encoding</h2>
          135  +<a name="examplesdelta"></a><h3>3.2 Delta encoding</h3>
   174    136   
   175    137   <p>An example of a delta using the specified encoding is:</p>
   176    138   
   177    139   <table border=1><tr><td><pre>
   178    140   1Xb
   179    141   4E@0,2:thFN@4C,6:scenda1B@Jd,6:scenda5x@Kt,6:pieces79@Qt,F: Example: eskil~E@Y0,2zMM3E;</pre>
   180    142   </td></tr></table>
................................................................................
   242    204   
   243    205     *  Ticketing interface (expand this bullet)
   244    206   
   245    207   </pre></td></tr></table>
   246    208   
   247    209   
   248    210   
   249         -<a name="notes"></a><h1>Notes</h1>
          211  +<a name="notes"></a><h2>Notes</h2>
   250    212   
   251    213   <ul>
   252    214   <li>Pure text files generate a pure text delta.
   253    215   </li>
   254    216   <li>Binary files generate a delta that may contain some binary data.
   255    217   </li>
   256    218   <li>The delta encoding does not attempt to compress the content.
   257    219   It was considered to be much
   258    220   more sensible to do compression using a separate general-purpose
   259    221   compression library, like <a href="http://www.zlib.net">zlib</a>.
   260    222   </li>
   261    223   </ul>

Changes to www/env-opts.md.

    29     29   global setting should be used to force the case sensitivity to the
    30     30   most sensible condition.
    31     31   
    32     32   `--chdir DIRECTORY`: Change to the named directory before processing
    33     33   any commands.
    34     34   
    35     35   
    36         -`--comfmtflags NUMBER`
           36  +`--comfmtflags NUMBER`  
    37     37   `--comment-format NUMBER`: Specify flags that control how check-in comments
    38     38   and certain other text outputs are formatted for display. The flags are
    39     39   individual bits in `NUMBER`, which must be specified in base 10:
    40     40   
    41     41     * _0_ &mdash; Uses the revised algorithm with no special handling.
    42     42   
    43     43     * _1_ &mdash; Uses the legacy algorithm, other flags are ignored.

Changes to www/fileformat.wiki.

   527    527   [#wikichng | wiki artifact].
   528    528   
   529    529   The <b>Z</b> card is the required checksum over the rest of the artifact.
   530    530   
   531    531   <a name="forum"></a>
   532    532   <h3>2.8 Forum Posts</h3>
   533    533   
   534         -Forum posts are intended as a mechanism for users and developers to
          534  +Forum posts are intended as a mechanism for users and developers to 
   535    535   discuss a project.  Forum posts are like messages on a mailing list.
   536    536   
   537    537   The following cards are allowed on an forum post artifact:
   538    538   
   539    539   <blockquote>
   540    540   <b>D</b> <i>time-and-date-stamp</i><br />
   541    541   <b>G</b> <i>thread-root</i><br />
................................................................................
   545    545   <b>P</b> <i>parent-artifact-id</i><br />
   546    546   <b>U</b> <i>user-name</i><br />
   547    547   <b>W</b> <i>size</i> <b>\n</b> <i>text</i> <b>\n</b><br />
   548    548   <b>Z</b> <i>checksum</i>
   549    549   </blockquote>
   550    550   
   551    551   Every forum post must have either one <b>I</b> card and one <b>G</b> card
   552         -or one <b>H</b> card.
          552  +or one <b>H</b> card.  
   553    553   Forum posts are organized into topic threads.  The initial
   554    554   post for a thread (the root post) has an <b>H</b> card giving the title or
   555    555   subject for that thread.  The argument to the <b>H</b> card is a string
   556    556   in the same format as a comment string in a <b>C</b> card.
   557    557   All follow-up posts have an <b>I</b> card that
   558    558   indicates which prior post in the same thread the current forum
   559    559   post is replying to, and a <b>G</b> card specifying the root post for

Changes to www/forum.wiki.

    64     64        nearest wifi router or cellular data tower.
    65     65   
    66     66     *  <b>Interlink with Other Fossil-Managed Artifacts:</b> Because forum
    67     67        posts are normal Fossil artifacts, you can interlink them with
    68     68        other Fossil artifacts using short internal links: link to forum
    69     69        threads from a [./tickets.wiki | ticket], link to a wiki document
    70     70        from a forum post, etc.
    71         -
           71  +     
    72     72     *  <b>Durable Links:</b> Once you create a valid internal artifact
    73     73        link in Fossil, it <em>remains</em> valid, durably. With
    74     74        third-party forum software and mailing list search engines, your
    75     75        links are only valid until the third-party component changes its
    76     76        URL scheme or disappears from the web.
    77     77   
    78     78     *  <b>Role-Based Access Control:</b> The forum uses the same

Changes to www/makefile.wiki.

    97     97   all of the makefiles for all targets will be rebuild.
    98     98   
    99     99   There is an option code verification step implemented using
   100    100   
   101    101     15.  [/file/src/codecheck1.c | codecheck1.c]
   102    102   
   103    103   This file implements a small utility program ("codecheck1")
   104         -that scans other Fossil source files looking for errors in printf-style
          104  +that scans other Fossil source files looking for errors in printf-style 
   105    105   format strings.
   106         -The codecheck1 utility detects missing or surplus arguments on
          106  +The codecheck1 utility detects missing or surplus arguments on 
   107    107   printf-like functions and dangerous uses of "%s" that might
   108    108   permit SQL injection or cross-site scripting attacks.  This code
   109    109   check step is run automatically on each build of Fossil, and can
   110    110   also be run separately by typing "make codecheck".  Note that the
   111    111   built-in printf format checking of GCC does not function for Fossil
   112    112   since Fossil implements its own printf (in the
   113    113   [/file/src/printf.c | printf.c] source file) that includes special

Deleted www/mirrortogithub.md.

     1         -# How To Mirror A Fossil Repository On GitHub
     2         -
     3         -Beginning with Fossil version 2.9, you can mirror a Fossil-based
     4         -project on GitHub by following these steps:
     5         -
     6         -<ol>
     7         -<li><p>Create an account on GitHub if you do not have one already.  Log
     8         -    into that account.
     9         -
    10         -<li><p>Create a new project.  GitHub will ask you if you want to prepopulate
    11         -    your project with various things like a README file.  Answer "no" to
    12         -    everything.  You want a completely blank project.  GitHub will then
    13         -    supply you with a URL for your project that will look something
    14         -    like this:
    15         -
    16         -<blockquote>
    17         -https://github.com/username/project.git
    18         -</blockquote>
    19         -
    20         -<li><p>Back on your workstation, move to a checkout for your Fossil
    21         -    project and type:
    22         -
    23         -<blockquote>
    24         -<pre>$ fossil git export /path/to/git/repo --autopush \
    25         -  https://<font color="orange">username</font>:<font color="red">password</font>@github.com/username/project.git</pre>
    26         -</blockquote>
    27         -
    28         -<p>   In place of the <code>/path/to...</code> argument above, put in
    29         -      some directory name that is <i>outside</i> of your Fossil checkout. If
    30         -      you keep multiple Fossil checkouts in a directory of their own,
    31         -      consider using <code>../git-mirror</code> to place the Git export
    32         -      mirror alongside them, for example.  Fossil will create this
    33         -      directory if necessary.  This directory will become a Git
    34         -      repository that holds a translation of your Fossil repository.
    35         -
    36         -<p>   The <code>--autopush</code> option tells Fossil that you want to
    37         -      push the Git translation up to GitHub every time it is updated.
    38         -      
    39         -<p>   The URL parameter is the same as the one GitHub gave you, but with
    40         -      your GitHub <font color="orange">username</font> and <font
    41         -      color="red">password</font> added.
    42         -      
    43         -<p>   If your GitHub account uses two-factor authentication (2FA), you
    44         -      will have to <a href="https://github.com/settings/tokens">generate
    45         -      a personal access token</a> and use that in place of your actual
    46         -      password in the URL. This token should have “repo” scope enabled,
    47         -      only.
    48         -
    49         -<p>   You can also run the command above outside of any open checkout of
    50         -      your project by supplying the “<code>-R&nbsp;repository</code>”
    51         -      option.
    52         -
    53         -<li><p>Get some coffee.  Depending on the size of your project, the
    54         -       command above can run for several minutes.
    55         -
    56         -<li><p>And you are done!  Assuming everything worked, your project is now
    57         -    mirrored on GitHub.
    58         -
    59         -<li><p>Whenever you update your project, simply run this command to update
    60         -    the mirror:
    61         -
    62         -<blockquote>
    63         -<pre>$ fossil git export</pre>
    64         -</blockquote>
    65         -
    66         -
    67         -<p>   Unlike with the first time you ran that command, you don’t need
    68         -      the remaining arguments, because Fossil remembers those things.
    69         -      Subsequent mirror updates should happen in a second or less.
    70         -</ol>
    71         -
    72         -## Notes:
    73         -
    74         -  *  The mirroring is one-way.  If you check in changes on GitHub, those
    75         -     changes will not be reabsorbed by Fossil.  There are technical problems
    76         -     that make a two-way mirror all but impossible.
    77         -
    78         -     This also means that you cannot accept pull requests on GitHub.
    79         -
    80         -  *  The "`fossil git export`" command creates subprocesses that run "`git`"
    81         -     commands, so you must have Git installed on your machine for any
    82         -     of this to work.
    83         -
    84         -  *  The Git repository will have an extra unmanaged top-level directory named
    85         -     "`.mirror_state`" that contains one or more files.  Those files are
    86         -     used to store the intermediate state of the translation so that
    87         -     subsequent invocations of "`fossil git export`" will know where you
    88         -     left off the last time and what new content needs to be moved over into
    89         -     Git.  Be careful not to mess with the `.mirror_state` directory or
    90         -     any of its contents.  Do not put those files under Git management.  Do
    91         -     not edit or delete them.
    92         -
    93         -  *  Only check-ins and simple tags are translated to Git.  Git does not
    94         -     support wiki or tickets or unversioned content or any of the other
    95         -     features of Fossil that make it so convenient to use, so those other
    96         -     elements cannot be mirrored in Git.
    97         -
    98         -  *  In Git, all tags must be unique.  If your Fossil repository has the
    99         -     same tag on two or more check-ins, the tag will only be preserved on
   100         -     the chronologically newest check-in.
   101         -
   102         -## Example GitHub Mirrors
   103         -
   104         -As of this writing (2019-03-16) Fossil’s own repository is mirrored
   105         -on GitHub at:
   106         -
   107         ->
   108         -<https://github.com/drhsqlite/fossil-mirror>
   109         -
   110         -In addition, an experimental SQLite mirror is available:
   111         -
   112         ->
   113         -<https://github.com/drhsqlite/sqlite-mirror>
   114         -
   115         -The Fossil source repositories for both of these mirrors are at
   116         -<https://www2.fossil-scm.org/fossil> and <https://www2.sqlite.org/src>,
   117         -respectively.  On that machine, there is a cron job that runs at
   118         -17 minutes after the hour, every hour that does:
   119         -
   120         ->
   121         -    /usr/bin/fossil sync -u -R /home/www/fossil/fossil.fossil
   122         -    /usr/bin/fossil sync -R /home/www/fossil/sqlite.fossil
   123         -    /usr/bin/fossil git export -R /home/www/fossil/fossil.fossil
   124         -    /usr/bin/fossil git export -R /home/www/fossil/sqlite.fossil
   125         -
   126         -The initial two "sync" commands pull in changes from the primary
   127         -Fossil repositores for Fossil and SQLite.  The last two lines
   128         -export the changes to Git and push the results up to GitHub.

Changes to www/mkindex.tcl.

    49     49     hacker-howto.wiki {Hacker How-To}
    50     50     hashpolicy.wiki {Hash Policy: Choosing Between SHA1 and SHA3-256}
    51     51     /help {Lists of Commands and Webpages}
    52     52     hints.wiki {Fossil Tips And Usage Hints}
    53     53     index.wiki {Home Page}
    54     54     inout.wiki {Import And Export To And From Git}
    55     55     makefile.wiki {The Fossil Build Process}
    56         -  mirrortogithub.md {How To Mirror A Fossil Repository On GitHub}
    57     56     /md_rules {Markdown Formatting Rules}
    58     57     newrepo.wiki {How To Create A New Fossil Repository}
    59     58     password.wiki {Password Management And Authentication}
    60     59     pop.wiki {Principles Of Operation}
    61     60     private.wiki {Creating, Syncing, and Deleting Private Branches}
    62     61     qandc.wiki {Questions And Criticisms}
    63     62     quickstart.wiki {Fossil Quick Start Guide}

Changes to www/permutedindex.html.

   121    121   <li><a href="fossil-v-git.wiki"><b>Fossil Versus Git</b></a></li>
   122    122   <li><a href="quotes.wiki">Fossil, Git, and DVCSes in General &mdash; Quotes: What People Are Saying About</a></li>
   123    123   <li><a href="faq.wiki"><b>Frequently Asked Questions</b></a></li>
   124    124   <li><a href="quotes.wiki">General &mdash; Quotes: What People Are Saying About Fossil, Git, and DVCSes in</a></li>
   125    125   <li><a href="fossil-v-git.wiki">Git &mdash; Fossil Versus</a></li>
   126    126   <li><a href="inout.wiki">Git &mdash; Import And Export To And From</a></li>
   127    127   <li><a href="quotes.wiki">Git, and DVCSes in General &mdash; Quotes: What People Are Saying About Fossil,</a></li>
   128         -<li><a href="mirrortogithub.md">GitHub &mdash; How To Mirror A Fossil Repository On</a></li>
   129    128   <li><a href="globs.md">Glob Patterns &mdash; File Name</a></li>
   130    129   <li><a href="env-opts.md">Global Options &mdash; Environment Variables and</a></li>
   131    130   <li><a href="customgraph.md">Graph &mdash; Theming: Customizing the Timeline</a></li>
   132    131   <li><a href="grep.md">grep &mdash; Fossil grep vs POSIX</a></li>
   133    132   <li><a href="grep.md">grep vs POSIX grep &mdash; Fossil</a></li>
   134    133   <li><a href="quickstart.wiki">Guide &mdash; Fossil Quick Start</a></li>
   135    134   <li><a href="style.wiki">Guidelines &mdash; Source Code Style</a></li>
................................................................................
   139    138   <li><a href="hints.wiki">Hints &mdash; Fossil Tips And Usage</a></li>
   140    139   <li><a href="index.wiki"><b>Home Page</b></a></li>
   141    140   <li><a href="selfhost.wiki">Hosting Repositories &mdash; Fossil Self</a></li>
   142    141   <li><a href="aboutcgi.wiki"><b>How CGI Works In Fossil</b></a></li>
   143    142   <li><a href="aboutdownload.wiki"><b>How The Download Page Works</b></a></li>
   144    143   <li><a href="server.wiki"><b>How To Configure A Fossil Server</b></a></li>
   145    144   <li><a href="newrepo.wiki"><b>How To Create A New Fossil Repository</b></a></li>
   146         -<li><a href="mirrortogithub.md"><b>How To Mirror A Fossil Repository On GitHub</b></a></li>
   147    145   <li><a href="encryptedrepos.wiki"><b>How To Use Encrypted Repositories</b></a></li>
   148    146   <li><a href="hacker-howto.wiki">How-To &mdash; Hacker</a></li>
   149    147   <li><a href="fossil-from-msvc.wiki">IDE &mdash; Integrating Fossil in the Microsoft Express 2010</a></li>
   150    148   <li><a href="tech_overview.wiki">Implementation Of Fossil &mdash; A Technical Overview Of The Design And</a></li>
   151    149   <li><a href="inout.wiki"><b>Import And Export To And From Git</b></a></li>
   152    150   <li><a href="build.wiki">Installing Fossil &mdash; Compiling and</a></li>
   153    151   <li><a href="fossil-from-msvc.wiki"><b>Integrating Fossil in the Microsoft Express 2010 IDE</b></a></li>
................................................................................
   159    157   <li><a href="password.wiki">Management And Authentication &mdash; Password</a></li>
   160    158   <li><a href="../../../sitemap">Map &mdash; Site</a></li>
   161    159   <li><a href="../../../md_rules"><b>Markdown Formatting Rules</b></a></li>
   162    160   <li><a href="backoffice.md">mechanism of Fossil &mdash; The Backoffice</a></li>
   163    161   <li><a href="branching.wiki">Merging, and Tagging &mdash; Branching, Forking,</a></li>
   164    162   <li><a href="fossil-from-msvc.wiki">Microsoft Express 2010 IDE &mdash; Integrating Fossil in the</a></li>
   165    163   <li><a href="fiveminutes.wiki">Minutes as a Single User &mdash; Up and Running in 5</a></li>
   166         -<li><a href="mirrortogithub.md">Mirror A Fossil Repository On GitHub &mdash; How To</a></li>
   167    164   <li><a href="globs.md">Name Glob Patterns &mdash; File</a></li>
   168    165   <li><a href="checkin_names.wiki">Names &mdash; Check-in And Version</a></li>
   169    166   <li><a href="adding_code.wiki">New Features To Fossil &mdash; Adding</a></li>
   170    167   <li><a href="newrepo.wiki">New Fossil Repository &mdash; How To Create A</a></li>
   171    168   <li><a href="alerts.md">Notifications &mdash; Email Alerts And</a></li>
   172    169   <li><a href="foss-cklist.wiki">Open-Source Projects &mdash; Checklist For Successful</a></li>
   173    170   <li><a href="pop.wiki">Operation &mdash; Principles Of</a></li>
................................................................................
   195    192   <li><a href="qandc.wiki"><b>Questions And Criticisms</b></a></li>
   196    193   <li><a href="quickstart.wiki">Quick Start Guide &mdash; Fossil</a></li>
   197    194   <li><a href="quotes.wiki"><b>Quotes: What People Are Saying About Fossil, Git, and DVCSes in General</b></a></li>
   198    195   <li><a href="selfhost.wiki">Repositories &mdash; Fossil Self Hosting</a></li>
   199    196   <li><a href="encryptedrepos.wiki">Repositories &mdash; How To Use Encrypted</a></li>
   200    197   <li><a href="newrepo.wiki">Repository &mdash; How To Create A New Fossil</a></li>
   201    198   <li><a href="selfcheck.wiki">Repository Integrity Self Checks &mdash; Fossil</a></li>
   202         -<li><a href="mirrortogithub.md">Repository On GitHub &mdash; How To Mirror A Fossil</a></li>
   203    199   <li><a href="reviews.wiki"><b>Reviews</b></a></li>
   204    200   <li><a href="../../../md_rules">Rules &mdash; Markdown Formatting</a></li>
   205    201   <li><a href="../../../wiki_rules">Rules &mdash; Wiki Formatting</a></li>
   206    202   <li><a href="fiveminutes.wiki">Running in 5 Minutes as a Single User &mdash; Up and</a></li>
   207    203   <li><a href="quotes.wiki">Saying About Fossil, Git, and DVCSes in General &mdash; Quotes: What People Are</a></li>
   208    204   <li><a href="th1.md">Scripting Language &mdash; The TH1</a></li>
   209    205   <li><a href="selfcheck.wiki">Self Checks &mdash; Fossil Repository Integrity</a></li>

Changes to www/server.wiki.

     1      1   <title>How To Configure A Fossil Server</title>
     2         -
     3         -<h2>Introduction</h2>
     4         -
     5         -<blockquote>
     6         -A server is not necessary to use Fossil, but a server does help in collaborating with
            2  +<h2>Introduction</h2><blockquote>
            3  +<p>A server is not necessary to use Fossil, but a server does help in collaborating with
     7      4   peers.  A Fossil server also works well as a complete website for a project.
     8      5   For example, the complete [https://www.fossil-scm.org/] website, including the
     9      6   page you are now reading,
    10      7   is just a Fossil server displaying the content of the
    11         -self-hosting repository for Fossil.
    12         -
    13         -This article is a guide for setting up your own Fossil server.
    14         -
    15         -See "[./aboutcgi.wiki|How CGI Works In Fossil]" for background
            8  +self-hosting repository for Fossil.</p>
            9  +<p>This article is a guide for setting up your own Fossil server.
           10  +<p>See "[./aboutcgi.wiki|How CGI Works In Fossil]" for background
    16     11   information on the underlying CGI technology.
    17     12   See "[./sync.wiki|The Fossil Sync Protocol]" for information on the
    18         -wire protocol used for client/server communication.
           13  +wire protocol used for client/server communication.</p>
    19     14   </blockquote>
    20         -
    21         -<h2>Overview</h2>
    22         -
    23         -<blockquote>
           15  +<h2>Overview</h2><blockquote>
    24     16   There are basically four ways to set up a Fossil server:
    25         -
    26     17   <ol>
    27         -  <li>A stand-alone server
    28         -  <li>Using inetd, xinetd, or stunnel
    29         -  <li>CGI
    30         -  <li>SCGI (a.k.a. SimpleCGI)
           18  +<li>A stand-alone server
           19  +<li>Using inetd or xinetd or stunnel
           20  +<li>CGI
           21  +<li>SCGI (a.k.a. SimpleCGI)
    31     22   </ol>
    32         -
    33     23   Each of these can serve either a single repository, or a directory hierarchy
    34     24   containing many repositories with names ending in ".fossil".
    35     25   </blockquote>
    36         -
    37         -
    38         -<h2 id="standalone">Standalone server</h2>
    39         -
    40         -<blockquote>
           26  +<a name="standalone"></a>
           27  +<h2>Standalone server</h2><blockquote>
    41     28   The easiest way to set up a Fossil server is to use either the
    42     29   [/help/server|server] or the [/help/ui|ui] commands:
    43         -
    44     30   <ul>
    45         -  <li><b>fossil server</b> <i>REPOSITORY</i>
    46         -  <li><b>fossil ui</b> <i>REPOSITORY</i>
           31  +<li><b>fossil server</b> <i>REPOSITORY</i>
           32  +<li><b>fossil ui</b> <i>REPOSITORY</i>
    47     33   </ul>
    48         -
           34  +<p>
    49     35   The <i>REPOSITORY</i> argument is either the name of the repository file, or
    50         -a directory containing many repositories named <tt>*.fossil</tt>.
           36  +a directory containing many repositories.
    51     37   Both of these commands start a Fossil server, usually on TCP port 8080, though
    52     38   a higher numbered port might also be used if 8080 is already occupied.  You can
    53     39   access these using URLs of the form <b>http://localhost:8080/</b>, or if
    54     40   <i>REPOSITORY</i> is a directory, URLs of the form
    55     41   <b>http://localhost:8080/</b><i>repo</i><b>/</b> where <i>repo</i> is the base
    56     42   name of the repository file without the ".fossil" suffix.
    57         -
    58         -There are several key differences between "ui" and "server":
    59         -
    60         -<ul>
    61         -  <li>"ui" always binds the server to the loopback IP address
    62         -      (127.0.0.1) so that it cannot serve to other machines.
    63         -  <li>anyone who visits this URL is treated as the all-powerful Setup
    64         -      user, which is why the first difference exists.
    65         -  <li>"ui" launches a local web browser pointed at this URL.
    66         -</ul>
    67         -
    68         -You can omit the <i>REPOSITORY</i> argument if you run one of the above
    69         -commands from within a Fossil checkout directory to serve that
    70         -repository:
    71         -
    72         -<blockquote><pre>
    73         -$ fossil ui          # or...
    74         -$ fossil serve
    75         -</pre></blockquote>
    76         -
    77         -Note that you can abbreviate Fossil sub-commands, as long as they are
    78         -unambiguous. "<tt>server</tt>" can currently be as short as
    79         -"<tt>ser</tt>".
    80         -
    81         -As a more complicated example, you can serve a directory containing
    82         -multiple <tt>*.fossil</tt> files like so:
    83         -
    84         -<blockquote><pre>
    85         -$ fossil server --port 9000 --repolist /path/to/repo/dir
    86         -</pre></blockquote>
    87         -
    88         -There is an [/file/tools/fslsrv | example script] in the Fossil
    89         -distribution that wraps <tt>fossil server</tt> to produce more
    90         -complicated effects. Feel free to take it, study it, and modify it to
    91         -suit your local needs.
    92         -
    93         -See the [/help/server|online documentation] for more information on the
    94         -options and arguments you can give to these commands.
           43  +The difference between "ui" and "server" is that "ui" will
           44  +also start a web browser and point it
           45  +to the URL mentioned above, and the "ui" command binds to
           46  +the loopback IP address (127.0.0.1) only so that the "ui" command cannot be
           47  +used to serve content to a different machine.
           48  +</p>
           49  +<p>
           50  +If one of the commands above is run from within an open checkout,
           51  +then the <i>REPOSITORY</i> argument can be omitted and the checkout is used as
           52  +the repository.
           53  +</p>
           54  +<p>
           55  +Both commands have additional command-line options that can be used to refine
           56  +their behavior.  See the [/help/server|online documentation] for an overview.
           57  +</p>
    95     58   </blockquote>
    96         -
    97         -
    98         -<h2 id="inetd">Fossil as an inetd/xinetd service</h2>
    99         -
   100         -<blockquote>
   101         -
           59  +<a name="inetd"></a>
           60  +<h2>Fossil as an inetd/xinetd or stunnel service</h2><blockquote>
           61  +<p>
   102     62   A Fossil server can be launched on-demand by inetd or xinetd using
   103     63   the [/help/http|fossil http] command. To launch Fossil from inetd, modify
   104     64   your inetd configuration file (typically "/etc/inetd.conf") to contain a
   105     65   line something like this:
   106         -
   107     66   <blockquote>
   108     67   <pre>
   109     68   80 stream tcp nowait.1000 root /usr/bin/fossil /usr/bin/fossil http /home/fossil/repo.fossil
   110     69   </pre>
   111     70   </blockquote>
   112         -
   113     71   In this example, you are telling "inetd" that when an incoming connection
   114     72   appears on TCP port "80", that it should launch the binary "/usr/bin/fossil"
   115     73   program with the arguments shown.
   116     74   Obviously you will
   117     75   need to modify the pathnames for your particular setup.
   118     76   The final argument is either the name of the fossil repository to be served,
   119     77   or a directory containing multiple repositories.
   120         -
   121         -
           78  +</p>
           79  +<p>
   122     80   If you use a non-standard TCP port on
   123     81   systems where the port-specification must be a symbolic name and cannot be
   124     82   numeric, add the desired name and port to /etc/services.  For example, if
   125     83   you want your Fossil server running on TCP port 12345 instead of 80, you
   126     84   will need to add:
   127         -
   128     85   <blockquote>
   129     86   <pre>
   130     87   fossil          12345/tcp  #fossil server
   131     88   </pre>
   132     89   </blockquote>
   133         -
   134     90   and use the symbolic name ('fossil' in this example) instead of the numeral ('12345')
   135     91   in inetd.conf. For details, see the relevant section in your system's documentation, e.g.
   136     92   the [https://www.freebsd.org/doc/en/books/handbook/network-inetd.html|FreeBSD Handbook] in
   137     93   case you use FreeBSD.
   138         -
           94  +</p>
           95  +<p>
   139     96   If your system is running xinetd, then the configuration is likely to be
   140     97   in the file "/etc/xinetd.conf" or in a subfile of "/etc/xinetd.d".
   141         -An xinetd configuration file will appear like this:
   142         -
           98  +An xinetd configuration file will appear like this:</p>
   143     99   <blockquote>
   144    100   <pre>
   145    101   service http
   146    102   {
   147    103     port = 80
   148    104     socket_type = stream
   149    105     wait = no
   150    106     user = root
   151    107     server = /usr/bin/fossil
   152    108     server_args = http /home/fossil/repos/
   153    109   }
   154    110   </pre>
   155    111   </blockquote>
   156         -
          112  +<p>
   157    113   The xinetd example above has Fossil configured to serve multiple
   158    114   repositories, contained under the "/home/fossil/repos/" directory.
   159         -
          115  +</p>
          116  +<p>
   160    117   In both cases notice that Fossil was launched as root.  This is not required,
   161    118   but if it is done, then Fossil will automatically put itself into a chroot
   162    119   jail for the user who owns the fossil repository before reading any information
   163    120   off of the wire.
   164         -
          121  +</p>
          122  +<p>
   165    123   Inetd or xinetd must be enabled, and must be (re)started whenever their configuration
   166    124   changes - consult your system's documentation for details.
   167         -
   168         -Using inetd or xinetd is a more complex setup
          125  +</p>
          126  +<p>
          127  +[https://www.stunnel.org/ | Stunnel version 5] is an inetd-like process that
          128  +accepts and decodes SSL-encrypted connections.  Fossil can be run directly from
          129  +stunnel in a manner similar to inetd and xinetd.  This can be used to provide
          130  +a secure link to a Fossil project.  The configuration needed to get stunnel5
          131  +to invoke Fossil is very similar to the inetd and xinetd examples shown above.
          132  +The relevant parts of an stunnel configuration might look something
          133  +like the following:
          134  +<blockquote><pre><nowiki>
          135  +[https]
          136  +accept       = www.ubercool-project.org:443
          137  +TIMEOUTclose = 0
          138  +exec         = /usr/bin/fossil
          139  +execargs     = /usr/bin/fossil http /home/fossil/ubercool.fossil --https
          140  +</nowiki></pre></blockquote>
          141  +See the stunnel5 documentation for further details about the /etc/stunnel/stunnel.conf
          142  +configuration file.  Note that the [/help/http|fossil http] command should include
          143  +the --https option to let Fossil know to use "https" instead of "http" as the scheme
          144  +on generated hyperlinks.
          145  +<p>
          146  +Using inetd or xinetd or stunnel is a more complex setup
   169    147   than the "standalone" server, but it has the
   170    148   advantage of only using system resources when an actual connection is
   171    149   attempted.  If no-one ever connects to that port, a Fossil server will
   172    150   not (automatically) run. It has the disadvantage of requiring "root" access
   173    151   and therefore may not normally be available to lower-priced "shared" servers
   174         -on the Internet.
   175         -
   176         -The configuration for <tt>stunnel</tt> is similar, but it is covered in
   177         -[./ssl.wiki#stunnel|a separate document].
          152  +on the internet.
          153  +</p>
   178    154   </blockquote>
   179         -
   180         -<h2 id="cgi">Fossil as CGI</h2>
   181         -
   182         -<blockquote>
   183         -
          155  +<a name="cgi"></a>
          156  +<h2>Fossil as CGI</h2><blockquote>
          157  +<p>
   184    158   A Fossil server can also be run from an ordinary web server as a CGI program.
   185    159   This feature allows Fossil to be seamlessly integrated into a larger website.
   186    160   CGI is how the [./selfhost.wiki | self-hosting fossil repositories] are
   187    161   implemented.
   188         -
          162  +</p>
          163  +<p>
   189    164   To run Fossil as CGI, create a CGI script (here called "repo") in the CGI directory
   190    165   of your web server and having content like this:
   191         -
   192    166   <blockquote><pre>
   193    167   #!/usr/bin/fossil
   194    168   repository: /home/fossil/repo.fossil
   195    169   </pre></blockquote>
          170  +</p>
   196    171   
          172  +<p>
   197    173   As always, adjust your paths appropriately.
   198    174   It may be necessary to set permissions properly, or to modify an ".htaccess"
   199    175   file or make other server-specific changes.  Consult the documentation
   200    176   for your particular web server. In particular, the following permissions are
   201    177   <em>normally</em> required (but, again, may be different for a particular
   202    178   configuration):
   203    179   
   204    180   <ul>
   205         -  <li>The Fossil binary (/usr/bin/fossil in the example above)
   206         -  must be readable/executable, and ALL directories leading up to it
   207         -  must be readable by the process which executes the CGI.</li>
   208         -  <li>ALL directories leading to the CGI script must also be readable and the CGI
   209         -  script itself must be executable for the user under which it will run (which often differs
   210         -  from the one running the web server - consult your site's documentation or administrator).</li>
   211         -  <li>The repository file AND the directory containing it must be writable by the same account
   212         -  which executes the Fossil binary (again, this might differ from the WWW user). The directory
   213         -  needs to be writable so that sqlite can write its journal files.</li>
   214         -  <li>Fossil must be able to create temporary files, the default directory
   215         -  for which depends on the OS.  When the CGI process is operating within
   216         -  a chroot, ensure that this directory exists and is readable/writeable
   217         -  by the user who executes the Fossil binary.</li>
          181  +<li>The Fossil binary (/usr/bin/fossil in the example above)
          182  +must be readable/executable, and ALL directories leading up to it
          183  +must be readable by the process which executes the CGI.</li>
          184  +<li>ALL directories leading to the CGI script must also be readable and the CGI
          185  +script itself must be executable for the user under which it will run (which often differs
          186  +from the one running the web server - consult your site's documentation or administrator).</li>
          187  +<li>The repository file AND the directory containing it must be writable by the same account
          188  +which executes the Fossil binary (again, this might differ from the WWW user). The directory
          189  +needs to be writable so that sqlite can write its journal files.</li>
          190  +<li>Fossil must be able to create temporary files, the default directory
          191  +for which depends on the OS.  When the CGI process is operating within
          192  +a chroot, ensure that this directory exists and is readable/writeable
          193  +by the user who executes the Fossil binary.</li>
   218    194   </ul>
          195  +</p>
   219    196   
          197  +<p>
   220    198   Once the script is set up correctly, and assuming your server is also set
   221    199   correctly, you should be able to access your repository with a URL like:
   222    200   <b>http://mydomain.org/cgi-bin/repo</b> (assuming the "repo" script is
   223    201   accessible under "cgi-bin", which would be a typical deployment on Apache
   224    202   for instance).
   225         -
          203  +</p>
          204  +<p>
   226    205   To serve multiple repositories from a directory using CGI, use the "directory:"
   227    206   tag in the CGI script rather than "repository:".   You might also want to add
   228    207   a "notfound:" tag to tell where to redirect if the particular repository requested
   229    208   by the URL is not found:
   230         -
   231    209   <blockquote><pre>
   232    210   #!/usr/bin/fossil
   233    211   directory: /home/fossil/repos
   234    212   notfound: http://url-to-go-to-if-repo-not-found/
   235    213   </pre></blockquote>
   236         -
          214  +</p>
          215  +<p>
   237    216   Once deployed, a URL like: <b>http://mydomain.org/cgi-bin/repo/XYZ</b>
   238    217   will serve up the repository "/home/fossil/repos/XYZ.fossil" (if it exists).
   239         -
          218  +</p>
          219  +<p>
   240    220   Additional options available to the CGI script are documented in the
   241    221   source code.  As of 2017-07-02, the available options are described at
   242    222   [/artifact/9a52a07b?ln=1777-1824|main.c lines 1777 through 1824].
          223  +</p>
   243    224   </blockquote>
   244    225   
   245         -<h2 id="scgi">Fossil as SCGI</h2>
   246         -<blockquote>
          226  +<a name="scgi"></a>
          227  +<h2>Fossil as SCGI</h2><blockquote>
   247    228   
          229  +<p>
   248    230   The [/help/server|fossil server] command, described above as a way of
   249    231   starting a stand-alone web server, can also be used for SCGI.  Simply add
   250    232   the --scgi command-line option and the stand-alone server will interpret
   251    233   and respond to the SimpleCGI or SCGI protocol rather than raw HTTP.  This can
   252    234   be used in combination with a webserver (such as [http://nginx.org|Nginx])
   253    235   that does not support CGI.  A typical Nginx configuration to support SCGI
   254    236   with Fossil would look something like this:
   255         -
   256    237   <blockquote><pre>
   257    238   location /demo_project/ {
   258    239       include scgi_params;
   259    240       scgi_pass localhost:9000;
   260    241       scgi_param SCRIPT_NAME "/demo_project";
   261    242       scgi_param HTTPS "on";
   262    243   }
   263    244   </pre></blockquote>
   264         -
          245  +<p>
   265    246   Note that Fossil requires the SCRIPT_NAME variable
   266    247   in order to function properly, but Nginx does not provide this
   267         -variable by default,
   268         -so it is necessary to provide the SCRIPT_NAME parameter in the configuration.
          248  +variable by default.
          249  +So it is necessary to provide the SCRIPT_NAME parameter in the configuration.
   269    250   Failure to do this will cause Fossil to return an error.
   270         -
          251  +</p>
          252  +<p>
   271    253   All of the features of the stand-alone server mode described above,
   272    254   such as the ability to serve a directory full of Fossil repositories
   273    255   rather than just a single repository, work the same way in SCGI mode.
   274         -
          256  +</p>
          257  +<p>
   275    258   For security, it is probably a good idea to add the --localhost option
   276    259   to the [/help/server|fossil server] command to prevent Fossil from accepting
   277         -off-site connections.  One might also want to specify the listening TCP port
          260  +off-site connections.  And one might want to specify the listening TCP port
   278    261   number, rather than letting Fossil choose one for itself, just to avoid
   279    262   ambiguity.  A typical command to start a Fossil SCGI server
   280    263   would be something like this:
   281         -
   282    264   <blockquote><pre>
   283    265   fossil server $REPOSITORY --scgi --localhost --port 9000
   284    266   </pre></blockquote>
   285    267   </blockquote>
   286    268   
   287         -<h2 id="tls">Securing a repository with TLS</h2>
   288         -
   289         -<blockquote>
   290         -  Fossil's built-in HTTP server (e.g. "fossil server") does not support
   291         -  TLS, but there are multiple ways to protect your Fossil server with
   292         -  TLS. All of this is covered in a separate document, <a
   293         -  href="./ssl.wiki">Using TLS-Encrypted Communications with Fossil</a>.
          269  +<h2>Securing a repository with SSL</h2><blockquote>
          270  +<p>
          271  +Using either CGI or SCGI, it is trivial to use SSL to
          272  +secure the server.  Simply set up the Fossil CGI scripts etc. as above,
          273  +but modify the Apache (or IIS, etc.) server to require SSL (that is, a
          274  +URL with "https://") in order to access the CGI script directory.  This
          275  +may also be accomplished (on Apache, at least) using appropriate
          276  +".htaccess" rules.
          277  +</p>
          278  +<p>
          279  +If you are using "inetd" to serve your repository, then you simply need
          280  +to add "/usr/bin/stunnel" (perhaps on a different path, depending on your
          281  +setup) before the command line to launch Fossil.
          282  +</p>
          283  +<p>
          284  +At this stage, the standalone server (e.g. "fossil server") does not
          285  +support SSL.
          286  +</p>
          287  +<p>
          288  +For more information, see <a href="./ssl.wiki">Using SSL with Fossil</a>.
          289  +</p>
   294    290   </blockquote>
   295    291   
   296         -<h2 id="loadmgmt">Managing Server Load</h2>
   297         -
   298         -<blockquote>
          292  +<a name="loadmgmt"></a>
          293  +<h2>Managing Server Load</h2><blockquote>
          294  +<p>
   299    295   A Fossil server is very efficient and normally presents a very light
   300    296   load on the server.
   301    297   The Fossil [./selfhost.wiki | self-hosting server] is a 1/24th slice VM at
   302    298   [http://www.linode.com | Linode.com] hosting 65 other repositories in
   303    299   addition to Fossil (and including some very high-traffic sites such
   304    300   as [http://www.sqlite.org] and [http://system.data.sqlite.org]) and
   305    301   it has a typical load of 0.05 to 0.1.  A single HTTP request to Fossil
   306         -normally takes less than 10 milliseconds of CPU time to complete, so
   307         -requests can be arriving at a continuous rate of 20 or more per second,
          302  +normally takes less than 10 milliseconds of CPU time to complete.  So
          303  +requests can be arriving at a continuous rate of 20 or more per second
   308    304   and the CPU can still be mostly idle.
   309         -
          305  +<p>
   310    306   However, there are some Fossil web pages that can consume large
   311    307   amounts of CPU time, especially on repositories with a large number
   312    308   of files or with long revision histories.  High CPU usage pages include
   313    309   [/help?cmd=/zip | /zip], [/help?cmd=/tarball | /tarball],
   314    310   [/help?cmd=/annotate | /annotate] and others.  On very large repositories,
   315    311   these commands can take 15 seconds or more of CPU time.
   316    312   If these kinds of requests arrive too quickly, the load average on the
   317    313   server can grow dramatically, making the server unresponsive.
   318         -
          314  +<p>
   319    315   Fossil provides two capabilities to help avoid server overload problems
   320    316   due to excessive requests to expensive pages:
   321         -
   322    317   <ol>
   323         -  <li><p>An optional cache is available that remembers the 10 most recently
   324         -      requested /zip or /tarball pages and returns the precomputed answer
   325         -      if the same page is requested again.</p>
   326         -  <li><p>Page requests can be configured to fail with a
   327         -      [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4 | "503 Server Overload"]
   328         -      HTTP error if an expensive request is received while the host load
   329         -      average is too high.</p>
          318  +<li><p>An optional cache is available that remembers the 10 most recently
          319  +    requested /zip or /tarball pages and returns the precomputed answer
          320  +    if the same page is requested again.
          321  +<li><p>Page requests can be configured to fail with a
          322  +    [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4 | "503 Server Overload"]
          323  +    HTTP error if an expensive request is received while the host load
          324  +    average is too high.
   330    325   </ol>
   331         -
   332    326   Both of these load-control mechanisms are turned off by default, but they
   333    327   are recommended for high-traffic sites.
   334         -
          328  +<p>
   335    329   The webpage cache is activated using the [/help?cmd=cache|fossil cache init]
   336    330   command-line on the server.  Add a -R option to specify the specific repository
   337    331   for which to enable caching.  If running this command as root, be sure to
   338    332   "chown" the cache database (which is a separate file in the same directory
   339    333   and with the same name as the repository but with the suffix changed to ".cache")
   340    334   to give it write permission for the userid of the webserver.
   341         -
          335  +<p>
   342    336   To activate the server load control feature
   343         -visit the Admin → Access setup page in the administrative web
   344         -interface; in the "<b>Server Load Average Limit</b>" box
          337  +visit the /Admin/Access setup page in the administrative web
          338  +interface and in the "<b>Server Load Average Limit</b>" box
   345    339   enter the load average threshold above which "503 Server
   346    340   Overload" replies will be issued for expensive requests.  On the
   347         -self-hosting Fossil server, that value is set to 1.5, but you could easily
          341  +self-host Fossil server, that value is set to 1.5.  But you could easily
   348    342   set it higher on a multi-core server.
   349         -
          343  +<p>
   350    344   The maximum load average can also be set on the command line using
   351    345   commands like this:
   352    346   <blockquote><pre>
   353    347   fossil set max-loadavg 1.5
   354    348   fossil all set max-loadavg 1.5
   355    349   </pre></blockquote>
   356         -
   357    350   The second form is especially useful for changing the maximum load average
   358    351   simultaneously on a large number of repositories.
   359         -
          352  +<p>
   360    353   Note that this load-average limiting feature is only available on operating
   361    354   systems that support the "getloadavg()" API.  Most modern Unix systems have
   362    355   this interface, but Windows does not, so the feature will not work on Windows.
   363    356   Note also that Linux implements "getloadavg()" by accessing the "/proc/loadavg"
   364    357   file in the "proc" virtual filesystem.  If you are running a Fossil instance
   365    358   inside a chroot() jail on Linux, you will need to make the "/proc" file
   366    359   system available inside that jail in order for this feature to work.  On
   367    360   the [./selfhost.wiki|self-hosting Fossil repositories], this was accomplished
   368    361   by adding a line to the "/etc/fstab" file that looks like:
   369         -
   370    362   <blockquote><pre>
   371    363   chroot_jail_proc /home/www/proc proc ro 0 0
   372    364   </pre></blockquote>
   373         -
   374    365   The /home/www/proc pathname should be adjusted so that the "/proc" component is
   375    366   in the root of the chroot jail, of course.
   376         -
          367  +<p>
   377    368   To see if the load-average limiter is functional, visit the [/test_env] page
   378    369   of the server to view the current load average.  If the value for the load
   379    370   average is greater than zero, that means that it is possible to activate
   380    371   the load-average limiter on that repository.  If the load average shows
   381    372   exactly "0.0", then that means that Fossil is unable to find the load average
   382    373   (either because it is in a chroot() jail without /proc access, or because
   383    374   it is running on a system that does not support "getloadavg()") and so the
   384    375   load-average limiter will not function.
   385    376   
   386    377   </blockquote>

Changes to www/ssl.wiki.

   209    209   way to serve via HTTP over TLS, a.k.a. HTTPS, even when you've linked
   210    210   Fossil to OpenSSL. To serve a Fossil repository via HTTPS, you must put
   211    211   it behind some kind of HTTPS proxy.
   212    212   
   213    213   
   214    214   <h3 id="stunnel">stunnel Alone</h3>
   215    215   
   216         -[https://www.stunnel.org/ | <tt>stunnel</tt>] is an
   217         -[https://en.wikipedia.org/wiki/Inetd | <tt>inetd</tt>]-like process that
   218         -accepts and decodes TLS-encrypted connections. It can directly proxy
   219         -Fossil communications, allowing secure TLS-encrypted communications to a
   220         -Fossil repository server. You simply need to install <tt>stunnel</tt>
   221         -and then place something like this in its main configuration file,
   222         -<tt>stunnel.conf</tt>:
          216  +Conceptually, the simplest option is to [https://www.stunnel.org/|set up
          217  +stunnel].  A typical configuration is to run Fossil as an HTTP server
          218  +bound to localhost only, then export access to it via HTTPS with stunnel
          219  +encrypting access to Fossil instance hiding behind it.
   223    220   
   224         -<nowiki><pre>
   225         -    [https]
   226         -    accept       = www.ubercool-project.org:443
   227         -    TIMEOUTclose = 0
   228         -    exec         = /usr/bin/fossil
   229         -    execargs     = /usr/bin/fossil http /home/fossil/ubercool.fossil --https
   230         -</pre></nowiki>
   231         -
   232         -The directory where that file goes varies between OSes, so check the man
   233         -pages on your system to find out where it should be locally.
   234         -
   235         -See the <tt>stunnel</tt> documentation for further details about this
   236         -configuration file.
   237         -
   238         -It is important that the [/help/http | <tt>fossil http</tt>] command in
   239         -that configuration include the <tt>--https</tt> option to let Fossil
   240         -know to use "<tt>https</tt>" instead of "<tt>http</tt>" as the URL
   241         -scheme on generated hyperlinks.
          221  +The difficulty comes in configuring it, which really wants a guide that
          222  +no one has written for us yet. Until that appears, you'll have to read
          223  +the stunnel documentation and that of your TLS certificate provider to
          224  +work out how to set this up.
   242    225   
   243    226   
   244    227   <h3 id="althttpd">stunnel + althttpd</h3>
   245    228   
   246    229   The public SQLite and Fossil web sites can't just use stunnel + Fossil
   247    230   because parts of the web site are static, served by
   248    231   [https://www.sqlite.org/docsrc/file/misc/althttpd.c|a separate web

Changes to www/tls-nginx.md.

    57     57       proxy access to another HTTP server, this option is overkill for our
    58     58       purposes.  nginx is itself a fully featured HTTP server, so we will
    59     59       choose in this guide not to make nginx reinterpret Fossil’s
    60     60       implementation of HTTP.
    61     61   
    62     62   *   **CGI** — This method is simple but inefficient, because it launches
    63     63       a separate Fossil instance on every HTTP hit.
    64         -
           64  +    
    65     65       Since Fossil is a relatively small self-contained program, and it’s
    66     66       designed to start up quickly, this method can work well in a
    67     67       surprisingly large number of cases.
    68     68   
    69     69       Nevertheless, we will avoid this option in this document because
    70     70       we’re already buying into a certain amount of complexity here in
    71     71       order to gain power.  There’s no sense in throwing away any of that
................................................................................
   231    231   `*.example.com` and `*.example.net`; and `local/foo` contains the
   232    232   configuration for `*.foo.net`.
   233    233   
   234    234   Here’s an example configuration:
   235    235   
   236    236         server {
   237    237             server_name .foo.net;
   238         -
          238  +      
   239    239             include local/tls-common;
   240         -
          240  +      
   241    241             charset utf-8;
   242         -
          242  +      
   243    243             access_log /var/log/nginx/foo.net-https-access.log;
   244    244              error_log /var/log/nginx/foo.net-https-error.log;
   245         -
          245  +      
   246    246             # Bypass Fossil for the static Doxygen docs
   247    247             location /doc/html {
   248    248                 root /var/www/foo.net;
   249         -
          249  +      
   250    250                 location ~* \.(html|ico|css|js|gif|jpg|png)$ {
   251    251                     expires 7d;
   252    252                     add_header Vary Accept-Encoding;
   253    253                     access_log off;
   254    254                 }
   255    255             }
   256         -
          256  +      
   257    257             # Redirect everything else to the Fossil instance
   258    258             location / {
   259    259                 include scgi_params;
   260    260                 scgi_pass 127.0.0.1:12345;
   261    261                 scgi_param HTTPS "on";
   262    262                 scgi_param SCRIPT_NAME "";
   263    263             }
................................................................................
   299    299   
   300    300   The first line tells nginx to accept TLS-encrypted HTTP connections on
   301    301   the standard HTTPS port. It is the same as `listen 443; ssl on;` in
   302    302   older versions of nginx.
   303    303   
   304    304   Since all of those domains share a single TLS certificate, we reference
   305    305   the same `example.com/*.pem` files written out by Certbot with the
   306         -`ssl_certificate*` lines.
          306  +`ssl_certificate*` lines. 
   307    307   
   308    308   The `ssl_dhparam` directive isn’t strictly required, but without it, the
   309    309   server becomes vulnerable to the [Logjam attack][lja] because some of
   310    310   the cryptography steps are precomputed, making the attacker’s job much
   311    311   easier. The parameter file this directive references should be
   312    312   generated automatically by the Let’s Encrypt package upon installation,
   313    313   making those parameters unique to your server and thus unguessable. If
................................................................................
   373    373       where it can speak HTTPS safely again.
   374    374   
   375    375   So, from the second `service { }` block, we include this file to set up
   376    376   the minimal HTTP service we reqiure, `local/http-certbot-only`:
   377    377   
   378    378         listen 80;
   379    379         listen [::]:80;
   380         -
          380  +  
   381    381         # This is expressed as a rewrite rule instead of an "if" because
   382    382         # http://wiki.nginx.org/IfIsEvil
   383    383         #rewrite ^(/.well-known/acme-challenge/.*) $1 break;
   384         -
          384  +  
   385    385         # Force everything else to HTTPS with a permanent redirect.
   386    386         #return 301 https://$host$request_uri;
   387    387   
   388    388   As written above, this configuration does nothing other than to tell
   389    389   nginx that it’s allowed to serve content via HTTP on port 80 as well.
   390    390   
   391    391   We’ll uncomment the `rewrite` and `return` directives below, when we’re