Fossil

Check-in [252aff3e62]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use built-in Tcl for "diff --tk" implementation if possible. Fallback is to spawn an external "tclsh" as before.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 252aff3e6242f540fdee795d338a25888319eb26
User & Date: jan.nijtmans 2014-02-04 09:34:31.783
References
2014-02-14
13:37
Cherrypick [252aff3e62] and related clean-ups: Use built-in Tcl for "diff --tk" implementation if possible. Fallback is to spawn an external "tclsh" as before. This makes "fossil diff --tk" work with ActiveState Tcl on Win32 out-of-the-box. check-in: f325b2343e user: jan.nijtmans tags: branch-1.28
Context
2014-02-14
13:37
Cherrypick [252aff3e62] and related clean-ups: Use built-in Tcl for "diff --tk" implementation if possible. Fallback is to spawn an external "tclsh" as before. This makes "fossil diff --tk" work with ActiveState Tcl on Win32 out-of-the-box. check-in: f325b2343e user: jan.nijtmans tags: branch-1.28
2014-02-04
20:14
Potential fix for ticket [d752140c7a]. The reconstruct op appears to have been importing raw directory entries into the blob table. check-in: 8e110293ed user: stephan tags: trunk
09:34
Use built-in Tcl for "diff --tk" implementation if possible. Fallback is to spawn an external "tclsh" as before. check-in: 252aff3e62 user: jan.nijtmans tags: trunk
2014-02-03
12:39
Make sure that the close-button of tk's "diff" window ends the main-loop in all circumstances. Remove unnecessary space. check-in: c275d8ddbb user: jan.nijtmans tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/diffcmd.c.
906
907
908
909
910
911
912


913
914
915
916
917
918
919
920
921
922
@ wm deiconify .
;

/*
** Show diff output in a Tcl/Tk window, in response to the --tk option
** to the diff command.
**


** Steps:
** (1) Write the Tcl/Tk script used for rendering into a temp file.
** (2) Invoke "wish" on the temp file using fossil_system().
** (3) Delete the temp file.
*/
void diff_tk(const char *zSubCmd, int firstArg){
  int i;
  Blob script;
  char *zTempFile = 0;
  char *zCmd;







>
>
|

|







906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
@ wm deiconify .
;

/*
** Show diff output in a Tcl/Tk window, in response to the --tk option
** to the diff command.
**
** If fossil has direct access to a Tcl interpreter (either loaded
** dynamically through stubs or linked in statically), we can use it
** directly. Otherwise:
** (1) Write the Tcl/Tk script used for rendering into a temp file.
** (2) Invoke "tclsh" on the temp file using fossil_system().
** (3) Delete the temp file.
*/
void diff_tk(const char *zSubCmd, int firstArg){
  int i;
  Blob script;
  char *zTempFile = 0;
  char *zCmd;
942
943
944
945
946
947
948











949
950
951
952
953
954
955
    shell_escape(&script, z);
  }
  blob_appendf(&script, "}\n%s", zDiffScript);
  if( zTempFile ){
    blob_write_to_file(&script, zTempFile);
    fossil_print("To see diff, run: tclsh \"%s\"\n", zTempFile);
  }else{











    zTempFile = write_blob_to_temp_file(&script);
    zCmd = mprintf("tclsh \"%s\"", zTempFile);
    fossil_system(zCmd);
    file_delete(zTempFile);
    fossil_free(zCmd);
  }
  blob_reset(&script);







>
>
>
>
>
>
>
>
>
>
>







944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
    shell_escape(&script, z);
  }
  blob_appendf(&script, "}\n%s", zDiffScript);
  if( zTempFile ){
    blob_write_to_file(&script, zTempFile);
    fossil_print("To see diff, run: tclsh \"%s\"\n", zTempFile);
  }else{
#if defined(FOSSIL_ENABLE_TCL)
    Th_FossilInit(TH_INIT_DEFAULT | TH_INIT_FORCE_TCL);
    if (runTclGui(g.interp, &g.tcl, blob_str(&script)) == TCL_OK){
      blob_reset(&script);
      return;
    }
    /* If evaluation of the script fails, the reason could be that Tk
     * cannot be found by the built-in Tcl, or that Tcl cannot be
     * loaded dynamically (e.g. Win64 Tcl in Win32 fossil). Try again
     * using an external "tclsh", which might work in those two cases. */
#endif
    zTempFile = write_blob_to_temp_file(&script);
    zCmd = mprintf("tclsh \"%s\"", zTempFile);
    fossil_system(zCmd);
    file_delete(zTempFile);
    fossil_free(zCmd);
  }
  blob_reset(&script);
Changes to src/th.h.
157
158
159
160
161
162
163

164
165
166
167
168
169
170
int th_register_sqlite(Th_Interp *interp);              /* th_sqlite.c */
int th_register_vfs(Th_Interp *interp);                 /* th_vfs.c */
int th_register_testvfs(Th_Interp *interp);             /* th_testvfs.c */

#ifdef FOSSIL_ENABLE_TCL
int th_register_tcl(Th_Interp *interp, void *pContext); /* th_tcl.c */
int unloadTcl(Th_Interp *interp, void *pContext);       /* th_tcl.c */

#endif

/*
** General purpose hash table from th_lang.c.
*/
typedef struct Th_Hash      Th_Hash;
typedef struct Th_HashEntry Th_HashEntry;







>







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
int th_register_sqlite(Th_Interp *interp);              /* th_sqlite.c */
int th_register_vfs(Th_Interp *interp);                 /* th_vfs.c */
int th_register_testvfs(Th_Interp *interp);             /* th_testvfs.c */

#ifdef FOSSIL_ENABLE_TCL
int th_register_tcl(Th_Interp *interp, void *pContext); /* th_tcl.c */
int unloadTcl(Th_Interp *interp, void *pContext);       /* th_tcl.c */
int runTclGui(Th_Interp *, void *, const char *);       /* th_tcl.c */
#endif

/*
** General purpose hash table from th_lang.c.
*/
typedef struct Th_Hash      Th_Hash;
typedef struct Th_HashEntry Th_HashEntry;
Changes to src/th_tcl.c.
764
765
766
767
768
769
770




















771
772
773
774
775
776
777
    if( !resultObjPtr ){
      rc = TCL_ERROR;
    }
  }
  Tcl_DecrRefCount(listPtr);
  return rc;
}





















/*
** Creates and initializes a Tcl interpreter for use with the specified TH1
** interpreter.  Stores the created Tcl interpreter in the Tcl context supplied
** by the caller.
*/
static int createTclInterp(







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
    if( !resultObjPtr ){
      rc = TCL_ERROR;
    }
  }
  Tcl_DecrRefCount(listPtr);
  return rc;
}

/*
** Run a Tcl script. If the script succeeds, start the main loop until
** there is no more work to be done or the script calls "exit".
*/
int runTclGui(Th_Interp *interp, void *pContext, const char *script){
  struct TclContext *tclContext = (struct TclContext *)pContext;
  int rc;

  if( createTclInterp(interp, pContext)!=TH_OK ){
    return TH_ERROR;
  }
  rc = Tcl_EvalEx(tclContext->interp, script, -1, TCL_EVAL_GLOBAL);
  if (rc == TCL_OK){
    while (Tcl_DoOneEvent(0)) {
      /* do nothing */
    }
  }
  return rc;
}

/*
** Creates and initializes a Tcl interpreter for use with the specified TH1
** interpreter.  Stores the created Tcl interpreter in the Tcl context supplied
** by the caller.
*/
static int createTclInterp(