Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Further improvements to unified diff. Simplified CSS that can be used in common with split diff. Separate columns for each line number and the change mark. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | diff-color-enhancements |
| Files: | files | file ages | folders |
| SHA3-256: |
ce856a86148b45befe6275c5f686460c |
| User & Date: | drh 2021-09-01 15:38:48.850 |
Context
|
2021-09-01
| ||
| 19:53 | First attempt to generate side-by-side diffs using the new formatter. This breaks the --tk option. The "fossil diff -b" and "--by" work, but side-by-side diff on /info pages and similar is currently busted. CSS is simplified, which means that skins will need to be modified. This is an incremental check-in. ... (check-in: 4cd8a743cd user: drh tags: diff-color-enhancements) | |
| 15:38 | Further improvements to unified diff. Simplified CSS that can be used in common with split diff. Separate columns for each line number and the change mark. ... (check-in: ce856a8614 user: drh tags: diff-color-enhancements) | |
|
2021-08-31
| ||
| 22:43 | Tweaks to diff formatting. ... (check-in: 598d7736e7 user: drh tags: diff-color-enhancements) | |
Changes
Changes to src/blob.c.
| ︙ | ︙ | |||
345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
** Copy a blob
*/
void blob_copy(Blob *pTo, Blob *pFrom){
blob_is_init(pFrom);
blob_zero(pTo);
blob_append(pTo, blob_buffer(pFrom), blob_size(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 ){
| > > > > > > > > > | 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
** Copy a blob
*/
void blob_copy(Blob *pTo, Blob *pFrom){
blob_is_init(pFrom);
blob_zero(pTo);
blob_append(pTo, blob_buffer(pFrom), blob_size(pFrom));
}
/*
** 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 ){
|
| ︙ | ︙ |
Changes to src/default.css.
| ︙ | ︙ | |||
604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
font-weight: bold;
}
pre.udifftxt del mark {
background-color: #ffc0c0;
text-decoration: none;
font-weight: bold;
}
span.modpending {
color: #b03800;
font-style: italic;
}
pre.th1result {
white-space: pre-wrap;
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
font-weight: bold;
}
pre.udifftxt del mark {
background-color: #ffc0c0;
text-decoration: none;
font-weight: bold;
}
table.diff {
width: 90%;
border-spacing: 0;
}
td.diffln {
text-align: right;
padding: 0 0 0 1em;
}
td.diffsep {
padding: 0 0.5em 0 0.5em;
}
td.difftxt {
width: 100%;
}
td.diffln ins {
background-color: #a0e4b2;
text-decoration: none;
}
td.diffln del {
background-color: #ffc0c0;
text-decoration: none;
}
td.difftxt del {
background-color: #ffe8e8;
text-decoration: none;
}
td.difftxt del > del {
background-color: #ffc0c0;
text-decoration: none;
font-weight: bold;
}
td.difftxt del mark {
background-color: #c0c0ff;
text-decoration: none;
font-weight: bold;
}
td.difftxt ins {
background-color: #dafbe1;
text-decoration: none;
}
td.udifftxt ins > ins {
background-color: #a0e4b2;
text-decoration: none;
font-weight: bold;
}
td.udifftxt ins mark {
background-color: #c0c0ff;
text-decoration: none;
font-weight: bold;
}
span.modpending {
color: #b03800;
font-style: italic;
}
pre.th1result {
white-space: pre-wrap;
|
| ︙ | ︙ |
Changes to src/diff.c.
| ︙ | ︙ | |||
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 | return p; } /************************* DiffBuilderUnified********************************/ /* Accumulator strategy: ** | | > > | | | > > | | | > > > > > > > | > > > > | > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > | | < < < | < < < < < | > > | | > | | > | | | | > > > > > > > > > | > | > | | > > > > > > > | > | > | | | | | | | | | | | | | | > | | < < < < < < > > | < < < > > | 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
*/
|
| ︙ | ︙ |
Changes to src/diffcmd.c.
| ︙ | ︙ | |||
184 185 186 187 188 189 190 |
static const char zWebpageHdr[] =
@ <!DOCTYPE html>
@ <html>
@ <head>
@ <meta charset="UTF-8">
@ <style>
@ table.sbsdiffcols {
| | | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
static const char zWebpageHdr[] =
@ <!DOCTYPE html>
@ <html>
@ <head>
@ <meta charset="UTF-8">
@ <style>
@ table.sbsdiffcols {
@ width: 90%;
@ border-spacing: 0;
@ }
@ table.sbsdiffcols td {
@ padding: 0;
@ vertical-align: top;
@ }
@ table.sbsdiffcols pre {
|
| ︙ | ︙ | |||
210 211 212 213 214 215 216 |
@ overflow-x: auto;
@ }
@ div.diffmkrcol {
@ padding: 0 1em;
@ }
@ span.diffchng {
@ background-color: #c0c0ff;
| | | | | | 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
@ overflow-x: auto;
@ }
@ div.diffmkrcol {
@ padding: 0 1em;
@ }
@ span.diffchng {
@ background-color: #c0c0ff;
@ font-weight: bold;
@ }
@ span.diffadd {
@ background-color: #c0ffc0;
@ font-weight: bold;
@ }
@ span.diffrm {
@ background-color: #ffc8c8;
@ font-weight: bold;
@ }
@ span.diffhr {
@ display: inline-block;
@ margin: .5em 0 1em;
@ color: #0000ff;
@ }
@ span.diffln {
@ color: #a0a0a0;
@ }
@ table.udiff {
@ width: 90%;
@ border-spacing: 0;
@ }
@ pre.udiffln {
@ color: #a0a0a0;
@ }
@ pre.udiffln ins {
@ background-color: #a0e4b2;
|
| ︙ | ︙ | |||
254 255 256 257 258 259 260 |
@ pre.udifftxt del {
@ background-color: #ffe8e8;
@ text-decoration: none;
@ }
@ pre.udifftxt ins mark {
@ background-color: #a0e4b2;
@ text-decoration: none;
| | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
@ pre.udifftxt del {
@ background-color: #ffe8e8;
@ text-decoration: none;
@ }
@ pre.udifftxt ins mark {
@ background-color: #a0e4b2;
@ text-decoration: none;
@ font-weight: bold;
@ }
@ pre.udifftxt del mark {
@ background-color: #ffc0c0;
@ text-decoration: none;
@ font-weight: bold;
@ }
@ h1 {
@ font-size: 150%;
@ }
@
@ table.diff {
@ width: 90%;
@ border-spacing: 0;
@ }
@ td.diffln {
@ text-align: right;
@ padding: 0 0 0 1em;
@ }
@ td.diffsep {
@ padding: 0 0.5em 0 0.5em;
@ }
@ td.difftxt {
@ width: 100%;
@ }
@ td.diffln ins {
@ background-color: #a0e4b2;
@ text-decoration: none;
@ }
@ td.diffln del {
@ background-color: #ffc0c0;
@ text-decoration: none;
@ }
@ td.difftxt del {
@ background-color: #ffe8e8;
@ text-decoration: none;
@ }
@ td.difftxt del > del {
@ background-color: #ffc0c0;
@ text-decoration: none;
@ font-weight: bold;
@ }
@ td.difftxt del mark {
@ background-color: #c0c0ff;
@ text-decoration: none;
@ font-weight: bold;
@ }
@ td.difftxt ins {
@ background-color: #dafbe1;
@ text-decoration: none;
@ }
@ td.difftxt ins > ins {
@ background-color: #a0e4b2;
@ text-decoration: none;
@ font-weight: bold;
@ }
@ td.difftxt ins mark {
@ background-color: #c0c0ff;
@ text-decoration: none;
@ font-weight: bold;
@ }
@
@ </style>
@ </head>
@ <body>
;
const char zWebpageEnd[] =
@ </body>
@ </html>
|
| ︙ | ︙ | |||
329 330 331 332 333 334 335 |
#ifndef _WIN32
signal(SIGINT, diff_www_interrupt);
#else
SetConsoleCtrlHandler(diff_console_ctrl_handler, TRUE);
#endif
}
if( (diffFlags & DIFF_WEBPAGE)!=0 ){
| | | 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
#ifndef _WIN32
signal(SIGINT, diff_www_interrupt);
#else
SetConsoleCtrlHandler(diff_console_ctrl_handler, TRUE);
#endif
}
if( (diffFlags & DIFF_WEBPAGE)!=0 ){
fossil_print("%s",zWebpageHdr);
fflush(stdout);
}
}
/* Do any final output required by a diff and complete the diff
** process.
**
|
| ︙ | ︙ |