Fossil SCM

Get the --tk option working for "fossil stash diff".

drh 2012-10-05 12:38 trunk
Commit 2ed8cdc5187acfda773ec17f01a72297848baea5
2 files changed +9 -5 +25 -2
+9 -5
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -617,10 +617,11 @@
617617
@ .t tag config add -background {#c0ffc0}
618618
@ .t tag config rm -background {#ffc0c0}
619619
@ proc dehtml {x} {
620620
@ return [string map {&amp; & &lt; < &gt; > &#39; ' &quot; \"} $x]
621621
@ }
622
+@ # puts $cmd
622623
@ set in [open $cmd r]
623624
@ while {![eof $in]} {
624625
@ set line [gets $in]
625626
@ if {[regexp {^<a name="chunk.*"></a>} $line]} continue
626627
@ if {[regexp {^===} $line]} {
@@ -652,25 +653,28 @@
652653
** Steps:
653654
** (1) Write the Tcl/Tk script used for rendering into a temp file.
654655
** (2) Invoke "wish" on the temp file using fossil_system().
655656
** (3) Delete the temp file.
656657
*/
657
-static void diff_tk(void){
658
+void diff_tk(const char *zSubCmd, int firstArg){
658659
int i;
659660
Blob script;
660661
char *zTempFile;
661662
char *zCmd;
662663
blob_zero(&script);
663
- blob_appendf(&script, "set cmd {| \"%/\" diff --html -y -i", g.nameOfExe);
664
- for(i=2; i<g.argc; i++){
665
- blob_appendf(&script, " \"%s\"", g.argv[i]);
664
+ blob_appendf(&script, "set cmd {| \"%/\" %s --html -y -i",
665
+ g.nameOfExe, zSubCmd);
666
+ for(i=firstArg; i<g.argc; i++){
667
+ blob_append(&script, " ", 1);
668
+ shell_escape(&script, g.argv[i]);
666669
}
667670
blob_appendf(&script, "}\n%s", zDiffScript);
668671
zTempFile = write_blob_to_temp_file(&script);
669672
zCmd = mprintf("tclsh \"%s\"", zTempFile);
670673
fossil_system(zCmd);
671674
file_delete(zTempFile);
675
+ fossil_free(zCmd);
672676
}
673677
674678
/*
675679
** Returns non-zero if files that may be binary should be used with external
676680
** diff programs.
@@ -757,11 +761,11 @@
757761
int fIncludeBinary = 0; /* Include binary files for external diff */
758762
u64 diffFlags = 0; /* Flags to control the DIFF */
759763
int f;
760764
761765
if( find_option("tk",0,0)!=0 ){
762
- diff_tk();
766
+ diff_tk("diff", 2);
763767
return;
764768
}
765769
isGDiff = g.argv[1][0]=='g';
766770
isInternDiff = find_option("internal","i",0)!=0;
767771
zFrom = find_option("from", "r", 1);
768772
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -617,10 +617,11 @@
617 @ .t tag config add -background {#c0ffc0}
618 @ .t tag config rm -background {#ffc0c0}
619 @ proc dehtml {x} {
620 @ return [string map {&amp; & &lt; < &gt; > &#39; ' &quot; \"} $x]
621 @ }
 
622 @ set in [open $cmd r]
623 @ while {![eof $in]} {
624 @ set line [gets $in]
625 @ if {[regexp {^<a name="chunk.*"></a>} $line]} continue
626 @ if {[regexp {^===} $line]} {
@@ -652,25 +653,28 @@
652 ** Steps:
653 ** (1) Write the Tcl/Tk script used for rendering into a temp file.
654 ** (2) Invoke "wish" on the temp file using fossil_system().
655 ** (3) Delete the temp file.
656 */
657 static void diff_tk(void){
658 int i;
659 Blob script;
660 char *zTempFile;
661 char *zCmd;
662 blob_zero(&script);
663 blob_appendf(&script, "set cmd {| \"%/\" diff --html -y -i", g.nameOfExe);
664 for(i=2; i<g.argc; i++){
665 blob_appendf(&script, " \"%s\"", g.argv[i]);
 
 
666 }
667 blob_appendf(&script, "}\n%s", zDiffScript);
668 zTempFile = write_blob_to_temp_file(&script);
669 zCmd = mprintf("tclsh \"%s\"", zTempFile);
670 fossil_system(zCmd);
671 file_delete(zTempFile);
 
672 }
673
674 /*
675 ** Returns non-zero if files that may be binary should be used with external
676 ** diff programs.
@@ -757,11 +761,11 @@
757 int fIncludeBinary = 0; /* Include binary files for external diff */
758 u64 diffFlags = 0; /* Flags to control the DIFF */
759 int f;
760
761 if( find_option("tk",0,0)!=0 ){
762 diff_tk();
763 return;
764 }
765 isGDiff = g.argv[1][0]=='g';
766 isInternDiff = find_option("internal","i",0)!=0;
767 zFrom = find_option("from", "r", 1);
768
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -617,10 +617,11 @@
617 @ .t tag config add -background {#c0ffc0}
618 @ .t tag config rm -background {#ffc0c0}
619 @ proc dehtml {x} {
620 @ return [string map {&amp; & &lt; < &gt; > &#39; ' &quot; \"} $x]
621 @ }
622 @ # puts $cmd
623 @ set in [open $cmd r]
624 @ while {![eof $in]} {
625 @ set line [gets $in]
626 @ if {[regexp {^<a name="chunk.*"></a>} $line]} continue
627 @ if {[regexp {^===} $line]} {
@@ -652,25 +653,28 @@
653 ** Steps:
654 ** (1) Write the Tcl/Tk script used for rendering into a temp file.
655 ** (2) Invoke "wish" on the temp file using fossil_system().
656 ** (3) Delete the temp file.
657 */
658 void diff_tk(const char *zSubCmd, int firstArg){
659 int i;
660 Blob script;
661 char *zTempFile;
662 char *zCmd;
663 blob_zero(&script);
664 blob_appendf(&script, "set cmd {| \"%/\" %s --html -y -i",
665 g.nameOfExe, zSubCmd);
666 for(i=firstArg; i<g.argc; i++){
667 blob_append(&script, " ", 1);
668 shell_escape(&script, g.argv[i]);
669 }
670 blob_appendf(&script, "}\n%s", zDiffScript);
671 zTempFile = write_blob_to_temp_file(&script);
672 zCmd = mprintf("tclsh \"%s\"", zTempFile);
673 fossil_system(zCmd);
674 file_delete(zTempFile);
675 fossil_free(zCmd);
676 }
677
678 /*
679 ** Returns non-zero if files that may be binary should be used with external
680 ** diff programs.
@@ -757,11 +761,11 @@
761 int fIncludeBinary = 0; /* Include binary files for external diff */
762 u64 diffFlags = 0; /* Flags to control the DIFF */
763 int f;
764
765 if( find_option("tk",0,0)!=0 ){
766 diff_tk("diff", 2);
767 return;
768 }
769 isGDiff = g.argv[1][0]=='g';
770 isInternDiff = find_option("internal","i",0)!=0;
771 zFrom = find_option("from", "r", 1);
772
+25 -2
--- src/stash.c
+++ src/stash.c
@@ -426,10 +426,21 @@
426426
** fossil stash diff ?STASHID?
427427
** fossil stash gdiff ?STASHID?
428428
**
429429
** Show diffs of the current working directory and what that
430430
** directory would be if STASHID were applied.
431
+**
432
+** SUMMARY:
433
+** fossil stash
434
+** fossil stash save ?-m COMMENT? ?FILES...?
435
+** fossil stash snapshot ?-m COMMENT? ?FILES...?
436
+** fossil stash list|ls ?-l? ?--detail?
437
+** fossil stash pop
438
+** fossil stash apply ?STASHID?
439
+** fossil stash goto ?STASHID?
440
+** fossil stash rm|drop ?STASHID? ?--all?
441
+** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
431442
*/
432443
void stash_cmd(void){
433444
const char *zDb;
434445
const char *zCmd;
435446
int nCmd;
@@ -572,13 +583,22 @@
572583
"(SELECT origname FROM stashfile WHERE stashid=%d)",
573584
stashid);
574585
undo_finish();
575586
}else
576587
if( memcmp(zCmd, "diff", nCmd)==0 ){
577
- const char *zDiffCmd = diff_command_external(0);
588
+ const char *zDiffCmd = 0;
578589
const char *zBinGlob = 0;
579590
int fIncludeBinary = 0;
591
+
592
+ if( find_option("tk",0,0)!=0 ){
593
+ db_close(0);
594
+ diff_tk("stash diff", 3);
595
+ return;
596
+ }
597
+ if( find_option("internal","i",0)==0 ){
598
+ zDiffCmd = diff_command_external(0);
599
+ }
580600
u64 diffFlags = diff_options();
581601
if( g.argc>4 ) usage("diff STASHID");
582602
if( zDiffCmd ){
583603
zBinGlob = diff_get_binary_glob();
584604
fIncludeBinary = diff_include_binary_files();
@@ -585,13 +605,16 @@
585605
}
586606
stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
587607
stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
588608
}else
589609
if( memcmp(zCmd, "gdiff", nCmd)==0 ){
590
- const char *zDiffCmd = diff_command_external(1);
610
+ const char *zDiffCmd = 0;
591611
const char *zBinGlob = 0;
592612
int fIncludeBinary = 0;
613
+ if( find_option("internal","i",0)==0 ){
614
+ zDiffCmd = diff_command_external(0);
615
+ }
593616
u64 diffFlags = diff_options();
594617
if( g.argc>4 ) usage("gdiff STASHID");
595618
if( zDiffCmd ){
596619
zBinGlob = diff_get_binary_glob();
597620
fIncludeBinary = diff_include_binary_files();
598621
--- src/stash.c
+++ src/stash.c
@@ -426,10 +426,21 @@
426 ** fossil stash diff ?STASHID?
427 ** fossil stash gdiff ?STASHID?
428 **
429 ** Show diffs of the current working directory and what that
430 ** directory would be if STASHID were applied.
 
 
 
 
 
 
 
 
 
 
 
431 */
432 void stash_cmd(void){
433 const char *zDb;
434 const char *zCmd;
435 int nCmd;
@@ -572,13 +583,22 @@
572 "(SELECT origname FROM stashfile WHERE stashid=%d)",
573 stashid);
574 undo_finish();
575 }else
576 if( memcmp(zCmd, "diff", nCmd)==0 ){
577 const char *zDiffCmd = diff_command_external(0);
578 const char *zBinGlob = 0;
579 int fIncludeBinary = 0;
 
 
 
 
 
 
 
 
 
580 u64 diffFlags = diff_options();
581 if( g.argc>4 ) usage("diff STASHID");
582 if( zDiffCmd ){
583 zBinGlob = diff_get_binary_glob();
584 fIncludeBinary = diff_include_binary_files();
@@ -585,13 +605,16 @@
585 }
586 stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
587 stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
588 }else
589 if( memcmp(zCmd, "gdiff", nCmd)==0 ){
590 const char *zDiffCmd = diff_command_external(1);
591 const char *zBinGlob = 0;
592 int fIncludeBinary = 0;
 
 
 
593 u64 diffFlags = diff_options();
594 if( g.argc>4 ) usage("gdiff STASHID");
595 if( zDiffCmd ){
596 zBinGlob = diff_get_binary_glob();
597 fIncludeBinary = diff_include_binary_files();
598
--- src/stash.c
+++ src/stash.c
@@ -426,10 +426,21 @@
426 ** fossil stash diff ?STASHID?
427 ** fossil stash gdiff ?STASHID?
428 **
429 ** Show diffs of the current working directory and what that
430 ** directory would be if STASHID were applied.
431 **
432 ** SUMMARY:
433 ** fossil stash
434 ** fossil stash save ?-m COMMENT? ?FILES...?
435 ** fossil stash snapshot ?-m COMMENT? ?FILES...?
436 ** fossil stash list|ls ?-l? ?--detail?
437 ** fossil stash pop
438 ** fossil stash apply ?STASHID?
439 ** fossil stash goto ?STASHID?
440 ** fossil stash rm|drop ?STASHID? ?--all?
441 ** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
442 */
443 void stash_cmd(void){
444 const char *zDb;
445 const char *zCmd;
446 int nCmd;
@@ -572,13 +583,22 @@
583 "(SELECT origname FROM stashfile WHERE stashid=%d)",
584 stashid);
585 undo_finish();
586 }else
587 if( memcmp(zCmd, "diff", nCmd)==0 ){
588 const char *zDiffCmd = 0;
589 const char *zBinGlob = 0;
590 int fIncludeBinary = 0;
591
592 if( find_option("tk",0,0)!=0 ){
593 db_close(0);
594 diff_tk("stash diff", 3);
595 return;
596 }
597 if( find_option("internal","i",0)==0 ){
598 zDiffCmd = diff_command_external(0);
599 }
600 u64 diffFlags = diff_options();
601 if( g.argc>4 ) usage("diff STASHID");
602 if( zDiffCmd ){
603 zBinGlob = diff_get_binary_glob();
604 fIncludeBinary = diff_include_binary_files();
@@ -585,13 +605,16 @@
605 }
606 stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
607 stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
608 }else
609 if( memcmp(zCmd, "gdiff", nCmd)==0 ){
610 const char *zDiffCmd = 0;
611 const char *zBinGlob = 0;
612 int fIncludeBinary = 0;
613 if( find_option("internal","i",0)==0 ){
614 zDiffCmd = diff_command_external(0);
615 }
616 u64 diffFlags = diff_options();
617 if( g.argc>4 ) usage("gdiff STASHID");
618 if( zDiffCmd ){
619 zBinGlob = diff_get_binary_glob();
620 fIncludeBinary = diff_include_binary_files();
621

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button