Fossil SCM
Improve stash diff commands when using external diff tool to make it behave a little bit more like the "fossil gdiff" command.
Commit
2a47673a9e00952f647ad64fa3f1c75ca6a892f2
Parent
9413c77358c094c…
2 files changed
+21
-7
+35
-32
+21
-7
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -151,10 +151,13 @@ | ||
| 151 | 151 | /* |
| 152 | 152 | ** Show the difference between two files, one in memory and one on disk. |
| 153 | 153 | ** |
| 154 | 154 | ** The difference is the set of edits needed to transform pFile1 into |
| 155 | 155 | ** zFile2. The content of pFile1 is in memory. zFile2 exists on disk. |
| 156 | +** | |
| 157 | +** If fSwapDiff is 1, show the set of edits to transform zFile2 into pFile1 | |
| 158 | +** instead of the opposite. | |
| 156 | 159 | ** |
| 157 | 160 | ** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the |
| 158 | 161 | ** command zDiffCmd to do the diffing. |
| 159 | 162 | ** |
| 160 | 163 | ** When using an external diff program, zBinGlob contains the GLOB patterns |
| @@ -167,11 +170,12 @@ | ||
| 167 | 170 | const char *zFile2, /* On disk content to compare to */ |
| 168 | 171 | const char *zName, /* Display name of the file */ |
| 169 | 172 | const char *zDiffCmd, /* Command for comparison */ |
| 170 | 173 | const char *zBinGlob, /* Treat file names matching this as binary */ |
| 171 | 174 | int fIncludeBinary, /* Include binary files for external diff */ |
| 172 | - u64 diffFlags /* Flags to control the diff */ | |
| 175 | + u64 diffFlags, /* Flags to control the diff */ | |
| 176 | + int fSwapDiff /* Diff from Zfile2 to Pfile1 */ | |
| 173 | 177 | ){ |
| 174 | 178 | if( zDiffCmd==0 ){ |
| 175 | 179 | Blob out; /* Diff output text */ |
| 176 | 180 | Blob file2; /* Content of zFile2 */ |
| 177 | 181 | const char *zName2; /* Name of zFile2 for display */ |
| @@ -194,11 +198,15 @@ | ||
| 194 | 198 | if( blob_compare(pFile1, &file2) ){ |
| 195 | 199 | fossil_print("CHANGED %s\n", zName); |
| 196 | 200 | } |
| 197 | 201 | }else{ |
| 198 | 202 | blob_zero(&out); |
| 199 | - text_diff(pFile1, &file2, &out, 0, diffFlags); | |
| 203 | + if( fSwapDiff ){ | |
| 204 | + text_diff(&file2, pFile1, &out, 0, diffFlags); | |
| 205 | + }else{ | |
| 206 | + text_diff(pFile1, &file2, &out, 0, diffFlags); | |
| 207 | + } | |
| 200 | 208 | if( blob_size(&out) ){ |
| 201 | 209 | diff_print_filenames(zName, zName2, diffFlags); |
| 202 | 210 | fossil_print("%s\n", blob_str(&out)); |
| 203 | 211 | } |
| 204 | 212 | blob_reset(&out); |
| @@ -252,13 +260,19 @@ | ||
| 252 | 260 | blob_write_to_file(pFile1, blob_str(&nameFile1)); |
| 253 | 261 | |
| 254 | 262 | /* Construct the external diff command */ |
| 255 | 263 | blob_zero(&cmd); |
| 256 | 264 | blob_appendf(&cmd, "%s ", zDiffCmd); |
| 257 | - shell_escape(&cmd, blob_str(&nameFile1)); | |
| 258 | - blob_append(&cmd, " ", 1); | |
| 259 | - shell_escape(&cmd, zFile2); | |
| 265 | + if( fSwapDiff ){ | |
| 266 | + shell_escape(&cmd, zFile2); | |
| 267 | + blob_append(&cmd, " ", 1); | |
| 268 | + shell_escape(&cmd, blob_str(&nameFile1)); | |
| 269 | + }else{ | |
| 270 | + shell_escape(&cmd, blob_str(&nameFile1)); | |
| 271 | + blob_append(&cmd, " ", 1); | |
| 272 | + shell_escape(&cmd, zFile2); | |
| 273 | + } | |
| 260 | 274 | |
| 261 | 275 | /* Run the external diff command */ |
| 262 | 276 | fossil_system(blob_str(&cmd)); |
| 263 | 277 | |
| 264 | 278 | /* Delete the temporary file and clean up memory used */ |
| @@ -482,11 +496,11 @@ | ||
| 482 | 496 | blob_zero(&content); |
| 483 | 497 | } |
| 484 | 498 | isBin = fIncludeBinary ? 0 : looks_like_binary(&content); |
| 485 | 499 | diff_print_index(zPathname, diffFlags); |
| 486 | 500 | diff_file(&content, isBin, zFullName, zPathname, zDiffCmd, |
| 487 | - zBinGlob, fIncludeBinary, diffFlags); | |
| 501 | + zBinGlob, fIncludeBinary, diffFlags, 0); | |
| 488 | 502 | blob_reset(&content); |
| 489 | 503 | } |
| 490 | 504 | blob_reset(&fname); |
| 491 | 505 | } |
| 492 | 506 | db_finalize(&q); |
| @@ -519,11 +533,11 @@ | ||
| 519 | 533 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 520 | 534 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 521 | 535 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| 522 | 536 | db_column_blob(&q, 1, &content); |
| 523 | 537 | diff_file(&content, 0, zFullName, zFile, |
| 524 | - zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); | |
| 538 | + zDiffCmd, zBinGlob, fIncludeBinary, diffFlags, 0); | |
| 525 | 539 | fossil_free(zFullName); |
| 526 | 540 | blob_reset(&content); |
| 527 | 541 | } |
| 528 | 542 | db_finalize(&q); |
| 529 | 543 | } |
| 530 | 544 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -151,10 +151,13 @@ | |
| 151 | /* |
| 152 | ** Show the difference between two files, one in memory and one on disk. |
| 153 | ** |
| 154 | ** The difference is the set of edits needed to transform pFile1 into |
| 155 | ** zFile2. The content of pFile1 is in memory. zFile2 exists on disk. |
| 156 | ** |
| 157 | ** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the |
| 158 | ** command zDiffCmd to do the diffing. |
| 159 | ** |
| 160 | ** When using an external diff program, zBinGlob contains the GLOB patterns |
| @@ -167,11 +170,12 @@ | |
| 167 | const char *zFile2, /* On disk content to compare to */ |
| 168 | const char *zName, /* Display name of the file */ |
| 169 | const char *zDiffCmd, /* Command for comparison */ |
| 170 | const char *zBinGlob, /* Treat file names matching this as binary */ |
| 171 | int fIncludeBinary, /* Include binary files for external diff */ |
| 172 | u64 diffFlags /* Flags to control the diff */ |
| 173 | ){ |
| 174 | if( zDiffCmd==0 ){ |
| 175 | Blob out; /* Diff output text */ |
| 176 | Blob file2; /* Content of zFile2 */ |
| 177 | const char *zName2; /* Name of zFile2 for display */ |
| @@ -194,11 +198,15 @@ | |
| 194 | if( blob_compare(pFile1, &file2) ){ |
| 195 | fossil_print("CHANGED %s\n", zName); |
| 196 | } |
| 197 | }else{ |
| 198 | blob_zero(&out); |
| 199 | text_diff(pFile1, &file2, &out, 0, diffFlags); |
| 200 | if( blob_size(&out) ){ |
| 201 | diff_print_filenames(zName, zName2, diffFlags); |
| 202 | fossil_print("%s\n", blob_str(&out)); |
| 203 | } |
| 204 | blob_reset(&out); |
| @@ -252,13 +260,19 @@ | |
| 252 | blob_write_to_file(pFile1, blob_str(&nameFile1)); |
| 253 | |
| 254 | /* Construct the external diff command */ |
| 255 | blob_zero(&cmd); |
| 256 | blob_appendf(&cmd, "%s ", zDiffCmd); |
| 257 | shell_escape(&cmd, blob_str(&nameFile1)); |
| 258 | blob_append(&cmd, " ", 1); |
| 259 | shell_escape(&cmd, zFile2); |
| 260 | |
| 261 | /* Run the external diff command */ |
| 262 | fossil_system(blob_str(&cmd)); |
| 263 | |
| 264 | /* Delete the temporary file and clean up memory used */ |
| @@ -482,11 +496,11 @@ | |
| 482 | blob_zero(&content); |
| 483 | } |
| 484 | isBin = fIncludeBinary ? 0 : looks_like_binary(&content); |
| 485 | diff_print_index(zPathname, diffFlags); |
| 486 | diff_file(&content, isBin, zFullName, zPathname, zDiffCmd, |
| 487 | zBinGlob, fIncludeBinary, diffFlags); |
| 488 | blob_reset(&content); |
| 489 | } |
| 490 | blob_reset(&fname); |
| 491 | } |
| 492 | db_finalize(&q); |
| @@ -519,11 +533,11 @@ | |
| 519 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 520 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 521 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| 522 | db_column_blob(&q, 1, &content); |
| 523 | diff_file(&content, 0, zFullName, zFile, |
| 524 | zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); |
| 525 | fossil_free(zFullName); |
| 526 | blob_reset(&content); |
| 527 | } |
| 528 | db_finalize(&q); |
| 529 | } |
| 530 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -151,10 +151,13 @@ | |
| 151 | /* |
| 152 | ** Show the difference between two files, one in memory and one on disk. |
| 153 | ** |
| 154 | ** The difference is the set of edits needed to transform pFile1 into |
| 155 | ** zFile2. The content of pFile1 is in memory. zFile2 exists on disk. |
| 156 | ** |
| 157 | ** If fSwapDiff is 1, show the set of edits to transform zFile2 into pFile1 |
| 158 | ** instead of the opposite. |
| 159 | ** |
| 160 | ** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the |
| 161 | ** command zDiffCmd to do the diffing. |
| 162 | ** |
| 163 | ** When using an external diff program, zBinGlob contains the GLOB patterns |
| @@ -167,11 +170,12 @@ | |
| 170 | const char *zFile2, /* On disk content to compare to */ |
| 171 | const char *zName, /* Display name of the file */ |
| 172 | const char *zDiffCmd, /* Command for comparison */ |
| 173 | const char *zBinGlob, /* Treat file names matching this as binary */ |
| 174 | int fIncludeBinary, /* Include binary files for external diff */ |
| 175 | u64 diffFlags, /* Flags to control the diff */ |
| 176 | int fSwapDiff /* Diff from Zfile2 to Pfile1 */ |
| 177 | ){ |
| 178 | if( zDiffCmd==0 ){ |
| 179 | Blob out; /* Diff output text */ |
| 180 | Blob file2; /* Content of zFile2 */ |
| 181 | const char *zName2; /* Name of zFile2 for display */ |
| @@ -194,11 +198,15 @@ | |
| 198 | if( blob_compare(pFile1, &file2) ){ |
| 199 | fossil_print("CHANGED %s\n", zName); |
| 200 | } |
| 201 | }else{ |
| 202 | blob_zero(&out); |
| 203 | if( fSwapDiff ){ |
| 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); |
| @@ -252,13 +260,19 @@ | |
| 260 | blob_write_to_file(pFile1, blob_str(&nameFile1)); |
| 261 | |
| 262 | /* Construct the external diff command */ |
| 263 | blob_zero(&cmd); |
| 264 | blob_appendf(&cmd, "%s ", zDiffCmd); |
| 265 | if( fSwapDiff ){ |
| 266 | shell_escape(&cmd, zFile2); |
| 267 | blob_append(&cmd, " ", 1); |
| 268 | shell_escape(&cmd, blob_str(&nameFile1)); |
| 269 | }else{ |
| 270 | shell_escape(&cmd, blob_str(&nameFile1)); |
| 271 | blob_append(&cmd, " ", 1); |
| 272 | shell_escape(&cmd, zFile2); |
| 273 | } |
| 274 | |
| 275 | /* Run the external diff command */ |
| 276 | fossil_system(blob_str(&cmd)); |
| 277 | |
| 278 | /* Delete the temporary file and clean up memory used */ |
| @@ -482,11 +496,11 @@ | |
| 496 | blob_zero(&content); |
| 497 | } |
| 498 | isBin = fIncludeBinary ? 0 : looks_like_binary(&content); |
| 499 | diff_print_index(zPathname, diffFlags); |
| 500 | diff_file(&content, isBin, zFullName, zPathname, zDiffCmd, |
| 501 | zBinGlob, fIncludeBinary, diffFlags, 0); |
| 502 | blob_reset(&content); |
| 503 | } |
| 504 | blob_reset(&fname); |
| 505 | } |
| 506 | db_finalize(&q); |
| @@ -519,11 +533,11 @@ | |
| 533 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 534 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 535 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| 536 | db_column_blob(&q, 1, &content); |
| 537 | diff_file(&content, 0, zFullName, zFile, |
| 538 | zDiffCmd, zBinGlob, fIncludeBinary, diffFlags, 0); |
| 539 | fossil_free(zFullName); |
| 540 | blob_reset(&content); |
| 541 | } |
| 542 | db_finalize(&q); |
| 543 | } |
| 544 |
+35
-32
| --- src/stash.c | ||
| +++ src/stash.c | ||
| @@ -332,52 +332,45 @@ | ||
| 332 | 332 | isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a); |
| 333 | 333 | diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd, |
| 334 | 334 | zBinGlob, fIncludeBinary, diffFlags); |
| 335 | 335 | }else if( isRemoved ){ |
| 336 | 336 | fossil_print("DELETE %s\n", zOrig); |
| 337 | - if( fBaseline==0 ){ | |
| 338 | - if( file_wd_islink(zOPath) ){ | |
| 339 | - blob_read_link(&a, zOPath); | |
| 340 | - }else{ | |
| 341 | - blob_read_from_file(&a, zOPath); | |
| 342 | - } | |
| 343 | - }else{ | |
| 344 | - content_get(rid, &a); | |
| 345 | - } | |
| 346 | - diff_print_index(zNew, diffFlags); | |
| 347 | - isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a); | |
| 348 | - isBin2 = 0; | |
| 349 | - diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd, | |
| 350 | - zBinGlob, fIncludeBinary, diffFlags); | |
| 351 | - }else{ | |
| 352 | - Blob delta, disk; | |
| 337 | + diff_print_index(zNew, diffFlags); | |
| 338 | + isBin2 = 0; | |
| 339 | + if( fBaseline ){ | |
| 340 | + content_get(rid, &a); | |
| 341 | + isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a); | |
| 342 | + diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd, | |
| 343 | + zBinGlob, fIncludeBinary, diffFlags); | |
| 344 | + }else{ | |
| 345 | + } | |
| 346 | + }else{ | |
| 347 | + Blob delta; | |
| 353 | 348 | int isOrigLink = file_wd_islink(zOPath); |
| 354 | 349 | db_ephemeral_blob(&q, 6, &delta); |
| 355 | - if( fBaseline==0 ){ | |
| 356 | - if( isOrigLink ){ | |
| 357 | - blob_read_link(&disk, zOPath); | |
| 358 | - }else{ | |
| 359 | - blob_read_from_file(&disk, zOPath); | |
| 360 | - } | |
| 361 | - } | |
| 362 | 350 | fossil_print("CHANGED %s\n", zNew); |
| 363 | 351 | if( !isOrigLink != !isLink ){ |
| 364 | 352 | diff_print_index(zNew, diffFlags); |
| 365 | 353 | diff_print_filenames(zOrig, zNew, diffFlags); |
| 366 | 354 | printf(DIFF_CANNOT_COMPUTE_SYMLINK); |
| 367 | 355 | }else{ |
| 368 | - Blob *pBase = fBaseline ? &a : &disk; | |
| 369 | 356 | content_get(rid, &a); |
| 370 | 357 | blob_delta_apply(&a, &delta, &b); |
| 371 | - isBin1 = fIncludeBinary ? 0 : looks_like_binary(pBase); | |
| 358 | + isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a); | |
| 372 | 359 | isBin2 = fIncludeBinary ? 0 : looks_like_binary(&b); |
| 373 | - diff_file_mem(fBaseline? &a : &disk, &b, isBin1, isBin2, zNew, | |
| 374 | - zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); | |
| 360 | + if( fBaseline ){ | |
| 361 | + diff_file_mem(&a, &b, isBin1, isBin2, zNew, | |
| 362 | + zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); | |
| 363 | + }else{ | |
| 364 | + /*Diff with file on disk using fSwapDiff=1 to show the diff in the | |
| 365 | + same direction as if fBaseline=1.*/ | |
| 366 | + diff_file(&b, isBin2, zOPath, zNew, zDiffCmd, | |
| 367 | + zBinGlob, fIncludeBinary, diffFlags, 1); | |
| 368 | + } | |
| 375 | 369 | blob_reset(&a); |
| 376 | 370 | blob_reset(&b); |
| 377 | 371 | } |
| 378 | - if( !fBaseline ) blob_reset(&disk); | |
| 379 | 372 | blob_reset(&delta); |
| 380 | 373 | } |
| 381 | 374 | } |
| 382 | 375 | db_finalize(&q); |
| 383 | 376 | } |
| @@ -433,12 +426,15 @@ | ||
| 433 | 426 | ** |
| 434 | 427 | ** List all changes sets currently stashed. Show information about |
| 435 | 428 | ** individual files in each changeset if -v or --verbose is used. |
| 436 | 429 | ** |
| 437 | 430 | ** fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? |
| 431 | +** fossil stash gshow|gcat ?STASHID? ?DIFF-OPTIONS? | |
| 438 | 432 | ** |
| 439 | -** Show the contents of a stash. | |
| 433 | +** Show the contents of a stash as a diff against it's baseline. | |
| 434 | +** With gshow and gcat, gdiff-command is used instead of internal | |
| 435 | +** diff logic. | |
| 440 | 436 | ** |
| 441 | 437 | ** fossil stash pop |
| 442 | 438 | ** fossil stash apply ?STASHID? |
| 443 | 439 | ** |
| 444 | 440 | ** Apply STASHID or the most recently create stash to the current |
| @@ -460,18 +456,20 @@ | ||
| 460 | 456 | ** |
| 461 | 457 | ** fossil stash diff ?STASHID? ?DIFF-OPTIONS? |
| 462 | 458 | ** fossil stash gdiff ?STASHID? ?DIFF-OPTIONS? |
| 463 | 459 | ** |
| 464 | 460 | ** Show diffs of the current working directory and what that |
| 465 | -** directory would be if STASHID were applied. | |
| 461 | +** directory would be if STASHID were applied. With gdiff, | |
| 462 | +** gdiff-command is used instead of internal diff logic. | |
| 466 | 463 | ** |
| 467 | 464 | ** SUMMARY: |
| 468 | 465 | ** fossil stash |
| 469 | 466 | ** fossil stash save ?-m|--comment COMMENT? ?FILES...? |
| 470 | 467 | ** fossil stash snapshot ?-m|--comment COMMENT? ?FILES...? |
| 471 | 468 | ** fossil stash list|ls ?-v|--verbose? ?-W|--width <num>? |
| 472 | 469 | ** fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? |
| 470 | +** fossil stash gshow|gcat ?STASHID? ?DIFF-OPTIONS? | |
| 473 | 471 | ** fossil stash pop |
| 474 | 472 | ** fossil stash apply|goto ?STASHID? |
| 475 | 473 | ** fossil stash drop|rm ?STASHID? ?-a|--all? |
| 476 | 474 | ** fossil stash diff ?STASHID? ?DIFF-OPTIONS? |
| 477 | 475 | ** fossil stash gdiff ?STASHID? ?DIFF-OPTIONS? |
| @@ -654,25 +652,30 @@ | ||
| 654 | 652 | undo_finish(); |
| 655 | 653 | }else |
| 656 | 654 | if( memcmp(zCmd, "diff", nCmd)==0 |
| 657 | 655 | || memcmp(zCmd, "gdiff", nCmd)==0 |
| 658 | 656 | || memcmp(zCmd, "show", nCmd)==0 |
| 657 | + || memcmp(zCmd, "gshow", nCmd)==0 | |
| 659 | 658 | || memcmp(zCmd, "cat", nCmd)==0 |
| 659 | + || memcmp(zCmd, "gcat", nCmd)==0 | |
| 660 | 660 | ){ |
| 661 | 661 | const char *zDiffCmd = 0; |
| 662 | 662 | const char *zBinGlob = 0; |
| 663 | 663 | int fIncludeBinary = 0; |
| 664 | - int fBaseline = zCmd[0]=='s' || zCmd[0]=='c'; | |
| 664 | + int fBaseline = 0; | |
| 665 | 665 | u64 diffFlags; |
| 666 | 666 | |
| 667 | + if( strstr(zCmd,"show")!=0 || strstr(zCmd,"cat")!=0 ){ | |
| 668 | + fBaseline = 1; | |
| 669 | + } | |
| 667 | 670 | if( find_option("tk",0,0)!=0 ){ |
| 668 | 671 | db_close(0); |
| 669 | 672 | diff_tk(fBaseline ? "stash show" : "stash diff", 3); |
| 670 | 673 | return; |
| 671 | 674 | } |
| 672 | 675 | if( find_option("internal","i",0)==0 ){ |
| 673 | - zDiffCmd = diff_command_external(memcmp(zCmd, "gdiff", nCmd)==0); | |
| 676 | + zDiffCmd = diff_command_external(zCmd[0]=='g'); | |
| 674 | 677 | } |
| 675 | 678 | diffFlags = diff_options(); |
| 676 | 679 | if( find_option("verbose","v",0)!=0 ) diffFlags |= DIFF_VERBOSE; |
| 677 | 680 | if( g.argc>4 ) usage(mprintf("%s ?STASHID? ?DIFF-OPTIONS?", zCmd)); |
| 678 | 681 | if( zDiffCmd ){ |
| 679 | 682 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -332,52 +332,45 @@ | |
| 332 | isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a); |
| 333 | diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd, |
| 334 | zBinGlob, fIncludeBinary, diffFlags); |
| 335 | }else if( isRemoved ){ |
| 336 | fossil_print("DELETE %s\n", zOrig); |
| 337 | if( fBaseline==0 ){ |
| 338 | if( file_wd_islink(zOPath) ){ |
| 339 | blob_read_link(&a, zOPath); |
| 340 | }else{ |
| 341 | blob_read_from_file(&a, zOPath); |
| 342 | } |
| 343 | }else{ |
| 344 | content_get(rid, &a); |
| 345 | } |
| 346 | diff_print_index(zNew, diffFlags); |
| 347 | isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a); |
| 348 | isBin2 = 0; |
| 349 | diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd, |
| 350 | zBinGlob, fIncludeBinary, diffFlags); |
| 351 | }else{ |
| 352 | Blob delta, disk; |
| 353 | int isOrigLink = file_wd_islink(zOPath); |
| 354 | db_ephemeral_blob(&q, 6, &delta); |
| 355 | if( fBaseline==0 ){ |
| 356 | if( isOrigLink ){ |
| 357 | blob_read_link(&disk, zOPath); |
| 358 | }else{ |
| 359 | blob_read_from_file(&disk, zOPath); |
| 360 | } |
| 361 | } |
| 362 | fossil_print("CHANGED %s\n", zNew); |
| 363 | if( !isOrigLink != !isLink ){ |
| 364 | diff_print_index(zNew, diffFlags); |
| 365 | diff_print_filenames(zOrig, zNew, diffFlags); |
| 366 | printf(DIFF_CANNOT_COMPUTE_SYMLINK); |
| 367 | }else{ |
| 368 | Blob *pBase = fBaseline ? &a : &disk; |
| 369 | content_get(rid, &a); |
| 370 | blob_delta_apply(&a, &delta, &b); |
| 371 | isBin1 = fIncludeBinary ? 0 : looks_like_binary(pBase); |
| 372 | isBin2 = fIncludeBinary ? 0 : looks_like_binary(&b); |
| 373 | diff_file_mem(fBaseline? &a : &disk, &b, isBin1, isBin2, zNew, |
| 374 | zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); |
| 375 | blob_reset(&a); |
| 376 | blob_reset(&b); |
| 377 | } |
| 378 | if( !fBaseline ) blob_reset(&disk); |
| 379 | blob_reset(&delta); |
| 380 | } |
| 381 | } |
| 382 | db_finalize(&q); |
| 383 | } |
| @@ -433,12 +426,15 @@ | |
| 433 | ** |
| 434 | ** List all changes sets currently stashed. Show information about |
| 435 | ** individual files in each changeset if -v or --verbose is used. |
| 436 | ** |
| 437 | ** fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? |
| 438 | ** |
| 439 | ** Show the contents of a stash. |
| 440 | ** |
| 441 | ** fossil stash pop |
| 442 | ** fossil stash apply ?STASHID? |
| 443 | ** |
| 444 | ** Apply STASHID or the most recently create stash to the current |
| @@ -460,18 +456,20 @@ | |
| 460 | ** |
| 461 | ** fossil stash diff ?STASHID? ?DIFF-OPTIONS? |
| 462 | ** fossil stash gdiff ?STASHID? ?DIFF-OPTIONS? |
| 463 | ** |
| 464 | ** Show diffs of the current working directory and what that |
| 465 | ** directory would be if STASHID were applied. |
| 466 | ** |
| 467 | ** SUMMARY: |
| 468 | ** fossil stash |
| 469 | ** fossil stash save ?-m|--comment COMMENT? ?FILES...? |
| 470 | ** fossil stash snapshot ?-m|--comment COMMENT? ?FILES...? |
| 471 | ** fossil stash list|ls ?-v|--verbose? ?-W|--width <num>? |
| 472 | ** fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? |
| 473 | ** fossil stash pop |
| 474 | ** fossil stash apply|goto ?STASHID? |
| 475 | ** fossil stash drop|rm ?STASHID? ?-a|--all? |
| 476 | ** fossil stash diff ?STASHID? ?DIFF-OPTIONS? |
| 477 | ** fossil stash gdiff ?STASHID? ?DIFF-OPTIONS? |
| @@ -654,25 +652,30 @@ | |
| 654 | undo_finish(); |
| 655 | }else |
| 656 | if( memcmp(zCmd, "diff", nCmd)==0 |
| 657 | || memcmp(zCmd, "gdiff", nCmd)==0 |
| 658 | || memcmp(zCmd, "show", nCmd)==0 |
| 659 | || memcmp(zCmd, "cat", nCmd)==0 |
| 660 | ){ |
| 661 | const char *zDiffCmd = 0; |
| 662 | const char *zBinGlob = 0; |
| 663 | int fIncludeBinary = 0; |
| 664 | int fBaseline = zCmd[0]=='s' || zCmd[0]=='c'; |
| 665 | u64 diffFlags; |
| 666 | |
| 667 | if( find_option("tk",0,0)!=0 ){ |
| 668 | db_close(0); |
| 669 | diff_tk(fBaseline ? "stash show" : "stash diff", 3); |
| 670 | return; |
| 671 | } |
| 672 | if( find_option("internal","i",0)==0 ){ |
| 673 | zDiffCmd = diff_command_external(memcmp(zCmd, "gdiff", nCmd)==0); |
| 674 | } |
| 675 | diffFlags = diff_options(); |
| 676 | if( find_option("verbose","v",0)!=0 ) diffFlags |= DIFF_VERBOSE; |
| 677 | if( g.argc>4 ) usage(mprintf("%s ?STASHID? ?DIFF-OPTIONS?", zCmd)); |
| 678 | if( zDiffCmd ){ |
| 679 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -332,52 +332,45 @@ | |
| 332 | isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a); |
| 333 | diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd, |
| 334 | zBinGlob, fIncludeBinary, diffFlags); |
| 335 | }else if( isRemoved ){ |
| 336 | fossil_print("DELETE %s\n", zOrig); |
| 337 | diff_print_index(zNew, diffFlags); |
| 338 | isBin2 = 0; |
| 339 | if( fBaseline ){ |
| 340 | content_get(rid, &a); |
| 341 | isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a); |
| 342 | diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd, |
| 343 | zBinGlob, fIncludeBinary, diffFlags); |
| 344 | }else{ |
| 345 | } |
| 346 | }else{ |
| 347 | Blob delta; |
| 348 | int isOrigLink = file_wd_islink(zOPath); |
| 349 | db_ephemeral_blob(&q, 6, &delta); |
| 350 | fossil_print("CHANGED %s\n", zNew); |
| 351 | if( !isOrigLink != !isLink ){ |
| 352 | diff_print_index(zNew, diffFlags); |
| 353 | diff_print_filenames(zOrig, zNew, diffFlags); |
| 354 | printf(DIFF_CANNOT_COMPUTE_SYMLINK); |
| 355 | }else{ |
| 356 | content_get(rid, &a); |
| 357 | blob_delta_apply(&a, &delta, &b); |
| 358 | isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a); |
| 359 | isBin2 = fIncludeBinary ? 0 : looks_like_binary(&b); |
| 360 | if( fBaseline ){ |
| 361 | diff_file_mem(&a, &b, isBin1, isBin2, zNew, |
| 362 | zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); |
| 363 | }else{ |
| 364 | /*Diff with file on disk using fSwapDiff=1 to show the diff in the |
| 365 | same direction as if fBaseline=1.*/ |
| 366 | diff_file(&b, isBin2, zOPath, zNew, zDiffCmd, |
| 367 | zBinGlob, fIncludeBinary, diffFlags, 1); |
| 368 | } |
| 369 | blob_reset(&a); |
| 370 | blob_reset(&b); |
| 371 | } |
| 372 | blob_reset(&delta); |
| 373 | } |
| 374 | } |
| 375 | db_finalize(&q); |
| 376 | } |
| @@ -433,12 +426,15 @@ | |
| 426 | ** |
| 427 | ** List all changes sets currently stashed. Show information about |
| 428 | ** individual files in each changeset if -v or --verbose is used. |
| 429 | ** |
| 430 | ** fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? |
| 431 | ** fossil stash gshow|gcat ?STASHID? ?DIFF-OPTIONS? |
| 432 | ** |
| 433 | ** Show the contents of a stash as a diff against it's baseline. |
| 434 | ** With gshow and gcat, gdiff-command is used instead of internal |
| 435 | ** diff logic. |
| 436 | ** |
| 437 | ** fossil stash pop |
| 438 | ** fossil stash apply ?STASHID? |
| 439 | ** |
| 440 | ** Apply STASHID or the most recently create stash to the current |
| @@ -460,18 +456,20 @@ | |
| 456 | ** |
| 457 | ** fossil stash diff ?STASHID? ?DIFF-OPTIONS? |
| 458 | ** fossil stash gdiff ?STASHID? ?DIFF-OPTIONS? |
| 459 | ** |
| 460 | ** Show diffs of the current working directory and what that |
| 461 | ** directory would be if STASHID were applied. With gdiff, |
| 462 | ** gdiff-command is used instead of internal diff logic. |
| 463 | ** |
| 464 | ** SUMMARY: |
| 465 | ** fossil stash |
| 466 | ** fossil stash save ?-m|--comment COMMENT? ?FILES...? |
| 467 | ** fossil stash snapshot ?-m|--comment COMMENT? ?FILES...? |
| 468 | ** fossil stash list|ls ?-v|--verbose? ?-W|--width <num>? |
| 469 | ** fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? |
| 470 | ** fossil stash gshow|gcat ?STASHID? ?DIFF-OPTIONS? |
| 471 | ** fossil stash pop |
| 472 | ** fossil stash apply|goto ?STASHID? |
| 473 | ** fossil stash drop|rm ?STASHID? ?-a|--all? |
| 474 | ** fossil stash diff ?STASHID? ?DIFF-OPTIONS? |
| 475 | ** fossil stash gdiff ?STASHID? ?DIFF-OPTIONS? |
| @@ -654,25 +652,30 @@ | |
| 652 | undo_finish(); |
| 653 | }else |
| 654 | if( memcmp(zCmd, "diff", nCmd)==0 |
| 655 | || memcmp(zCmd, "gdiff", nCmd)==0 |
| 656 | || memcmp(zCmd, "show", nCmd)==0 |
| 657 | || memcmp(zCmd, "gshow", nCmd)==0 |
| 658 | || memcmp(zCmd, "cat", nCmd)==0 |
| 659 | || memcmp(zCmd, "gcat", nCmd)==0 |
| 660 | ){ |
| 661 | const char *zDiffCmd = 0; |
| 662 | const char *zBinGlob = 0; |
| 663 | int fIncludeBinary = 0; |
| 664 | int fBaseline = 0; |
| 665 | u64 diffFlags; |
| 666 | |
| 667 | if( strstr(zCmd,"show")!=0 || strstr(zCmd,"cat")!=0 ){ |
| 668 | fBaseline = 1; |
| 669 | } |
| 670 | if( find_option("tk",0,0)!=0 ){ |
| 671 | db_close(0); |
| 672 | diff_tk(fBaseline ? "stash show" : "stash diff", 3); |
| 673 | return; |
| 674 | } |
| 675 | if( find_option("internal","i",0)==0 ){ |
| 676 | zDiffCmd = diff_command_external(zCmd[0]=='g'); |
| 677 | } |
| 678 | diffFlags = diff_options(); |
| 679 | if( find_option("verbose","v",0)!=0 ) diffFlags |= DIFF_VERBOSE; |
| 680 | if( g.argc>4 ) usage(mprintf("%s ?STASHID? ?DIFF-OPTIONS?", zCmd)); |
| 681 | if( zDiffCmd ){ |
| 682 |