Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Further simplification of the DiffConfig object by splitting out the lines of context and column width values from the diffFlags vector into separate columns. There should be no user-visible changes in behavior. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
ca6fa4b2f3d12aedfa3fea4ecc1641a1 |
| User & Date: | drh 2021-09-07 16:06:13.103 |
Context
|
2021-09-07
| ||
| 17:11 | Fix the diff block alignment so that it correctly suppresses unnecessary diff marks, even when in ignore-whitespace mode. ... (check-in: 85ca2fe5b5 user: drh tags: trunk) | |
| 16:06 | Further simplification of the DiffConfig object by splitting out the lines of context and column width values from the diffFlags vector into separate columns. There should be no user-visible changes in behavior. ... (check-in: ca6fa4b2f3 user: drh tags: trunk) | |
| 13:29 | Take advantage of the new pBlob==NULL capabilities in blob_appendf() to simplify some of the diff logic. ... (check-in: 590e01dbdd user: drh tags: trunk) | |
Changes
Changes to src/diff.c.
| ︙ | ︙ | |||
24 25 26 27 28 29 30 | #if INTERFACE /* ** Flag parameters to the text_diff() routine used to control the formatting ** of the diff output. */ | < < | | | | | | | | | | | | | | | | | | | | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#if INTERFACE
/*
** Flag parameters to the text_diff() routine used to control the formatting
** of the diff output.
*/
#define DIFF_IGNORE_EOLWS 0x00000001 /* Ignore end-of-line whitespace */
#define DIFF_IGNORE_ALLWS 0x00000003 /* Ignore all whitespace */
#define DIFF_SIDEBYSIDE 0x00000004 /* Generate a side-by-side diff */
#define DIFF_VERBOSE 0x00000008 /* Missing shown as empty files */
#define DIFF_BRIEF 0x00000010 /* Show filenames only */
#define DIFF_HTML 0x00000020 /* Render for HTML */
#define DIFF_LINENO 0x00000040 /* Show line numbers */
#define DIFF_NUMSTAT 0x00000080 /* Show line count of changes */
#define DIFF_NOOPT 0x00000100 /* Suppress optimizations (debug) */
#define DIFF_INVERT 0x00000200 /* Invert the diff (debug) */
#define DIFF_CONTEXT_EX 0x00000400 /* Use context even if zero */
#define DIFF_NOTTOOBIG 0x00000800 /* Only display if not too big */
#define DIFF_STRIP_EOLCR 0x00001000 /* Strip trailing CR */
#define DIFF_SLOW_SBS 0x00002000 /* Better but slower side-by-side */
#define DIFF_WEBPAGE 0x00004000 /* Complete webpage */
#define DIFF_BROWSER 0x00008000 /* The --browser option */
#define DIFF_JSON 0x00010000 /* JSON output */
#define DIFF_DEBUG 0x00020000 /* Debugging diff output */
#define DIFF_RAW 0x00040000 /* Raw triples - for debugging */
#define DIFF_TCL 0x00080000 /* For the --tk option */
#define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */
/*
** These error messages are shared in multiple locations. They are defined
** here for consistency.
*/
#define DIFF_CANNOT_COMPUTE_BINARY \
"cannot compute difference between binary files\n"
|
| ︙ | ︙ | |||
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
**
** * Number of lines of context surrounding each difference block
**
** * Width of output columns for text side-by-side diffop
*/
struct DiffConfig {
u64 diffFlags; /* Diff flags */
u32 nFile; /* Number of files diffed so far */
const char *zDiffCmd; /* External diff command to use instead of builtin */
const char *zBinGlob; /* GLOB pattern for binary files */
ReCompiled *pRe; /* Show only changes matching this pattern */
};
#endif /* INTERFACE */
| > > | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
**
** * Number of lines of context surrounding each difference block
**
** * Width of output columns for text side-by-side diffop
*/
struct DiffConfig {
u64 diffFlags; /* Diff flags */
int nContext; /* Number of lines of context */
int wColumn; /* Column width in -y mode */
u32 nFile; /* Number of files diffed so far */
const char *zDiffCmd; /* External diff command to use instead of builtin */
const char *zBinGlob; /* GLOB pattern for binary files */
ReCompiled *pRe; /* Show only changes matching this pattern */
};
#endif /* INTERFACE */
|
| ︙ | ︙ | |||
2545 2546 2547 2548 2549 2550 2551 |
}
/*
** Extract the number of lines of context from diffFlags. Supply an
** appropriate default if no context width is specified.
*/
int diff_context_lines(DiffConfig *pCfg){
| | | | | 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 |
}
/*
** Extract the number of lines of context from diffFlags. Supply an
** appropriate default if no context width is specified.
*/
int diff_context_lines(DiffConfig *pCfg){
int n = pCfg->nContext;
if( n<=0 && (pCfg->diffFlags & DIFF_CONTEXT_EX)==0 ) n = 5;
return n;
}
/*
** Extract the width of columns for side-by-side diff. Supply an
** appropriate default if no width is given.
**
** Calculate the default automatically, based on terminal's current width:
** term-width = 2*diff-col + diff-marker + 1
** diff-col = lineno + lmargin + text-width + rmargin
**
** text-width = (term-width - diff-marker - 1)/2 - lineno - lmargin - rmargin
*/
int diff_width(DiffConfig *pCfg){
int w = pCfg->wColumn;
if( w==0 ){
static struct {
unsigned int lineno, lmargin, text, rmargin, marker;
} sbsW = { 5, 2, 0, 0, 3 };
const unsigned int wMin = 24, wMax = 132;
unsigned int tw = terminal_get_width(80);
unsigned int twMin =
|
| ︙ | ︙ | |||
2747 2748 2749 2750 2751 2752 2753 | /* ** Initialize the DiffConfig object using command-line options. ** ** Process diff-related command-line options and return an appropriate ** "diffFlags" integer. ** ** --brief Show filenames only DIFF_BRIEF | | | | 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 |
/*
** Initialize the DiffConfig object using command-line options.
**
** Process diff-related command-line options and return an appropriate
** "diffFlags" integer.
**
** --brief Show filenames only DIFF_BRIEF
** -c|--context N N lines of context. nContext
** --html Format for HTML DIFF_HTML
** --invert Invert the diff DIFF_INVERT
** -n|--linenum Show line numbers DIFF_LINENO
** --noopt Disable optimization DIFF_NOOPT
** --numstat Show change counts DIFF_NUMSTAT
** --strip-trailing-cr Strip trailing CR DIFF_STRIP_EOLCR
** --unified Unified diff. ~DIFF_SIDEBYSIDE
** -w|--ignore-all-space Ignore all whitespaces DIFF_IGNORE_ALLWS
** -W|--width N N character lines. wColumn
** -y|--side-by-side Side-by-side diff. DIFF_SIDEBYSIDE
** -Z|--ignore-trailing-space Ignore eol-whitespaces DIFF_IGNORE_EOLWS
*/
void diff_options(DiffConfig *pCfg, int isGDiff, int bUnifiedTextOnly){
u64 diffFlags = 0;
const char *z;
int f;
|
| ︙ | ︙ | |||
2805 2806 2807 2808 2809 2810 2811 |
/* Undocumented and unsupported flags used for development
** debugging and analysis: */
if( find_option("debug",0,0)!=0 ) diffFlags |= DIFF_DEBUG;
if( find_option("raw",0,0)!=0 ) diffFlags |= DIFF_RAW;
}
if( (z = find_option("context","c",1))!=0 && (f = atoi(z))>=0 ){
| | | < < | | 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 |
/* Undocumented and unsupported flags used for development
** debugging and analysis: */
if( find_option("debug",0,0)!=0 ) diffFlags |= DIFF_DEBUG;
if( find_option("raw",0,0)!=0 ) diffFlags |= DIFF_RAW;
}
if( (z = find_option("context","c",1))!=0 && (f = atoi(z))>=0 ){
pCfg->nContext = f;
diffFlags |= DIFF_CONTEXT_EX;
}
if( (z = find_option("width","W",1))!=0 && (f = atoi(z))>0 ){
pCfg->wColumn = f;
}
if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO;
if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT;
if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT;
if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT;
if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF;
if( find_option("internal","i",0)==0
|
| ︙ | ︙ |
Changes to src/info.c.
| ︙ | ︙ | |||
448 449 450 451 452 453 454 |
** Construct an appropriate diffFlag for text_diff() based on query
** parameters and the to boolean arguments.
*/
DiffConfig *construct_diff_flags(int diffType, DiffConfig *pCfg){
u64 diffFlags = 0; /* Zero means do not show any diff */
if( diffType>0 ){
int x;
| | | | < < < | < | < < | < | < < < | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
** Construct an appropriate diffFlag for text_diff() based on query
** parameters and the to boolean arguments.
*/
DiffConfig *construct_diff_flags(int diffType, DiffConfig *pCfg){
u64 diffFlags = 0; /* Zero means do not show any diff */
if( diffType>0 ){
int x;
if( diffType==2 ) diffFlags = DIFF_SIDEBYSIDE;
if( P("w") ) diffFlags |= DIFF_IGNORE_ALLWS;
if( PD("noopt",0)!=0 ) diffFlags |= DIFF_NOOPT;
diffFlags |= DIFF_STRIP_EOLCR;
diff_config_init(pCfg, diffFlags);
/* "dc" query parameter determines lines of context */
x = atoi(PD("dc","7"));
if( x>0 ) pCfg->nContext = x;
/* The "noopt" parameter disables diff optimization */
return pCfg;
}else{
diff_config_init(pCfg, 0);
return 0;
}
}
|
| ︙ | ︙ |