| | @@ -282,15 +282,16 @@ |
| 282 | 282 | |
| 283 | 283 | /* |
| 284 | 284 | ** Show the diffs associate with a single stash. |
| 285 | 285 | */ |
| 286 | 286 | static void stash_diff( |
| 287 | | - int stashid, |
| 288 | | - const char *zDiffCmd, |
| 289 | | - const char *zBinGlob, |
| 290 | | - int fIncludeBinary, |
| 291 | | - u64 diffFlags |
| 287 | + int stashid, /* The stash entry to diff */ |
| 288 | + const char *zDiffCmd, /* Command used for diffing */ |
| 289 | + const char *zBinGlob, /* GLOB pattern to determine binary files */ |
| 290 | + int fBaseline, /* Diff against original baseline check-in if true */ |
| 291 | + int fIncludeBinary, /* Do diffs against binary files */ |
| 292 | + u64 diffFlags /* Other diff flags */ |
| 292 | 293 | ){ |
| 293 | 294 | Stmt q; |
| 294 | 295 | Blob empty; |
| 295 | 296 | blob_zero(&empty); |
| 296 | 297 | db_prepare(&q, |
| | @@ -304,62 +305,62 @@ |
| 304 | 305 | int isLink = db_column_int(&q, 3); |
| 305 | 306 | int isBin1, isBin2; |
| 306 | 307 | const char *zOrig = db_column_text(&q, 4); |
| 307 | 308 | const char *zNew = db_column_text(&q, 5); |
| 308 | 309 | char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig); |
| 309 | | - Blob delta; |
| 310 | + Blob delta, a, b, disk; |
| 310 | 311 | if( rid==0 ){ |
| 311 | | - db_ephemeral_blob(&q, 6, &delta); |
| 312 | + db_ephemeral_blob(&q, 6, &a); |
| 312 | 313 | fossil_print("ADDED %s\n", zNew); |
| 313 | 314 | diff_print_index(zNew, diffFlags); |
| 314 | | - isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&empty), |
| 315 | | - blob_size(&empty)); |
| 316 | | - isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&delta), |
| 317 | | - blob_size(&delta)); |
| 318 | | - diff_file_mem(&empty, &delta, isBin1, isBin2, zNew, zDiffCmd, |
| 315 | + isBin1 = 0; |
| 316 | + isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a); |
| 317 | + diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd, |
| 319 | 318 | zBinGlob, fIncludeBinary, diffFlags); |
| 320 | 319 | }else if( isRemoved ){ |
| 321 | 320 | fossil_print("DELETE %s\n", zOrig); |
| 322 | | - if( file_wd_islink(zOPath) ){ |
| 323 | | - blob_read_link(&delta, zOPath); |
| 321 | + if( fBaseline==0 ){ |
| 322 | + if( file_wd_islink(zOPath) ){ |
| 323 | + blob_read_link(&a, zOPath); |
| 324 | + }else{ |
| 325 | + blob_read_from_file(&a, zOPath); |
| 326 | + } |
| 324 | 327 | }else{ |
| 325 | | - blob_read_from_file(&delta, zOPath); |
| 328 | + content_get(rid, &a); |
| 326 | 329 | } |
| 327 | 330 | diff_print_index(zNew, diffFlags); |
| 328 | | - isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&delta), |
| 329 | | - blob_size(&delta)); |
| 330 | | - isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&empty), |
| 331 | | - blob_size(&empty)); |
| 332 | | - diff_file_mem(&delta, &empty, isBin1, isBin2, zOrig, zDiffCmd, |
| 331 | + isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a); |
| 332 | + isBin2 = 0; |
| 333 | + diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd, |
| 333 | 334 | zBinGlob, fIncludeBinary, diffFlags); |
| 334 | 335 | }else{ |
| 335 | | - Blob a, b, disk; |
| 336 | 336 | int isOrigLink = file_wd_islink(zOPath); |
| 337 | 337 | db_ephemeral_blob(&q, 6, &delta); |
| 338 | | - if( isOrigLink ){ |
| 339 | | - blob_read_link(&disk, zOPath); |
| 340 | | - }else{ |
| 341 | | - blob_read_from_file(&disk, zOPath); |
| 338 | + if( fBaseline==0 ){ |
| 339 | + if( isOrigLink ){ |
| 340 | + blob_read_link(&disk, zOPath); |
| 341 | + }else{ |
| 342 | + blob_read_from_file(&disk, zOPath); |
| 343 | + } |
| 342 | 344 | } |
| 343 | 345 | fossil_print("CHANGED %s\n", zNew); |
| 344 | 346 | if( !isOrigLink != !isLink ){ |
| 345 | 347 | diff_print_index(zNew, diffFlags); |
| 346 | 348 | diff_print_filenames(zOrig, zNew, diffFlags); |
| 347 | 349 | printf(DIFF_CANNOT_COMPUTE_SYMLINK); |
| 348 | 350 | }else{ |
| 351 | + Blob *pBase = fBaseline ? &a : &disk; |
| 349 | 352 | content_get(rid, &a); |
| 350 | 353 | blob_delta_apply(&a, &delta, &b); |
| 351 | | - isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&disk), |
| 352 | | - blob_size(&disk)); |
| 353 | | - isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&b), |
| 354 | | - blob_size(&b)); |
| 355 | | - diff_file_mem(&disk, &b, isBin1, isBin2, zNew, zDiffCmd, |
| 356 | | - zBinGlob, fIncludeBinary, diffFlags); |
| 354 | + isBin1 = fIncludeBinary ? 0 : looks_like_binary(pBase); |
| 355 | + isBin2 = fIncludeBinary ? 0 : looks_like_binary(&b); |
| 356 | + diff_file_mem(fBaseline? &a : &disk, &b, isBin1, isBin2, zNew, |
| 357 | + zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); |
| 357 | 358 | blob_reset(&a); |
| 358 | 359 | blob_reset(&b); |
| 359 | 360 | } |
| 360 | | - blob_reset(&disk); |
| 361 | + if( !fBaseline ) blob_reset(&disk); |
| 361 | 362 | } |
| 362 | 363 | blob_reset(&delta); |
| 363 | 364 | } |
| 364 | 365 | db_finalize(&q); |
| 365 | 366 | } |
| | @@ -415,10 +416,14 @@ |
| 415 | 416 | ** fossil stash ls ?-l? |
| 416 | 417 | ** |
| 417 | 418 | ** List all changes sets currently stashed. Show information about |
| 418 | 419 | ** individual files in each changeset if --detail or -l is used. |
| 419 | 420 | ** |
| 421 | +** fossil stash show ?STASHID? ?DIFF-FLAGS? |
| 422 | +** |
| 423 | +** Show the content of a stash |
| 424 | +** |
| 420 | 425 | ** fossil stash pop |
| 421 | 426 | ** fossil stash apply ?STASHID? |
| 422 | 427 | ** |
| 423 | 428 | ** Apply STASHID or the most recently create stash to the current |
| 424 | 429 | ** working check-out. The "pop" command deletes that changeset from |
| | @@ -446,10 +451,11 @@ |
| 446 | 451 | ** SUMMARY: |
| 447 | 452 | ** fossil stash |
| 448 | 453 | ** fossil stash save ?-m COMMENT? ?FILES...? |
| 449 | 454 | ** fossil stash snapshot ?-m COMMENT? ?FILES...? |
| 450 | 455 | ** fossil stash list|ls ?-l? ?--detail? |
| 456 | +** fossil stash show ?STASHID? ?DIFF-OPTIONS? |
| 451 | 457 | ** fossil stash pop |
| 452 | 458 | ** fossil stash apply ?STASHID? |
| 453 | 459 | ** fossil stash goto ?STASHID? |
| 454 | 460 | ** fossil stash rm|drop ?STASHID? ?--all? |
| 455 | 461 | ** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS? |
| | @@ -596,50 +602,36 @@ |
| 596 | 602 | db_multi_exec("UPDATE vfile SET mtime=0 WHERE pathname IN " |
| 597 | 603 | "(SELECT origname FROM stashfile WHERE stashid=%d)", |
| 598 | 604 | stashid); |
| 599 | 605 | undo_finish(); |
| 600 | 606 | }else |
| 601 | | - if( memcmp(zCmd, "diff", nCmd)==0 ){ |
| 607 | + if( memcmp(zCmd, "diff", nCmd)==0 |
| 608 | + || memcmp(zCmd, "gdiff", nCmd)==0 |
| 609 | + || memcmp(zCmd, "show", nCmd)==0 |
| 610 | + ){ |
| 602 | 611 | const char *zDiffCmd = 0; |
| 603 | 612 | const char *zBinGlob = 0; |
| 604 | 613 | int fIncludeBinary = 0; |
| 605 | 614 | u64 diffFlags; |
| 606 | 615 | |
| 607 | 616 | if( find_option("tk",0,0)!=0 ){ |
| 608 | 617 | db_close(0); |
| 609 | | - diff_tk("stash diff", 3); |
| 618 | + diff_tk((zCmd[0]=='s' ? "stash show" : "stash diff"), 3); |
| 610 | 619 | return; |
| 611 | 620 | } |
| 612 | 621 | if( find_option("internal","i",0)==0 ){ |
| 613 | 622 | zDiffCmd = diff_command_external(0); |
| 614 | 623 | } |
| 615 | 624 | diffFlags = diff_options(); |
| 616 | | - if( g.argc>4 ) usage("diff STASHID"); |
| 625 | + if( g.argc>4 ) usage(mprintf("%s STASHID", zCmd)); |
| 617 | 626 | if( zDiffCmd ){ |
| 618 | 627 | zBinGlob = diff_get_binary_glob(); |
| 619 | 628 | fIncludeBinary = diff_include_binary_files(); |
| 620 | 629 | } |
| 621 | 630 | stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); |
| 622 | | - stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); |
| 623 | | - }else |
| 624 | | - if( memcmp(zCmd, "gdiff", nCmd)==0 ){ |
| 625 | | - const char *zDiffCmd = 0; |
| 626 | | - const char *zBinGlob = 0; |
| 627 | | - int fIncludeBinary = 0; |
| 628 | | - u64 diffFlags; |
| 629 | | - |
| 630 | | - if( find_option("internal","i",0)==0 ){ |
| 631 | | - zDiffCmd = diff_command_external(0); |
| 632 | | - } |
| 633 | | - diffFlags = diff_options(); |
| 634 | | - if( g.argc>4 ) usage("gdiff STASHID"); |
| 635 | | - if( zDiffCmd ){ |
| 636 | | - zBinGlob = diff_get_binary_glob(); |
| 637 | | - fIncludeBinary = diff_include_binary_files(); |
| 638 | | - } |
| 639 | | - stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); |
| 640 | | - stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags); |
| 631 | + stash_diff(stashid, zDiffCmd, zBinGlob, zCmd[0]=='s', fIncludeBinary, |
| 632 | + diffFlags); |
| 641 | 633 | }else |
| 642 | 634 | if( memcmp(zCmd, "help", nCmd)==0 ){ |
| 643 | 635 | g.argv[1] = "help"; |
| 644 | 636 | g.argv[2] = "stash"; |
| 645 | 637 | g.argc = 3; |
| 646 | 638 | |