Fossil SCM

The various "diff --tk" commands now take an optional, undocumented option "--script FILENAME" that causes the Tk script to be written into FILENAME rather than to be run. One use for this is to get a copy of the diff script in a form were it can be easily edited and enhanced before being moved back into Fossil.

drh 2013-09-27 14:41 trunk
Commit 326a736493e4bd8eb00fbb33eb9d7c341c3ae6d7
1 file changed +17 -6
+17 -6
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -915,11 +915,11 @@
915915
** (3) Delete the temp file.
916916
*/
917917
void diff_tk(const char *zSubCmd, int firstArg){
918918
int i;
919919
Blob script;
920
- char *zTempFile;
920
+ char *zTempFile = 0;
921921
char *zCmd;
922922
blob_zero(&script);
923923
blob_appendf(&script, "set fossilcmd {| \"%/\" %s --html -y -i -v",
924924
g.nameOfExe, zSubCmd);
925925
for(i=firstArg; i<g.argc; i++){
@@ -926,20 +926,31 @@
926926
const char *z = g.argv[i];
927927
if( z[0]=='-' ){
928928
if( strglob("*-html",z) ) continue;
929929
if( strglob("*-y",z) ) continue;
930930
if( strglob("*-i",z) ) continue;
931
+ if( strglob("*-script",z) && i<g.argc-1 ){
932
+ i++;
933
+ zTempFile = g.argv[i];
934
+ continue;
935
+ }
931936
}
932937
blob_append(&script, " ", 1);
933938
shell_escape(&script, z);
934939
}
935940
blob_appendf(&script, "}\n%s", zDiffScript);
936
- zTempFile = write_blob_to_temp_file(&script);
937
- zCmd = mprintf("tclsh \"%s\"", zTempFile);
938
- fossil_system(zCmd);
939
- file_delete(zTempFile);
940
- fossil_free(zCmd);
941
+ if( zTempFile ){
942
+ blob_write_to_file(&script, zTempFile);
943
+ fossil_print("To see diff, run: tclsh \"%s\"\n", zTempFile);
944
+ }else{
945
+ zTempFile = write_blob_to_temp_file(&script);
946
+ zCmd = mprintf("tclsh \"%s\"", zTempFile);
947
+ fossil_system(zCmd);
948
+ file_delete(zTempFile);
949
+ fossil_free(zCmd);
950
+ }
951
+ blob_reset(&script);
941952
}
942953
943954
/*
944955
** Returns non-zero if files that may be binary should be used with external
945956
** diff programs.
946957
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -915,11 +915,11 @@
915 ** (3) Delete the temp file.
916 */
917 void diff_tk(const char *zSubCmd, int firstArg){
918 int i;
919 Blob script;
920 char *zTempFile;
921 char *zCmd;
922 blob_zero(&script);
923 blob_appendf(&script, "set fossilcmd {| \"%/\" %s --html -y -i -v",
924 g.nameOfExe, zSubCmd);
925 for(i=firstArg; i<g.argc; i++){
@@ -926,20 +926,31 @@
926 const char *z = g.argv[i];
927 if( z[0]=='-' ){
928 if( strglob("*-html",z) ) continue;
929 if( strglob("*-y",z) ) continue;
930 if( strglob("*-i",z) ) continue;
 
 
 
 
 
931 }
932 blob_append(&script, " ", 1);
933 shell_escape(&script, z);
934 }
935 blob_appendf(&script, "}\n%s", zDiffScript);
936 zTempFile = write_blob_to_temp_file(&script);
937 zCmd = mprintf("tclsh \"%s\"", zTempFile);
938 fossil_system(zCmd);
939 file_delete(zTempFile);
940 fossil_free(zCmd);
 
 
 
 
 
 
941 }
942
943 /*
944 ** Returns non-zero if files that may be binary should be used with external
945 ** diff programs.
946
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -915,11 +915,11 @@
915 ** (3) Delete the temp file.
916 */
917 void diff_tk(const char *zSubCmd, int firstArg){
918 int i;
919 Blob script;
920 char *zTempFile = 0;
921 char *zCmd;
922 blob_zero(&script);
923 blob_appendf(&script, "set fossilcmd {| \"%/\" %s --html -y -i -v",
924 g.nameOfExe, zSubCmd);
925 for(i=firstArg; i<g.argc; i++){
@@ -926,20 +926,31 @@
926 const char *z = g.argv[i];
927 if( z[0]=='-' ){
928 if( strglob("*-html",z) ) continue;
929 if( strglob("*-y",z) ) continue;
930 if( strglob("*-i",z) ) continue;
931 if( strglob("*-script",z) && i<g.argc-1 ){
932 i++;
933 zTempFile = g.argv[i];
934 continue;
935 }
936 }
937 blob_append(&script, " ", 1);
938 shell_escape(&script, z);
939 }
940 blob_appendf(&script, "}\n%s", zDiffScript);
941 if( zTempFile ){
942 blob_write_to_file(&script, zTempFile);
943 fossil_print("To see diff, run: tclsh \"%s\"\n", zTempFile);
944 }else{
945 zTempFile = write_blob_to_temp_file(&script);
946 zCmd = mprintf("tclsh \"%s\"", zTempFile);
947 fossil_system(zCmd);
948 file_delete(zTempFile);
949 fossil_free(zCmd);
950 }
951 blob_reset(&script);
952 }
953
954 /*
955 ** Returns non-zero if files that may be binary should be used with external
956 ** diff programs.
957

Keyboard Shortcuts

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