Fossil

Check-in [b0511022]
Login

Check-in [b0511022]

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

Overview
Comment:New format for JSON diff output. Promote the "test-diff" command to "xdiff", retaining the older spelling as a backup for compatibility.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | diff-color-enhancements
Files: files | file ages | folders
SHA3-256: b0511022724d7bf02169a54ae9e2c846f7b32a35f402ce262f155c82f5560901
User & Date: drh 2021-09-02 19:38:26
Context
2021-09-02
22:28
Improved comments on the diff formatter and related logic. ... (check-in: d29ddba3 user: drh tags: diff-color-enhancements)
19:38
New format for JSON diff output. Promote the "test-diff" command to "xdiff", retaining the older spelling as a backup for compatibility. ... (check-in: b0511022 user: drh tags: diff-color-enhancements)
18:44
Better control over the blue/red/green colors in the --tk TCL code. ... (check-in: 1df8b9d7 user: drh tags: diff-color-enhancements)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/blob.c.

354
355
356
357
358
359
360























361
362
363
364
365
366
367
** Append the second blob onto the end of the first blob and reset the
** second blob.
*/
void blob_append_xfer(Blob *pTo, Blob *pFrom){
  blob_append(pTo, blob_buffer(pFrom), blob_size(pFrom));
  blob_reset(pFrom);
}
























/*
** Return a pointer to a null-terminated string for a blob.
*/
char *blob_str(Blob *p){
  blob_is_init(p);
  if( p->nUsed==0 ){







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







354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
** Append the second blob onto the end of the first blob and reset the
** second blob.
*/
void blob_append_xfer(Blob *pTo, Blob *pFrom){
  blob_append(pTo, blob_buffer(pFrom), blob_size(pFrom));
  blob_reset(pFrom);
}

/*
** Write into pOut, a string literal representation for the first n bytes
** of z[].  The string literal representation is compatible with C, TCL,
** and JSON.  Double-quotes are added to both ends.  Double-quote and
** backslash characters are escaped.
*/
void blob_append_string_literal(Blob *pOut, const char *z, int n){
  int i;
  blob_append_char(pOut, '"');
  for(i=0; i<n; i++){
    switch( z[i] ){
      case '"':
      case '\\':
        blob_append_char(pOut, '\\');
        /* Fall thru */
      default:
        blob_append_char(pOut, z[i]);
    }
  }
  blob_append_char(pOut, '"');
}


/*
** Return a pointer to a null-terminated string for a blob.
*/
char *blob_str(Blob *p){
  blob_is_init(p);
  if( p->nUsed==0 ){

Changes to src/diff.c.

1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804

1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833

1834
1835
1836
1837
1838
1839




1840
1841
1842
1843
1844


1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923

1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952

1953
1954
1955
1956
1957
1958
1959
1960
}

/************************* DiffBuilderTcl ********************************/
/*
** This variant outputs a description of the diff formatted as TCL, for
** use by the --tk option to "diff".
*/

/*
** Write out a quoted TCL string
*/
void blob_append_tcl_string(Blob *pOut, const char *z, int n){
  int i;
  blob_append_char(pOut, '"');
  for(i=0; i<n; i++){
    switch( z[i] ){
      case '"':
      case '\\':
        blob_append_char(pOut, '\\');
        /* Fall thru */
      default:
        blob_append_char(pOut, z[i]);
    }
  }
  blob_append_char(pOut, '"');
}

static void dftclSkip(DiffBuilder *p, unsigned int n, int isFinal){
  blob_appendf(p->pOut, "SKIP %u\n", n);
}
static void dftclCommon(DiffBuilder *p, const DLine *pLine){
  blob_appendf(p->pOut, "COM ");
  blob_append_tcl_string(p->pOut, pLine->z, pLine->n);
  blob_append_char(p->pOut, '\n');
}
static void dftclInsert(DiffBuilder *p, const DLine *pLine){
  blob_append(p->pOut, "INS ", -1);
  blob_append_tcl_string(p->pOut, pLine->z, pLine->n);
  blob_append_char(p->pOut, '\n');
}
static void dftclDelete(DiffBuilder *p, const DLine *pLine){
  blob_append(p->pOut, "DEL ", -1);
  blob_append_tcl_string(p->pOut, pLine->z, pLine->n);
  blob_append_char(p->pOut, '\n');
}
static void dftclReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
  blob_append(p->pOut, "EDIT ", -1);
  blob_append_tcl_string(p->pOut, pX->z, pX->n);
  blob_append_char(p->pOut, ' ');
  blob_append_tcl_string(p->pOut, pY->z, pY->n);
  blob_append_char(p->pOut, '\n');
}
static void dftclEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i, x;
  ChangeSpan span;
  blob_append(p->pOut, "EDIT", 4);
  oneLineChange(pX, pY, &span);
  for(i=x=0; i<span.n; i++){
    blob_append_char(p->pOut, ' ');
    blob_append_tcl_string(p->pOut, pX->z + x, span.a[i].iStart1 - x);
    x = span.a[i].iStart1;
    blob_append_char(p->pOut, ' ');
    blob_append_tcl_string(p->pOut, pX->z + x, span.a[i].iLen1);
    x += span.a[i].iLen1;
    blob_append_char(p->pOut, ' ');

    blob_append_tcl_string(p->pOut, pY->z + span.a[i].iStart2,span.a[i].iLen2);
  }
  if( x<pX->n ){
    blob_append_char(p->pOut, ' ');
    blob_append_tcl_string(p->pOut, pX->z + x, pX->n - x);
  }
  blob_append_char(p->pOut, '\n');
}
static void dftclEnd(DiffBuilder *p){
  fossil_free(p);
}
static DiffBuilder *dftclNew(Blob *pOut){
  DiffBuilder *p = fossil_malloc(sizeof(*p));
  p->xSkip = dftclSkip;
  p->xCommon = dftclCommon;
  p->xInsert = dftclInsert;
  p->xDelete = dftclDelete;
  p->xReplace = dftclReplace;
  p->xEdit = dftclEdit;
  p->xEnd = dftclEnd;
  p->pOut = pOut;
  return p;
}

/************************* DiffBuilderJson ********************************/

/* Convert raw text into content suitable for a JSON string.  Escape
** charaters that are special to HTML and to JSON:
**

**     <   ->   &lt;
**     >   ->   &gt;
**     &   ->   &amp;
**     "   ->   &quot;
**     '   ->   &#39;
**     \   ->   &#92;




**
** In addition, TAB characters are converted into an appropriate number
** of spaces.  The *piCol value is the number of prior columns in the
** current line.  Update the column count before returning, so that
** subsequent invocations can figure out the right number of spaces to


** insert for each tab.
*/
static void jsonize_to_blob(Blob *p, const char *zIn, int n, int *piCol){
  int c, i, x;
  int iCol = *piCol;
  for(i=0; i<n; i++){
    c = zIn[i];
    switch( c ){
      case '<':
        blob_append(p, "&lt;", 4);
        iCol++;
        break;
      case '>':
        blob_append(p, "&gt;", 4);
        iCol++;
        break;
      case '&':
        blob_append(p, "&amp;", 5);
        iCol++;
        break;
      case '"':
        blob_append(p, "&quot;", 6);
        iCol++;
        break;
      case '\'':
        blob_append(p, "&#39;", 5);
        iCol++;
        break;
      case '\\':
        blob_append(p, "&#92;", 5);
        iCol++;
        break;
      case '\t':
        x = 1 + (iCol+7)%8;
        blob_appendf(p, "%*s", x, "");
        iCol += x;
        break;
      default:
        blob_append_char(p, c);
        if( (c&0xc0)!=0x80 ) iCol++;
        break;
    }
  }
  *piCol = iCol;
}
static void dfjsonSkip(DiffBuilder *p, unsigned int n, int isFinal){
  blob_appendf(p->pOut, "1,%u,\n", n);
}
static void dfjsonCommon(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  blob_append(p->pOut, "2,\"",3);
  jsonize_to_blob(p->pOut, pLine->z, (int)pLine->n, &iCol);
  blob_append(p->pOut, "\",\n",3);
}
static void dfjsonInsert(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  blob_append(p->pOut, "3,\"",3);
  jsonize_to_blob(p->pOut, pLine->z, (int)pLine->n, &iCol);
  blob_append(p->pOut, "\",\n",3);
}
static void dfjsonDelete(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  blob_append(p->pOut, "4,\"",3);
  jsonize_to_blob(p->pOut, pLine->z, (int)pLine->n, &iCol);
  blob_append(p->pOut, "\",\n",3);
}
static void dfjsonReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int iCol = 0;
  blob_append(p->pOut, "5,\"",3);
  jsonize_to_blob(p->pOut, pX->z, (int)pX->n, &iCol);
  blob_append(p->pOut, "\",\"",3);
  jsonize_to_blob(p->pOut, pY->z, (int)pY->n, &iCol);
  blob_append(p->pOut, "\",\n",3);
}
static void dfjsonEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i;
  int x;
  int iCol;
  ChangeSpan span;

  oneLineChange(pX, pY, &span);
  blob_appendf(p->pOut, "5,\"");
  for(i=x=iCol=0; i<span.n; i++){
    int ofst = span.a[i].iStart1;
    int len = span.a[i].iLen1;
    if( len ){
      jsonize_to_blob(p->pOut, pX->z+x, ofst - x, &iCol);
      x = ofst;
      blob_append(p->pOut, "<mark>", 6);
      jsonize_to_blob(p->pOut, pX->z+x, len, &iCol);
      x += len;
      blob_append(p->pOut, "</mark>", 7);
    }
  }
  if( x<pX->n ) jsonize_to_blob(p->pOut, pX->z+x,  pX->n - x, &iCol);
  blob_append(p->pOut, "\",\n  \"", -1);
  for(i=x=iCol=0; i<span.n; i++){
    int ofst = span.a[i].iStart2;
    int len = span.a[i].iLen2;
    if( len ){
      jsonize_to_blob(p->pOut, pY->z+x, ofst - x, &iCol);
      x = ofst;
      blob_append(p->pOut, "<mark>", 6);
      jsonize_to_blob(p->pOut, pY->z+x, len, &iCol);
      x += len;
      blob_append(p->pOut, "</mark>", 7);
    }
  }
  if( x<pY->n ) jsonize_to_blob(p->pOut, pY->z+x,  pY->n - x, &iCol);

  blob_append(p->pOut, "\",\n", -1);
}
static void dfjsonEnd(DiffBuilder *p){
  blob_append(p->pOut, "0]", 2);
  fossil_free(p);
}
static DiffBuilder *dfjsonNew(Blob *pOut){
  DiffBuilder *p = fossil_malloc(sizeof(*p));







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





|




|




|




|

|









|


|


>
|



|




















|
|
<

>
|
|
|
|
|
|
>
>
>
>

<
|
<
<
>
>
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




<
|
|
|


<
|
|
|


<
|
|
|


<
|
|
|
|
|


|
<
<

>

<
|
|
|
<
<
<
|
|
|
|
<
<
<
|
<
|
<
<
<
<
<
<
<
<
|
<
|
>
|







1740
1741
1742
1743
1744
1745
1746




















1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812

1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825

1826


1827
1828
1829
1830











































1831
1832
1833
1834

1835
1836
1837
1838
1839

1840
1841
1842
1843
1844

1845
1846
1847
1848
1849

1850
1851
1852
1853
1854
1855
1856
1857


1858
1859
1860

1861
1862
1863



1864
1865
1866
1867



1868

1869








1870

1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
}

/************************* DiffBuilderTcl ********************************/
/*
** This variant outputs a description of the diff formatted as TCL, for
** use by the --tk option to "diff".
*/




















static void dftclSkip(DiffBuilder *p, unsigned int n, int isFinal){
  blob_appendf(p->pOut, "SKIP %u\n", n);
}
static void dftclCommon(DiffBuilder *p, const DLine *pLine){
  blob_appendf(p->pOut, "COM ");
  blob_append_string_literal(p->pOut, pLine->z, pLine->n);
  blob_append_char(p->pOut, '\n');
}
static void dftclInsert(DiffBuilder *p, const DLine *pLine){
  blob_append(p->pOut, "INS ", -1);
  blob_append_string_literal(p->pOut, pLine->z, pLine->n);
  blob_append_char(p->pOut, '\n');
}
static void dftclDelete(DiffBuilder *p, const DLine *pLine){
  blob_append(p->pOut, "DEL ", -1);
  blob_append_string_literal(p->pOut, pLine->z, pLine->n);
  blob_append_char(p->pOut, '\n');
}
static void dftclReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
  blob_append(p->pOut, "EDIT ", -1);
  blob_append_string_literal(p->pOut, pX->z, pX->n);
  blob_append_char(p->pOut, ' ');
  blob_append_string_literal(p->pOut, pY->z, pY->n);
  blob_append_char(p->pOut, '\n');
}
static void dftclEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i, x;
  ChangeSpan span;
  blob_append(p->pOut, "EDIT", 4);
  oneLineChange(pX, pY, &span);
  for(i=x=0; i<span.n; i++){
    blob_append_char(p->pOut, ' ');
    blob_append_string_literal(p->pOut, pX->z + x, span.a[i].iStart1 - x);
    x = span.a[i].iStart1;
    blob_append_char(p->pOut, ' ');
    blob_append_string_literal(p->pOut, pX->z + x, span.a[i].iLen1);
    x += span.a[i].iLen1;
    blob_append_char(p->pOut, ' ');
    blob_append_string_literal(p->pOut, 
                         pY->z + span.a[i].iStart2, span.a[i].iLen2);
  }
  if( x<pX->n ){
    blob_append_char(p->pOut, ' ');
    blob_append_string_literal(p->pOut, pX->z + x, pX->n - x);
  }
  blob_append_char(p->pOut, '\n');
}
static void dftclEnd(DiffBuilder *p){
  fossil_free(p);
}
static DiffBuilder *dftclNew(Blob *pOut){
  DiffBuilder *p = fossil_malloc(sizeof(*p));
  p->xSkip = dftclSkip;
  p->xCommon = dftclCommon;
  p->xInsert = dftclInsert;
  p->xDelete = dftclDelete;
  p->xReplace = dftclReplace;
  p->xEdit = dftclEdit;
  p->xEnd = dftclEnd;
  p->pOut = pOut;
  return p;
}

/************************* DiffBuilderJson ********************************/
/*
** This module generates a JSON array that describes the difference.

**
** The Json array consists of integer opcodes with each opcode followed
** by zero or more arguments:
**
**   Syntax        Mnemonic    Description
**   -----------   --------    --------------------------
**   0             END         This is the end of the diff
**   1  INTEGER    SKIP        Skip N lines from both files
**   2  STRING     COMMON      The line show by STRING is in both files
**   3  STRING     INSERT      The line STRING is in only the right file
**   4  STRING     DELETE      The STRING line is in only the left file
**   5  SUBARRAY   EDIT        One line is different on left and right.
**

** The SUBARRAY is an array of 3*N+1 strings with N>=0.  The triples


** represent common-text, left-text, and right-text.  The last string
** in SUBARRAY is the common-suffix.  Any string can be empty if it does
** not apply.
*/











































static void dfjsonSkip(DiffBuilder *p, unsigned int n, int isFinal){
  blob_appendf(p->pOut, "1,%u,\n", n);
}
static void dfjsonCommon(DiffBuilder *p, const DLine *pLine){

  blob_append(p->pOut, "2,",2);
  blob_append_string_literal(p->pOut, pLine->z, (int)pLine->n);
  blob_append(p->pOut, ",\n",2);
}
static void dfjsonInsert(DiffBuilder *p, const DLine *pLine){

  blob_append(p->pOut, "3,",2);
  blob_append_string_literal(p->pOut, pLine->z, (int)pLine->n);
  blob_append(p->pOut, ",\n",2);
}
static void dfjsonDelete(DiffBuilder *p, const DLine *pLine){

  blob_append(p->pOut, "4,",2);
  blob_append_string_literal(p->pOut, pLine->z, (int)pLine->n);
  blob_append(p->pOut, ",\n",2);
}
static void dfjsonReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){

  blob_append(p->pOut, "5,[\"\",",-1);
  blob_append_string_literal(p->pOut, pX->z, (int)pX->n);
  blob_append(p->pOut, ",",1);
  blob_append_string_literal(p->pOut, pY->z, (int)pY->n);
  blob_append(p->pOut, ",\"\"],\n",-1);
}
static void dfjsonEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i, x;


  ChangeSpan span;
  blob_append(p->pOut, "5,[", 3);
  oneLineChange(pX, pY, &span);

  for(i=x=0; i<span.n; i++){
    blob_append_string_literal(p->pOut, pX->z + x, span.a[i].iStart1 - x);
    x = span.a[i].iStart1;



    blob_append_char(p->pOut, ',');
    blob_append_string_literal(p->pOut, pX->z + x, span.a[i].iLen1);
    x += span.a[i].iLen1;
    blob_append_char(p->pOut, ',');



    blob_append_string_literal(p->pOut, 

                         pY->z + span.a[i].iStart2, span.a[i].iLen2);








  }

  blob_append_char(p->pOut, ',');
  blob_append_string_literal(p->pOut, pX->z + x, pX->n - x);
  blob_append(p->pOut, "],\n",3);
}
static void dfjsonEnd(DiffBuilder *p){
  blob_append(p->pOut, "0]", 2);
  fossil_free(p);
}
static DiffBuilder *dfjsonNew(Blob *pOut){
  DiffBuilder *p = fossil_malloc(sizeof(*p));
1968
1969
1970
1971
1972
1973
1974
1975

1976
1977
1978
1979
1980
1981
1982
1983
  p->lnLeft = p->lnRight = 0;
  p->pOut = pOut;
  blob_append_char(pOut, '[');
  return p;
}

/************************* DiffBuilderUnified********************************/


/* Accumulator strategy:
**
**    *   Delete line numbers are output directly to p->pOut
**    *   Insert line numbers accumulate in p->aCol[0].
**    *   Separator marks accumulate in p->aCol[1].
**    *   Change text accumulates in p->aCol[2].
**    *   Pending insert line numbers go into p->aCol[3].
**    *   Pending insert text goes into p->aCol[4].







|
>
|







1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
  p->lnLeft = p->lnRight = 0;
  p->pOut = pOut;
  blob_append_char(pOut, '[');
  return p;
}

/************************* DiffBuilderUnified********************************/
/* This module generates a unified diff for HTML
**
** Accumulator strategy:
**
**    *   Delete line numbers are output directly to p->pOut
**    *   Insert line numbers accumulate in p->aCol[0].
**    *   Separator marks accumulate in p->aCol[1].
**    *   Change text accumulates in p->aCol[2].
**    *   Pending insert line numbers go into p->aCol[3].
**    *   Pending insert text goes into p->aCol[4].
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
    blob_append(p->pOut, "<tr><td class=\"diffln difflne\">"
                         "&#xfe19;</td><td></td><td></td></tr>\n", -1);
  }
  p->lnLeft += n;
  p->lnRight += n;
}
static void dfunifiedCommon(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  dfunifiedStartRow(p);
  dfunifiedFinishDelete(p);
  dfunifiedFinishInsert(p);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_appendf(&p->aCol[0],"%d\n",p->lnRight);
  blob_append_char(&p->aCol[1], '\n');
  jsonize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n, &iCol);
  blob_append_char(&p->aCol[2], '\n');
}
static void dfunifiedInsert(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  dfunifiedStartRow(p);
  p->lnRight++;
  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
  blob_append(&p->aCol[4], "<ins>", 5);
  jsonize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n, &iCol);
  blob_append(&p->aCol[4], "</ins>\n", 7);
  p->nPending++;
}
static void dfunifiedDelete(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  dfunifiedStartRow(p);
  dfunifiedFinishInsert(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0],'\n');
  blob_append(&p->aCol[1],"-\n",2);
  blob_append(&p->aCol[2], "<del>", 5);
  jsonize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n, &iCol);
  blob_append(&p->aCol[2], "</del>\n", 7);
}
static void dfunifiedReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int iCol;
  dfunifiedStartRow(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "-\n", 2);

  iCol = 0;
  jsonize_to_blob(&p->aCol[2], pX->z,  pX->n, &iCol);
  blob_append_char(&p->aCol[2], '\n');

  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);

  iCol = 0;
  jsonize_to_blob(&p->aCol[4], pY->z,  pY->n, &iCol);
  blob_append_char(&p->aCol[4], '\n');
  p->nPending++;
}
static void dfunifiedEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i;
  int x;
  int iCol;
  ChangeSpan span;
  oneLineChange(pX, pY, &span);
  dfunifiedStartRow(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "-\n", 2);

  for(i=x=iCol=0; i<span.n; i++){
    int ofst = span.a[i].iStart1;
    int len = span.a[i].iLen1;
    if( len ){
      jsonize_to_blob(&p->aCol[2], pX->z+x, ofst - x, &iCol);
      x = ofst;
      blob_append(&p->aCol[2], "<del>", 5);
      jsonize_to_blob(&p->aCol[2], pX->z+x, len, &iCol);
      x += len;
      blob_append(&p->aCol[2], "</del>", 6);
    }
  }
  if( x<pX->n ) jsonize_to_blob(&p->aCol[2], pX->z+x,  pX->n - x, &iCol);
  blob_append_char(&p->aCol[2], '\n');

  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
  for(i=x=iCol=0; i<span.n; i++){
    int ofst = span.a[i].iStart2;
    int len = span.a[i].iLen2;
    if( len ){
      jsonize_to_blob(&p->aCol[4], pY->z+x, ofst - x, &iCol);
      x = ofst;
      blob_append(&p->aCol[4], "<ins>", 5);
      jsonize_to_blob(&p->aCol[4], pY->z+x, len, &iCol);
      x += len;
      blob_append(&p->aCol[4], "</ins>", 6);
    }
  }
  if( x<pY->n ) jsonize_to_blob(&p->aCol[4], pY->z+x,  pY->n - x, &iCol);
  blob_append_char(&p->aCol[4], '\n');
  p->nPending++;
}
static void dfunifiedEnd(DiffBuilder *p){
  dfunifiedFinishRow(p);
  blob_append(p->pOut, "</table>\n",-1);
  fossil_free(p);







<








|



<




|




<













|



<













<
|




<
|






<















|



|


|




|



|



|


|




|







1958
1959
1960
1961
1962
1963
1964

1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976

1977
1978
1979
1980
1981
1982
1983
1984
1985

1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002

2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015

2016
2017
2018
2019
2020

2021
2022
2023
2024
2025
2026
2027

2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
    blob_append(p->pOut, "<tr><td class=\"diffln difflne\">"
                         "&#xfe19;</td><td></td><td></td></tr>\n", -1);
  }
  p->lnLeft += n;
  p->lnRight += n;
}
static void dfunifiedCommon(DiffBuilder *p, const DLine *pLine){

  dfunifiedStartRow(p);
  dfunifiedFinishDelete(p);
  dfunifiedFinishInsert(p);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_appendf(&p->aCol[0],"%d\n",p->lnRight);
  blob_append_char(&p->aCol[1], '\n');
  htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
  blob_append_char(&p->aCol[2], '\n');
}
static void dfunifiedInsert(DiffBuilder *p, const DLine *pLine){

  dfunifiedStartRow(p);
  p->lnRight++;
  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
  blob_append(&p->aCol[4], "<ins>", 5);
  htmlize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n);
  blob_append(&p->aCol[4], "</ins>\n", 7);
  p->nPending++;
}
static void dfunifiedDelete(DiffBuilder *p, const DLine *pLine){

  dfunifiedStartRow(p);
  dfunifiedFinishInsert(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0],'\n');
  blob_append(&p->aCol[1],"-\n",2);
  blob_append(&p->aCol[2], "<del>", 5);
  htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
  blob_append(&p->aCol[2], "</del>\n", 7);
}
static void dfunifiedReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){

  dfunifiedStartRow(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "-\n", 2);


  htmlize_to_blob(&p->aCol[2], pX->z,  pX->n);
  blob_append_char(&p->aCol[2], '\n');

  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);


  htmlize_to_blob(&p->aCol[4], pY->z,  pY->n);
  blob_append_char(&p->aCol[4], '\n');
  p->nPending++;
}
static void dfunifiedEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i;
  int x;

  ChangeSpan span;
  oneLineChange(pX, pY, &span);
  dfunifiedStartRow(p);
  if( p->eState==0 ){
    dfunifiedFinishInsert(p);
    blob_append(p->pOut, "<del>", 5);
    blob_append(&p->aCol[2], "<del>", 5);
    p->eState = 1;
  }
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "-\n", 2);

  for(i=x=0; i<span.n; i++){
    int ofst = span.a[i].iStart1;
    int len = span.a[i].iLen1;
    if( len ){
      htmlize_to_blob(&p->aCol[2], pX->z+x, ofst - x);
      x = ofst;
      blob_append(&p->aCol[2], "<del>", 5);
      htmlize_to_blob(&p->aCol[2], pX->z+x, len);
      x += len;
      blob_append(&p->aCol[2], "</del>", 6);
    }
  }
  htmlize_to_blob(&p->aCol[2], pX->z+x,  pX->n - x);
  blob_append_char(&p->aCol[2], '\n');

  blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
  for(i=x=0; i<span.n; i++){
    int ofst = span.a[i].iStart2;
    int len = span.a[i].iLen2;
    if( len ){
      htmlize_to_blob(&p->aCol[4], pY->z+x, ofst - x);
      x = ofst;
      blob_append(&p->aCol[4], "<ins>", 5);
      htmlize_to_blob(&p->aCol[4], pY->z+x, len);
      x += len;
      blob_append(&p->aCol[4], "</ins>", 6);
    }
  }
  htmlize_to_blob(&p->aCol[4], pY->z+x,  pY->n - x);
  blob_append_char(&p->aCol[4], '\n');
  p->nPending++;
}
static void dfunifiedEnd(DiffBuilder *p){
  dfunifiedFinishRow(p);
  blob_append(p->pOut, "</table>\n",-1);
  fossil_free(p);
2182
2183
2184
2185
2186
2187
2188
2189

2190
2191
2192
2193
2194
2195
2196
2197
  blob_init(&p->aCol[2], 0, 0);
  blob_init(&p->aCol[3], 0, 0);
  blob_init(&p->aCol[4], 0, 0);
  return p;
}

/************************* DiffBuilderSplit  ******************************/


/* Accumulator strategy:
**
**    *   Left line numbers are output directly to p->pOut
**    *   Left text accumulates in p->aCol[0].
**    *   Edit marks accumulates in p->aCol[1].
**    *   Right line numbers accumulate in p->aCol[2].
**    *   Right text accumulates in p->aCol[3].
**







|
>
|







2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
  blob_init(&p->aCol[2], 0, 0);
  blob_init(&p->aCol[3], 0, 0);
  blob_init(&p->aCol[4], 0, 0);
  return p;
}

/************************* DiffBuilderSplit  ******************************/
/* This module generates a side-by-side diff for HTML.
**
** Accumulator strategy:
**
**    *   Left line numbers are output directly to p->pOut
**    *   Left text accumulates in p->aCol[0].
**    *   Edit marks accumulates in p->aCol[1].
**    *   Right line numbers accumulate in p->aCol[2].
**    *   Right text accumulates in p->aCol[3].
**
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
       "<td class=\"diffln difflnr difflne\">&#xfe19;</td>"
       "<td/td></tr>\n", -1);
  }
  p->lnLeft += n;
  p->lnRight += n;
}
static void dfsplitCommon(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  dfsplitStartRow(p);
  dfsplitChangeState(p, 0);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  jsonize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n, &iCol);
  blob_append_char(&p->aCol[0], '\n');
  blob_append_char(&p->aCol[1], '\n');
  blob_appendf(&p->aCol[2],"%d\n",p->lnRight);
  jsonize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n, &iCol);
  blob_append_char(&p->aCol[3], '\n');
}
static void dfsplitInsert(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  dfsplitStartRow(p);
  dfsplitChangeState(p, 2);
  p->lnRight++;
  blob_append_char(p->pOut, '\n');
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "&gt;\n", -1);
  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
  blob_append(&p->aCol[3], "<ins>", 5);
  jsonize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n, &iCol);
  blob_append(&p->aCol[3], "</ins>\n", 7);
}
static void dfsplitDelete(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  dfsplitStartRow(p);
  dfsplitChangeState(p, 1);
  p->lnLeft++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append(&p->aCol[0], "<del>", 5);
  jsonize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n, &iCol);
  blob_append(&p->aCol[0], "</del>\n", 7);
  blob_append(&p->aCol[1], "&lt;\n", -1);
  blob_append_char(&p->aCol[2],'\n');
  blob_append_char(&p->aCol[3],'\n');
}
static void dfsplitReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int iCol;
  dfsplitStartRow(p);
  dfsplitChangeState(p, 3);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  iCol = 0;
  jsonize_to_blob(&p->aCol[0], pX->z,  pX->n, &iCol);
  blob_append_char(&p->aCol[0], '\n');

  blob_append(&p->aCol[1], "|\n", 2);

  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);

  iCol = 0;
  jsonize_to_blob(&p->aCol[3], pY->z,  pY->n, &iCol);
  blob_append_char(&p->aCol[3], '\n');
}
static void dfsplitEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i;
  int x;
  int iCol;
  ChangeSpan span;
  oneLineChange(pX, pY, &span);
  dfsplitStartRow(p);
  dfsplitChangeState(p, 3);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  for(i=x=iCol=0; i<span.n; i++){
    int ofst = span.a[i].iStart1;
    int len = span.a[i].iLen1;
    if( len ){
      jsonize_to_blob(&p->aCol[0], pX->z+x, ofst - x, &iCol);
      x = ofst;
      blob_append(&p->aCol[0], "<del>", 5);
      jsonize_to_blob(&p->aCol[0], pX->z+x, len, &iCol);
      x += len;
      blob_append(&p->aCol[0], "</del>", 6);
    }
  }
  if( x<pX->n ) jsonize_to_blob(&p->aCol[0], pX->z+x,  pX->n - x, &iCol);
  blob_append_char(&p->aCol[0], '\n');

  blob_append(&p->aCol[1], "|\n", 2);

  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
  for(i=x=iCol=0; i<span.n; i++){
    int ofst = span.a[i].iStart2;
    int len = span.a[i].iLen2;
    if( len ){
      jsonize_to_blob(&p->aCol[3], pY->z+x, ofst - x, &iCol);
      x = ofst;
      blob_append(&p->aCol[3], "<ins>", 5);
      jsonize_to_blob(&p->aCol[3], pY->z+x, len, &iCol);
      x += len;
      blob_append(&p->aCol[3], "</ins>", 6);
    }
  }
  if( x<pY->n ) jsonize_to_blob(&p->aCol[3], pY->z+x,  pY->n - x, &iCol);
  blob_append_char(&p->aCol[3], '\n');
}
static void dfsplitEnd(DiffBuilder *p){
  dfsplitFinishRow(p);
  blob_append(p->pOut, "</table>\n",-1);
  fossil_free(p);
}







<





|



|



<








|



<





|






<





<
|






<
|





<
|






|



|


|




|





|



|


|




|







2164
2165
2166
2167
2168
2169
2170

2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183

2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195

2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207

2208
2209
2210
2211
2212

2213
2214
2215
2216
2217
2218
2219

2220
2221
2222
2223
2224
2225

2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
       "<td class=\"diffln difflnr difflne\">&#xfe19;</td>"
       "<td/td></tr>\n", -1);
  }
  p->lnLeft += n;
  p->lnRight += n;
}
static void dfsplitCommon(DiffBuilder *p, const DLine *pLine){

  dfsplitStartRow(p);
  dfsplitChangeState(p, 0);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  htmlize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n);
  blob_append_char(&p->aCol[0], '\n');
  blob_append_char(&p->aCol[1], '\n');
  blob_appendf(&p->aCol[2],"%d\n",p->lnRight);
  htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
  blob_append_char(&p->aCol[3], '\n');
}
static void dfsplitInsert(DiffBuilder *p, const DLine *pLine){

  dfsplitStartRow(p);
  dfsplitChangeState(p, 2);
  p->lnRight++;
  blob_append_char(p->pOut, '\n');
  blob_append_char(&p->aCol[0], '\n');
  blob_append(&p->aCol[1], "&gt;\n", -1);
  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
  blob_append(&p->aCol[3], "<ins>", 5);
  htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
  blob_append(&p->aCol[3], "</ins>\n", 7);
}
static void dfsplitDelete(DiffBuilder *p, const DLine *pLine){

  dfsplitStartRow(p);
  dfsplitChangeState(p, 1);
  p->lnLeft++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  blob_append(&p->aCol[0], "<del>", 5);
  htmlize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n);
  blob_append(&p->aCol[0], "</del>\n", 7);
  blob_append(&p->aCol[1], "&lt;\n", -1);
  blob_append_char(&p->aCol[2],'\n');
  blob_append_char(&p->aCol[3],'\n');
}
static void dfsplitReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){

  dfsplitStartRow(p);
  dfsplitChangeState(p, 3);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);

  htmlize_to_blob(&p->aCol[0], pX->z,  pX->n);
  blob_append_char(&p->aCol[0], '\n');

  blob_append(&p->aCol[1], "|\n", 2);

  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);


  htmlize_to_blob(&p->aCol[3], pY->z,  pY->n);
  blob_append_char(&p->aCol[3], '\n');
}
static void dfsplitEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i;
  int x;

   ChangeSpan span;
  oneLineChange(pX, pY, &span);
  dfsplitStartRow(p);
  dfsplitChangeState(p, 3);
  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%d\n", p->lnLeft);
  for(i=x=0; i<span.n; i++){
    int ofst = span.a[i].iStart1;
    int len = span.a[i].iLen1;
    if( len ){
      htmlize_to_blob(&p->aCol[0], pX->z+x, ofst - x);
      x = ofst;
      blob_append(&p->aCol[0], "<del>", 5);
      htmlize_to_blob(&p->aCol[0], pX->z+x, len);
      x += len;
      blob_append(&p->aCol[0], "</del>", 6);
    }
  }
  htmlize_to_blob(&p->aCol[0], pX->z+x,  pX->n - x);
  blob_append_char(&p->aCol[0], '\n');

  blob_append(&p->aCol[1], "|\n", 2);

  blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
  for(i=x=0; i<span.n; i++){
    int ofst = span.a[i].iStart2;
    int len = span.a[i].iLen2;
    if( len ){
      htmlize_to_blob(&p->aCol[3], pY->z+x, ofst - x);
      x = ofst;
      blob_append(&p->aCol[3], "<ins>", 5);
      htmlize_to_blob(&p->aCol[3], pY->z+x, len);
      x += len;
      blob_append(&p->aCol[3], "</ins>", 6);
    }
  }
  htmlize_to_blob(&p->aCol[3], pY->z+x,  pY->n - x);
  blob_append_char(&p->aCol[3], '\n');
}
static void dfsplitEnd(DiffBuilder *p){
  dfsplitFinishRow(p);
  blob_append(p->pOut, "</table>\n",-1);
  fossil_free(p);
}
3210
3211
3212
3213
3214
3215
3216

3217
3218
3219





3220




3221
3222
3223
3224
3225
3226
3227
  if( find_option("debug",0,0)!=0 ) diffFlags |= DIFF_DEBUG;
  if( find_option("raw",0,0)!=0 )   diffFlags |= DIFF_RAW;
  return diffFlags;
}

/*
** COMMAND: test-diff

**
** Usage: %fossil [options] FILE1 FILE2
**





** Print the difference between two files.  The usual diff options apply.




*/
void test_diff_cmd(void){
  Blob a, b, out;
  u64 diffFlag;
  const char *zRe;           /* Regex filter for diff output */
  ReCompiled *pRe = 0;       /* Regex filter for diff output */








>

|

>
>
>
>
>
|
>
>
>
>







3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
  if( find_option("debug",0,0)!=0 ) diffFlags |= DIFF_DEBUG;
  if( find_option("raw",0,0)!=0 )   diffFlags |= DIFF_RAW;
  return diffFlags;
}

/*
** COMMAND: test-diff
** COMMAND: xdiff
**
** Usage: %fossil xdiff [options] FILE1 FILE2
**
** This is the "external diff" feature.  By "external" here we mean a diff
** applied to files that are not under version control.  See the "diff"
** command for computing differences between files that are under control.
**
** This command prints the differences between the two files FILE1 and FILE2.
** all of the usual diff command-line options apply.  See the "diff" command
** for a full list of command-line options.
**
** This command used to be called "test-diff".  The older "test-diff" spelling
** still works, for compatibility.
*/
void test_diff_cmd(void){
  Blob a, b, out;
  u64 diffFlag;
  const char *zRe;           /* Regex filter for diff output */
  ReCompiled *pRe = 0;       /* Regex filter for diff output */

Changes to src/diffcmd.c.

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  return 0;
}

/*
** Print the "Index:" message that patches wants to see at the top of a diff.
*/
void diff_print_index(const char *zFile, u64 diffFlags, Blob *diffBlob){
  if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT|
                    DIFF_WEBPAGE|DIFF_TCL))==0 ){
    char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
    if( !diffBlob ){
      fossil_print("%s", z);
    }else{
      blob_appendf(diffBlob, "%s", z);
    }







|







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  return 0;
}

/*
** Print the "Index:" message that patches wants to see at the top of a diff.
*/
void diff_print_index(const char *zFile, u64 diffFlags, Blob *diffBlob){
  if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT|DIFF_JSON|
                    DIFF_WEBPAGE|DIFF_TCL))==0 ){
    char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
    if( !diffBlob ){
      fossil_print("%s", z);
    }else{
      blob_appendf(diffBlob, "%s", z);
    }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
void diff_print_filenames(
  const char *zLeft,
  const char *zRight,
  u64 diffFlags,
  Blob *diffBlob
){
  char *z = 0;
  if( diffFlags & (DIFF_BRIEF|DIFF_RAW) ){
    /* no-op */
  }else if( diffFlags & DIFF_DEBUG ){
    fossil_print("FILE-LEFT   %s\nFILE-RIGHT  %s\n",
       zLeft, zRight);
  }else if( diffFlags & DIFF_WEBPAGE ){
    if( fossil_strcmp(zLeft,zRight)==0 ){
      z = mprintf("<h1>%h</h1>\n", zLeft);
    }else{
      z = mprintf("<h1>%h &lrarr; %h</h1>\n", zLeft, zRight);
    }
  }else if( diffFlags & DIFF_TCL ){
    Blob *pOut;
    Blob x;
    if( diffBlob ){
      pOut = diffBlob;
    }else{
      blob_init(&x, 0, 0);
      pOut = &x;
    }
    blob_append(pOut, "FILE ", 5);
    blob_append_tcl_string(pOut, zLeft, (int)strlen(zLeft));
    blob_append_char(pOut, ' ');
    blob_append_tcl_string(pOut, zRight, (int)strlen(zRight));
    blob_append_char(pOut, '\n');
    if( !diffBlob ){
      fossil_print("%s", blob_str(pOut));
      blob_reset(&x);
    }
    return;
  }else if( diffFlags & DIFF_SIDEBYSIDE ){







|




















|

|







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
void diff_print_filenames(
  const char *zLeft,
  const char *zRight,
  u64 diffFlags,
  Blob *diffBlob
){
  char *z = 0;
  if( diffFlags & (DIFF_BRIEF|DIFF_RAW|DIFF_JSON) ){
    /* no-op */
  }else if( diffFlags & DIFF_DEBUG ){
    fossil_print("FILE-LEFT   %s\nFILE-RIGHT  %s\n",
       zLeft, zRight);
  }else if( diffFlags & DIFF_WEBPAGE ){
    if( fossil_strcmp(zLeft,zRight)==0 ){
      z = mprintf("<h1>%h</h1>\n", zLeft);
    }else{
      z = mprintf("<h1>%h &lrarr; %h</h1>\n", zLeft, zRight);
    }
  }else if( diffFlags & DIFF_TCL ){
    Blob *pOut;
    Blob x;
    if( diffBlob ){
      pOut = diffBlob;
    }else{
      blob_init(&x, 0, 0);
      pOut = &x;
    }
    blob_append(pOut, "FILE ", 5);
    blob_append_string_literal(pOut, zLeft, (int)strlen(zLeft));
    blob_append_char(pOut, ' ');
    blob_append_string_literal(pOut, zRight, (int)strlen(zRight));
    blob_append_char(pOut, '\n');
    if( !diffBlob ){
      fossil_print("%s", blob_str(pOut));
      blob_reset(&x);
    }
    return;
  }else if( diffFlags & DIFF_SIDEBYSIDE ){