| | @@ -113,13 +113,15 @@ |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /* |
| 116 | 116 | ** Print the "Index:" message that patches wants to see at the top of a diff. |
| 117 | 117 | */ |
| 118 | | -void diff_print_index(const char *zFile, u64 diffFlags, Blob *diffBlob){ |
| 119 | | - if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT|DIFF_JSON| |
| 120 | | - DIFF_WEBPAGE|DIFF_TCL))==0 ){ |
| 118 | +void diff_print_index(const char *zFile, DiffConfig *pCfg, Blob *diffBlob){ |
| 119 | + if( (pCfg->diffFlags & |
| 120 | + (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT|DIFF_JSON| |
| 121 | + DIFF_WEBPAGE|DIFF_TCL))==0 |
| 122 | + ){ |
| 121 | 123 | char *z = mprintf("Index: %s\n%.66c\n", zFile, '='); |
| 122 | 124 | if( !diffBlob ){ |
| 123 | 125 | fossil_print("%s", z); |
| 124 | 126 | }else{ |
| 125 | 127 | blob_appendf(diffBlob, "%s", z); |
| | @@ -127,19 +129,21 @@ |
| 127 | 129 | fossil_free(z); |
| 128 | 130 | } |
| 129 | 131 | } |
| 130 | 132 | |
| 131 | 133 | /* |
| 132 | | -** Print the +++/--- filename lines for a diff operation. |
| 134 | +** Print the +++/--- filename lines or whatever filename information |
| 135 | +** is appropriate for the output format. |
| 133 | 136 | */ |
| 134 | 137 | void diff_print_filenames( |
| 135 | | - const char *zLeft, |
| 136 | | - const char *zRight, |
| 137 | | - u64 diffFlags, |
| 138 | | - Blob *diffBlob |
| 138 | + const char *zLeft, /* Name of the left file */ |
| 139 | + const char *zRight, /* Name of the right file */ |
| 140 | + DiffConfig *pCfg, /* Diff configuration */ |
| 141 | + Blob *diffBlob /* Write to this blob, or stdout of this is NULL */ |
| 139 | 142 | ){ |
| 140 | 143 | char *z = 0; |
| 144 | + u64 diffFlags = pCfg->diffFlags; |
| 141 | 145 | if( diffFlags & (DIFF_BRIEF|DIFF_RAW|DIFF_JSON) ){ |
| 142 | 146 | /* no-op */ |
| 143 | 147 | }else if( diffFlags & DIFF_DEBUG ){ |
| 144 | 148 | fossil_print("FILE-LEFT %s\nFILE-RIGHT %s\n", |
| 145 | 149 | zLeft, zRight); |
| | @@ -167,12 +171,11 @@ |
| 167 | 171 | fossil_print("%s", blob_str(pOut)); |
| 168 | 172 | blob_reset(&x); |
| 169 | 173 | } |
| 170 | 174 | return; |
| 171 | 175 | }else if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 172 | | - DiffConfig DCfg; |
| 173 | | - int w = diff_width(diff_config_init(&DCfg,diffFlags)); |
| 176 | + int w = diff_width(pCfg); |
| 174 | 177 | int n1 = strlen(zLeft); |
| 175 | 178 | int n2 = strlen(zRight); |
| 176 | 179 | int x; |
| 177 | 180 | if( n1==n2 && fossil_strcmp(zLeft,zRight)==0 ){ |
| 178 | 181 | if( n1>w*2 ) n1 = w*2; |
| | @@ -283,11 +286,13 @@ |
| 283 | 286 | @ </body> |
| 284 | 287 | @ </html> |
| 285 | 288 | ; |
| 286 | 289 | |
| 287 | 290 | /* |
| 288 | | -** State variables used by the --browser option for diff |
| 291 | +** State variables used by the --browser option for diff. These must |
| 292 | +** be static variables, not elements of DiffConfig, since they are |
| 293 | +** used by the interrupt handler. |
| 289 | 294 | */ |
| 290 | 295 | static char *tempDiffFilename; /* File holding the diff HTML */ |
| 291 | 296 | static FILE *diffOut; /* Open to write into tempDiffFilename */ |
| 292 | 297 | |
| 293 | 298 | /* Amount of delay (in milliseconds) between launching the |
| | @@ -322,12 +327,12 @@ |
| 322 | 327 | ** hold the result. Make arrangements to delete that temporary |
| 323 | 328 | ** file if the diff is interrupted. |
| 324 | 329 | ** |
| 325 | 330 | ** For --browser and --webpage, output the HTML header. |
| 326 | 331 | */ |
| 327 | | -void diff_begin(u64 diffFlags){ |
| 328 | | - if( (diffFlags & DIFF_BROWSER)!=0 ){ |
| 332 | +void diff_begin(DiffConfig *pCfg){ |
| 333 | + if( (pCfg->diffFlags & DIFF_BROWSER)!=0 ){ |
| 329 | 334 | tempDiffFilename = fossil_temp_filename(); |
| 330 | 335 | tempDiffFilename = sqlite3_mprintf("%z.html", tempDiffFilename); |
| 331 | 336 | diffOut = fossil_freopen(tempDiffFilename,"wb",stdout); |
| 332 | 337 | if( diffOut==0 ){ |
| 333 | 338 | fossil_fatal("unable to create temporary file \"%s\"", |
| | @@ -337,11 +342,11 @@ |
| 337 | 342 | signal(SIGINT, diff_www_interrupt); |
| 338 | 343 | #else |
| 339 | 344 | SetConsoleCtrlHandler(diff_console_ctrl_handler, TRUE); |
| 340 | 345 | #endif |
| 341 | 346 | } |
| 342 | | - if( (diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 347 | + if( (pCfg->diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 343 | 348 | fossil_print("%s",zWebpageHdr); |
| 344 | 349 | fflush(stdout); |
| 345 | 350 | } |
| 346 | 351 | } |
| 347 | 352 | |
| | @@ -353,19 +358,19 @@ |
| 353 | 358 | ** |
| 354 | 359 | ** For --browser, close the connection to the temporary file, then |
| 355 | 360 | ** launch a web browser to view the file. After a delay |
| 356 | 361 | ** of FOSSIL_BROWSER_DIFF_DELAY milliseconds, delete the temp file. |
| 357 | 362 | */ |
| 358 | | -void diff_end(u64 diffFlags, int nErr){ |
| 359 | | - if( (diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 360 | | - if( diffFlags & DIFF_SIDEBYSIDE ){ |
| 363 | +void diff_end(DiffConfig *pCfg, int nErr){ |
| 364 | + if( (pCfg->diffFlags & DIFF_WEBPAGE)!=0 ){ |
| 365 | + if( pCfg->diffFlags & DIFF_SIDEBYSIDE ){ |
| 361 | 366 | const unsigned char *zJs = builtin_file("diff.js", 0); |
| 362 | 367 | fossil_print("<script>\n%s</script>\n", zJs); |
| 363 | 368 | } |
| 364 | 369 | fossil_print("%s", zWebpageEnd); |
| 365 | 370 | } |
| 366 | | - if( (diffFlags & DIFF_BROWSER)!=0 && nErr==0 ){ |
| 371 | + if( (pCfg->diffFlags & DIFF_BROWSER)!=0 && nErr==0 ){ |
| 367 | 372 | char *zCmd = mprintf("%s %$", fossil_web_browser(), tempDiffFilename); |
| 368 | 373 | fclose(diffOut); |
| 369 | 374 | diffOut = fossil_freopen(NULL_DEVICE, "wb", stdout); |
| 370 | 375 | fossil_system(zCmd); |
| 371 | 376 | fossil_free(zCmd); |
| | @@ -437,15 +442,14 @@ |
| 437 | 442 | fossil_print("%s %s\n", blob_str(&out), zName); |
| 438 | 443 | }else{ |
| 439 | 444 | blob_appendf(diffBlob, "%s %s\n", blob_str(&out), zName); |
| 440 | 445 | } |
| 441 | 446 | }else{ |
| 447 | + diff_print_filenames(zName, zName2, pCfg, diffBlob); |
| 442 | 448 | if( !diffBlob ){ |
| 443 | | - diff_print_filenames(zName, zName2, pCfg->diffFlags, 0); |
| 444 | 449 | fossil_print("%s\n", blob_str(&out)); |
| 445 | 450 | }else{ |
| 446 | | - diff_print_filenames(zName, zName2, pCfg->diffFlags, diffBlob); |
| 447 | 451 | blob_appendf(diffBlob, "%s\n", blob_str(&out)); |
| 448 | 452 | } |
| 449 | 453 | } |
| 450 | 454 | } |
| 451 | 455 | blob_reset(&out); |
| | @@ -541,11 +545,11 @@ |
| 541 | 545 | blob_zero(&out); |
| 542 | 546 | text_diff(pFile1, pFile2, &out, 0, pCfg); |
| 543 | 547 | if( pCfg->diffFlags & DIFF_NUMSTAT ){ |
| 544 | 548 | fossil_print("%s %s\n", blob_str(&out), zName); |
| 545 | 549 | }else{ |
| 546 | | - diff_print_filenames(zName, zName, pCfg->diffFlags, 0); |
| 550 | + diff_print_filenames(zName, zName, pCfg, 0); |
| 547 | 551 | fossil_print("%s\n", blob_str(&out)); |
| 548 | 552 | } |
| 549 | 553 | |
| 550 | 554 | /* Release memory resources */ |
| 551 | 555 | blob_reset(&out); |
| | @@ -707,22 +711,22 @@ |
| 707 | 711 | } |
| 708 | 712 | if( showDiff ){ |
| 709 | 713 | Blob content; |
| 710 | 714 | int isBin; |
| 711 | 715 | if( !isLink != !file_islink(zFullName) ){ |
| 712 | | - diff_print_index(zPathname, pCfg->diffFlags, 0); |
| 713 | | - diff_print_filenames(zPathname, zPathname, pCfg->diffFlags, 0); |
| 716 | + diff_print_index(zPathname, pCfg, 0); |
| 717 | + diff_print_filenames(zPathname, zPathname, pCfg, 0); |
| 714 | 718 | fossil_print("%s",DIFF_CANNOT_COMPUTE_SYMLINK); |
| 715 | 719 | continue; |
| 716 | 720 | } |
| 717 | 721 | if( srcid>0 ){ |
| 718 | 722 | content_get(srcid, &content); |
| 719 | 723 | }else{ |
| 720 | 724 | blob_zero(&content); |
| 721 | 725 | } |
| 722 | 726 | isBin = fIncludeBinary ? 0 : looks_like_binary(&content); |
| 723 | | - diff_print_index(zPathname, pCfg->diffFlags, diffBlob); |
| 727 | + diff_print_index(zPathname, pCfg, diffBlob); |
| 724 | 728 | diff_file(&content, isBin, zFullName, zPathname, zDiffCmd, |
| 725 | 729 | zBinGlob, fIncludeBinary, pCfg, 0, diffBlob); |
| 726 | 730 | blob_reset(&content); |
| 727 | 731 | } |
| 728 | 732 | blob_reset(&fname); |
| | @@ -795,11 +799,11 @@ |
| 795 | 799 | zName = pTo->zName; |
| 796 | 800 | }else{ |
| 797 | 801 | zName = DIFF_NO_NAME; |
| 798 | 802 | } |
| 799 | 803 | if( pCfg->diffFlags & DIFF_BRIEF ) return; |
| 800 | | - diff_print_index(zName, pCfg->diffFlags, 0); |
| 804 | + diff_print_index(zName, pCfg, 0); |
| 801 | 805 | if( pFrom ){ |
| 802 | 806 | rid = uuid_to_rid(pFrom->zUuid, 0); |
| 803 | 807 | content_get(rid, &f1); |
| 804 | 808 | }else{ |
| 805 | 809 | blob_zero(&f1); |
| | @@ -1190,11 +1194,11 @@ |
| 1190 | 1194 | ridTo); |
| 1191 | 1195 | if( zFrom==0 ){ |
| 1192 | 1196 | fossil_fatal("check-in %s has no parent", zTo); |
| 1193 | 1197 | } |
| 1194 | 1198 | } |
| 1195 | | - diff_begin(DCfg.diffFlags); |
| 1199 | + diff_begin(&DCfg); |
| 1196 | 1200 | if( againstUndo ){ |
| 1197 | 1201 | if( db_lget_int("undo_available",0)==0 ){ |
| 1198 | 1202 | fossil_print("No undo or redo is available\n"); |
| 1199 | 1203 | return; |
| 1200 | 1204 | } |
| | @@ -1218,11 +1222,11 @@ |
| 1218 | 1222 | } |
| 1219 | 1223 | fossil_free(pFileDir[i].zName); |
| 1220 | 1224 | } |
| 1221 | 1225 | fossil_free(pFileDir); |
| 1222 | 1226 | } |
| 1223 | | - diff_end(DCfg.diffFlags, 0); |
| 1227 | + diff_end(&DCfg, 0); |
| 1224 | 1228 | if ( DCfg.diffFlags & DIFF_NUMSTAT ){ |
| 1225 | 1229 | fossil_print("%10d %10d TOTAL over %d changed files\n", |
| 1226 | 1230 | g.diffCnt[1], g.diffCnt[2], g.diffCnt[0]); |
| 1227 | 1231 | } |
| 1228 | 1232 | } |
| 1229 | 1233 | |