Fossil SCM
Add the --www option to the various "diff" commands.
Commit
f3961f453aee1ef5642190e567e816ab86dd55656bec043f43e71456cf7d718a
Parent
eb6611c4dc76f4a…
2 files changed
+4
+76
-1
+4
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -43,10 +43,11 @@ | ||
| 43 | 43 | #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */ |
| 44 | 44 | #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */ |
| 45 | 45 | #define DIFF_STRIP_EOLCR (((u64)0x10)<<32) /* Strip trailing CR */ |
| 46 | 46 | #define DIFF_SLOW_SBS (((u64)0x20)<<32) /* Better but slower side-by-side */ |
| 47 | 47 | #define DIFF_WEBPAGE (((u64)0x40)<<32) /* Complete webpage */ |
| 48 | +#define DIFF_WWW (((u64)0x80)<<32) /* The --www option */ | |
| 48 | 49 | |
| 49 | 50 | /* |
| 50 | 51 | ** These error messages are shared in multiple locations. They are defined |
| 51 | 52 | ** here for consistency. |
| 52 | 53 | */ |
| @@ -2041,10 +2042,13 @@ | ||
| 2041 | 2042 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 2042 | 2043 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 2043 | 2044 | if( find_option("webpage",0,0)!=0 ){ |
| 2044 | 2045 | diffFlags |= DIFF_HTML|DIFF_WEBPAGE|DIFF_LINENO; |
| 2045 | 2046 | } |
| 2047 | + if( find_option("www",0,0)!=0 ){ | |
| 2048 | + diffFlags |= DIFF_HTML|DIFF_WEBPAGE|DIFF_LINENO|DIFF_WWW; | |
| 2049 | + } | |
| 2046 | 2050 | return diffFlags; |
| 2047 | 2051 | } |
| 2048 | 2052 | |
| 2049 | 2053 | /* |
| 2050 | 2054 | ** COMMAND: test-rawdiff |
| 2051 | 2055 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -43,10 +43,11 @@ | |
| 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 */ |
| 46 | #define DIFF_SLOW_SBS (((u64)0x20)<<32) /* Better but slower side-by-side */ |
| 47 | #define DIFF_WEBPAGE (((u64)0x40)<<32) /* Complete webpage */ |
| 48 | |
| 49 | /* |
| 50 | ** These error messages are shared in multiple locations. They are defined |
| 51 | ** here for consistency. |
| 52 | */ |
| @@ -2041,10 +2042,13 @@ | |
| 2041 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 2042 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 2043 | if( find_option("webpage",0,0)!=0 ){ |
| 2044 | diffFlags |= DIFF_HTML|DIFF_WEBPAGE|DIFF_LINENO; |
| 2045 | } |
| 2046 | return diffFlags; |
| 2047 | } |
| 2048 | |
| 2049 | /* |
| 2050 | ** COMMAND: test-rawdiff |
| 2051 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -43,10 +43,11 @@ | |
| 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 */ |
| 46 | #define DIFF_SLOW_SBS (((u64)0x20)<<32) /* Better but slower side-by-side */ |
| 47 | #define DIFF_WEBPAGE (((u64)0x40)<<32) /* Complete webpage */ |
| 48 | #define DIFF_WWW (((u64)0x80)<<32) /* The --www option */ |
| 49 | |
| 50 | /* |
| 51 | ** These error messages are shared in multiple locations. They are defined |
| 52 | ** here for consistency. |
| 53 | */ |
| @@ -2041,10 +2042,13 @@ | |
| 2042 | if( find_option("invert",0,0)!=0 ) diffFlags |= DIFF_INVERT; |
| 2043 | if( find_option("brief",0,0)!=0 ) diffFlags |= DIFF_BRIEF; |
| 2044 | if( find_option("webpage",0,0)!=0 ){ |
| 2045 | diffFlags |= DIFF_HTML|DIFF_WEBPAGE|DIFF_LINENO; |
| 2046 | } |
| 2047 | if( find_option("www",0,0)!=0 ){ |
| 2048 | diffFlags |= DIFF_HTML|DIFF_WEBPAGE|DIFF_LINENO|DIFF_WWW; |
| 2049 | } |
| 2050 | return diffFlags; |
| 2051 | } |
| 2052 | |
| 2053 | /* |
| 2054 | ** COMMAND: test-rawdiff |
| 2055 |
+76
-1
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -19,10 +19,15 @@ | ||
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include "diffcmd.h" |
| 22 | 22 | #include <assert.h> |
| 23 | 23 | |
| 24 | +/* Need to catch the interrupt signal on unix */ | |
| 25 | +#ifndef _WIN32 | |
| 26 | +# include <signal.h> | |
| 27 | +#endif | |
| 28 | + | |
| 24 | 29 | /* |
| 25 | 30 | ** Use the right null device for the platform. |
| 26 | 31 | */ |
| 27 | 32 | #if defined(_WIN32) |
| 28 | 33 | # define NULL_DEVICE "NUL" |
| @@ -232,13 +237,64 @@ | ||
| 232 | 237 | @ </body> |
| 233 | 238 | @ </html> |
| 234 | 239 | ; |
| 235 | 240 | |
| 236 | 241 | /* |
| 237 | -** Do preliminary output before computing a diff. | |
| 242 | +** State variables used by the --www option for diff | |
| 243 | +*/ | |
| 244 | +static char *tempDiffFilename; /* File holding the diff HTML */ | |
| 245 | +static FILE *diffOut; /* Open to write into tempDiffFilename */ | |
| 246 | + | |
| 247 | +/* Amount of delay (in milliseconds) between launching the | |
| 248 | +** web browser and deleting the temporary file used by --www | |
| 249 | +*/ | |
| 250 | +#ifndef FOSSIL_WWW_DIFF_DELAY | |
| 251 | +# define FOSSIL_WWW_DIFF_DELAY 5000 /* 5 seconds by default */ | |
| 252 | +#endif | |
| 253 | + | |
| 254 | +/* | |
| 255 | +** If we catch a single while writing the temporary file for the --www | |
| 256 | +** diff output, then delete the temporary file and exit. | |
| 257 | +*/ | |
| 258 | +static void diff_www_interrupt(int NotUsed){ | |
| 259 | + (void)NotUsed; | |
| 260 | + if( diffOut ) fclose(diffOut); | |
| 261 | + if( tempDiffFilename ) file_delete(tempDiffFilename); | |
| 262 | + exit(1); | |
| 263 | +} | |
| 264 | +#ifdef _WIN32 | |
| 265 | +static BOOL WINAPI diff_console_ctrl_handler(DWORD dwCtrlType){ | |
| 266 | + if( dwCtrlType==CTRL_C_EVENT ) diff_www_interrupt(0); | |
| 267 | + return FALSE; | |
| 268 | +} | |
| 269 | +#endif | |
| 270 | + | |
| 271 | + | |
| 272 | +/* | |
| 273 | +** Do preliminary setup and output before computing a diff. | |
| 274 | +** | |
| 275 | +** For --www, redirect stdout to a temporary file that will | |
| 276 | +** hold the result. Make arrangements to delete that temporary | |
| 277 | +** file if the diff is interrupted. | |
| 278 | +** | |
| 279 | +** For --www and --webpage, output the HTML header. | |
| 238 | 280 | */ |
| 239 | 281 | void diff_begin(u64 diffFlags){ |
| 282 | + if( (diffFlags & DIFF_WWW)!=0 ){ | |
| 283 | + tempDiffFilename = fossil_temp_filename(); | |
| 284 | + tempDiffFilename = sqlite3_mprintf("%z.html", tempDiffFilename); | |
| 285 | + diffOut = freopen(tempDiffFilename,"wb",stdout); | |
| 286 | + if( diffOut==0 ){ | |
| 287 | + fossil_fatal("unable to create temporary file \"%s\"", | |
| 288 | + tempDiffFilename); | |
| 289 | + } | |
| 290 | +#ifndef _WIN32 | |
| 291 | + signal(SIGINT, diff_www_interrupt); | |
| 292 | +#else | |
| 293 | + SetConsoleCtrlHandler(diff_console_ctrl_handler, TRUE); | |
| 294 | +#endif | |
| 295 | + } | |
| 240 | 296 | if( (diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 241 | 297 | const char *zExtra; |
| 242 | 298 | if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 243 | 299 | zExtra = zSbsCss; |
| 244 | 300 | }else{ |
| @@ -248,18 +304,36 @@ | ||
| 248 | 304 | } |
| 249 | 305 | } |
| 250 | 306 | |
| 251 | 307 | /* Do any final output required by a diff and complete the diff |
| 252 | 308 | ** process. |
| 309 | +** | |
| 310 | +** For --www and --webpage, output any javascript required by | |
| 311 | +** the diff. (Currently JS is only needed for side-by-side diffs). | |
| 312 | +** | |
| 313 | +** For --www, close the connection to the temporary file, then | |
| 314 | +** launch a web browser to view the file. After a delay | |
| 315 | +** of FOSSIL_WWW_DIFF_DELAY milliseconds, delete the temp file. | |
| 253 | 316 | */ |
| 254 | 317 | void diff_end(u64 diffFlags, int nErr){ |
| 255 | 318 | if( (diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 256 | 319 | if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 257 | 320 | const unsigned char *zJs = builtin_file("sbsdiff.js", 0); |
| 258 | 321 | fossil_print("<script>\n%s</script>\n", zJs); |
| 259 | 322 | } |
| 260 | 323 | fossil_print("%s", zWebpageEnd); |
| 324 | + } | |
| 325 | + if( (diffFlags & DIFF_WWW)!=0 && nErr==0 ){ | |
| 326 | + char *zCmd = mprintf("%$ %$", fossil_web_browser(), tempDiffFilename); | |
| 327 | + fclose(diffOut); | |
| 328 | + freopen(NULL_DEVICE, "wb", stdout); | |
| 329 | + fossil_system(zCmd); | |
| 330 | + fossil_free(zCmd); | |
| 331 | + sqlite3_sleep(FOSSIL_WWW_DIFF_DELAY); | |
| 332 | + file_delete(tempDiffFilename); | |
| 333 | + sqlite3_free(tempDiffFilename); | |
| 334 | + tempDiffFilename = 0; | |
| 261 | 335 | } |
| 262 | 336 | } |
| 263 | 337 | |
| 264 | 338 | /* |
| 265 | 339 | ** Show the difference between two files, one in memory and one on disk. |
| @@ -965,10 +1039,11 @@ | ||
| 965 | 1039 | ** --undo Diff against the "undo" buffer |
| 966 | 1040 | ** --unified Unified diff |
| 967 | 1041 | ** -v|--verbose Output complete text of added or deleted files |
| 968 | 1042 | ** --webpage Format output as a stand-alone HTML webpage |
| 969 | 1043 | ** -W|--width N Width of lines in side-by-side diff |
| 1044 | +** --www Show the diff output in a web-browser | |
| 970 | 1045 | ** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace |
| 971 | 1046 | */ |
| 972 | 1047 | void diff_cmd(void){ |
| 973 | 1048 | int isGDiff; /* True for gdiff. False for normal diff */ |
| 974 | 1049 | int isInternDiff; /* True for internal diff */ |
| 975 | 1050 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -19,10 +19,15 @@ | |
| 19 | */ |
| 20 | #include "config.h" |
| 21 | #include "diffcmd.h" |
| 22 | #include <assert.h> |
| 23 | |
| 24 | /* |
| 25 | ** Use the right null device for the platform. |
| 26 | */ |
| 27 | #if defined(_WIN32) |
| 28 | # define NULL_DEVICE "NUL" |
| @@ -232,13 +237,64 @@ | |
| 232 | @ </body> |
| 233 | @ </html> |
| 234 | ; |
| 235 | |
| 236 | /* |
| 237 | ** Do preliminary output before computing a diff. |
| 238 | */ |
| 239 | void diff_begin(u64 diffFlags){ |
| 240 | if( (diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 241 | const char *zExtra; |
| 242 | if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 243 | zExtra = zSbsCss; |
| 244 | }else{ |
| @@ -248,18 +304,36 @@ | |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /* Do any final output required by a diff and complete the diff |
| 252 | ** process. |
| 253 | */ |
| 254 | void diff_end(u64 diffFlags, int nErr){ |
| 255 | if( (diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 256 | if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 257 | const unsigned char *zJs = builtin_file("sbsdiff.js", 0); |
| 258 | fossil_print("<script>\n%s</script>\n", zJs); |
| 259 | } |
| 260 | fossil_print("%s", zWebpageEnd); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | ** Show the difference between two files, one in memory and one on disk. |
| @@ -965,10 +1039,11 @@ | |
| 965 | ** --undo Diff against the "undo" buffer |
| 966 | ** --unified Unified diff |
| 967 | ** -v|--verbose Output complete text of added or deleted files |
| 968 | ** --webpage Format output as a stand-alone HTML webpage |
| 969 | ** -W|--width N Width of lines in side-by-side diff |
| 970 | ** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace |
| 971 | */ |
| 972 | void diff_cmd(void){ |
| 973 | int isGDiff; /* True for gdiff. False for normal diff */ |
| 974 | int isInternDiff; /* True for internal diff */ |
| 975 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -19,10 +19,15 @@ | |
| 19 | */ |
| 20 | #include "config.h" |
| 21 | #include "diffcmd.h" |
| 22 | #include <assert.h> |
| 23 | |
| 24 | /* Need to catch the interrupt signal on unix */ |
| 25 | #ifndef _WIN32 |
| 26 | # include <signal.h> |
| 27 | #endif |
| 28 | |
| 29 | /* |
| 30 | ** Use the right null device for the platform. |
| 31 | */ |
| 32 | #if defined(_WIN32) |
| 33 | # define NULL_DEVICE "NUL" |
| @@ -232,13 +237,64 @@ | |
| 237 | @ </body> |
| 238 | @ </html> |
| 239 | ; |
| 240 | |
| 241 | /* |
| 242 | ** State variables used by the --www option for diff |
| 243 | */ |
| 244 | static char *tempDiffFilename; /* File holding the diff HTML */ |
| 245 | static FILE *diffOut; /* Open to write into tempDiffFilename */ |
| 246 | |
| 247 | /* Amount of delay (in milliseconds) between launching the |
| 248 | ** web browser and deleting the temporary file used by --www |
| 249 | */ |
| 250 | #ifndef FOSSIL_WWW_DIFF_DELAY |
| 251 | # define FOSSIL_WWW_DIFF_DELAY 5000 /* 5 seconds by default */ |
| 252 | #endif |
| 253 | |
| 254 | /* |
| 255 | ** If we catch a single while writing the temporary file for the --www |
| 256 | ** diff output, then delete the temporary file and exit. |
| 257 | */ |
| 258 | static void diff_www_interrupt(int NotUsed){ |
| 259 | (void)NotUsed; |
| 260 | if( diffOut ) fclose(diffOut); |
| 261 | if( tempDiffFilename ) file_delete(tempDiffFilename); |
| 262 | exit(1); |
| 263 | } |
| 264 | #ifdef _WIN32 |
| 265 | static BOOL WINAPI diff_console_ctrl_handler(DWORD dwCtrlType){ |
| 266 | if( dwCtrlType==CTRL_C_EVENT ) diff_www_interrupt(0); |
| 267 | return FALSE; |
| 268 | } |
| 269 | #endif |
| 270 | |
| 271 | |
| 272 | /* |
| 273 | ** Do preliminary setup and output before computing a diff. |
| 274 | ** |
| 275 | ** For --www, redirect stdout to a temporary file that will |
| 276 | ** hold the result. Make arrangements to delete that temporary |
| 277 | ** file if the diff is interrupted. |
| 278 | ** |
| 279 | ** For --www and --webpage, output the HTML header. |
| 280 | */ |
| 281 | void diff_begin(u64 diffFlags){ |
| 282 | if( (diffFlags & DIFF_WWW)!=0 ){ |
| 283 | tempDiffFilename = fossil_temp_filename(); |
| 284 | tempDiffFilename = sqlite3_mprintf("%z.html", tempDiffFilename); |
| 285 | diffOut = freopen(tempDiffFilename,"wb",stdout); |
| 286 | if( diffOut==0 ){ |
| 287 | fossil_fatal("unable to create temporary file \"%s\"", |
| 288 | tempDiffFilename); |
| 289 | } |
| 290 | #ifndef _WIN32 |
| 291 | signal(SIGINT, diff_www_interrupt); |
| 292 | #else |
| 293 | SetConsoleCtrlHandler(diff_console_ctrl_handler, TRUE); |
| 294 | #endif |
| 295 | } |
| 296 | if( (diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 297 | const char *zExtra; |
| 298 | if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 299 | zExtra = zSbsCss; |
| 300 | }else{ |
| @@ -248,18 +304,36 @@ | |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /* Do any final output required by a diff and complete the diff |
| 308 | ** process. |
| 309 | ** |
| 310 | ** For --www and --webpage, output any javascript required by |
| 311 | ** the diff. (Currently JS is only needed for side-by-side diffs). |
| 312 | ** |
| 313 | ** For --www, close the connection to the temporary file, then |
| 314 | ** launch a web browser to view the file. After a delay |
| 315 | ** of FOSSIL_WWW_DIFF_DELAY milliseconds, delete the temp file. |
| 316 | */ |
| 317 | void diff_end(u64 diffFlags, int nErr){ |
| 318 | if( (diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 319 | if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 320 | const unsigned char *zJs = builtin_file("sbsdiff.js", 0); |
| 321 | fossil_print("<script>\n%s</script>\n", zJs); |
| 322 | } |
| 323 | fossil_print("%s", zWebpageEnd); |
| 324 | } |
| 325 | if( (diffFlags & DIFF_WWW)!=0 && nErr==0 ){ |
| 326 | char *zCmd = mprintf("%$ %$", fossil_web_browser(), tempDiffFilename); |
| 327 | fclose(diffOut); |
| 328 | freopen(NULL_DEVICE, "wb", stdout); |
| 329 | fossil_system(zCmd); |
| 330 | fossil_free(zCmd); |
| 331 | sqlite3_sleep(FOSSIL_WWW_DIFF_DELAY); |
| 332 | file_delete(tempDiffFilename); |
| 333 | sqlite3_free(tempDiffFilename); |
| 334 | tempDiffFilename = 0; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | ** Show the difference between two files, one in memory and one on disk. |
| @@ -965,10 +1039,11 @@ | |
| 1039 | ** --undo Diff against the "undo" buffer |
| 1040 | ** --unified Unified diff |
| 1041 | ** -v|--verbose Output complete text of added or deleted files |
| 1042 | ** --webpage Format output as a stand-alone HTML webpage |
| 1043 | ** -W|--width N Width of lines in side-by-side diff |
| 1044 | ** --www Show the diff output in a web-browser |
| 1045 | ** -Z|--ignore-trailing-space Ignore changes to end-of-line whitespace |
| 1046 | */ |
| 1047 | void diff_cmd(void){ |
| 1048 | int isGDiff; /* True for gdiff. False for normal diff */ |
| 1049 | int isInternDiff; /* True for internal diff */ |
| 1050 |