Fossil SCM
Add the --numstat option to the diff command.
Commit
3d6cf6a7226c740936af790d02a62691a3fcd4d1d23c3c4a244a662062cb3e0c
Parent
038dcc00e5ead3a…
2 files changed
+11
-2
+30
-15
+11
-2
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -35,10 +35,11 @@ | ||
| 35 | 35 | #define DIFF_SIDEBYSIDE ((u64)0x04000000) /* Generate a side-by-side diff */ |
| 36 | 36 | #define DIFF_VERBOSE ((u64)0x08000000) /* Missing shown as empty files */ |
| 37 | 37 | #define DIFF_BRIEF ((u64)0x10000000) /* Show filenames only */ |
| 38 | 38 | #define DIFF_HTML ((u64)0x20000000) /* Render for HTML */ |
| 39 | 39 | #define DIFF_LINENO ((u64)0x40000000) /* Show line numbers */ |
| 40 | +#define DIFF_NUMSTAT ((u64)0x80000000) /* Show line count of changes */ | |
| 40 | 41 | #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */ |
| 41 | 42 | #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */ |
| 42 | 43 | #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */ |
| 43 | 44 | #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */ |
| 44 | 45 | #define DIFF_STRIP_EOLCR (((u64)0x10)<<32) /* Strip trailing CR */ |
| @@ -1918,12 +1919,18 @@ | ||
| 1918 | 1919 | if( (diffFlags & DIFF_NOOPT)==0 ){ |
| 1919 | 1920 | diff_optimize(&c); |
| 1920 | 1921 | } |
| 1921 | 1922 | |
| 1922 | 1923 | if( pOut ){ |
| 1923 | - /* Compute a context or side-by-side diff into pOut */ | |
| 1924 | - if( diffFlags & DIFF_SIDEBYSIDE ){ | |
| 1924 | + if( diffFlags & DIFF_NUMSTAT ){ | |
| 1925 | + int nDel = 0, nIns = 0, i; | |
| 1926 | + for(i=0; c.aEdit[i] || c.aEdit[i+1] || c.aEdit[i+2]; i+=3){ | |
| 1927 | + nDel += c.aEdit[i+1]; | |
| 1928 | + nIns += c.aEdit[i+2]; | |
| 1929 | + } | |
| 1930 | + blob_appendf(pOut, "%10d %10d", nIns, nDel); | |
| 1931 | + }else if( diffFlags & DIFF_SIDEBYSIDE ){ | |
| 1925 | 1932 | sbsDiff(&c, pOut, pRe, diffFlags); |
| 1926 | 1933 | }else{ |
| 1927 | 1934 | contextDiff(&c, pOut, pRe, diffFlags); |
| 1928 | 1935 | } |
| 1929 | 1936 | fossil_free(c.aFrom); |
| @@ -1948,10 +1955,11 @@ | ||
| 1948 | 1955 | ** -c|--context N N lines of context. DIFF_CONTEXT_MASK |
| 1949 | 1956 | ** --html Format for HTML DIFF_HTML |
| 1950 | 1957 | ** --invert Invert the diff DIFF_INVERT |
| 1951 | 1958 | ** -n|--linenum Show line numbers DIFF_LINENO |
| 1952 | 1959 | ** --noopt Disable optimization DIFF_NOOPT |
| 1960 | +** --numstat Show change counts DIFF_NUMSTAT | |
| 1953 | 1961 | ** --strip-trailing-cr Strip trailing CR DIFF_STRIP_EOLCR |
| 1954 | 1962 | ** --unified Unified diff. ~DIFF_SIDEBYSIDE |
| 1955 | 1963 | ** -w|--ignore-all-space Ignore all whitespaces DIFF_IGNORE_ALLWS |
| 1956 | 1964 | ** -W|--width N N character lines. DIFF_WIDTH_MASK |
| 1957 | 1965 | ** -y|--side-by-side Side-by-side diff. DIFF_SIDEBYSIDE |
| @@ -1985,10 +1993,11 @@ | ||
| 1985 | 1993 | diffFlags |= f; |
| 1986 | 1994 | } |
| 1987 | 1995 | if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML; |
| 1988 | 1996 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 1989 | 1997 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 1998 | + if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT; | |
| 1990 | 1999 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 1991 | 2000 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 1992 | 2001 | return diffFlags; |
| 1993 | 2002 | } |
| 1994 | 2003 | |
| 1995 | 2004 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -35,10 +35,11 @@ | |
| 35 | #define DIFF_SIDEBYSIDE ((u64)0x04000000) /* Generate a side-by-side diff */ |
| 36 | #define DIFF_VERBOSE ((u64)0x08000000) /* Missing shown as empty files */ |
| 37 | #define DIFF_BRIEF ((u64)0x10000000) /* Show filenames only */ |
| 38 | #define DIFF_HTML ((u64)0x20000000) /* Render for HTML */ |
| 39 | #define DIFF_LINENO ((u64)0x40000000) /* Show line numbers */ |
| 40 | #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */ |
| 41 | #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */ |
| 42 | #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */ |
| 43 | #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */ |
| 44 | #define DIFF_STRIP_EOLCR (((u64)0x10)<<32) /* Strip trailing CR */ |
| @@ -1918,12 +1919,18 @@ | |
| 1918 | if( (diffFlags & DIFF_NOOPT)==0 ){ |
| 1919 | diff_optimize(&c); |
| 1920 | } |
| 1921 | |
| 1922 | if( pOut ){ |
| 1923 | /* Compute a context or side-by-side diff into pOut */ |
| 1924 | if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 1925 | sbsDiff(&c, pOut, pRe, diffFlags); |
| 1926 | }else{ |
| 1927 | contextDiff(&c, pOut, pRe, diffFlags); |
| 1928 | } |
| 1929 | fossil_free(c.aFrom); |
| @@ -1948,10 +1955,11 @@ | |
| 1948 | ** -c|--context N N lines of context. DIFF_CONTEXT_MASK |
| 1949 | ** --html Format for HTML DIFF_HTML |
| 1950 | ** --invert Invert the diff DIFF_INVERT |
| 1951 | ** -n|--linenum Show line numbers DIFF_LINENO |
| 1952 | ** --noopt Disable optimization DIFF_NOOPT |
| 1953 | ** --strip-trailing-cr Strip trailing CR DIFF_STRIP_EOLCR |
| 1954 | ** --unified Unified diff. ~DIFF_SIDEBYSIDE |
| 1955 | ** -w|--ignore-all-space Ignore all whitespaces DIFF_IGNORE_ALLWS |
| 1956 | ** -W|--width N N character lines. DIFF_WIDTH_MASK |
| 1957 | ** -y|--side-by-side Side-by-side diff. DIFF_SIDEBYSIDE |
| @@ -1985,10 +1993,11 @@ | |
| 1985 | diffFlags |= f; |
| 1986 | } |
| 1987 | if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML; |
| 1988 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 1989 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 1990 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 1991 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 1992 | return diffFlags; |
| 1993 | } |
| 1994 | |
| 1995 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -35,10 +35,11 @@ | |
| 35 | #define DIFF_SIDEBYSIDE ((u64)0x04000000) /* Generate a side-by-side diff */ |
| 36 | #define DIFF_VERBOSE ((u64)0x08000000) /* Missing shown as empty files */ |
| 37 | #define DIFF_BRIEF ((u64)0x10000000) /* Show filenames only */ |
| 38 | #define DIFF_HTML ((u64)0x20000000) /* Render for HTML */ |
| 39 | #define DIFF_LINENO ((u64)0x40000000) /* Show line numbers */ |
| 40 | #define DIFF_NUMSTAT ((u64)0x80000000) /* Show line count of changes */ |
| 41 | #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */ |
| 42 | #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */ |
| 43 | #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */ |
| 44 | #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */ |
| 45 | #define DIFF_STRIP_EOLCR (((u64)0x10)<<32) /* Strip trailing CR */ |
| @@ -1918,12 +1919,18 @@ | |
| 1919 | if( (diffFlags & DIFF_NOOPT)==0 ){ |
| 1920 | diff_optimize(&c); |
| 1921 | } |
| 1922 | |
| 1923 | if( pOut ){ |
| 1924 | if( diffFlags & DIFF_NUMSTAT ){ |
| 1925 | int nDel = 0, nIns = 0, i; |
| 1926 | for(i=0; c.aEdit[i] || c.aEdit[i+1] || c.aEdit[i+2]; i+=3){ |
| 1927 | nDel += c.aEdit[i+1]; |
| 1928 | nIns += c.aEdit[i+2]; |
| 1929 | } |
| 1930 | blob_appendf(pOut, "%10d %10d", nIns, nDel); |
| 1931 | }else if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 1932 | sbsDiff(&c, pOut, pRe, diffFlags); |
| 1933 | }else{ |
| 1934 | contextDiff(&c, pOut, pRe, diffFlags); |
| 1935 | } |
| 1936 | fossil_free(c.aFrom); |
| @@ -1948,10 +1955,11 @@ | |
| 1955 | ** -c|--context N N lines of context. DIFF_CONTEXT_MASK |
| 1956 | ** --html Format for HTML DIFF_HTML |
| 1957 | ** --invert Invert the diff DIFF_INVERT |
| 1958 | ** -n|--linenum Show line numbers DIFF_LINENO |
| 1959 | ** --noopt Disable optimization DIFF_NOOPT |
| 1960 | ** --numstat Show change counts DIFF_NUMSTAT |
| 1961 | ** --strip-trailing-cr Strip trailing CR DIFF_STRIP_EOLCR |
| 1962 | ** --unified Unified diff. ~DIFF_SIDEBYSIDE |
| 1963 | ** -w|--ignore-all-space Ignore all whitespaces DIFF_IGNORE_ALLWS |
| 1964 | ** -W|--width N N character lines. DIFF_WIDTH_MASK |
| 1965 | ** -y|--side-by-side Side-by-side diff. DIFF_SIDEBYSIDE |
| @@ -1985,10 +1993,11 @@ | |
| 1993 | diffFlags |= f; |
| 1994 | } |
| 1995 | if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML; |
| 1996 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 1997 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 1998 | if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT; |
| 1999 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 2000 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 2001 | return diffFlags; |
| 2002 | } |
| 2003 | |
| 2004 |
+30
-15
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | |
| 108 | 108 | /* |
| 109 | 109 | ** Print the "Index:" message that patches wants to see at the top of a diff. |
| 110 | 110 | */ |
| 111 | 111 | void diff_print_index(const char *zFile, u64 diffFlags){ |
| 112 | - if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF))==0 ){ | |
| 112 | + if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT))==0 ){ | |
| 113 | 113 | char *z = mprintf("Index: %s\n%.66c\n", zFile, '='); |
| 114 | 114 | fossil_print("%s", z); |
| 115 | 115 | fossil_free(z); |
| 116 | 116 | } |
| 117 | 117 | } |
| @@ -204,12 +204,16 @@ | ||
| 204 | 204 | text_diff(&file2, pFile1, &out, 0, diffFlags); |
| 205 | 205 | }else{ |
| 206 | 206 | text_diff(pFile1, &file2, &out, 0, diffFlags); |
| 207 | 207 | } |
| 208 | 208 | if( blob_size(&out) ){ |
| 209 | - diff_print_filenames(zName, zName2, diffFlags); | |
| 210 | - fossil_print("%s\n", blob_str(&out)); | |
| 209 | + if( diffFlags & DIFF_NUMSTAT ){ | |
| 210 | + fossil_print("%s %s\n", blob_str(&out), zName); | |
| 211 | + }else{ | |
| 212 | + diff_print_filenames(zName, zName2, diffFlags); | |
| 213 | + fossil_print("%s\n", blob_str(&out)); | |
| 214 | + } | |
| 211 | 215 | } |
| 212 | 216 | blob_reset(&out); |
| 213 | 217 | } |
| 214 | 218 | |
| 215 | 219 | /* Release memory resources */ |
| @@ -310,13 +314,17 @@ | ||
| 310 | 314 | if( zDiffCmd==0 ){ |
| 311 | 315 | Blob out; /* Diff output text */ |
| 312 | 316 | |
| 313 | 317 | blob_zero(&out); |
| 314 | 318 | text_diff(pFile1, pFile2, &out, 0, diffFlags); |
| 315 | - diff_print_filenames(zName, zName, diffFlags); | |
| 316 | - fossil_print("%s\n", blob_str(&out)); | |
| 317 | - | |
| 319 | + if( diffFlags & DIFF_NUMSTAT ){ | |
| 320 | + fossil_print("%s %s\n", blob_str(&out), zName); | |
| 321 | + }else{ | |
| 322 | + diff_print_filenames(zName, zName, diffFlags); | |
| 323 | + fossil_print("%s\n", blob_str(&out)); | |
| 324 | + } | |
| 325 | + | |
| 318 | 326 | /* Release memory resources */ |
| 319 | 327 | blob_reset(&out); |
| 320 | 328 | }else{ |
| 321 | 329 | Blob cmd; |
| 322 | 330 | Blob temp1; |
| @@ -396,12 +404,14 @@ | ||
| 396 | 404 | ){ |
| 397 | 405 | int vid; |
| 398 | 406 | Blob sql; |
| 399 | 407 | Stmt q; |
| 400 | 408 | int asNewFile; /* Treat non-existant files as empty files */ |
| 409 | + int isNumStat; /* True for --numstat */ | |
| 401 | 410 | |
| 402 | - asNewFile = (diffFlags & DIFF_VERBOSE)!=0; | |
| 411 | + asNewFile = (diffFlags & (DIFF_VERBOSE|DIFF_NUMSTAT))!=0; | |
| 412 | + isNumStat = (diffFlags & DIFF_NUMSTAT)!=0; | |
| 403 | 413 | vid = db_lget_int("checkout", 0); |
| 404 | 414 | vfile_check_signature(vid, CKSIG_ENOTFILE); |
| 405 | 415 | blob_zero(&sql); |
| 406 | 416 | db_begin_transaction(); |
| 407 | 417 | if( zFrom ){ |
| @@ -461,25 +471,25 @@ | ||
| 461 | 471 | blob_set(&fname, g.zLocalRoot); |
| 462 | 472 | blob_append(&fname, zPathname, -1); |
| 463 | 473 | } |
| 464 | 474 | zFullName = blob_str(&fname); |
| 465 | 475 | if( isDeleted ){ |
| 466 | - fossil_print("DELETED %s\n", zPathname); | |
| 476 | + if( !isNumStat ){ fossil_print("DELETED %s\n", zPathname); } | |
| 467 | 477 | if( !asNewFile ){ showDiff = 0; zFullName = NULL_DEVICE; } |
| 468 | 478 | }else if( file_access(zFullName, F_OK) ){ |
| 469 | - fossil_print("MISSING %s\n", zPathname); | |
| 479 | + if( !isNumStat ){ fossil_print("MISSING %s\n", zPathname); } | |
| 470 | 480 | if( !asNewFile ){ showDiff = 0; } |
| 471 | 481 | }else if( isNew ){ |
| 472 | - fossil_print("ADDED %s\n", zPathname); | |
| 482 | + if( !isNumStat ){ fossil_print("ADDED %s\n", zPathname); } | |
| 473 | 483 | srcid = 0; |
| 474 | 484 | if( !asNewFile ){ showDiff = 0; } |
| 475 | 485 | }else if( isChnged==3 ){ |
| 476 | - fossil_print("ADDED_BY_MERGE %s\n", zPathname); | |
| 486 | + if( !isNumStat ){ fossil_print("ADDED_BY_MERGE %s\n", zPathname); } | |
| 477 | 487 | srcid = 0; |
| 478 | 488 | if( !asNewFile ){ showDiff = 0; } |
| 479 | 489 | }else if( isChnged==5 ){ |
| 480 | - fossil_print("ADDED_BY_INTEGRATE %s\n", zPathname); | |
| 490 | + if( !isNumStat ){ fossil_print("ADDED_BY_INTEGRATE %s\n", zPathname); } | |
| 481 | 491 | srcid = 0; |
| 482 | 492 | if( !asNewFile ){ showDiff = 0; } |
| 483 | 493 | } |
| 484 | 494 | if( showDiff ){ |
| 485 | 495 | Blob content; |
| @@ -613,11 +623,11 @@ | ||
| 613 | 623 | u64 diffFlags, |
| 614 | 624 | FileDirList *pFileDir |
| 615 | 625 | ){ |
| 616 | 626 | Manifest *pFrom, *pTo; |
| 617 | 627 | ManifestFile *pFromFile, *pToFile; |
| 618 | - int asNewFlag = (diffFlags & DIFF_VERBOSE)!=0 ? 1 : 0; | |
| 628 | + int asNewFlag = (diffFlags & (DIFF_VERBOSE|DIFF_NUMSTAT))!=0 ? 1 : 0; | |
| 619 | 629 | |
| 620 | 630 | pFrom = manifest_get_by_name(zFrom, 0); |
| 621 | 631 | manifest_file_rewind(pFrom); |
| 622 | 632 | pFromFile = manifest_file_next(pFrom,0); |
| 623 | 633 | pTo = manifest_get_by_name(zTo, 0); |
| @@ -633,20 +643,24 @@ | ||
| 633 | 643 | }else{ |
| 634 | 644 | cmp = fossil_strcmp(pFromFile->zName, pToFile->zName); |
| 635 | 645 | } |
| 636 | 646 | if( cmp<0 ){ |
| 637 | 647 | if( file_dir_match(pFileDir, pFromFile->zName) ){ |
| 638 | - fossil_print("DELETED %s\n", pFromFile->zName); | |
| 648 | + if( (diffFlags & DIFF_NUMSTAT)==0 ){ | |
| 649 | + fossil_print("DELETED %s\n", pFromFile->zName); | |
| 650 | + } | |
| 639 | 651 | if( asNewFlag ){ |
| 640 | 652 | diff_manifest_entry(pFromFile, 0, zDiffCmd, zBinGlob, |
| 641 | 653 | fIncludeBinary, diffFlags); |
| 642 | 654 | } |
| 643 | 655 | } |
| 644 | 656 | pFromFile = manifest_file_next(pFrom,0); |
| 645 | 657 | }else if( cmp>0 ){ |
| 646 | 658 | if( file_dir_match(pFileDir, pToFile->zName) ){ |
| 647 | - fossil_print("ADDED %s\n", pToFile->zName); | |
| 659 | + if( (diffFlags & DIFF_NUMSTAT)==0 ){ | |
| 660 | + fossil_print("ADDED %s\n", pToFile->zName); | |
| 661 | + } | |
| 648 | 662 | if( asNewFlag ){ |
| 649 | 663 | diff_manifest_entry(0, pToFile, zDiffCmd, zBinGlob, |
| 650 | 664 | fIncludeBinary, diffFlags); |
| 651 | 665 | } |
| 652 | 666 | } |
| @@ -833,10 +847,11 @@ | ||
| 833 | 847 | ** --diff-binary BOOL Include binary files when using external commands |
| 834 | 848 | ** --exec-abs-paths Force absolute path names with external commands. |
| 835 | 849 | ** --exec-rel-paths Force relative path names with external commands. |
| 836 | 850 | ** --from|-r VERSION Select VERSION as source for the diff |
| 837 | 851 | ** --internal|-i Use internal diff logic |
| 852 | +** --numstat Show only the number of lines delete and added | |
| 838 | 853 | ** --side-by-side|-y Side-by-side diff |
| 839 | 854 | ** --strip-trailing-cr Strip trailing CR |
| 840 | 855 | ** --tk Launch a Tcl/Tk GUI for display |
| 841 | 856 | ** --to VERSION Select VERSION as target for the diff |
| 842 | 857 | ** --undo Diff against the "undo" buffer |
| 843 | 858 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -107,11 +107,11 @@ | |
| 107 | |
| 108 | /* |
| 109 | ** Print the "Index:" message that patches wants to see at the top of a diff. |
| 110 | */ |
| 111 | void diff_print_index(const char *zFile, u64 diffFlags){ |
| 112 | if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF))==0 ){ |
| 113 | char *z = mprintf("Index: %s\n%.66c\n", zFile, '='); |
| 114 | fossil_print("%s", z); |
| 115 | fossil_free(z); |
| 116 | } |
| 117 | } |
| @@ -204,12 +204,16 @@ | |
| 204 | text_diff(&file2, pFile1, &out, 0, diffFlags); |
| 205 | }else{ |
| 206 | text_diff(pFile1, &file2, &out, 0, diffFlags); |
| 207 | } |
| 208 | if( blob_size(&out) ){ |
| 209 | diff_print_filenames(zName, zName2, diffFlags); |
| 210 | fossil_print("%s\n", blob_str(&out)); |
| 211 | } |
| 212 | blob_reset(&out); |
| 213 | } |
| 214 | |
| 215 | /* Release memory resources */ |
| @@ -310,13 +314,17 @@ | |
| 310 | if( zDiffCmd==0 ){ |
| 311 | Blob out; /* Diff output text */ |
| 312 | |
| 313 | blob_zero(&out); |
| 314 | text_diff(pFile1, pFile2, &out, 0, diffFlags); |
| 315 | diff_print_filenames(zName, zName, diffFlags); |
| 316 | fossil_print("%s\n", blob_str(&out)); |
| 317 | |
| 318 | /* Release memory resources */ |
| 319 | blob_reset(&out); |
| 320 | }else{ |
| 321 | Blob cmd; |
| 322 | Blob temp1; |
| @@ -396,12 +404,14 @@ | |
| 396 | ){ |
| 397 | int vid; |
| 398 | Blob sql; |
| 399 | Stmt q; |
| 400 | int asNewFile; /* Treat non-existant files as empty files */ |
| 401 | |
| 402 | asNewFile = (diffFlags & DIFF_VERBOSE)!=0; |
| 403 | vid = db_lget_int("checkout", 0); |
| 404 | vfile_check_signature(vid, CKSIG_ENOTFILE); |
| 405 | blob_zero(&sql); |
| 406 | db_begin_transaction(); |
| 407 | if( zFrom ){ |
| @@ -461,25 +471,25 @@ | |
| 461 | blob_set(&fname, g.zLocalRoot); |
| 462 | blob_append(&fname, zPathname, -1); |
| 463 | } |
| 464 | zFullName = blob_str(&fname); |
| 465 | if( isDeleted ){ |
| 466 | fossil_print("DELETED %s\n", zPathname); |
| 467 | if( !asNewFile ){ showDiff = 0; zFullName = NULL_DEVICE; } |
| 468 | }else if( file_access(zFullName, F_OK) ){ |
| 469 | fossil_print("MISSING %s\n", zPathname); |
| 470 | if( !asNewFile ){ showDiff = 0; } |
| 471 | }else if( isNew ){ |
| 472 | fossil_print("ADDED %s\n", zPathname); |
| 473 | srcid = 0; |
| 474 | if( !asNewFile ){ showDiff = 0; } |
| 475 | }else if( isChnged==3 ){ |
| 476 | fossil_print("ADDED_BY_MERGE %s\n", zPathname); |
| 477 | srcid = 0; |
| 478 | if( !asNewFile ){ showDiff = 0; } |
| 479 | }else if( isChnged==5 ){ |
| 480 | fossil_print("ADDED_BY_INTEGRATE %s\n", zPathname); |
| 481 | srcid = 0; |
| 482 | if( !asNewFile ){ showDiff = 0; } |
| 483 | } |
| 484 | if( showDiff ){ |
| 485 | Blob content; |
| @@ -613,11 +623,11 @@ | |
| 613 | u64 diffFlags, |
| 614 | FileDirList *pFileDir |
| 615 | ){ |
| 616 | Manifest *pFrom, *pTo; |
| 617 | ManifestFile *pFromFile, *pToFile; |
| 618 | int asNewFlag = (diffFlags & DIFF_VERBOSE)!=0 ? 1 : 0; |
| 619 | |
| 620 | pFrom = manifest_get_by_name(zFrom, 0); |
| 621 | manifest_file_rewind(pFrom); |
| 622 | pFromFile = manifest_file_next(pFrom,0); |
| 623 | pTo = manifest_get_by_name(zTo, 0); |
| @@ -633,20 +643,24 @@ | |
| 633 | }else{ |
| 634 | cmp = fossil_strcmp(pFromFile->zName, pToFile->zName); |
| 635 | } |
| 636 | if( cmp<0 ){ |
| 637 | if( file_dir_match(pFileDir, pFromFile->zName) ){ |
| 638 | fossil_print("DELETED %s\n", pFromFile->zName); |
| 639 | if( asNewFlag ){ |
| 640 | diff_manifest_entry(pFromFile, 0, zDiffCmd, zBinGlob, |
| 641 | fIncludeBinary, diffFlags); |
| 642 | } |
| 643 | } |
| 644 | pFromFile = manifest_file_next(pFrom,0); |
| 645 | }else if( cmp>0 ){ |
| 646 | if( file_dir_match(pFileDir, pToFile->zName) ){ |
| 647 | fossil_print("ADDED %s\n", pToFile->zName); |
| 648 | if( asNewFlag ){ |
| 649 | diff_manifest_entry(0, pToFile, zDiffCmd, zBinGlob, |
| 650 | fIncludeBinary, diffFlags); |
| 651 | } |
| 652 | } |
| @@ -833,10 +847,11 @@ | |
| 833 | ** --diff-binary BOOL Include binary files when using external commands |
| 834 | ** --exec-abs-paths Force absolute path names with external commands. |
| 835 | ** --exec-rel-paths Force relative path names with external commands. |
| 836 | ** --from|-r VERSION Select VERSION as source for the diff |
| 837 | ** --internal|-i Use internal diff logic |
| 838 | ** --side-by-side|-y Side-by-side diff |
| 839 | ** --strip-trailing-cr Strip trailing CR |
| 840 | ** --tk Launch a Tcl/Tk GUI for display |
| 841 | ** --to VERSION Select VERSION as target for the diff |
| 842 | ** --undo Diff against the "undo" buffer |
| 843 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -107,11 +107,11 @@ | |
| 107 | |
| 108 | /* |
| 109 | ** Print the "Index:" message that patches wants to see at the top of a diff. |
| 110 | */ |
| 111 | void diff_print_index(const char *zFile, u64 diffFlags){ |
| 112 | if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT))==0 ){ |
| 113 | char *z = mprintf("Index: %s\n%.66c\n", zFile, '='); |
| 114 | fossil_print("%s", z); |
| 115 | fossil_free(z); |
| 116 | } |
| 117 | } |
| @@ -204,12 +204,16 @@ | |
| 204 | text_diff(&file2, pFile1, &out, 0, diffFlags); |
| 205 | }else{ |
| 206 | text_diff(pFile1, &file2, &out, 0, diffFlags); |
| 207 | } |
| 208 | if( blob_size(&out) ){ |
| 209 | if( diffFlags & DIFF_NUMSTAT ){ |
| 210 | fossil_print("%s %s\n", blob_str(&out), zName); |
| 211 | }else{ |
| 212 | diff_print_filenames(zName, zName2, diffFlags); |
| 213 | fossil_print("%s\n", blob_str(&out)); |
| 214 | } |
| 215 | } |
| 216 | blob_reset(&out); |
| 217 | } |
| 218 | |
| 219 | /* Release memory resources */ |
| @@ -310,13 +314,17 @@ | |
| 314 | if( zDiffCmd==0 ){ |
| 315 | Blob out; /* Diff output text */ |
| 316 | |
| 317 | blob_zero(&out); |
| 318 | text_diff(pFile1, pFile2, &out, 0, diffFlags); |
| 319 | if( diffFlags & DIFF_NUMSTAT ){ |
| 320 | fossil_print("%s %s\n", blob_str(&out), zName); |
| 321 | }else{ |
| 322 | diff_print_filenames(zName, zName, diffFlags); |
| 323 | fossil_print("%s\n", blob_str(&out)); |
| 324 | } |
| 325 | |
| 326 | /* Release memory resources */ |
| 327 | blob_reset(&out); |
| 328 | }else{ |
| 329 | Blob cmd; |
| 330 | Blob temp1; |
| @@ -396,12 +404,14 @@ | |
| 404 | ){ |
| 405 | int vid; |
| 406 | Blob sql; |
| 407 | Stmt q; |
| 408 | int asNewFile; /* Treat non-existant files as empty files */ |
| 409 | int isNumStat; /* True for --numstat */ |
| 410 | |
| 411 | asNewFile = (diffFlags & (DIFF_VERBOSE|DIFF_NUMSTAT))!=0; |
| 412 | isNumStat = (diffFlags & DIFF_NUMSTAT)!=0; |
| 413 | vid = db_lget_int("checkout", 0); |
| 414 | vfile_check_signature(vid, CKSIG_ENOTFILE); |
| 415 | blob_zero(&sql); |
| 416 | db_begin_transaction(); |
| 417 | if( zFrom ){ |
| @@ -461,25 +471,25 @@ | |
| 471 | blob_set(&fname, g.zLocalRoot); |
| 472 | blob_append(&fname, zPathname, -1); |
| 473 | } |
| 474 | zFullName = blob_str(&fname); |
| 475 | if( isDeleted ){ |
| 476 | if( !isNumStat ){ fossil_print("DELETED %s\n", zPathname); } |
| 477 | if( !asNewFile ){ showDiff = 0; zFullName = NULL_DEVICE; } |
| 478 | }else if( file_access(zFullName, F_OK) ){ |
| 479 | if( !isNumStat ){ fossil_print("MISSING %s\n", zPathname); } |
| 480 | if( !asNewFile ){ showDiff = 0; } |
| 481 | }else if( isNew ){ |
| 482 | if( !isNumStat ){ fossil_print("ADDED %s\n", zPathname); } |
| 483 | srcid = 0; |
| 484 | if( !asNewFile ){ showDiff = 0; } |
| 485 | }else if( isChnged==3 ){ |
| 486 | if( !isNumStat ){ fossil_print("ADDED_BY_MERGE %s\n", zPathname); } |
| 487 | srcid = 0; |
| 488 | if( !asNewFile ){ showDiff = 0; } |
| 489 | }else if( isChnged==5 ){ |
| 490 | if( !isNumStat ){ fossil_print("ADDED_BY_INTEGRATE %s\n", zPathname); } |
| 491 | srcid = 0; |
| 492 | if( !asNewFile ){ showDiff = 0; } |
| 493 | } |
| 494 | if( showDiff ){ |
| 495 | Blob content; |
| @@ -613,11 +623,11 @@ | |
| 623 | u64 diffFlags, |
| 624 | FileDirList *pFileDir |
| 625 | ){ |
| 626 | Manifest *pFrom, *pTo; |
| 627 | ManifestFile *pFromFile, *pToFile; |
| 628 | int asNewFlag = (diffFlags & (DIFF_VERBOSE|DIFF_NUMSTAT))!=0 ? 1 : 0; |
| 629 | |
| 630 | pFrom = manifest_get_by_name(zFrom, 0); |
| 631 | manifest_file_rewind(pFrom); |
| 632 | pFromFile = manifest_file_next(pFrom,0); |
| 633 | pTo = manifest_get_by_name(zTo, 0); |
| @@ -633,20 +643,24 @@ | |
| 643 | }else{ |
| 644 | cmp = fossil_strcmp(pFromFile->zName, pToFile->zName); |
| 645 | } |
| 646 | if( cmp<0 ){ |
| 647 | if( file_dir_match(pFileDir, pFromFile->zName) ){ |
| 648 | if( (diffFlags & DIFF_NUMSTAT)==0 ){ |
| 649 | fossil_print("DELETED %s\n", pFromFile->zName); |
| 650 | } |
| 651 | if( asNewFlag ){ |
| 652 | diff_manifest_entry(pFromFile, 0, zDiffCmd, zBinGlob, |
| 653 | fIncludeBinary, diffFlags); |
| 654 | } |
| 655 | } |
| 656 | pFromFile = manifest_file_next(pFrom,0); |
| 657 | }else if( cmp>0 ){ |
| 658 | if( file_dir_match(pFileDir, pToFile->zName) ){ |
| 659 | if( (diffFlags & DIFF_NUMSTAT)==0 ){ |
| 660 | fossil_print("ADDED %s\n", pToFile->zName); |
| 661 | } |
| 662 | if( asNewFlag ){ |
| 663 | diff_manifest_entry(0, pToFile, zDiffCmd, zBinGlob, |
| 664 | fIncludeBinary, diffFlags); |
| 665 | } |
| 666 | } |
| @@ -833,10 +847,11 @@ | |
| 847 | ** --diff-binary BOOL Include binary files when using external commands |
| 848 | ** --exec-abs-paths Force absolute path names with external commands. |
| 849 | ** --exec-rel-paths Force relative path names with external commands. |
| 850 | ** --from|-r VERSION Select VERSION as source for the diff |
| 851 | ** --internal|-i Use internal diff logic |
| 852 | ** --numstat Show only the number of lines delete and added |
| 853 | ** --side-by-side|-y Side-by-side diff |
| 854 | ** --strip-trailing-cr Strip trailing CR |
| 855 | ** --tk Launch a Tcl/Tk GUI for display |
| 856 | ** --to VERSION Select VERSION as target for the diff |
| 857 | ** --undo Diff against the "undo" buffer |
| 858 |