Fossil SCM
Add '--versions' option to 'fossil diff' to display details about the compared versions.
Commit
49ef1b574ee606ec7d82c9662a4fb0c6a84a2563763910353a9e5050603f2912
Parent
87955d92741f8f0…
2 files changed
+2
+39
-1
+2
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -47,10 +47,11 @@ | ||
| 47 | 47 | #define DIFF_JSON 0x00010000 /* JSON output */ |
| 48 | 48 | #define DIFF_DEBUG 0x00020000 /* Debugging diff output */ |
| 49 | 49 | #define DIFF_RAW 0x00040000 /* Raw triples - for debugging */ |
| 50 | 50 | #define DIFF_TCL 0x00080000 /* For the --tk option */ |
| 51 | 51 | #define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */ |
| 52 | +#define DIFF_SHOW_VERS 0x00200000 /* Show compared versions */ | |
| 52 | 53 | |
| 53 | 54 | /* |
| 54 | 55 | ** These error messages are shared in multiple locations. They are defined |
| 55 | 56 | ** here for consistency. |
| 56 | 57 | */ |
| @@ -3180,10 +3181,11 @@ | ||
| 3180 | 3181 | pCfg->wColumn = f; |
| 3181 | 3182 | } |
| 3182 | 3183 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 3183 | 3184 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 3184 | 3185 | if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT; |
| 3186 | + if( find_option("versions","h",0)!=0 ) diffFlags |= DIFF_SHOW_VERS; | |
| 3185 | 3187 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 3186 | 3188 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 3187 | 3189 | if( find_option("internal","i",0)==0 |
| 3188 | 3190 | && (diffFlags & (DIFF_HTML|DIFF_TCL|DIFF_DEBUG|DIFF_JSON))==0 |
| 3189 | 3191 | ){ |
| 3190 | 3192 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -47,10 +47,11 @@ | |
| 47 | #define DIFF_JSON 0x00010000 /* JSON output */ |
| 48 | #define DIFF_DEBUG 0x00020000 /* Debugging diff output */ |
| 49 | #define DIFF_RAW 0x00040000 /* Raw triples - for debugging */ |
| 50 | #define DIFF_TCL 0x00080000 /* For the --tk option */ |
| 51 | #define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */ |
| 52 | |
| 53 | /* |
| 54 | ** These error messages are shared in multiple locations. They are defined |
| 55 | ** here for consistency. |
| 56 | */ |
| @@ -3180,10 +3181,11 @@ | |
| 3180 | pCfg->wColumn = f; |
| 3181 | } |
| 3182 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 3183 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 3184 | if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT; |
| 3185 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 3186 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 3187 | if( find_option("internal","i",0)==0 |
| 3188 | && (diffFlags & (DIFF_HTML|DIFF_TCL|DIFF_DEBUG|DIFF_JSON))==0 |
| 3189 | ){ |
| 3190 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -47,10 +47,11 @@ | |
| 47 | #define DIFF_JSON 0x00010000 /* JSON output */ |
| 48 | #define DIFF_DEBUG 0x00020000 /* Debugging diff output */ |
| 49 | #define DIFF_RAW 0x00040000 /* Raw triples - for debugging */ |
| 50 | #define DIFF_TCL 0x00080000 /* For the --tk option */ |
| 51 | #define DIFF_INCBINARY 0x00100000 /* The --diff-binary option */ |
| 52 | #define DIFF_SHOW_VERS 0x00200000 /* Show compared versions */ |
| 53 | |
| 54 | /* |
| 55 | ** These error messages are shared in multiple locations. They are defined |
| 56 | ** here for consistency. |
| 57 | */ |
| @@ -3180,10 +3181,11 @@ | |
| 3181 | pCfg->wColumn = f; |
| 3182 | } |
| 3183 | if( find_option("linenum","n",0)!=0 ) diffFlags |= DIFF_LINENO; |
| 3184 | if( find_option("noopt",0,0)!=0 ) diffFlags |= DIFF_NOOPT; |
| 3185 | if( find_option("numstat",0,0)!=0 ) diffFlags |= DIFF_NUMSTAT; |
| 3186 | if( find_option("versions","h",0)!=0 ) diffFlags |= DIFF_SHOW_VERS; |
| 3187 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 3188 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 3189 | if( find_option("internal","i",0)==0 |
| 3190 | && (diffFlags & (DIFF_HTML|DIFF_TCL|DIFF_DEBUG|DIFF_JSON))==0 |
| 3191 | ){ |
| 3192 |
+39
-1
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -109,10 +109,37 @@ | ||
| 109 | 109 | p->nUsed++; |
| 110 | 110 | return 1; |
| 111 | 111 | } |
| 112 | 112 | return 0; |
| 113 | 113 | } |
| 114 | + | |
| 115 | +/* | |
| 116 | +** Print details about the compared versions - possibly the working directory | |
| 117 | +** or the undo buffer. For check-ins, show hash and commit time. | |
| 118 | +** | |
| 119 | +** This is intended primarily to go into the "header garbage" that is ignored | |
| 120 | +** by patch(1). | |
| 121 | +** | |
| 122 | +** zFrom and zTo are interpreted as symbolic version names, unless they | |
| 123 | +** start with '(', in which case they are printed directly. | |
| 124 | +*/ | |
| 125 | +void diff_print_versions(const char *zFrom, const char *zTo, DiffConfig *pCfg){ | |
| 126 | + if( (pCfg->diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT| | |
| 127 | + DIFF_HTML|DIFF_WEBPAGE|DIFF_BROWSER|DIFF_JSON|DIFF_TCL))==0 ){ | |
| 128 | + fossil_print("Fossil-Diff-From: %s\n", | |
| 129 | + zFrom[0]=='(' ? zFrom : mprintf("%S %s", | |
| 130 | + rid_to_uuid(symbolic_name_to_rid(zFrom, "ci")), | |
| 131 | + db_text("","SELECT datetime(%f)||' UTC'", | |
| 132 | + symbolic_name_to_mtime(zFrom, 0)))); | |
| 133 | + fossil_print("Fossil-Diff-To: %s\n", | |
| 134 | + zTo[0]=='(' ? zTo : mprintf("%S %s", | |
| 135 | + rid_to_uuid(symbolic_name_to_rid(zTo, "ci")), | |
| 136 | + db_text("","SELECT datetime(%f)||' UTC'", | |
| 137 | + symbolic_name_to_mtime(zTo, 0)))); | |
| 138 | + fossil_print("%.66c\n", '-'); | |
| 139 | + } | |
| 140 | +} | |
| 114 | 141 | |
| 115 | 142 | /* |
| 116 | 143 | ** Print the "Index:" message that patches wants to see at the top of a diff. |
| 117 | 144 | */ |
| 118 | 145 | void diff_print_index(const char *zFile, DiffConfig *pCfg, Blob *pOut){ |
| @@ -125,10 +152,11 @@ | ||
| 125 | 152 | } |
| 126 | 153 | |
| 127 | 154 | /* |
| 128 | 155 | ** Print the +++/--- filename lines or whatever filename information |
| 129 | 156 | ** is appropriate for the output format. |
| 157 | +** | |
| 130 | 158 | */ |
| 131 | 159 | void diff_print_filenames( |
| 132 | 160 | const char *zLeft, /* Name of the left file */ |
| 133 | 161 | const char *zRight, /* Name of the right file */ |
| 134 | 162 | DiffConfig *pCfg, /* Diff configuration */ |
| @@ -659,10 +687,14 @@ | ||
| 659 | 687 | " WHERE vid=%d" |
| 660 | 688 | " AND (deleted OR chnged OR rid==0)" |
| 661 | 689 | " ORDER BY pathname /*scan*/", |
| 662 | 690 | vid |
| 663 | 691 | ); |
| 692 | + } | |
| 693 | + if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){ | |
| 694 | + diff_print_versions(zFrom ? zFrom : db_lget("checkout-hash", 0), | |
| 695 | + "(workdir)", pCfg); | |
| 664 | 696 | } |
| 665 | 697 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| 666 | 698 | blob_reset(&sql); |
| 667 | 699 | while( db_step(&q)==SQLITE_ROW ){ |
| 668 | 700 | const char *zPathname = db_column_text(&q,0); |
| @@ -744,10 +776,13 @@ | ||
| 744 | 776 | ){ |
| 745 | 777 | Stmt q; |
| 746 | 778 | Blob content; |
| 747 | 779 | db_prepare(&q, "SELECT pathname, content FROM undo"); |
| 748 | 780 | blob_init(&content, 0, 0); |
| 781 | + if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){ | |
| 782 | + diff_print_versions("(undo)", "(workdir)", pCfg); | |
| 783 | + } | |
| 749 | 784 | while( db_step(&q)==SQLITE_ROW ){ |
| 750 | 785 | char *zFullName; |
| 751 | 786 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 752 | 787 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 753 | 788 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| @@ -828,11 +863,13 @@ | ||
| 828 | 863 | manifest_file_rewind(pFrom); |
| 829 | 864 | pFromFile = manifest_file_next(pFrom,0); |
| 830 | 865 | pTo = manifest_get_by_name(zTo, 0); |
| 831 | 866 | manifest_file_rewind(pTo); |
| 832 | 867 | pToFile = manifest_file_next(pTo,0); |
| 833 | - | |
| 868 | + if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){ | |
| 869 | + diff_print_versions(zFrom, zTo, pCfg); | |
| 870 | + } | |
| 834 | 871 | while( pFromFile || pToFile ){ |
| 835 | 872 | int cmp; |
| 836 | 873 | if( pFromFile==0 ){ |
| 837 | 874 | cmp = +1; |
| 838 | 875 | }else if( pToFile==0 ){ |
| @@ -1058,10 +1095,11 @@ | ||
| 1058 | 1095 | ** --tk Launch a Tcl/Tk GUI for display |
| 1059 | 1096 | ** --to VERSION Select VERSION as target for the diff |
| 1060 | 1097 | ** --undo Diff against the "undo" buffer |
| 1061 | 1098 | ** --unified Unified diff |
| 1062 | 1099 | ** -v|--verbose Output complete text of added or deleted files |
| 1100 | +** -h|--versions Show compared versions in the diff header | |
| 1063 | 1101 | ** --webpage Format output as a stand-alone HTML webpage |
| 1064 | 1102 | ** -W|--width N Width of lines in side-by-side diff |
| 1065 | 1103 | ** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace |
| 1066 | 1104 | */ |
| 1067 | 1105 | void diff_cmd(void){ |
| 1068 | 1106 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -109,10 +109,37 @@ | |
| 109 | p->nUsed++; |
| 110 | return 1; |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | ** Print the "Index:" message that patches wants to see at the top of a diff. |
| 117 | */ |
| 118 | void diff_print_index(const char *zFile, DiffConfig *pCfg, Blob *pOut){ |
| @@ -125,10 +152,11 @@ | |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | ** Print the +++/--- filename lines or whatever filename information |
| 129 | ** is appropriate for the output format. |
| 130 | */ |
| 131 | void diff_print_filenames( |
| 132 | const char *zLeft, /* Name of the left file */ |
| 133 | const char *zRight, /* Name of the right file */ |
| 134 | DiffConfig *pCfg, /* Diff configuration */ |
| @@ -659,10 +687,14 @@ | |
| 659 | " WHERE vid=%d" |
| 660 | " AND (deleted OR chnged OR rid==0)" |
| 661 | " ORDER BY pathname /*scan*/", |
| 662 | vid |
| 663 | ); |
| 664 | } |
| 665 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| 666 | blob_reset(&sql); |
| 667 | while( db_step(&q)==SQLITE_ROW ){ |
| 668 | const char *zPathname = db_column_text(&q,0); |
| @@ -744,10 +776,13 @@ | |
| 744 | ){ |
| 745 | Stmt q; |
| 746 | Blob content; |
| 747 | db_prepare(&q, "SELECT pathname, content FROM undo"); |
| 748 | blob_init(&content, 0, 0); |
| 749 | while( db_step(&q)==SQLITE_ROW ){ |
| 750 | char *zFullName; |
| 751 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 752 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 753 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| @@ -828,11 +863,13 @@ | |
| 828 | manifest_file_rewind(pFrom); |
| 829 | pFromFile = manifest_file_next(pFrom,0); |
| 830 | pTo = manifest_get_by_name(zTo, 0); |
| 831 | manifest_file_rewind(pTo); |
| 832 | pToFile = manifest_file_next(pTo,0); |
| 833 | |
| 834 | while( pFromFile || pToFile ){ |
| 835 | int cmp; |
| 836 | if( pFromFile==0 ){ |
| 837 | cmp = +1; |
| 838 | }else if( pToFile==0 ){ |
| @@ -1058,10 +1095,11 @@ | |
| 1058 | ** --tk Launch a Tcl/Tk GUI for display |
| 1059 | ** --to VERSION Select VERSION as target for the diff |
| 1060 | ** --undo Diff against the "undo" buffer |
| 1061 | ** --unified Unified diff |
| 1062 | ** -v|--verbose Output complete text of added or deleted files |
| 1063 | ** --webpage Format output as a stand-alone HTML webpage |
| 1064 | ** -W|--width N Width of lines in side-by-side diff |
| 1065 | ** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace |
| 1066 | */ |
| 1067 | void diff_cmd(void){ |
| 1068 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -109,10 +109,37 @@ | |
| 109 | p->nUsed++; |
| 110 | return 1; |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | ** Print details about the compared versions - possibly the working directory |
| 117 | ** or the undo buffer. For check-ins, show hash and commit time. |
| 118 | ** |
| 119 | ** This is intended primarily to go into the "header garbage" that is ignored |
| 120 | ** by patch(1). |
| 121 | ** |
| 122 | ** zFrom and zTo are interpreted as symbolic version names, unless they |
| 123 | ** start with '(', in which case they are printed directly. |
| 124 | */ |
| 125 | void diff_print_versions(const char *zFrom, const char *zTo, DiffConfig *pCfg){ |
| 126 | if( (pCfg->diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT| |
| 127 | DIFF_HTML|DIFF_WEBPAGE|DIFF_BROWSER|DIFF_JSON|DIFF_TCL))==0 ){ |
| 128 | fossil_print("Fossil-Diff-From: %s\n", |
| 129 | zFrom[0]=='(' ? zFrom : mprintf("%S %s", |
| 130 | rid_to_uuid(symbolic_name_to_rid(zFrom, "ci")), |
| 131 | db_text("","SELECT datetime(%f)||' UTC'", |
| 132 | symbolic_name_to_mtime(zFrom, 0)))); |
| 133 | fossil_print("Fossil-Diff-To: %s\n", |
| 134 | zTo[0]=='(' ? zTo : mprintf("%S %s", |
| 135 | rid_to_uuid(symbolic_name_to_rid(zTo, "ci")), |
| 136 | db_text("","SELECT datetime(%f)||' UTC'", |
| 137 | symbolic_name_to_mtime(zTo, 0)))); |
| 138 | fossil_print("%.66c\n", '-'); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | ** Print the "Index:" message that patches wants to see at the top of a diff. |
| 144 | */ |
| 145 | void diff_print_index(const char *zFile, DiffConfig *pCfg, Blob *pOut){ |
| @@ -125,10 +152,11 @@ | |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | ** Print the +++/--- filename lines or whatever filename information |
| 156 | ** is appropriate for the output format. |
| 157 | ** |
| 158 | */ |
| 159 | void diff_print_filenames( |
| 160 | const char *zLeft, /* Name of the left file */ |
| 161 | const char *zRight, /* Name of the right file */ |
| 162 | DiffConfig *pCfg, /* Diff configuration */ |
| @@ -659,10 +687,14 @@ | |
| 687 | " WHERE vid=%d" |
| 688 | " AND (deleted OR chnged OR rid==0)" |
| 689 | " ORDER BY pathname /*scan*/", |
| 690 | vid |
| 691 | ); |
| 692 | } |
| 693 | if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){ |
| 694 | diff_print_versions(zFrom ? zFrom : db_lget("checkout-hash", 0), |
| 695 | "(workdir)", pCfg); |
| 696 | } |
| 697 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| 698 | blob_reset(&sql); |
| 699 | while( db_step(&q)==SQLITE_ROW ){ |
| 700 | const char *zPathname = db_column_text(&q,0); |
| @@ -744,10 +776,13 @@ | |
| 776 | ){ |
| 777 | Stmt q; |
| 778 | Blob content; |
| 779 | db_prepare(&q, "SELECT pathname, content FROM undo"); |
| 780 | blob_init(&content, 0, 0); |
| 781 | if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){ |
| 782 | diff_print_versions("(undo)", "(workdir)", pCfg); |
| 783 | } |
| 784 | while( db_step(&q)==SQLITE_ROW ){ |
| 785 | char *zFullName; |
| 786 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 787 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 788 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| @@ -828,11 +863,13 @@ | |
| 863 | manifest_file_rewind(pFrom); |
| 864 | pFromFile = manifest_file_next(pFrom,0); |
| 865 | pTo = manifest_get_by_name(zTo, 0); |
| 866 | manifest_file_rewind(pTo); |
| 867 | pToFile = manifest_file_next(pTo,0); |
| 868 | if( (pCfg->diffFlags & DIFF_SHOW_VERS)!=0 ){ |
| 869 | diff_print_versions(zFrom, zTo, pCfg); |
| 870 | } |
| 871 | while( pFromFile || pToFile ){ |
| 872 | int cmp; |
| 873 | if( pFromFile==0 ){ |
| 874 | cmp = +1; |
| 875 | }else if( pToFile==0 ){ |
| @@ -1058,10 +1095,11 @@ | |
| 1095 | ** --tk Launch a Tcl/Tk GUI for display |
| 1096 | ** --to VERSION Select VERSION as target for the diff |
| 1097 | ** --undo Diff against the "undo" buffer |
| 1098 | ** --unified Unified diff |
| 1099 | ** -v|--verbose Output complete text of added or deleted files |
| 1100 | ** -h|--versions Show compared versions in the diff header |
| 1101 | ** --webpage Format output as a stand-alone HTML webpage |
| 1102 | ** -W|--width N Width of lines in side-by-side diff |
| 1103 | ** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace |
| 1104 | */ |
| 1105 | void diff_cmd(void){ |
| 1106 |