Fossil SCM
"stash cat" worked the same as "stash diff", yet "stash cat -tk" worked the same as "stash show -tk". Make "stash cat" behave like "stash show" which matches the -tk case and also the documentation. Also add mention of DIFF-OPTIONS to the stash show|cat|diff|gdiff usage text. Remove unnecessary variable initialization in stash_get_id(), plus show the bad stash ID string rather than "0" if a non-numeric was used.
Commit
48ecfe6645a86d154db78b787879a30ecd3ad1ed
Parent
ce8937facc63cdf…
1 file changed
+9
-16
+9
-16
| --- src/stash.c | ||
| +++ src/stash.c | ||
| @@ -398,18 +398,18 @@ | ||
| 398 | 398 | ** return that number. Or throw a fatal error if it is not a valid |
| 399 | 399 | ** stash number. If it is NULL, return the most recent stash or |
| 400 | 400 | ** throw an error if the stash is empty. |
| 401 | 401 | */ |
| 402 | 402 | static int stash_get_id(const char *zStashId){ |
| 403 | - int stashid = 0; | |
| 403 | + int stashid; | |
| 404 | 404 | if( zStashId==0 ){ |
| 405 | 405 | stashid = db_int(0, "SELECT max(stashid) FROM stash"); |
| 406 | 406 | if( stashid==0 ) fossil_fatal("empty stash"); |
| 407 | 407 | }else{ |
| 408 | 408 | stashid = atoi(zStashId); |
| 409 | 409 | if( !db_exists("SELECT 1 FROM stash WHERE stashid=%d", stashid) ){ |
| 410 | - fossil_fatal("no such stash: %d\n", stashid); | |
| 410 | + fossil_fatal("no such stash: %s", zStashId); | |
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | return stashid; |
| 414 | 414 | } |
| 415 | 415 | |
| @@ -432,11 +432,11 @@ | ||
| 432 | 432 | ** fossil stash list|ls ?-v|--verbose? ?-W|--width <num>? |
| 433 | 433 | ** |
| 434 | 434 | ** List all changes sets currently stashed. Show information about |
| 435 | 435 | ** individual files in each changeset if -v or --verbose is used. |
| 436 | 436 | ** |
| 437 | -** fossil stash show|cat ?STASHID? ?DIFF-FLAGS? | |
| 437 | +** fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? | |
| 438 | 438 | ** |
| 439 | 439 | ** Show the contents of a stash. |
| 440 | 440 | ** |
| 441 | 441 | ** fossil stash pop |
| 442 | 442 | ** fossil stash apply ?STASHID? |
| @@ -467,15 +467,15 @@ | ||
| 467 | 467 | ** SUMMARY: |
| 468 | 468 | ** fossil stash |
| 469 | 469 | ** fossil stash save ?-m|--comment COMMENT? ?FILES...? |
| 470 | 470 | ** fossil stash snapshot ?-m|--comment COMMENT? ?FILES...? |
| 471 | 471 | ** fossil stash list|ls ?-v|--verbose? ?-W|--width <num>? |
| 472 | -** fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? | |
| 472 | +** fossil stash show ?STASHID? ?DIFF-OPTIONS? | |
| 473 | 473 | ** fossil stash pop |
| 474 | 474 | ** fossil stash apply|goto ?STASHID? |
| 475 | 475 | ** fossil stash drop|rm ?STASHID? ?-a|--all? |
| 476 | -** fossil stash diff ?STASHID? ?DIFF-OPTIONS? | |
| 476 | +** fossil stash diff|cat ?STASHID? ?DIFF-OPTIONS? | |
| 477 | 477 | ** fossil stash gdiff ?STASHID? ?DIFF-OPTIONS? |
| 478 | 478 | */ |
| 479 | 479 | void stash_cmd(void){ |
| 480 | 480 | const char *zCmd; |
| 481 | 481 | int nCmd; |
| @@ -659,37 +659,30 @@ | ||
| 659 | 659 | || memcmp(zCmd, "cat", 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 | 665 | u64 diffFlags; |
| 665 | 666 | |
| 666 | 667 | if( find_option("tk",0,0)!=0 ){ |
| 667 | 668 | db_close(0); |
| 668 | - switch (zCmd[0]) { | |
| 669 | - case 's': | |
| 670 | - case 'c': | |
| 671 | - diff_tk("stash show", 3); | |
| 672 | - break; | |
| 673 | - | |
| 674 | - default: | |
| 675 | - diff_tk("stash diff", 3); | |
| 676 | - } | |
| 669 | + diff_tk(fBaseline ? "stash show" : "stash diff", 3); | |
| 677 | 670 | return; |
| 678 | 671 | } |
| 679 | 672 | if( find_option("internal","i",0)==0 ){ |
| 680 | 673 | zDiffCmd = diff_command_external(memcmp(zCmd, "gdiff", nCmd)==0); |
| 681 | 674 | } |
| 682 | 675 | diffFlags = diff_options(); |
| 683 | 676 | if( find_option("verbose","v",0)!=0 ) diffFlags |= DIFF_VERBOSE; |
| 684 | - if( g.argc>4 ) usage(mprintf("%s STASHID", zCmd)); | |
| 677 | + if( g.argc>4 ) usage(mprintf("%s ?STASHID? ?DIFF-OPTIONS?", zCmd)); | |
| 685 | 678 | if( zDiffCmd ){ |
| 686 | 679 | zBinGlob = diff_get_binary_glob(); |
| 687 | 680 | fIncludeBinary = diff_include_binary_files(); |
| 688 | 681 | } |
| 689 | 682 | stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); |
| 690 | - stash_diff(stashid, zDiffCmd, zBinGlob, zCmd[0]=='s', fIncludeBinary, | |
| 683 | + stash_diff(stashid, zDiffCmd, zBinGlob, fBaseline, fIncludeBinary, | |
| 691 | 684 | diffFlags); |
| 692 | 685 | }else |
| 693 | 686 | if( memcmp(zCmd, "help", nCmd)==0 ){ |
| 694 | 687 | g.argv[1] = "help"; |
| 695 | 688 | g.argv[2] = "stash"; |
| 696 | 689 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -398,18 +398,18 @@ | |
| 398 | ** return that number. Or throw a fatal error if it is not a valid |
| 399 | ** stash number. If it is NULL, return the most recent stash or |
| 400 | ** throw an error if the stash is empty. |
| 401 | */ |
| 402 | static int stash_get_id(const char *zStashId){ |
| 403 | int stashid = 0; |
| 404 | if( zStashId==0 ){ |
| 405 | stashid = db_int(0, "SELECT max(stashid) FROM stash"); |
| 406 | if( stashid==0 ) fossil_fatal("empty stash"); |
| 407 | }else{ |
| 408 | stashid = atoi(zStashId); |
| 409 | if( !db_exists("SELECT 1 FROM stash WHERE stashid=%d", stashid) ){ |
| 410 | fossil_fatal("no such stash: %d\n", stashid); |
| 411 | } |
| 412 | } |
| 413 | return stashid; |
| 414 | } |
| 415 | |
| @@ -432,11 +432,11 @@ | |
| 432 | ** fossil stash list|ls ?-v|--verbose? ?-W|--width <num>? |
| 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-FLAGS? |
| 438 | ** |
| 439 | ** Show the contents of a stash. |
| 440 | ** |
| 441 | ** fossil stash pop |
| 442 | ** fossil stash apply ?STASHID? |
| @@ -467,15 +467,15 @@ | |
| 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? |
| 478 | */ |
| 479 | void stash_cmd(void){ |
| 480 | const char *zCmd; |
| 481 | int nCmd; |
| @@ -659,37 +659,30 @@ | |
| 659 | || memcmp(zCmd, "cat", nCmd)==0 |
| 660 | ){ |
| 661 | const char *zDiffCmd = 0; |
| 662 | const char *zBinGlob = 0; |
| 663 | int fIncludeBinary = 0; |
| 664 | u64 diffFlags; |
| 665 | |
| 666 | if( find_option("tk",0,0)!=0 ){ |
| 667 | db_close(0); |
| 668 | switch (zCmd[0]) { |
| 669 | case 's': |
| 670 | case 'c': |
| 671 | diff_tk("stash show", 3); |
| 672 | break; |
| 673 | |
| 674 | default: |
| 675 | diff_tk("stash diff", 3); |
| 676 | } |
| 677 | return; |
| 678 | } |
| 679 | if( find_option("internal","i",0)==0 ){ |
| 680 | zDiffCmd = diff_command_external(memcmp(zCmd, "gdiff", nCmd)==0); |
| 681 | } |
| 682 | diffFlags = diff_options(); |
| 683 | if( find_option("verbose","v",0)!=0 ) diffFlags |= DIFF_VERBOSE; |
| 684 | if( g.argc>4 ) usage(mprintf("%s STASHID", zCmd)); |
| 685 | if( zDiffCmd ){ |
| 686 | zBinGlob = diff_get_binary_glob(); |
| 687 | fIncludeBinary = diff_include_binary_files(); |
| 688 | } |
| 689 | stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); |
| 690 | stash_diff(stashid, zDiffCmd, zBinGlob, zCmd[0]=='s', fIncludeBinary, |
| 691 | diffFlags); |
| 692 | }else |
| 693 | if( memcmp(zCmd, "help", nCmd)==0 ){ |
| 694 | g.argv[1] = "help"; |
| 695 | g.argv[2] = "stash"; |
| 696 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -398,18 +398,18 @@ | |
| 398 | ** return that number. Or throw a fatal error if it is not a valid |
| 399 | ** stash number. If it is NULL, return the most recent stash or |
| 400 | ** throw an error if the stash is empty. |
| 401 | */ |
| 402 | static int stash_get_id(const char *zStashId){ |
| 403 | int stashid; |
| 404 | if( zStashId==0 ){ |
| 405 | stashid = db_int(0, "SELECT max(stashid) FROM stash"); |
| 406 | if( stashid==0 ) fossil_fatal("empty stash"); |
| 407 | }else{ |
| 408 | stashid = atoi(zStashId); |
| 409 | if( !db_exists("SELECT 1 FROM stash WHERE stashid=%d", stashid) ){ |
| 410 | fossil_fatal("no such stash: %s", zStashId); |
| 411 | } |
| 412 | } |
| 413 | return stashid; |
| 414 | } |
| 415 | |
| @@ -432,11 +432,11 @@ | |
| 432 | ** fossil stash list|ls ?-v|--verbose? ?-W|--width <num>? |
| 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? |
| @@ -467,15 +467,15 @@ | |
| 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 ?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|cat ?STASHID? ?DIFF-OPTIONS? |
| 477 | ** fossil stash gdiff ?STASHID? ?DIFF-OPTIONS? |
| 478 | */ |
| 479 | void stash_cmd(void){ |
| 480 | const char *zCmd; |
| 481 | int nCmd; |
| @@ -659,37 +659,30 @@ | |
| 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 | zBinGlob = diff_get_binary_glob(); |
| 680 | fIncludeBinary = diff_include_binary_files(); |
| 681 | } |
| 682 | stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); |
| 683 | stash_diff(stashid, zDiffCmd, zBinGlob, fBaseline, fIncludeBinary, |
| 684 | diffFlags); |
| 685 | }else |
| 686 | if( memcmp(zCmd, "help", nCmd)==0 ){ |
| 687 | g.argv[1] = "help"; |
| 688 | g.argv[2] = "stash"; |
| 689 |