Fossil

Diff
Login

Diff

Differences From Artifact [980fbafcec]:

To Artifact [cda92a83e3]:


1633
1634
1635
1636
1637
1638
1639


1640
1641
1642
1643
1644
1645
1646
  void (*xCommon)(DiffBuilder*,const DLine*);
  void (*xInsert)(DiffBuilder*,const DLine*);
  void (*xDelete)(DiffBuilder*,const DLine*);
  void (*xEdit)(DiffBuilder*,const DLine*,const DLine*);
  void (*xEnd)(DiffBuilder*);
  unsigned int lnLeft;              /* Lines seen on the left (delete) side */
  unsigned int lnRight;             /* Lines seen on the right (insert) side */


  Blob *pOut;                       /* Output blob */
  Blob aCol[5];                     /* Holding blobs */
};

/************************* DiffBuilderDebug ********************************/
static void dfdebugSkip(DiffBuilder *p, unsigned int n, int isFinal){
  blob_appendf(p->pOut, "SKIP %d (%d..%d left and %d..%d right)%s\n",







>
>







1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
  void (*xCommon)(DiffBuilder*,const DLine*);
  void (*xInsert)(DiffBuilder*,const DLine*);
  void (*xDelete)(DiffBuilder*,const DLine*);
  void (*xEdit)(DiffBuilder*,const DLine*,const DLine*);
  void (*xEnd)(DiffBuilder*);
  unsigned int lnLeft;              /* Lines seen on the left (delete) side */
  unsigned int lnRight;             /* Lines seen on the right (insert) side */
  unsigned int nPending;            /* Number of pending lines */
  int eState;                       /* State of the output */
  Blob *pOut;                       /* Output blob */
  Blob aCol[5];                     /* Holding blobs */
};

/************************* DiffBuilderDebug ********************************/
static void dfdebugSkip(DiffBuilder *p, unsigned int n, int isFinal){
  blob_appendf(p->pOut, "SKIP %d (%d..%d left and %d..%d right)%s\n",
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
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
  return p;
}

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

/* Accumulator strategy:
**
**    *   Common and Delete line numbers are output directly to p->pOut


**    *   Common and Delete text accumulates in p->aCol[0].
**    *   Pending insert lines numbers go into p->aCol[1].
**    *   Pending insert text goes into p->aCol[2].


*/
static void dfunifiedEmitInsert(DiffBuilder *p){
  if( blob_size(&p->aCol[1])==0 ) return;
  blob_append(p->pOut, blob_buffer(&p->aCol[1]), blob_size(&p->aCol[1]));







  blob_reset(&p->aCol[1]);




  blob_append(&p->aCol[0], blob_buffer(&p->aCol[2]), blob_size(&p->aCol[2]));






















  blob_reset(&p->aCol[2]);

}






static void dfunifiedSkip(DiffBuilder *p, unsigned int n, int isFinal){
  dfunifiedEmitInsert(p);
  if( (p->lnLeft || p->lnRight) && !isFinal ){
    blob_append(p->pOut,
       "<span class=\"diffhr\">"
       ".................."
       "</span>\n",
       -1);
    blob_append(&p->aCol[0],
       "<span class=\"diffhr\">"
       "..............................................................."
       "</span>\n",
       -1);
  }
  p->lnLeft += n;
  p->lnRight += n;
}
static void dfunifiedCommon(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;
  dfunifiedEmitInsert(p);


  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"%6d  %6d  \n", p->lnLeft, p->lnRight);
  blob_append(&p->aCol[0], "  ", 2);

  jsonize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n, &iCol);
  blob_append_char(&p->aCol[0], '\n');
}
static void dfunifiedInsert(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;

  p->lnRight++;
  blob_appendf(&p->aCol[1],"<ins>        %6d  </ins>\n", p->lnRight);
  blob_append(&p->aCol[2],"<ins>+ <mark>",-1);
  jsonize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n, &iCol);
  blob_append(&p->aCol[2], "</mark></ins>\n", -1);

}
static void dfunifiedDelete(DiffBuilder *p, const DLine *pLine){
  int iCol = 0;








  p->lnLeft++;
  blob_appendf(p->pOut,"<del>%6d          </del>\n", p->lnLeft);

  blob_append(&p->aCol[0],"<del>- <mark>",-1);

  jsonize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n, &iCol);
  blob_append(&p->aCol[0], "</mark></del>\n", -1);
}
static void dfunifiedEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
  int i;
  int x;
  int iCol;
  ChangeSpan span;
  oneLineChange(pX, pY, &span);







  p->lnLeft++;
  p->lnRight++;
  blob_appendf(p->pOut,"<del>%6d          </del>\n", p->lnLeft);

  blob_append(&p->aCol[0], "<del>- ", -1);

  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], "<mark>", 6);
      jsonize_to_blob(&p->aCol[0], pX->z+x, len, &iCol);
      x += len;
      blob_append(&p->aCol[0], "</mark>", 7);
    }
  }
  if( x<pX->n ) jsonize_to_blob(&p->aCol[0], pX->z+x,  pX->n - x, &iCol);
  blob_append(&p->aCol[0], "</del>\n", -1);
  blob_appendf(&p->aCol[1],"<ins>        %6d  </ins>\n", p->lnRight);
  blob_append(&p->aCol[2], "<ins>+ ", -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->aCol[2], pY->z+x, ofst - x, &iCol);
      x = ofst;
      blob_append(&p->aCol[2], "<mark>", 6);
      jsonize_to_blob(&p->aCol[2], pY->z+x, len, &iCol);
      x += len;
      blob_append(&p->aCol[2], "</mark>", 7);
    }
  }
  if( x<pY->n ) jsonize_to_blob(&p->aCol[2], pY->z+x,  pY->n - x, &iCol);
  blob_append(&p->aCol[2], "</ins>\n", -1);

}
static void dfunifiedEnd(DiffBuilder *p){
  dfunifiedEmitInsert(p);
  blob_append(p->pOut,
     "</pre></td>\n"
     "<td class=\"udifftxt\" width=\"100%\"><pre class=\"udifftxt\">\n",
     -1);
  blob_append(p->pOut, blob_buffer(&p->aCol[0]), blob_size(&p->aCol[0]));
  blob_reset(&p->aCol[0]);
  blob_append(p->pOut, "</pre></td></tr>\n</table>\n", -1);
  fossil_free(p);
}
static DiffBuilder *dfunifiedNew(Blob *pOut){
  DiffBuilder *p = fossil_malloc(sizeof(*p));
  p->xSkip = dfunifiedSkip;
  p->xCommon = dfunifiedCommon;
  p->xInsert = dfunifiedInsert;
  p->xDelete = dfunifiedDelete;
  p->xEdit = dfunifiedEdit;
  p->xEnd = dfunifiedEnd;
  p->lnLeft = p->lnRight = 0;


  p->pOut = pOut;
  blob_append(pOut,
    "<table class=\"sbsdiffcols\">\n"
    "<tr><td class=\"udiffln\"><pre class=\"udiffln\">\n",
    -1);
  blob_init(&p->aCol[0], 0, 0);
  blob_init(&p->aCol[1], 0, 0);
  blob_init(&p->aCol[2], 0, 0);


  return p;
}
/****************************************************************************/

/*
** Format a diff using a DiffBuilder object
*/







|
>
>
|
|
|
>
>

|
|
|
>
>
>
>
>
>
>
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>

>
>
>
>
>
>

|

|
<
<
<
|
<
<
<
<
<






|
>
>


|
|
>
|
|



>

|
|
|
|
>



>
>
>
>
>
>
>
>

|
>
|
>
|
|







>
>
>
>
>
>
>


|
>
|
>




|

|
|

|


|
|
|
|




|

|
|

|


|
|
>


|
|
<
<
<
<
<
<











>
>

|
<
<
<



>
>







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
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
  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].
**
** eState is 1 if text has an open <del>
*/
static void dfunifiedFinishDelete(DiffBuilder *p){
  if( p->eState==0 ) return;
  blob_append(p->pOut, "</del>", 6);
  blob_append(&p->aCol[2], "</del>", 6);
  p->eState = 0;
}
static void dfunifiedFinishInsert(DiffBuilder *p){
  unsigned int i;
  if( p->nPending==0 ) return;
  dfunifiedFinishDelete(p);

  /* Blank lines for delete line numbers for each inserted line */
  for(i=0; i<p->nPending; i++) blob_append_char(p->pOut, '\n');

  /* Insert line numbers */
  blob_append(&p->aCol[0], "<ins>", 5);
  blob_append_xfer(&p->aCol[0], &p->aCol[3]);
  blob_append(&p->aCol[0], "</ins>", 6);

  /* "+" marks for the separator on inserted lines */
  for(i=0; i<p->nPending; i++) blob_append(&p->aCol[1], "+\n", 2);

  /* Text of the inserted lines */
  blob_append(&p->aCol[2], "<ins>", 5);
  blob_append_xfer(&p->aCol[2], &p->aCol[4]);
  blob_append(&p->aCol[2], "</ins>", 6);
  
  p->nPending = 0;
}
static void dfunifiedFinishRow(DiffBuilder *p){
  dfunifiedFinishDelete(p);
  dfunifiedFinishInsert(p);
  if( blob_size(&p->aCol[0])==0 ) return;
  blob_append(p->pOut, "</pre></td><td class=\"diffln difflnr\"><pre>\n", -1);
  blob_append_xfer(p->pOut, &p->aCol[0]);
  blob_append(p->pOut, "</pre></td><td class=\"diffsep\"><pre>\n", -1);
  blob_append_xfer(p->pOut, &p->aCol[1]);
  blob_append(p->pOut, "</pre></td><td class=\"difftxt difftxtu\"><pre>\n",-1);
  blob_append_xfer(p->pOut, &p->aCol[2]);
  blob_append(p->pOut, "</pre></td></tr>\n", -1);
}
static void dfunifiedStartRow(DiffBuilder *p){
  if( blob_size(&p->aCol[0])>0 ) return;
  blob_append(p->pOut,"<tr><td class=\"diffln difflnl\"><pre>\n", -1);
  p->eState = 0;
  p->nPending = 0;
}
static void dfunifiedSkip(DiffBuilder *p, unsigned int n, int isFinal){
  dfunifiedFinishRow(p);
  if( (p->lnLeft || p->lnRight) && !isFinal ){
    blob_append(p->pOut, "<tr><td class=\"diffskip\" colspan=\"2\">"



                         "<hr></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 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);
}
static DiffBuilder *dfunifiedNew(Blob *pOut){
  DiffBuilder *p = fossil_malloc(sizeof(*p));
  p->xSkip = dfunifiedSkip;
  p->xCommon = dfunifiedCommon;
  p->xInsert = dfunifiedInsert;
  p->xDelete = dfunifiedDelete;
  p->xEdit = dfunifiedEdit;
  p->xEnd = dfunifiedEnd;
  p->lnLeft = p->lnRight = 0;
  p->eState = 0;
  p->nPending = 0;
  p->pOut = pOut;
  blob_append(pOut, "<table class=\"diff\">\n", -1);



  blob_init(&p->aCol[0], 0, 0);
  blob_init(&p->aCol[1], 0, 0);
  blob_init(&p->aCol[2], 0, 0);
  blob_init(&p->aCol[3], 0, 0);
  blob_init(&p->aCol[4], 0, 0);
  return p;
}
/****************************************************************************/

/*
** Format a diff using a DiffBuilder object
*/