Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Revised default color scheme. Add line-numbers to context diff. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | retro-sbsdiff |
| Files: | files | file ages | folders |
| SHA1: |
6a6697694cadd11cc244e930ddf68aaf |
| User & Date: | drh 2012-02-04 19:34:18.857 |
Context
|
2012-02-04
| ||
| 19:55 | Colorize the context diff. Add color to the line numbers so that they can be deemphasized. ... (check-in: b57b035654 user: drh tags: retro-sbsdiff) | |
| 19:34 | Revised default color scheme. Add line-numbers to context diff. ... (check-in: 6a6697694c user: drh tags: retro-sbsdiff) | |
| 18:54 | Add color to the retro sbs diff. ... (check-in: 7372c0a5c4 user: drh tags: retro-sbsdiff) | |
Changes
Changes to src/diff.c.
| ︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #define DIFF_CONTEXT_MASK 0x0000ffff /* Lines of context. Default if 0 */ #define DIFF_WIDTH_MASK 0x00ff0000 /* side-by-side column width */ #define DIFF_IGNORE_EOLWS 0x01000000 /* Ignore end-of-line whitespace */ #define DIFF_SIDEBYSIDE 0x02000000 /* Generate a side-by-side diff */ #define DIFF_NEWFILE 0x04000000 /* Missing files are as empty files */ #define DIFF_INLINE 0x08000000 /* Inline (not side-by-side) diff */ #define DIFF_HTML 0x10000000 /* Render for HTML */ #endif /* INTERFACE */ /* ** Maximum length of a line in a text file. (8192) */ #define LENGTH_MASK_SZ 13 | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #define DIFF_CONTEXT_MASK 0x0000ffff /* Lines of context. Default if 0 */ #define DIFF_WIDTH_MASK 0x00ff0000 /* side-by-side column width */ #define DIFF_IGNORE_EOLWS 0x01000000 /* Ignore end-of-line whitespace */ #define DIFF_SIDEBYSIDE 0x02000000 /* Generate a side-by-side diff */ #define DIFF_NEWFILE 0x04000000 /* Missing files are as empty files */ #define DIFF_INLINE 0x08000000 /* Inline (not side-by-side) diff */ #define DIFF_HTML 0x10000000 /* Render for HTML */ #define DIFF_LINENO 0x20000000 /* Show line numbers in context diff */ #endif /* INTERFACE */ /* ** Maximum length of a line in a text file. (8192) */ #define LENGTH_MASK_SZ 13 |
| ︙ | ︙ | |||
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
** Append a single line of "diff" output to pOut.
*/
static void appendDiffLine(Blob *pOut, char *zPrefix, DLine *pLine){
blob_append(pOut, zPrefix, 1);
blob_append(pOut, pLine->z, pLine->h & LENGTH_MASK);
blob_append(pOut, "\n", 1);
}
/*
** Expand the size of aEdit[] array to hold nEdit elements.
*/
static void expandEdit(DContext *p, int nEdit){
p->aEdit = fossil_realloc(p->aEdit, nEdit*sizeof(int));
p->nEditAlloc = nEdit;
| > > > > > > > > > > > > > > > > > | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
** Append a single line of "diff" output to pOut.
*/
static void appendDiffLine(Blob *pOut, char *zPrefix, DLine *pLine){
blob_append(pOut, zPrefix, 1);
blob_append(pOut, pLine->z, pLine->h & LENGTH_MASK);
blob_append(pOut, "\n", 1);
}
/*
** Append line numbers to the context diff output. Zero or negative numbers
** are blanks.
*/
static void appendDiffLineno(Blob *pOut, int lnA, int lnB){
if( lnA>0 ){
blob_appendf(pOut, "%6d ", lnA);
}else{
blob_append(pOut, " ", 7);
}
if( lnB>0 ){
blob_appendf(pOut, "%6d ", lnB);
}else{
blob_append(pOut, " ", 8);
}
}
/*
** Expand the size of aEdit[] array to hold nEdit elements.
*/
static void expandEdit(DContext *p, int nEdit){
p->aEdit = fossil_realloc(p->aEdit, nEdit*sizeof(int));
p->nEditAlloc = nEdit;
|
| ︙ | ︙ | |||
198 199 200 201 202 203 204 | } /* ** Given a diff context in which the aEdit[] array has been filled ** in, compute a context diff into pOut. */ | | | 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
}
/*
** Given a diff context in which the aEdit[] array has been filled
** in, compute a context diff into pOut.
*/
static void contextDiff(DContext *p, Blob *pOut, int nContext, int showLn){
DLine *A; /* Left side of the diff */
DLine *B; /* Right side of the diff */
int a = 0; /* Index of next line in A[] */
int b = 0; /* Index of next line in B[] */
int *R; /* Array of COPY/DELETE/INSERT triples */
int r; /* Index into R[] */
int nr; /* Number of COPY/DELETE/INSERT triples to process */
|
| ︙ | ︙ | |||
252 253 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 |
nb += R[r+i*3];
}
/*
* If the patch changes an empty file or results in an empty file,
* the block header must use 0,0 as position indicator and not 1,0.
* Otherwise, patch would be confused and may reject the diff.
*/
blob_appendf(pOut,"@@ -%d,%d +%d,%d @@\n",
na ? a+skip+1 : 0, na,
nb ? b+skip+1 : 0, nb);
/* Show the initial common area */
a += skip;
b += skip;
m = R[r] - skip;
for(j=0; j<m; j++){
appendDiffLine(pOut, " ", &A[a+j]);
}
a += m;
b += m;
/* Show the differences */
for(i=0; i<nr; i++){
m = R[r+i*3+1];
for(j=0; j<m; j++){
appendDiffLine(pOut, "-", &A[a+j]);
}
a += m;
m = R[r+i*3+2];
for(j=0; j<m; j++){
appendDiffLine(pOut, "+", &B[b+j]);
}
b += m;
if( i<nr-1 ){
m = R[r+i*3+3];
for(j=0; j<m; j++){
appendDiffLine(pOut, " ", &B[b+j]);
}
b += m;
a += m;
}
}
/* Show the final common area */
assert( nr==i );
m = R[r+nr*3];
if( m>nContext ) m = nContext;
for(j=0; j<m; j++){
appendDiffLine(pOut, " ", &B[b+j]);
}
}
}
/*
** Status of a single output line
| > > > > > > | 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 330 |
nb += R[r+i*3];
}
/*
* If the patch changes an empty file or results in an empty file,
* the block header must use 0,0 as position indicator and not 1,0.
* Otherwise, patch would be confused and may reject the diff.
*/
if( showLn ) blob_appendf(pOut, "%*s", 15, "");
blob_appendf(pOut,"@@ -%d,%d +%d,%d @@\n",
na ? a+skip+1 : 0, na,
nb ? b+skip+1 : 0, nb);
/* Show the initial common area */
a += skip;
b += skip;
m = R[r] - skip;
for(j=0; j<m; j++){
if( showLn ) appendDiffLineno(pOut, a+j, b+j);
appendDiffLine(pOut, " ", &A[a+j]);
}
a += m;
b += m;
/* Show the differences */
for(i=0; i<nr; i++){
m = R[r+i*3+1];
for(j=0; j<m; j++){
if( showLn ) appendDiffLineno(pOut, a+j, 0);
appendDiffLine(pOut, "-", &A[a+j]);
}
a += m;
m = R[r+i*3+2];
for(j=0; j<m; j++){
if( showLn ) appendDiffLineno(pOut, 0, b+j);
appendDiffLine(pOut, "+", &B[b+j]);
}
b += m;
if( i<nr-1 ){
m = R[r+i*3+3];
for(j=0; j<m; j++){
if( showLn ) appendDiffLineno(pOut, a+j, b+j);
appendDiffLine(pOut, " ", &B[b+j]);
}
b += m;
a += m;
}
}
/* Show the final common area */
assert( nr==i );
m = R[r+nr*3];
if( m>nContext ) m = nContext;
for(j=0; j<m; j++){
if( showLn ) appendDiffLineno(pOut, a+j, b+j);
appendDiffLine(pOut, " ", &B[b+j]);
}
}
}
/*
** Status of a single output line
|
| ︙ | ︙ | |||
332 333 334 335 336 337 338 |
/*
** Write up to width characters of pLine into z[]. Translate tabs into
** spaces. Add a newline if SBS_NEWLINE is set. Translate HTML characters
** if SBS_HTML is set. Pad the rendering out width bytes if SBS_PAD is set.
*/
static void sbsWriteText(SbsLine *p, DLine *pLine, unsigned flags){
int n = pLine->h & LENGTH_MASK;
| | | 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
/*
** Write up to width characters of pLine into z[]. Translate tabs into
** spaces. Add a newline if SBS_NEWLINE is set. Translate HTML characters
** if SBS_HTML is set. Pad the rendering out width bytes if SBS_PAD is set.
*/
static void sbsWriteText(SbsLine *p, DLine *pLine, unsigned flags){
int n = pLine->h & LENGTH_MASK;
int i, j;
const char *zIn = pLine->z;
char *z = &p->zLine[p->n];
int w = p->width;
if( n>w ) n = w;
for(i=j=0; i<n; i++){
char c = zIn[i];
if( c=='\t' ){
|
| ︙ | ︙ | |||
866 867 868 869 870 871 872 |
if( pOut ){
/* Compute a context or side-by-side diff into pOut */
if( diffFlags & DIFF_SIDEBYSIDE ){
int width = diff_width(diffFlags);
int escHtml = (diffFlags & DIFF_HTML)!=0;
sbsDiff(&c, pOut, nContext, width, escHtml);
}else{
| > | | 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 |
if( pOut ){
/* Compute a context or side-by-side diff into pOut */
if( diffFlags & DIFF_SIDEBYSIDE ){
int width = diff_width(diffFlags);
int escHtml = (diffFlags & DIFF_HTML)!=0;
sbsDiff(&c, pOut, nContext, width, escHtml);
}else{
int showLn = (diffFlags & DIFF_LINENO)!=0;
contextDiff(&c, pOut, nContext, showLn);
}
free(c.aFrom);
free(c.aTo);
free(c.aEdit);
return 0;
}else{
/* If a context diff is not requested, then return the
|
| ︙ | ︙ | |||
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
/*
** Process diff-related command-line options and return an appropriate
** "diffFlags" integer.
**
** --side-by-side|-y Side-by-side diff. DIFF_SIDEBYSIDE
** --context|-c N N lines of context. DIFF_CONTEXT_MASK
** --width|-W N N character lines. DIFF_WIDTH_MASK
*/
int diff_options(void){
int diffFlags = 0;
const char *z;
int f;
if( find_option("side-by-side","y",0)!=0 ) diffFlags |= DIFF_SIDEBYSIDE;
if( (z = find_option("context","c",1))!=0 && (f = atoi(z))>0 ){
if( f > DIFF_CONTEXT_MASK ) f = DIFF_CONTEXT_MASK;
diffFlags |= f;
}
if( (z = find_option("width","W",1))!=0 && (f = atoi(z))>0 ){
f *= DIFF_CONTEXT_MASK+1;
if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK;
diffFlags |= f;
}
if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML;
return diffFlags;
}
/*
** COMMAND: test-udiff
**
** Print the difference between two files. The usual diff options apply.
| > > > | 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
/*
** Process diff-related command-line options and return an appropriate
** "diffFlags" integer.
**
** --side-by-side|-y Side-by-side diff. DIFF_SIDEBYSIDE
** --context|-c N N lines of context. DIFF_CONTEXT_MASK
** --width|-W N N character lines. DIFF_WIDTH_MASK
** --html Format for HTML DIFF_HTML
** --linenum|-n Show line numbers DIFF_LINENO
*/
int diff_options(void){
int diffFlags = 0;
const char *z;
int f;
if( find_option("side-by-side","y",0)!=0 ) diffFlags |= DIFF_SIDEBYSIDE;
if( (z = find_option("context","c",1))!=0 && (f = atoi(z))>0 ){
if( f > DIFF_CONTEXT_MASK ) f = DIFF_CONTEXT_MASK;
diffFlags |= f;
}
if( (z = find_option("width","W",1))!=0 && (f = atoi(z))>0 ){
f *= DIFF_CONTEXT_MASK+1;
if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK;
diffFlags |= f;
}
if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML;
if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
return diffFlags;
}
/*
** COMMAND: test-udiff
**
** Print the difference between two files. The usual diff options apply.
|
| ︙ | ︙ |
Changes to src/info.c.
| ︙ | ︙ | |||
272 273 274 275 276 277 278 |
blob_zero(&out);
if( diffFlags & DIFF_SIDEBYSIDE ){
text_diff(&from, &to, &out, diffFlags | DIFF_HTML);
@ <div class="sbsdiff">
@ %s(blob_str(&out))
@ </div>
}else{
| | | 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
blob_zero(&out);
if( diffFlags & DIFF_SIDEBYSIDE ){
text_diff(&from, &to, &out, diffFlags | DIFF_HTML);
@ <div class="sbsdiff">
@ %s(blob_str(&out))
@ </div>
}else{
text_diff(&from, &to, &out, diffFlags | DIFF_LINENO);
@ %h(blob_str(&out))
}
blob_reset(&from);
blob_reset(&to);
blob_reset(&out);
}
|
| ︙ | ︙ |
Changes to src/style.c.
| ︙ | ︙ | |||
755 756 757 758 759 760 761 |
},
{ "div.sbsdiff",
"side-by-side diff display",
@ font-family: monospace;
@ white-space: pre;
},
{ "div.udiff",
| | | | | | 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
},
{ "div.sbsdiff",
"side-by-side diff display",
@ font-family: monospace;
@ white-space: pre;
},
{ "div.udiff",
"context diff display",
@ font-family: monospace;
@ white-space: pre;
},
{ "span.diffchng",
"changes in a diff",
@ background-color: #ffffc8;
},
{ "span.diffadd",
"added code in a diff",
@ background-color: #e0ffe0;
},
{ "span.diffrm",
"deleted in a diff",
@ background-color: #ffe0e0;
},
{ "span.diffhr",
"suppressed lines in a diff",
@ color: #0000ff;
},
{ 0,
0,
|
| ︙ | ︙ |