{"thread":{"id":"21345","subject":"[PATCH 0/2] gitk: Fix error display when Tcl is too old","startedAt":"2009-10-24T20:20:38Z","lastAt":"2009-11-03T11:31:21Z","messageCount":8,"participants":["Bernt Hansen","Junio C Hamano","Pat Thoyts","Paul Mackerras"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"125858","messageId":"1256415640-10328-1-git-send-email-bernt@norang.ca","threadId":"21345","inReplyTo":null,"subject":"[PATCH 0/2] gitk: Fix error display when Tcl is too old","fromName":"Bernt Hansen","fromEmail":"bernt@norang.ca","sentAt":"2009-10-24T20:20:38Z","receivedAt":"2009-10-24T20:20:38Z","isPatch":true,"sender":{"key":"bernt@norang.ca","avatar":null},"body":"The following patch series cleans up error message reporting when your\nversion of Tcl is too old.\n\nThe old code checked the Tcl version first and then tried to report\nthe error with show_error.  show_error uses msgcat for translation but\nmsgcat is not yet initialized when we are checking the Tcl version\nrequirement.\n\nThe first patch moves the initialization of msgcat before the check\nfor the Tcl version.  This version will fail is msgcat is not\navailable.\n\nThe second patch handles the case where the msgcat package is not\navailable by providing a default mc procedure than just returns the\nargument text unchanged (essentially bypassing message text\ntranslation).\n\nThis lets us continue to use show_error as-is.\n\nBernt Hansen (2):\n  gitk: Initialize msgcat before first use\n  gitk: Provide a default mc function if msgcat is not available\n\n gitk |   46 ++++++++++++++++++++++++++--------------------\n 1 files changed, 26 insertions(+), 20 deletions(-)\n"},{"id":"125859","messageId":"1256415640-10328-2-git-send-email-bernt@norang.ca","threadId":"21345","inReplyTo":"1256415640-10328-1-git-send-email-bernt@norang.ca","subject":"[PATCH 1/2] gitk: Initialize msgcat before first use","fromName":"Bernt Hansen","fromEmail":"bernt@norang.ca","sentAt":"2009-10-24T20:20:39Z","receivedAt":"2009-10-24T20:20:39Z","isPatch":true,"sender":{"key":"bernt@norang.ca","avatar":null},"body":"The error text generated when your version of Tcl is too old is\ntranslated with msgcat (mc) before msgcat is initialized.  This\ncauses Tcl to abort with:\n\n    Error in startup script: invalid command name \"mc\"\n\nWe now initialize msgcat first before we check the Tcl version.  Msgcat\nis available since Tcl 8.1.\n\nSigned-off-by: Bernt Hansen <bernt@norang.ca>\n---\n gitk |   41 +++++++++++++++++++++--------------------\n 1 files changed, 21 insertions(+), 20 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex a0214b7..d4cd566 100755\n--- a/gitk\n+++ b/gitk\n@@ -11004,7 +11004,27 @@ proc get_path_encoding {path} {\n     return $tcl_enc\n }\n \n-# First check that Tcl/Tk is recent enough\n+# First setup up mc for translating text\n+## For msgcat loading, first locate the installation location.\n+if { [info exists ::env(GITK_MSGSDIR)] } {\n+    ## Msgsdir was manually set in the environment.\n+    set gitk_msgsdir $::env(GITK_MSGSDIR)\n+} else {\n+    ## Let's guess the prefix from argv0.\n+    set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]\n+    set gitk_libdir [file join $gitk_prefix share gitk lib]\n+    set gitk_msgsdir [file join $gitk_libdir msgs]\n+    unset gitk_prefix\n+}\n+\n+## Internationalization (i18n) through msgcat and gettext. See\n+## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html\n+package require msgcat\n+namespace import ::msgcat::mc\n+## And eventually load the actual message catalog\n+::msgcat::mcload $gitk_msgsdir\n+\n+# Check that Tcl/Tk is recent enough\n if {[catch {package require Tk 8.4} err]} {\n     show_error {} . [mc \"Sorry, gitk cannot run with this version of Tcl/Tk.\\n\\\n \t\t     Gitk requires at least Tcl/Tk 8.4.\"]\n@@ -11096,25 +11116,6 @@ if {[tk windowingsystem] eq \"aqua\"} {\n     set ctxbut <Button-3>\n }\n \n-## For msgcat loading, first locate the installation location.\n-if { [info exists ::env(GITK_MSGSDIR)] } {\n-    ## Msgsdir was manually set in the environment.\n-    set gitk_msgsdir $::env(GITK_MSGSDIR)\n-} else {\n-    ## Let's guess the prefix from argv0.\n-    set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]\n-    set gitk_libdir [file join $gitk_prefix share gitk lib]\n-    set gitk_msgsdir [file join $gitk_libdir msgs]\n-    unset gitk_prefix\n-}\n-\n-## Internationalization (i18n) through msgcat and gettext. See\n-## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html\n-package require msgcat\n-namespace import ::msgcat::mc\n-## And eventually load the actual message catalog\n-::msgcat::mcload $gitk_msgsdir\n-\n catch {source ~/.gitk}\n \n font create optionfont -family sans-serif -size -12\n-- \n1.6.5.1.69.g36942\n"},{"id":"125860","messageId":"1256415640-10328-3-git-send-email-bernt@norang.ca","threadId":"21345","inReplyTo":"1256415640-10328-1-git-send-email-bernt@norang.ca","subject":"[PATCH 2/2] gitk: Provide a default mc function if msgcat is not available","fromName":"Bernt Hansen","fromEmail":"bernt@norang.ca","sentAt":"2009-10-24T20:20:40Z","receivedAt":"2009-10-24T20:20:40Z","isPatch":true,"sender":{"key":"bernt@norang.ca","avatar":null},"body":"Msgcat is available since Tcl 8.1.  For really old versions of Tcl\nprovide a default mc that just returns the text untranslated.  This\nallows the Tcl version check to return the error in a window instead\nof making Tcl abort when attempting to load the msgcat package.\n\nSigned-off-by: Bernt Hansen <bernt@norang.ca>\n---\nI'm not sure if we care about Tcl versions older than 8.1 but this at\nleast shows the error in the window with the [OK] button.\n\n gitk |   13 +++++++++----\n 1 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex d4cd566..bff891d 100755\n--- a/gitk\n+++ b/gitk\n@@ -11019,10 +11019,15 @@ if { [info exists ::env(GITK_MSGSDIR)] } {\n \n ## Internationalization (i18n) through msgcat and gettext. See\n ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html\n-package require msgcat\n-namespace import ::msgcat::mc\n-## And eventually load the actual message catalog\n-::msgcat::mcload $gitk_msgsdir\n+if {[catch {package require msgcat}]} {\n+    proc mc {arg} {\n+\treturn $arg\n+    }\n+} else {\n+    namespace import ::msgcat::mc\n+    ## And eventually load the actual message catalog\n+    ::msgcat::mcload $gitk_msgsdir\n+}\n \n # Check that Tcl/Tk is recent enough\n if {[catch {package require Tk 8.4} err]} {\n-- \n1.6.5.1.69.g36942\n"},{"id":"125861","messageId":"7vws2k4f7u.fsf@alter.siamese.dyndns.org","threadId":"21345","inReplyTo":"1256415640-10328-3-git-send-email-bernt@norang.ca","subject":"Re: [PATCH 2/2] gitk: Provide a default mc function if msgcat is not available","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-24T22:08:53Z","receivedAt":"2009-10-24T22:08:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bernt Hansen <bernt@norang.ca> writes:\n\n> Msgcat is available since Tcl 8.1.  For really old versions of Tcl\n> provide a default mc that just returns the text untranslated.  This\n> allows the Tcl version check to return the error in a window instead\n> of making Tcl abort when attempting to load the msgcat package.\n>\n> Signed-off-by: Bernt Hansen <bernt@norang.ca>\n> ---\n> I'm not sure if we care about Tcl versions older than 8.1 but this at\n> least shows the error in the window with the [OK] button.\n\nBoth patches sound very sensible.\n"},{"id":"126541","messageId":"87d443xn5u.fsf@users.sourceforge.net","threadId":"21345","inReplyTo":"1256415640-10328-2-git-send-email-bernt@norang.ca","subject":"Re: [PATCH 1/2] gitk: Initialize msgcat before first use","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2009-10-31T21:34:53Z","receivedAt":"2009-10-31T21:34:53Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"Bernt Hansen <bernt@norang.ca> writes:\n\n>The error text generated when your version of Tcl is too old is\n>translated with msgcat (mc) before msgcat is initialized.  This\n>causes Tcl to abort with:\n>\n>    Error in startup script: invalid command name \"mc\"\n>\n>We now initialize msgcat first before we check the Tcl version.  Msgcat\n>is available since Tcl 8.1.\n>\n\nThis doesn't quite work. [file normalize] was introduced with Tcl 8.4\nand when I test this by starting it using Tcl 8.3 I get an error:\n \"bad option \"normalize\": must be atime, attributes, channels...\"\nfrom line 11014. It is probably sufficient to just drop the [file\nnormalize] here. On Windows $argv0 is fully qualified and \n[file dirname] works ok on it. By removing the [file normalize] I get\nthe expected error dialog when testing with 8.3.\n\nHowever, on Windows we actually get a better looking result by not\ncatching the [package require Tcl 8.4] and just letting Tk bring up a\nstandard message box with the version conflict error message.\n\nWell, actually if show_error just used tk_messageBox it would look\nbetter on Windows.\n\n-- \nPat Thoyts                            http://www.patthoyts.tk/\nPGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD\n"},{"id":"126548","messageId":"874opel7de.fsf@gollum.intra.norang.ca","threadId":"21345","inReplyTo":"87d443xn5u.fsf@users.sourceforge.net","subject":"Re: [PATCH 1/2] gitk: Initialize msgcat before first use","fromName":"Bernt Hansen","fromEmail":"bernt@norang.ca","sentAt":"2009-11-01T13:09:01Z","receivedAt":"2009-11-01T13:09:01Z","isPatch":true,"sender":{"key":"bernt@norang.ca","avatar":null},"body":"Pat Thoyts <patthoyts@users.sourceforge.net> writes:\n\n> Bernt Hansen <bernt@norang.ca> writes:\n>\n>>The error text generated when your version of Tcl is too old is\n>>translated with msgcat (mc) before msgcat is initialized.  This\n>>causes Tcl to abort with:\n>>\n>>    Error in startup script: invalid command name \"mc\"\n>>\n>>We now initialize msgcat first before we check the Tcl version.  Msgcat\n>>is available since Tcl 8.1.\n>>\n>\n> This doesn't quite work. [file normalize] was introduced with Tcl 8.4\n> and when I test this by starting it using Tcl 8.3 I get an error:\n>  \"bad option \"normalize\": must be atime, attributes, channels...\"\n> from line 11014. It is probably sufficient to just drop the [file\n> normalize] here. On Windows $argv0 is fully qualified and \n> [file dirname] works ok on it. By removing the [file normalize] I get\n> the expected error dialog when testing with 8.3.\n> However, on Windows we actually get a better looking result by not\n> catching the [package require Tcl 8.4] and just letting Tk bring up a\n> standard message box with the version conflict error message.\n>\n> Well, actually if show_error just used tk_messageBox it would look\n> better on Windows.\n\nYou're right.  Thanks for catching this.  When I tested this code I\nbumped the version number temporarily to 8.5 instead of downgrading TK\nto 8.3.\n\nThe problem I was trying to fix was show_error using mc internally\nbefore it was initialized.  Maybe it would be better to give show_error\nan optional parameter that controls calling mc - so that the call for\nthe version check can just bypass the mc translation of the text and OK\nbuttons.  With this approach the code I moved around can just stay where\nit is and all of the existing calls to show_error will use the default\nparameter setting which invokes mc.\n\nWould that be a better approach?\n\n-Bernt\n"},{"id":"126582","messageId":"87ljipje03.fsf@gollum.intra.norang.ca","threadId":"21345","inReplyTo":"874opel7de.fsf@gollum.intra.norang.ca","subject":"[PATCH] Skip translation of wrong Tcl version text","fromName":"Bernt Hansen","fromEmail":"bernt@norang.ca","sentAt":"2009-11-02T12:41:00Z","receivedAt":"2009-11-02T12:41:00Z","isPatch":true,"sender":{"key":"bernt@norang.ca","avatar":null},"body":"We check the required Tcl version number before we setup msgcat for\nlanguage translation.  If the Tcl version is too old just display the\nuntranslated error text.\n\nThe caller of show_error can now pass an alternative function for mc.\nThe Tcl list function turns the transalation into a no-op.\n\nThis fixes the\n    Error in startup script: invalid command name \"mc\"\nwhen attempting to start gitk with Tcl 8.3.\n\nSigned-off-by: Bernt Hansen <bernt@norang.ca>\n---\nI tested this patch with both Tcl 8.3 and 8.4.\n\nThis is an alternative to the previous 2 patches I sent attempting\nto initialize msgcat before first use.  This patch is much simpler\nbut does not attempt to translate the wrong version message text.\n\nThis patch fixes the version number error message by displaying it\nuntranslated since msgcat is not initialized yet.  The current\ninitialization code for msgcat uses normalize which is only available as\nof Tcl 8.4 so moving the code up front didn't work in Tcl 8.3.\n\n gitk |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex a0214b7..d1f32a9 100755\n--- a/gitk\n+++ b/gitk\n@@ -1787,10 +1787,10 @@ proc make_transient {window origin} {\n     }\n }\n \n-proc show_error {w top msg} {\n+proc show_error {w top msg {mc mc}} {\n     message $w.m -text $msg -justify center -aspect 400\n     pack $w.m -side top -fill x -padx 20 -pady 20\n-    button $w.ok -text [mc OK] -command \"destroy $top\"\n+    button $w.ok -text [$mc OK] -command \"destroy $top\"\n     pack $w.ok -side bottom -fill x\n     bind $top <Visibility> \"grab $top; focus $top\"\n     bind $top <Key-Return> \"destroy $top\"\n@@ -11006,8 +11006,8 @@ proc get_path_encoding {path} {\n \n # First check that Tcl/Tk is recent enough\n if {[catch {package require Tk 8.4} err]} {\n-    show_error {} . [mc \"Sorry, gitk cannot run with this version of Tcl/Tk.\\n\\\n-\t\t     Gitk requires at least Tcl/Tk 8.4.\"]\n+    show_error {} . \"Sorry, gitk cannot run with this version of Tcl/Tk.\\n\\\n+\t\t     Gitk requires at least Tcl/Tk 8.4.\" list\n     exit 1\n }\n \n-- \n1.6.5.2.141.gc8a58\n"},{"id":"126645","messageId":"19184.5257.944412.835848@cargo.ozlabs.ibm.com","threadId":"21345","inReplyTo":"87ljipje03.fsf@gollum.intra.norang.ca","subject":"Re: [PATCH] Skip translation of wrong Tcl version text","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2009-11-03T11:31:21Z","receivedAt":"2009-11-03T11:31:21Z","isPatch":true,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"Bernt Hansen writes:\n\n> We check the required Tcl version number before we setup msgcat for\n> language translation.  If the Tcl version is too old just display the\n> untranslated error text.\n> \n> The caller of show_error can now pass an alternative function for mc.\n> The Tcl list function turns the transalation into a no-op.\n> \n> This fixes the\n>     Error in startup script: invalid command name \"mc\"\n> when attempting to start gitk with Tcl 8.3.\n> \n> Signed-off-by: Bernt Hansen <bernt@norang.ca>\n\nThanks, applied.\n\nPaul.\n"}]}