| | @@ -1742,73 +1742,54 @@ |
| 1742 | 1742 | /************************* DiffBuilderTcl ********************************/ |
| 1743 | 1743 | /* |
| 1744 | 1744 | ** This variant outputs a description of the diff formatted as TCL, for |
| 1745 | 1745 | ** use by the --tk option to "diff". |
| 1746 | 1746 | */ |
| 1747 | | - |
| 1748 | | -/* |
| 1749 | | -** Write out a quoted TCL string |
| 1750 | | -*/ |
| 1751 | | -void blob_append_tcl_string(Blob *pOut, const char *z, int n){ |
| 1752 | | - int i; |
| 1753 | | - blob_append_char(pOut, '"'); |
| 1754 | | - for(i=0; i<n; i++){ |
| 1755 | | - switch( z[i] ){ |
| 1756 | | - case '"': |
| 1757 | | - case '\\': |
| 1758 | | - blob_append_char(pOut, '\\'); |
| 1759 | | - /* Fall thru */ |
| 1760 | | - default: |
| 1761 | | - blob_append_char(pOut, z[i]); |
| 1762 | | - } |
| 1763 | | - } |
| 1764 | | - blob_append_char(pOut, '"'); |
| 1765 | | -} |
| 1766 | | - |
| 1767 | 1747 | static void dftclSkip(DiffBuilder *p, unsigned int n, int isFinal){ |
| 1768 | 1748 | blob_appendf(p->pOut, "SKIP %u\n", n); |
| 1769 | 1749 | } |
| 1770 | 1750 | static void dftclCommon(DiffBuilder *p, const DLine *pLine){ |
| 1771 | 1751 | blob_appendf(p->pOut, "COM "); |
| 1772 | | - blob_append_tcl_string(p->pOut, pLine->z, pLine->n); |
| 1752 | + blob_append_string_literal(p->pOut, pLine->z, pLine->n); |
| 1773 | 1753 | blob_append_char(p->pOut, '\n'); |
| 1774 | 1754 | } |
| 1775 | 1755 | static void dftclInsert(DiffBuilder *p, const DLine *pLine){ |
| 1776 | 1756 | blob_append(p->pOut, "INS ", -1); |
| 1777 | | - blob_append_tcl_string(p->pOut, pLine->z, pLine->n); |
| 1757 | + blob_append_string_literal(p->pOut, pLine->z, pLine->n); |
| 1778 | 1758 | blob_append_char(p->pOut, '\n'); |
| 1779 | 1759 | } |
| 1780 | 1760 | static void dftclDelete(DiffBuilder *p, const DLine *pLine){ |
| 1781 | 1761 | blob_append(p->pOut, "DEL ", -1); |
| 1782 | | - blob_append_tcl_string(p->pOut, pLine->z, pLine->n); |
| 1762 | + blob_append_string_literal(p->pOut, pLine->z, pLine->n); |
| 1783 | 1763 | blob_append_char(p->pOut, '\n'); |
| 1784 | 1764 | } |
| 1785 | 1765 | static void dftclReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){ |
| 1786 | 1766 | blob_append(p->pOut, "EDIT ", -1); |
| 1787 | | - blob_append_tcl_string(p->pOut, pX->z, pX->n); |
| 1767 | + blob_append_string_literal(p->pOut, pX->z, pX->n); |
| 1788 | 1768 | blob_append_char(p->pOut, ' '); |
| 1789 | | - blob_append_tcl_string(p->pOut, pY->z, pY->n); |
| 1769 | + blob_append_string_literal(p->pOut, pY->z, pY->n); |
| 1790 | 1770 | blob_append_char(p->pOut, '\n'); |
| 1791 | 1771 | } |
| 1792 | 1772 | static void dftclEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){ |
| 1793 | 1773 | int i, x; |
| 1794 | 1774 | ChangeSpan span; |
| 1795 | 1775 | blob_append(p->pOut, "EDIT", 4); |
| 1796 | 1776 | oneLineChange(pX, pY, &span); |
| 1797 | 1777 | for(i=x=0; i<span.n; i++){ |
| 1798 | 1778 | blob_append_char(p->pOut, ' '); |
| 1799 | | - blob_append_tcl_string(p->pOut, pX->z + x, span.a[i].iStart1 - x); |
| 1779 | + blob_append_string_literal(p->pOut, pX->z + x, span.a[i].iStart1 - x); |
| 1800 | 1780 | x = span.a[i].iStart1; |
| 1801 | 1781 | blob_append_char(p->pOut, ' '); |
| 1802 | | - blob_append_tcl_string(p->pOut, pX->z + x, span.a[i].iLen1); |
| 1782 | + blob_append_string_literal(p->pOut, pX->z + x, span.a[i].iLen1); |
| 1803 | 1783 | x += span.a[i].iLen1; |
| 1804 | 1784 | blob_append_char(p->pOut, ' '); |
| 1805 | | - blob_append_tcl_string(p->pOut, pY->z + span.a[i].iStart2,span.a[i].iLen2); |
| 1785 | + blob_append_string_literal(p->pOut, |
| 1786 | + pY->z + span.a[i].iStart2, span.a[i].iLen2); |
| 1806 | 1787 | } |
| 1807 | 1788 | if( x<pX->n ){ |
| 1808 | 1789 | blob_append_char(p->pOut, ' '); |
| 1809 | | - blob_append_tcl_string(p->pOut, pX->z + x, pX->n - x); |
| 1790 | + blob_append_string_literal(p->pOut, pX->z + x, pX->n - x); |
| 1810 | 1791 | } |
| 1811 | 1792 | blob_append_char(p->pOut, '\n'); |
| 1812 | 1793 | } |
| 1813 | 1794 | static void dftclEnd(DiffBuilder *p){ |
| 1814 | 1795 | fossil_free(p); |
| | @@ -1825,134 +1806,73 @@ |
| 1825 | 1806 | p->pOut = pOut; |
| 1826 | 1807 | return p; |
| 1827 | 1808 | } |
| 1828 | 1809 | |
| 1829 | 1810 | /************************* DiffBuilderJson ********************************/ |
| 1830 | | - |
| 1831 | | -/* Convert raw text into content suitable for a JSON string. Escape |
| 1832 | | -** charaters that are special to HTML and to JSON: |
| 1833 | | -** |
| 1834 | | -** < -> < |
| 1835 | | -** > -> > |
| 1836 | | -** & -> & |
| 1837 | | -** " -> " |
| 1838 | | -** ' -> ' |
| 1839 | | -** \ -> \ |
| 1840 | | -** |
| 1841 | | -** In addition, TAB characters are converted into an appropriate number |
| 1842 | | -** of spaces. The *piCol value is the number of prior columns in the |
| 1843 | | -** current line. Update the column count before returning, so that |
| 1844 | | -** subsequent invocations can figure out the right number of spaces to |
| 1845 | | -** insert for each tab. |
| 1846 | | -*/ |
| 1847 | | -static void jsonize_to_blob(Blob *p, const char *zIn, int n, int *piCol){ |
| 1848 | | - int c, i, x; |
| 1849 | | - int iCol = *piCol; |
| 1850 | | - for(i=0; i<n; i++){ |
| 1851 | | - c = zIn[i]; |
| 1852 | | - switch( c ){ |
| 1853 | | - case '<': |
| 1854 | | - blob_append(p, "<", 4); |
| 1855 | | - iCol++; |
| 1856 | | - break; |
| 1857 | | - case '>': |
| 1858 | | - blob_append(p, ">", 4); |
| 1859 | | - iCol++; |
| 1860 | | - break; |
| 1861 | | - case '&': |
| 1862 | | - blob_append(p, "&", 5); |
| 1863 | | - iCol++; |
| 1864 | | - break; |
| 1865 | | - case '"': |
| 1866 | | - blob_append(p, """, 6); |
| 1867 | | - iCol++; |
| 1868 | | - break; |
| 1869 | | - case '\'': |
| 1870 | | - blob_append(p, "'", 5); |
| 1871 | | - iCol++; |
| 1872 | | - break; |
| 1873 | | - case '\\': |
| 1874 | | - blob_append(p, "\", 5); |
| 1875 | | - iCol++; |
| 1876 | | - break; |
| 1877 | | - case '\t': |
| 1878 | | - x = 1 + (iCol+7)%8; |
| 1879 | | - blob_appendf(p, "%*s", x, ""); |
| 1880 | | - iCol += x; |
| 1881 | | - break; |
| 1882 | | - default: |
| 1883 | | - blob_append_char(p, c); |
| 1884 | | - if( (c&0xc0)!=0x80 ) iCol++; |
| 1885 | | - break; |
| 1886 | | - } |
| 1887 | | - } |
| 1888 | | - *piCol = iCol; |
| 1889 | | -} |
| 1811 | +/* |
| 1812 | +** This module generates a JSON array that describes the difference. |
| 1813 | +** |
| 1814 | +** The Json array consists of integer opcodes with each opcode followed |
| 1815 | +** by zero or more arguments: |
| 1816 | +** |
| 1817 | +** Syntax Mnemonic Description |
| 1818 | +** ----------- -------- -------------------------- |
| 1819 | +** 0 END This is the end of the diff |
| 1820 | +** 1 INTEGER SKIP Skip N lines from both files |
| 1821 | +** 2 STRING COMMON The line show by STRING is in both files |
| 1822 | +** 3 STRING INSERT The line STRING is in only the right file |
| 1823 | +** 4 STRING DELETE The STRING line is in only the left file |
| 1824 | +** 5 SUBARRAY EDIT One line is different on left and right. |
| 1825 | +** |
| 1826 | +** The SUBARRAY is an array of 3*N+1 strings with N>=0. The triples |
| 1827 | +** represent common-text, left-text, and right-text. The last string |
| 1828 | +** in SUBARRAY is the common-suffix. Any string can be empty if it does |
| 1829 | +** not apply. |
| 1830 | +*/ |
| 1890 | 1831 | static void dfjsonSkip(DiffBuilder *p, unsigned int n, int isFinal){ |
| 1891 | 1832 | blob_appendf(p->pOut, "1,%u,\n", n); |
| 1892 | 1833 | } |
| 1893 | 1834 | static void dfjsonCommon(DiffBuilder *p, const DLine *pLine){ |
| 1894 | | - int iCol = 0; |
| 1895 | | - blob_append(p->pOut, "2,\"",3); |
| 1896 | | - jsonize_to_blob(p->pOut, pLine->z, (int)pLine->n, &iCol); |
| 1897 | | - blob_append(p->pOut, "\",\n",3); |
| 1835 | + blob_append(p->pOut, "2,",2); |
| 1836 | + blob_append_string_literal(p->pOut, pLine->z, (int)pLine->n); |
| 1837 | + blob_append(p->pOut, ",\n",2); |
| 1898 | 1838 | } |
| 1899 | 1839 | static void dfjsonInsert(DiffBuilder *p, const DLine *pLine){ |
| 1900 | | - int iCol = 0; |
| 1901 | | - blob_append(p->pOut, "3,\"",3); |
| 1902 | | - jsonize_to_blob(p->pOut, pLine->z, (int)pLine->n, &iCol); |
| 1903 | | - blob_append(p->pOut, "\",\n",3); |
| 1840 | + blob_append(p->pOut, "3,",2); |
| 1841 | + blob_append_string_literal(p->pOut, pLine->z, (int)pLine->n); |
| 1842 | + blob_append(p->pOut, ",\n",2); |
| 1904 | 1843 | } |
| 1905 | 1844 | static void dfjsonDelete(DiffBuilder *p, const DLine *pLine){ |
| 1906 | | - int iCol = 0; |
| 1907 | | - blob_append(p->pOut, "4,\"",3); |
| 1908 | | - jsonize_to_blob(p->pOut, pLine->z, (int)pLine->n, &iCol); |
| 1909 | | - blob_append(p->pOut, "\",\n",3); |
| 1845 | + blob_append(p->pOut, "4,",2); |
| 1846 | + blob_append_string_literal(p->pOut, pLine->z, (int)pLine->n); |
| 1847 | + blob_append(p->pOut, ",\n",2); |
| 1910 | 1848 | } |
| 1911 | 1849 | static void dfjsonReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){ |
| 1912 | | - int iCol = 0; |
| 1913 | | - blob_append(p->pOut, "5,\"",3); |
| 1914 | | - jsonize_to_blob(p->pOut, pX->z, (int)pX->n, &iCol); |
| 1915 | | - blob_append(p->pOut, "\",\"",3); |
| 1916 | | - jsonize_to_blob(p->pOut, pY->z, (int)pY->n, &iCol); |
| 1917 | | - blob_append(p->pOut, "\",\n",3); |
| 1850 | + blob_append(p->pOut, "5,[\"\",",-1); |
| 1851 | + blob_append_string_literal(p->pOut, pX->z, (int)pX->n); |
| 1852 | + blob_append(p->pOut, ",",1); |
| 1853 | + blob_append_string_literal(p->pOut, pY->z, (int)pY->n); |
| 1854 | + blob_append(p->pOut, ",\"\"],\n",-1); |
| 1918 | 1855 | } |
| 1919 | 1856 | static void dfjsonEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){ |
| 1920 | | - int i; |
| 1921 | | - int x; |
| 1922 | | - int iCol; |
| 1857 | + int i, x; |
| 1923 | 1858 | ChangeSpan span; |
| 1859 | + blob_append(p->pOut, "5,[", 3); |
| 1924 | 1860 | oneLineChange(pX, pY, &span); |
| 1925 | | - blob_appendf(p->pOut, "5,\""); |
| 1926 | | - for(i=x=iCol=0; i<span.n; i++){ |
| 1927 | | - int ofst = span.a[i].iStart1; |
| 1928 | | - int len = span.a[i].iLen1; |
| 1929 | | - if( len ){ |
| 1930 | | - jsonize_to_blob(p->pOut, pX->z+x, ofst - x, &iCol); |
| 1931 | | - x = ofst; |
| 1932 | | - blob_append(p->pOut, "<mark>", 6); |
| 1933 | | - jsonize_to_blob(p->pOut, pX->z+x, len, &iCol); |
| 1934 | | - x += len; |
| 1935 | | - blob_append(p->pOut, "</mark>", 7); |
| 1936 | | - } |
| 1937 | | - } |
| 1938 | | - if( x<pX->n ) jsonize_to_blob(p->pOut, pX->z+x, pX->n - x, &iCol); |
| 1939 | | - blob_append(p->pOut, "\",\n \"", -1); |
| 1940 | | - for(i=x=iCol=0; i<span.n; i++){ |
| 1941 | | - int ofst = span.a[i].iStart2; |
| 1942 | | - int len = span.a[i].iLen2; |
| 1943 | | - if( len ){ |
| 1944 | | - jsonize_to_blob(p->pOut, pY->z+x, ofst - x, &iCol); |
| 1945 | | - x = ofst; |
| 1946 | | - blob_append(p->pOut, "<mark>", 6); |
| 1947 | | - jsonize_to_blob(p->pOut, pY->z+x, len, &iCol); |
| 1948 | | - x += len; |
| 1949 | | - blob_append(p->pOut, "</mark>", 7); |
| 1950 | | - } |
| 1951 | | - } |
| 1952 | | - if( x<pY->n ) jsonize_to_blob(p->pOut, pY->z+x, pY->n - x, &iCol); |
| 1953 | | - blob_append(p->pOut, "\",\n", -1); |
| 1861 | + for(i=x=0; i<span.n; i++){ |
| 1862 | + blob_append_string_literal(p->pOut, pX->z + x, span.a[i].iStart1 - x); |
| 1863 | + x = span.a[i].iStart1; |
| 1864 | + blob_append_char(p->pOut, ','); |
| 1865 | + blob_append_string_literal(p->pOut, pX->z + x, span.a[i].iLen1); |
| 1866 | + x += span.a[i].iLen1; |
| 1867 | + blob_append_char(p->pOut, ','); |
| 1868 | + blob_append_string_literal(p->pOut, |
| 1869 | + pY->z + span.a[i].iStart2, span.a[i].iLen2); |
| 1870 | + } |
| 1871 | + blob_append_char(p->pOut, ','); |
| 1872 | + blob_append_string_literal(p->pOut, pX->z + x, pX->n - x); |
| 1873 | + blob_append(p->pOut, "],\n",3); |
| 1954 | 1874 | } |
| 1955 | 1875 | static void dfjsonEnd(DiffBuilder *p){ |
| 1956 | 1876 | blob_append(p->pOut, "0]", 2); |
| 1957 | 1877 | fossil_free(p); |
| 1958 | 1878 | } |
| | @@ -1970,12 +1890,13 @@ |
| 1970 | 1890 | blob_append_char(pOut, '['); |
| 1971 | 1891 | return p; |
| 1972 | 1892 | } |
| 1973 | 1893 | |
| 1974 | 1894 | /************************* DiffBuilderUnified********************************/ |
| 1975 | | - |
| 1976 | | -/* Accumulator strategy: |
| 1895 | +/* This module generates a unified diff for HTML |
| 1896 | +** |
| 1897 | +** Accumulator strategy: |
| 1977 | 1898 | ** |
| 1978 | 1899 | ** * Delete line numbers are output directly to p->pOut |
| 1979 | 1900 | ** * Insert line numbers accumulate in p->aCol[0]. |
| 1980 | 1901 | ** * Separator marks accumulate in p->aCol[1]. |
| 1981 | 1902 | ** * Change text accumulates in p->aCol[2]. |
| | @@ -2039,34 +1960,31 @@ |
| 2039 | 1960 | } |
| 2040 | 1961 | p->lnLeft += n; |
| 2041 | 1962 | p->lnRight += n; |
| 2042 | 1963 | } |
| 2043 | 1964 | static void dfunifiedCommon(DiffBuilder *p, const DLine *pLine){ |
| 2044 | | - int iCol = 0; |
| 2045 | 1965 | dfunifiedStartRow(p); |
| 2046 | 1966 | dfunifiedFinishDelete(p); |
| 2047 | 1967 | dfunifiedFinishInsert(p); |
| 2048 | 1968 | p->lnLeft++; |
| 2049 | 1969 | p->lnRight++; |
| 2050 | 1970 | blob_appendf(p->pOut,"%d\n", p->lnLeft); |
| 2051 | 1971 | blob_appendf(&p->aCol[0],"%d\n",p->lnRight); |
| 2052 | 1972 | blob_append_char(&p->aCol[1], '\n'); |
| 2053 | | - jsonize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n, &iCol); |
| 1973 | + htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n); |
| 2054 | 1974 | blob_append_char(&p->aCol[2], '\n'); |
| 2055 | 1975 | } |
| 2056 | 1976 | static void dfunifiedInsert(DiffBuilder *p, const DLine *pLine){ |
| 2057 | | - int iCol = 0; |
| 2058 | 1977 | dfunifiedStartRow(p); |
| 2059 | 1978 | p->lnRight++; |
| 2060 | 1979 | blob_appendf(&p->aCol[3],"%d\n", p->lnRight); |
| 2061 | 1980 | blob_append(&p->aCol[4], "<ins>", 5); |
| 2062 | | - jsonize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n, &iCol); |
| 1981 | + htmlize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n); |
| 2063 | 1982 | blob_append(&p->aCol[4], "</ins>\n", 7); |
| 2064 | 1983 | p->nPending++; |
| 2065 | 1984 | } |
| 2066 | 1985 | static void dfunifiedDelete(DiffBuilder *p, const DLine *pLine){ |
| 2067 | | - int iCol = 0; |
| 2068 | 1986 | dfunifiedStartRow(p); |
| 2069 | 1987 | dfunifiedFinishInsert(p); |
| 2070 | 1988 | if( p->eState==0 ){ |
| 2071 | 1989 | dfunifiedFinishInsert(p); |
| 2072 | 1990 | blob_append(p->pOut, "<del>", 5); |
| | @@ -2076,15 +1994,14 @@ |
| 2076 | 1994 | p->lnLeft++; |
| 2077 | 1995 | blob_appendf(p->pOut,"%d\n", p->lnLeft); |
| 2078 | 1996 | blob_append_char(&p->aCol[0],'\n'); |
| 2079 | 1997 | blob_append(&p->aCol[1],"-\n",2); |
| 2080 | 1998 | blob_append(&p->aCol[2], "<del>", 5); |
| 2081 | | - jsonize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n, &iCol); |
| 1999 | + htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n); |
| 2082 | 2000 | blob_append(&p->aCol[2], "</del>\n", 7); |
| 2083 | 2001 | } |
| 2084 | 2002 | static void dfunifiedReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){ |
| 2085 | | - int iCol; |
| 2086 | 2003 | dfunifiedStartRow(p); |
| 2087 | 2004 | if( p->eState==0 ){ |
| 2088 | 2005 | dfunifiedFinishInsert(p); |
| 2089 | 2006 | blob_append(p->pOut, "<del>", 5); |
| 2090 | 2007 | blob_append(&p->aCol[2], "<del>", 5); |
| | @@ -2094,25 +2011,22 @@ |
| 2094 | 2011 | p->lnRight++; |
| 2095 | 2012 | blob_appendf(p->pOut,"%d\n", p->lnLeft); |
| 2096 | 2013 | blob_append_char(&p->aCol[0], '\n'); |
| 2097 | 2014 | blob_append(&p->aCol[1], "-\n", 2); |
| 2098 | 2015 | |
| 2099 | | - iCol = 0; |
| 2100 | | - jsonize_to_blob(&p->aCol[2], pX->z, pX->n, &iCol); |
| 2016 | + htmlize_to_blob(&p->aCol[2], pX->z, pX->n); |
| 2101 | 2017 | blob_append_char(&p->aCol[2], '\n'); |
| 2102 | 2018 | |
| 2103 | 2019 | blob_appendf(&p->aCol[3],"%d\n", p->lnRight); |
| 2104 | 2020 | |
| 2105 | | - iCol = 0; |
| 2106 | | - jsonize_to_blob(&p->aCol[4], pY->z, pY->n, &iCol); |
| 2021 | + htmlize_to_blob(&p->aCol[4], pY->z, pY->n); |
| 2107 | 2022 | blob_append_char(&p->aCol[4], '\n'); |
| 2108 | 2023 | p->nPending++; |
| 2109 | 2024 | } |
| 2110 | 2025 | static void dfunifiedEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){ |
| 2111 | 2026 | int i; |
| 2112 | 2027 | int x; |
| 2113 | | - int iCol; |
| 2114 | 2028 | ChangeSpan span; |
| 2115 | 2029 | oneLineChange(pX, pY, &span); |
| 2116 | 2030 | dfunifiedStartRow(p); |
| 2117 | 2031 | if( p->eState==0 ){ |
| 2118 | 2032 | dfunifiedFinishInsert(p); |
| | @@ -2124,39 +2038,39 @@ |
| 2124 | 2038 | p->lnRight++; |
| 2125 | 2039 | blob_appendf(p->pOut,"%d\n", p->lnLeft); |
| 2126 | 2040 | blob_append_char(&p->aCol[0], '\n'); |
| 2127 | 2041 | blob_append(&p->aCol[1], "-\n", 2); |
| 2128 | 2042 | |
| 2129 | | - for(i=x=iCol=0; i<span.n; i++){ |
| 2043 | + for(i=x=0; i<span.n; i++){ |
| 2130 | 2044 | int ofst = span.a[i].iStart1; |
| 2131 | 2045 | int len = span.a[i].iLen1; |
| 2132 | 2046 | if( len ){ |
| 2133 | | - jsonize_to_blob(&p->aCol[2], pX->z+x, ofst - x, &iCol); |
| 2047 | + htmlize_to_blob(&p->aCol[2], pX->z+x, ofst - x); |
| 2134 | 2048 | x = ofst; |
| 2135 | 2049 | blob_append(&p->aCol[2], "<del>", 5); |
| 2136 | | - jsonize_to_blob(&p->aCol[2], pX->z+x, len, &iCol); |
| 2050 | + htmlize_to_blob(&p->aCol[2], pX->z+x, len); |
| 2137 | 2051 | x += len; |
| 2138 | 2052 | blob_append(&p->aCol[2], "</del>", 6); |
| 2139 | 2053 | } |
| 2140 | 2054 | } |
| 2141 | | - if( x<pX->n ) jsonize_to_blob(&p->aCol[2], pX->z+x, pX->n - x, &iCol); |
| 2055 | + htmlize_to_blob(&p->aCol[2], pX->z+x, pX->n - x); |
| 2142 | 2056 | blob_append_char(&p->aCol[2], '\n'); |
| 2143 | 2057 | |
| 2144 | 2058 | blob_appendf(&p->aCol[3],"%d\n", p->lnRight); |
| 2145 | | - for(i=x=iCol=0; i<span.n; i++){ |
| 2059 | + for(i=x=0; i<span.n; i++){ |
| 2146 | 2060 | int ofst = span.a[i].iStart2; |
| 2147 | 2061 | int len = span.a[i].iLen2; |
| 2148 | 2062 | if( len ){ |
| 2149 | | - jsonize_to_blob(&p->aCol[4], pY->z+x, ofst - x, &iCol); |
| 2063 | + htmlize_to_blob(&p->aCol[4], pY->z+x, ofst - x); |
| 2150 | 2064 | x = ofst; |
| 2151 | 2065 | blob_append(&p->aCol[4], "<ins>", 5); |
| 2152 | | - jsonize_to_blob(&p->aCol[4], pY->z+x, len, &iCol); |
| 2066 | + htmlize_to_blob(&p->aCol[4], pY->z+x, len); |
| 2153 | 2067 | x += len; |
| 2154 | 2068 | blob_append(&p->aCol[4], "</ins>", 6); |
| 2155 | 2069 | } |
| 2156 | 2070 | } |
| 2157 | | - if( x<pY->n ) jsonize_to_blob(&p->aCol[4], pY->z+x, pY->n - x, &iCol); |
| 2071 | + htmlize_to_blob(&p->aCol[4], pY->z+x, pY->n - x); |
| 2158 | 2072 | blob_append_char(&p->aCol[4], '\n'); |
| 2159 | 2073 | p->nPending++; |
| 2160 | 2074 | } |
| 2161 | 2075 | static void dfunifiedEnd(DiffBuilder *p){ |
| 2162 | 2076 | dfunifiedFinishRow(p); |
| | @@ -2184,12 +2098,13 @@ |
| 2184 | 2098 | blob_init(&p->aCol[4], 0, 0); |
| 2185 | 2099 | return p; |
| 2186 | 2100 | } |
| 2187 | 2101 | |
| 2188 | 2102 | /************************* DiffBuilderSplit ******************************/ |
| 2189 | | - |
| 2190 | | -/* Accumulator strategy: |
| 2103 | +/* This module generates a side-by-side diff for HTML. |
| 2104 | +** |
| 2105 | +** Accumulator strategy: |
| 2191 | 2106 | ** |
| 2192 | 2107 | ** * Left line numbers are output directly to p->pOut |
| 2193 | 2108 | ** * Left text accumulates in p->aCol[0]. |
| 2194 | 2109 | ** * Edit marks accumulates in p->aCol[1]. |
| 2195 | 2110 | ** * Right line numbers accumulate in p->aCol[2]. |
| | @@ -2251,110 +2166,103 @@ |
| 2251 | 2166 | } |
| 2252 | 2167 | p->lnLeft += n; |
| 2253 | 2168 | p->lnRight += n; |
| 2254 | 2169 | } |
| 2255 | 2170 | static void dfsplitCommon(DiffBuilder *p, const DLine *pLine){ |
| 2256 | | - int iCol = 0; |
| 2257 | 2171 | dfsplitStartRow(p); |
| 2258 | 2172 | dfsplitChangeState(p, 0); |
| 2259 | 2173 | p->lnLeft++; |
| 2260 | 2174 | p->lnRight++; |
| 2261 | 2175 | blob_appendf(p->pOut,"%d\n", p->lnLeft); |
| 2262 | | - jsonize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n, &iCol); |
| 2176 | + htmlize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n); |
| 2263 | 2177 | blob_append_char(&p->aCol[0], '\n'); |
| 2264 | 2178 | blob_append_char(&p->aCol[1], '\n'); |
| 2265 | 2179 | blob_appendf(&p->aCol[2],"%d\n",p->lnRight); |
| 2266 | | - jsonize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n, &iCol); |
| 2180 | + htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n); |
| 2267 | 2181 | blob_append_char(&p->aCol[3], '\n'); |
| 2268 | 2182 | } |
| 2269 | 2183 | static void dfsplitInsert(DiffBuilder *p, const DLine *pLine){ |
| 2270 | | - int iCol = 0; |
| 2271 | 2184 | dfsplitStartRow(p); |
| 2272 | 2185 | dfsplitChangeState(p, 2); |
| 2273 | 2186 | p->lnRight++; |
| 2274 | 2187 | blob_append_char(p->pOut, '\n'); |
| 2275 | 2188 | blob_append_char(&p->aCol[0], '\n'); |
| 2276 | 2189 | blob_append(&p->aCol[1], ">\n", -1); |
| 2277 | 2190 | blob_appendf(&p->aCol[2],"%d\n", p->lnRight); |
| 2278 | 2191 | blob_append(&p->aCol[3], "<ins>", 5); |
| 2279 | | - jsonize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n, &iCol); |
| 2192 | + htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n); |
| 2280 | 2193 | blob_append(&p->aCol[3], "</ins>\n", 7); |
| 2281 | 2194 | } |
| 2282 | 2195 | static void dfsplitDelete(DiffBuilder *p, const DLine *pLine){ |
| 2283 | | - int iCol = 0; |
| 2284 | 2196 | dfsplitStartRow(p); |
| 2285 | 2197 | dfsplitChangeState(p, 1); |
| 2286 | 2198 | p->lnLeft++; |
| 2287 | 2199 | blob_appendf(p->pOut,"%d\n", p->lnLeft); |
| 2288 | 2200 | blob_append(&p->aCol[0], "<del>", 5); |
| 2289 | | - jsonize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n, &iCol); |
| 2201 | + htmlize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n); |
| 2290 | 2202 | blob_append(&p->aCol[0], "</del>\n", 7); |
| 2291 | 2203 | blob_append(&p->aCol[1], "<\n", -1); |
| 2292 | 2204 | blob_append_char(&p->aCol[2],'\n'); |
| 2293 | 2205 | blob_append_char(&p->aCol[3],'\n'); |
| 2294 | 2206 | } |
| 2295 | 2207 | static void dfsplitReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){ |
| 2296 | | - int iCol; |
| 2297 | 2208 | dfsplitStartRow(p); |
| 2298 | 2209 | dfsplitChangeState(p, 3); |
| 2299 | 2210 | p->lnLeft++; |
| 2300 | 2211 | p->lnRight++; |
| 2301 | 2212 | blob_appendf(p->pOut,"%d\n", p->lnLeft); |
| 2302 | | - iCol = 0; |
| 2303 | | - jsonize_to_blob(&p->aCol[0], pX->z, pX->n, &iCol); |
| 2213 | + htmlize_to_blob(&p->aCol[0], pX->z, pX->n); |
| 2304 | 2214 | blob_append_char(&p->aCol[0], '\n'); |
| 2305 | 2215 | |
| 2306 | 2216 | blob_append(&p->aCol[1], "|\n", 2); |
| 2307 | 2217 | |
| 2308 | 2218 | blob_appendf(&p->aCol[2],"%d\n", p->lnRight); |
| 2309 | 2219 | |
| 2310 | | - iCol = 0; |
| 2311 | | - jsonize_to_blob(&p->aCol[3], pY->z, pY->n, &iCol); |
| 2220 | + htmlize_to_blob(&p->aCol[3], pY->z, pY->n); |
| 2312 | 2221 | blob_append_char(&p->aCol[3], '\n'); |
| 2313 | 2222 | } |
| 2314 | 2223 | static void dfsplitEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){ |
| 2315 | 2224 | int i; |
| 2316 | 2225 | int x; |
| 2317 | | - int iCol; |
| 2318 | | - ChangeSpan span; |
| 2226 | + ChangeSpan span; |
| 2319 | 2227 | oneLineChange(pX, pY, &span); |
| 2320 | 2228 | dfsplitStartRow(p); |
| 2321 | 2229 | dfsplitChangeState(p, 3); |
| 2322 | 2230 | p->lnLeft++; |
| 2323 | 2231 | p->lnRight++; |
| 2324 | 2232 | blob_appendf(p->pOut,"%d\n", p->lnLeft); |
| 2325 | | - for(i=x=iCol=0; i<span.n; i++){ |
| 2233 | + for(i=x=0; i<span.n; i++){ |
| 2326 | 2234 | int ofst = span.a[i].iStart1; |
| 2327 | 2235 | int len = span.a[i].iLen1; |
| 2328 | 2236 | if( len ){ |
| 2329 | | - jsonize_to_blob(&p->aCol[0], pX->z+x, ofst - x, &iCol); |
| 2237 | + htmlize_to_blob(&p->aCol[0], pX->z+x, ofst - x); |
| 2330 | 2238 | x = ofst; |
| 2331 | 2239 | blob_append(&p->aCol[0], "<del>", 5); |
| 2332 | | - jsonize_to_blob(&p->aCol[0], pX->z+x, len, &iCol); |
| 2240 | + htmlize_to_blob(&p->aCol[0], pX->z+x, len); |
| 2333 | 2241 | x += len; |
| 2334 | 2242 | blob_append(&p->aCol[0], "</del>", 6); |
| 2335 | 2243 | } |
| 2336 | 2244 | } |
| 2337 | | - if( x<pX->n ) jsonize_to_blob(&p->aCol[0], pX->z+x, pX->n - x, &iCol); |
| 2245 | + htmlize_to_blob(&p->aCol[0], pX->z+x, pX->n - x); |
| 2338 | 2246 | blob_append_char(&p->aCol[0], '\n'); |
| 2339 | 2247 | |
| 2340 | 2248 | blob_append(&p->aCol[1], "|\n", 2); |
| 2341 | 2249 | |
| 2342 | 2250 | blob_appendf(&p->aCol[2],"%d\n", p->lnRight); |
| 2343 | | - for(i=x=iCol=0; i<span.n; i++){ |
| 2251 | + for(i=x=0; i<span.n; i++){ |
| 2344 | 2252 | int ofst = span.a[i].iStart2; |
| 2345 | 2253 | int len = span.a[i].iLen2; |
| 2346 | 2254 | if( len ){ |
| 2347 | | - jsonize_to_blob(&p->aCol[3], pY->z+x, ofst - x, &iCol); |
| 2255 | + htmlize_to_blob(&p->aCol[3], pY->z+x, ofst - x); |
| 2348 | 2256 | x = ofst; |
| 2349 | 2257 | blob_append(&p->aCol[3], "<ins>", 5); |
| 2350 | | - jsonize_to_blob(&p->aCol[3], pY->z+x, len, &iCol); |
| 2258 | + htmlize_to_blob(&p->aCol[3], pY->z+x, len); |
| 2351 | 2259 | x += len; |
| 2352 | 2260 | blob_append(&p->aCol[3], "</ins>", 6); |
| 2353 | 2261 | } |
| 2354 | 2262 | } |
| 2355 | | - if( x<pY->n ) jsonize_to_blob(&p->aCol[3], pY->z+x, pY->n - x, &iCol); |
| 2263 | + htmlize_to_blob(&p->aCol[3], pY->z+x, pY->n - x); |
| 2356 | 2264 | blob_append_char(&p->aCol[3], '\n'); |
| 2357 | 2265 | } |
| 2358 | 2266 | static void dfsplitEnd(DiffBuilder *p){ |
| 2359 | 2267 | dfsplitFinishRow(p); |
| 2360 | 2268 | blob_append(p->pOut, "</table>\n",-1); |
| | @@ -3212,14 +3120,24 @@ |
| 3212 | 3120 | return diffFlags; |
| 3213 | 3121 | } |
| 3214 | 3122 | |
| 3215 | 3123 | /* |
| 3216 | 3124 | ** COMMAND: test-diff |
| 3125 | +** COMMAND: xdiff |
| 3126 | +** |
| 3127 | +** Usage: %fossil xdiff [options] FILE1 FILE2 |
| 3128 | +** |
| 3129 | +** This is the "external diff" feature. By "external" here we mean a diff |
| 3130 | +** applied to files that are not under version control. See the "diff" |
| 3131 | +** command for computing differences between files that are under control. |
| 3217 | 3132 | ** |
| 3218 | | -** Usage: %fossil [options] FILE1 FILE2 |
| 3133 | +** This command prints the differences between the two files FILE1 and FILE2. |
| 3134 | +** all of the usual diff command-line options apply. See the "diff" command |
| 3135 | +** for a full list of command-line options. |
| 3219 | 3136 | ** |
| 3220 | | -** Print the difference between two files. The usual diff options apply. |
| 3137 | +** This command used to be called "test-diff". The older "test-diff" spelling |
| 3138 | +** still works, for compatibility. |
| 3221 | 3139 | */ |
| 3222 | 3140 | void test_diff_cmd(void){ |
| 3223 | 3141 | Blob a, b, out; |
| 3224 | 3142 | u64 diffFlag; |
| 3225 | 3143 | const char *zRe; /* Regex filter for diff output */ |
| 3226 | 3144 | |