{"thread":{"id":"51749","subject":"[PATCH] gitk: Make web links clickable","startedAt":"2019-08-26T22:14:53Z","lastAt":"2019-09-14T14:30:56Z","messageCount":10,"participants":["Paul Mackerras","Barret Rhoden","Junio C Hamano","Pratyush Yadav"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"381258","messageId":"20190826221444.GB7402@blackberry","threadId":"51749","inReplyTo":null,"subject":"[PATCH] gitk: Make web links clickable","fromName":"Paul Mackerras","fromEmail":"paulus@ozlabs.org","sentAt":"2019-08-26T22:14:44Z","receivedAt":"2019-08-26T22:14:53Z","isPatch":true,"sender":{"key":"paulus@ozlabs.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"This makes gitk look for lines in the commit message which start with\n\"Link:\" or \"BugLink:\" followed by a http or https URL, and make the\nURL clickable.  Clicking on it will invoke an external web browser with\nthe URL.\n\nThe web browser command is by default \"xdg-open\" on Linux, \"open\" on\nMacOS, and \"cmd /c start\" on Windows.  The command can be changed in\nthe preferences window, and it can include parameters as well as the\ncommand name.  If it is set to the empty string then URLs will no\nlonger be made clickable.\n\nSigned-off-by: Paul Mackerras <paulus@ozlabs.org>\n---\n gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 50 insertions(+), 1 deletion(-)\n\ndiff --git a/gitk b/gitk\nindex a14d7a1..4577150 100755\n--- a/gitk\n+++ b/gitk\n@@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {\n \n # append some text to the ctext widget, and make any SHA1 ID\n # that we know about be a clickable link.\n+# Also look for lines of the form \"Link: http...\" and make them web links.\n proc appendwithlinks {text tags} {\n     global ctext linknum curview\n \n@@ -7032,6 +7033,18 @@ proc appendwithlinks {text tags} {\n \tsetlink $linkid link$linknum\n \tincr linknum\n     }\n+    set wlinks [regexp -indices -all -inline -line \\\n+\t\t    {^ *(Bug|)Link: (https?://.*)$} $text]\n+    foreach {l sub1 sub2} $wlinks {\n+\tset s2 [lindex $sub2 0]\n+\tset e2 [lindex $sub2 1]\n+\tset url [string range $text $s2 $e2]\n+\tincr e2\n+\t$ctext tag delete link$linknum\n+\t$ctext tag add link$linknum \"$start + $s2 c\" \"$start + $e2 c\"\n+\tsetwlink $url link$linknum\n+\tincr linknum\n+    }\n }\n \n proc setlink {id lk} {\n@@ -7064,6 +7077,18 @@ proc setlink {id lk} {\n     }\n }\n \n+proc setwlink {url lk} {\n+    global ctext\n+    global linkfgcolor\n+    global web_browser\n+\n+    if {$web_browser eq {}} return\n+    $ctext tag conf $lk -foreground $linkfgcolor -underline 1\n+    $ctext tag bind $lk <1> [list browseweb $url]\n+    $ctext tag bind $lk <Enter> {linkcursor %W 1}\n+    $ctext tag bind $lk <Leave> {linkcursor %W -1}\n+}\n+\n proc appendshortlink {id {pre {}} {post {}}} {\n     global ctext linknum\n \n@@ -7098,6 +7123,16 @@ proc linkcursor {w inc} {\n     }\n }\n \n+proc browseweb {url} {\n+    global web_browser\n+\n+    if {$web_browser eq {}} return\n+    # Use eval here in case $web_browser is a command plus some arguments\n+    if {[catch {eval exec $web_browser [list $url] &} err]} {\n+\terror_popup \"[mc \"Error starting web browser:\"] $err\"\n+    }\n+}\n+\n proc viewnextline {dir} {\n     global canv linespc\n \n@@ -11488,7 +11523,7 @@ proc create_prefs_page {w} {\n proc prefspage_general {notebook} {\n     global NS maxwidth maxgraphpct showneartags showlocalchanges\n     global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs\n-    global hideremotes want_ttk have_ttk maxrefs\n+    global hideremotes want_ttk have_ttk maxrefs web_browser\n \n     set page [create_prefs_page $notebook.general]\n \n@@ -11539,6 +11574,13 @@ proc prefspage_general {notebook} {\n     pack configure $page.extdifff.l -padx 10\n     grid x $page.extdifff $page.extdifft -sticky ew\n \n+    ${NS}::entry $page.webbrowser -textvariable web_browser\n+    ${NS}::frame $page.webbrowserf\n+    ${NS}::label $page.webbrowserf.l -text [mc \"Web browser\" ]\n+    pack $page.webbrowserf.l -side left\n+    pack configure $page.webbrowserf.l -padx 10\n+    grid x $page.webbrowserf $page.webbrowser -sticky ew\n+\n     ${NS}::label $page.lgen -text [mc \"General options\"]\n     grid $page.lgen - -sticky w -pady 10\n     ${NS}::checkbutton $page.want_ttk -variable want_ttk \\\n@@ -12310,6 +12352,7 @@ if {[tk windowingsystem] eq \"win32\"} {\n     set bgcolor SystemWindow\n     set fgcolor SystemWindowText\n     set selectbgcolor SystemHighlight\n+    set web_browser \"cmd /c start\"\n } else {\n     set uicolor grey85\n     set uifgcolor black\n@@ -12317,6 +12360,11 @@ if {[tk windowingsystem] eq \"win32\"} {\n     set bgcolor white\n     set fgcolor black\n     set selectbgcolor gray85\n+    if {[tk windowingsystem] eq \"aqua\"} {\n+\tset web_browser \"open\"\n+    } else {\n+\tset web_browser \"xdg-open\"\n+    }\n }\n set diffcolors {red \"#00a000\" blue}\n set diffcontext 3\n@@ -12390,6 +12438,7 @@ set config_variables {\n     filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor\n     linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor\n     indexcirclecolor circlecolors linkfgcolor circleoutlinecolor\n+    web_browser\n }\n foreach var $config_variables {\n     config_init_trace $var\n-- \n2.7.4\n\n"},{"id":"381370","messageId":"24ec7841-0996-b3d7-81b4-f48a446341ee@google.com","threadId":"51749","inReplyTo":"20190826221444.GB7402@blackberry","subject":"Re: [PATCH] gitk: Make web links clickable","fromName":"Barret Rhoden","fromEmail":"brho@google.com","sentAt":"2019-08-27T15:33:16Z","receivedAt":"2019-08-27T15:33:22Z","isPatch":true,"sender":{"key":"brho@google.com","avatar":null},"body":"On 8/26/19 6:14 PM, Paul Mackerras wrote:\n> This makes gitk look for lines in the commit message which start with\n> \"Link:\" or \"BugLink:\" followed by a http or https URL, and make the\n> URL clickable.  Clicking on it will invoke an external web browser with\n> the URL.\n> \n> The web browser command is by default \"xdg-open\" on Linux, \"open\" on\n> MacOS, and \"cmd /c start\" on Windows.  The command can be changed in\n> the preferences window, and it can include parameters as well as the\n> command name.  If it is set to the empty string then URLs will no\n> longer be made clickable.\n> \n> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>\n\nFWIW:\n\nTested-by: Barret Rhoden <brho@google.com>\n\n\n> ---\n>   gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n>   1 file changed, 50 insertions(+), 1 deletion(-)\n> \n> diff --git a/gitk b/gitk\n> index a14d7a1..4577150 100755\n> --- a/gitk\n> +++ b/gitk\n> @@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {\n>   \n>   # append some text to the ctext widget, and make any SHA1 ID\n>   # that we know about be a clickable link.\n> +# Also look for lines of the form \"Link: http...\" and make them web links.\n>   proc appendwithlinks {text tags} {\n>       global ctext linknum curview\n>   \n> @@ -7032,6 +7033,18 @@ proc appendwithlinks {text tags} {\n>   \tsetlink $linkid link$linknum\n>   \tincr linknum\n>       }\n> +    set wlinks [regexp -indices -all -inline -line \\\n> +\t\t    {^ *(Bug|)Link: (https?://.*)$} $text]\n> +    foreach {l sub1 sub2} $wlinks {\n> +\tset s2 [lindex $sub2 0]\n> +\tset e2 [lindex $sub2 1]\n> +\tset url [string range $text $s2 $e2]\n> +\tincr e2\n> +\t$ctext tag delete link$linknum\n> +\t$ctext tag add link$linknum \"$start + $s2 c\" \"$start + $e2 c\"\n> +\tsetwlink $url link$linknum\n> +\tincr linknum\n> +    }\n>   }\n>   \n>   proc setlink {id lk} {\n> @@ -7064,6 +7077,18 @@ proc setlink {id lk} {\n>       }\n>   }\n>   \n> +proc setwlink {url lk} {\n> +    global ctext\n> +    global linkfgcolor\n> +    global web_browser\n> +\n> +    if {$web_browser eq {}} return\n> +    $ctext tag conf $lk -foreground $linkfgcolor -underline 1\n> +    $ctext tag bind $lk <1> [list browseweb $url]\n> +    $ctext tag bind $lk <Enter> {linkcursor %W 1}\n> +    $ctext tag bind $lk <Leave> {linkcursor %W -1}\n> +}\n> +\n>   proc appendshortlink {id {pre {}} {post {}}} {\n>       global ctext linknum\n>   \n> @@ -7098,6 +7123,16 @@ proc linkcursor {w inc} {\n>       }\n>   }\n>   \n> +proc browseweb {url} {\n> +    global web_browser\n> +\n> +    if {$web_browser eq {}} return\n> +    # Use eval here in case $web_browser is a command plus some arguments\n> +    if {[catch {eval exec $web_browser [list $url] &} err]} {\n> +\terror_popup \"[mc \"Error starting web browser:\"] $err\"\n> +    }\n> +}\n> +\n>   proc viewnextline {dir} {\n>       global canv linespc\n>   \n> @@ -11488,7 +11523,7 @@ proc create_prefs_page {w} {\n>   proc prefspage_general {notebook} {\n>       global NS maxwidth maxgraphpct showneartags showlocalchanges\n>       global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs\n> -    global hideremotes want_ttk have_ttk maxrefs\n> +    global hideremotes want_ttk have_ttk maxrefs web_browser\n>   \n>       set page [create_prefs_page $notebook.general]\n>   \n> @@ -11539,6 +11574,13 @@ proc prefspage_general {notebook} {\n>       pack configure $page.extdifff.l -padx 10\n>       grid x $page.extdifff $page.extdifft -sticky ew\n>   \n> +    ${NS}::entry $page.webbrowser -textvariable web_browser\n> +    ${NS}::frame $page.webbrowserf\n> +    ${NS}::label $page.webbrowserf.l -text [mc \"Web browser\" ]\n> +    pack $page.webbrowserf.l -side left\n> +    pack configure $page.webbrowserf.l -padx 10\n> +    grid x $page.webbrowserf $page.webbrowser -sticky ew\n> +\n>       ${NS}::label $page.lgen -text [mc \"General options\"]\n>       grid $page.lgen - -sticky w -pady 10\n>       ${NS}::checkbutton $page.want_ttk -variable want_ttk \\\n> @@ -12310,6 +12352,7 @@ if {[tk windowingsystem] eq \"win32\"} {\n>       set bgcolor SystemWindow\n>       set fgcolor SystemWindowText\n>       set selectbgcolor SystemHighlight\n> +    set web_browser \"cmd /c start\"\n>   } else {\n>       set uicolor grey85\n>       set uifgcolor black\n> @@ -12317,6 +12360,11 @@ if {[tk windowingsystem] eq \"win32\"} {\n>       set bgcolor white\n>       set fgcolor black\n>       set selectbgcolor gray85\n> +    if {[tk windowingsystem] eq \"aqua\"} {\n> +\tset web_browser \"open\"\n> +    } else {\n> +\tset web_browser \"xdg-open\"\n> +    }\n>   }\n>   set diffcolors {red \"#00a000\" blue}\n>   set diffcontext 3\n> @@ -12390,6 +12438,7 @@ set config_variables {\n>       filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor\n>       linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor\n>       indexcirclecolor circlecolors linkfgcolor circleoutlinecolor\n> +    web_browser\n>   }\n>   foreach var $config_variables {\n>       config_init_trace $var\n> \n\n"},{"id":"381393","messageId":"xmqqimqi2vtt.fsf@gitster-ct.c.googlers.com","threadId":"51749","inReplyTo":"20190826221444.GB7402@blackberry","subject":"Re: [PATCH] gitk: Make web links clickable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-27T20:32:30Z","receivedAt":"2019-08-27T20:32:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paul Mackerras <paulus@ozlabs.org> writes:\n\n> This makes gitk look for lines in the commit message which start with\n> \"Link:\" or \"BugLink:\" followed by a http or https URL, and make the\n> URL clickable.  Clicking on it will invoke an external web browser with\n> the URL.\n>\n> The web browser command is by default \"xdg-open\" on Linux, \"open\" on\n> MacOS, and \"cmd /c start\" on Windows.  The command can be changed in\n> the preferences window, and it can include parameters as well as the\n> command name.  If it is set to the empty string then URLs will no\n> longer be made clickable.\n>\n> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>\n> ---\n\n>  gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n>  1 file changed, 50 insertions(+), 1 deletion(-)\n>\n> diff --git a/gitk b/gitk\n> index a14d7a1..4577150 100755\n> --- a/gitk\n> +++ b/gitk\n> @@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {\n>  \n>  # append some text to the ctext widget, and make any SHA1 ID\n>  # that we know about be a clickable link.\n> +# Also look for lines of the form \"Link: http...\" and make them web links.\n\nFWIW, I personally hate those \"Link:\" that do not say what the links\nare for (IOW, I am OK with \"BugLink:\" or even \"Bug:\").\n\nIn any case, I polled your repository but I did not find anything to\npull.  Do you want me to start my own gitk mirror, queue this patch\nthere and pull from it myself, or is this meant to be a preview of\nwhat you'll tell me to pull in a few days?\n\nThanks.\n\n"},{"id":"381398","messageId":"20190827215832.ela2e6cuanuk6rvp@yadavpratyush.com","threadId":"51749","inReplyTo":"20190826221444.GB7402@blackberry","subject":"Re: [PATCH] gitk: Make web links clickable","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2019-08-27T21:58:32Z","receivedAt":"2019-08-27T21:58:38Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"On 27/08/19 08:14AM, Paul Mackerras wrote:\n> This makes gitk look for lines in the commit message which start with\n> \"Link:\" or \"BugLink:\" followed by a http or https URL, and make the\n> URL clickable.  Clicking on it will invoke an external web browser with\n> the URL.\n \nWhy just lines starting with \"Link:\" or \"BugLink:\"? Why not do it for \nall links?\n\n> The web browser command is by default \"xdg-open\" on Linux, \"open\" on\n> MacOS, and \"cmd /c start\" on Windows.  The command can be changed in\n> the preferences window, and it can include parameters as well as the\n> command name.  If it is set to the empty string then URLs will no\n> longer be made clickable.\n> \n> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>\n> ---\n>  gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n>  1 file changed, 50 insertions(+), 1 deletion(-)\n> \n> diff --git a/gitk b/gitk\n> index a14d7a1..4577150 100755\n> --- a/gitk\n> +++ b/gitk\n> @@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {\n>  \n>  # append some text to the ctext widget, and make any SHA1 ID\n>  # that we know about be a clickable link.\n> +# Also look for lines of the form \"Link: http...\" and make them web links.\n>  proc appendwithlinks {text tags} {\n>      global ctext linknum curview\n>  \n> @@ -7032,6 +7033,18 @@ proc appendwithlinks {text tags} {\n>  \tsetlink $linkid link$linknum\n>  \tincr linknum\n>      }\n> +    set wlinks [regexp -indices -all -inline -line \\\n> +\t\t    {^ *(Bug|)Link: (https?://.*)$} $text]\n\nWill it be a better idea to stop at the first whitespace character, \ninstead of stopping at the end of the line?\n\n> +    foreach {l sub1 sub2} $wlinks {\n> +\tset s2 [lindex $sub2 0]\n> +\tset e2 [lindex $sub2 1]\n> +\tset url [string range $text $s2 $e2]\n> +\tincr e2\n> +\t$ctext tag delete link$linknum\n> +\t$ctext tag add link$linknum \"$start + $s2 c\" \"$start + $e2 c\"\n> +\tsetwlink $url link$linknum\n> +\tincr linknum\n> +    }\n>  }\n>  \n>  proc setlink {id lk} {\n> @@ -7064,6 +7077,18 @@ proc setlink {id lk} {\n>      }\n>  }\n>  \n> +proc setwlink {url lk} {\n> +    global ctext\n> +    global linkfgcolor\n> +    global web_browser\n> +\n> +    if {$web_browser eq {}} return\n> +    $ctext tag conf $lk -foreground $linkfgcolor -underline 1\n> +    $ctext tag bind $lk <1> [list browseweb $url]\n> +    $ctext tag bind $lk <Enter> {linkcursor %W 1}\n> +    $ctext tag bind $lk <Leave> {linkcursor %W -1}\n> +}\n> +\n>  proc appendshortlink {id {pre {}} {post {}}} {\n>      global ctext linknum\n>  \n> @@ -7098,6 +7123,16 @@ proc linkcursor {w inc} {\n>      }\n>  }\n>  \n> +proc browseweb {url} {\n> +    global web_browser\n> +\n> +    if {$web_browser eq {}} return\n> +    # Use eval here in case $web_browser is a command plus some arguments\n> +    if {[catch {eval exec $web_browser [list $url] &} err]} {\n> +\terror_popup \"[mc \"Error starting web browser:\"] $err\"\n> +    }\n> +}\n> +\n>  proc viewnextline {dir} {\n>      global canv linespc\n>  \n> @@ -11488,7 +11523,7 @@ proc create_prefs_page {w} {\n>  proc prefspage_general {notebook} {\n>      global NS maxwidth maxgraphpct showneartags showlocalchanges\n>      global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs\n> -    global hideremotes want_ttk have_ttk maxrefs\n> +    global hideremotes want_ttk have_ttk maxrefs web_browser\n>  \n>      set page [create_prefs_page $notebook.general]\n>  \n> @@ -11539,6 +11574,13 @@ proc prefspage_general {notebook} {\n>      pack configure $page.extdifff.l -padx 10\n>      grid x $page.extdifff $page.extdifft -sticky ew\n>  \n> +    ${NS}::entry $page.webbrowser -textvariable web_browser\n> +    ${NS}::frame $page.webbrowserf\n> +    ${NS}::label $page.webbrowserf.l -text [mc \"Web browser\" ]\n> +    pack $page.webbrowserf.l -side left\n> +    pack configure $page.webbrowserf.l -padx 10\n> +    grid x $page.webbrowserf $page.webbrowser -sticky ew\n> +\n>      ${NS}::label $page.lgen -text [mc \"General options\"]\n>      grid $page.lgen - -sticky w -pady 10\n>      ${NS}::checkbutton $page.want_ttk -variable want_ttk \\\n> @@ -12310,6 +12352,7 @@ if {[tk windowingsystem] eq \"win32\"} {\n>      set bgcolor SystemWindow\n>      set fgcolor SystemWindowText\n>      set selectbgcolor SystemHighlight\n> +    set web_browser \"cmd /c start\"\n>  } else {\n>      set uicolor grey85\n>      set uifgcolor black\n> @@ -12317,6 +12360,11 @@ if {[tk windowingsystem] eq \"win32\"} {\n>      set bgcolor white\n>      set fgcolor black\n>      set selectbgcolor gray85\n> +    if {[tk windowingsystem] eq \"aqua\"} {\n> +\tset web_browser \"open\"\n> +    } else {\n> +\tset web_browser \"xdg-open\"\n> +    }\n>  }\n>  set diffcolors {red \"#00a000\" blue}\n>  set diffcontext 3\n> @@ -12390,6 +12438,7 @@ set config_variables {\n>      filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor\n>      linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor\n>      indexcirclecolor circlecolors linkfgcolor circleoutlinecolor\n> +    web_browser\n>  }\n>  foreach var $config_variables {\n>      config_init_trace $var\n> -- \n> 2.7.4\n> \n\n-- \nRegards,\nPratyush Yadav\n"},{"id":"381489","messageId":"20190829005011.GA3297@blackberry","threadId":"51749","inReplyTo":"xmqqimqi2vtt.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH] gitk: Make web links clickable","fromName":"Paul Mackerras","fromEmail":"paulus@ozlabs.org","sentAt":"2019-08-29T00:50:11Z","receivedAt":"2019-08-29T00:53:23Z","isPatch":true,"sender":{"key":"paulus@ozlabs.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"Hi Junio,\n\nOn Tue, Aug 27, 2019 at 01:32:30PM -0700, Junio C Hamano wrote:\n> Paul Mackerras <paulus@ozlabs.org> writes:\n> \n> > This makes gitk look for lines in the commit message which start with\n> > \"Link:\" or \"BugLink:\" followed by a http or https URL, and make the\n> > URL clickable.  Clicking on it will invoke an external web browser with\n> > the URL.\n> >\n> > The web browser command is by default \"xdg-open\" on Linux, \"open\" on\n> > MacOS, and \"cmd /c start\" on Windows.  The command can be changed in\n> > the preferences window, and it can include parameters as well as the\n> > command name.  If it is set to the empty string then URLs will no\n> > longer be made clickable.\n> >\n> > Signed-off-by: Paul Mackerras <paulus@ozlabs.org>\n> > ---\n> \n> >  gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n> >  1 file changed, 50 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/gitk b/gitk\n> > index a14d7a1..4577150 100755\n> > --- a/gitk\n> > +++ b/gitk\n> > @@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {\n> >  \n> >  # append some text to the ctext widget, and make any SHA1 ID\n> >  # that we know about be a clickable link.\n> > +# Also look for lines of the form \"Link: http...\" and make them web links.\n> \n> FWIW, I personally hate those \"Link:\" that do not say what the links\n> are for (IOW, I am OK with \"BugLink:\" or even \"Bug:\").\n> \n> In any case, I polled your repository but I did not find anything to\n> pull.  Do you want me to start my own gitk mirror, queue this patch\n> there and pull from it myself, or is this meant to be a preview of\n> what you'll tell me to pull in a few days?\n\nI was expecting some comments and suggestions, so I didn't push it out\nyet.  One suggestion which seems reasonable is to match any http or\nhttps URL anywhere in the commit description, not just with Link: or\nBugLink: at the start of the line.  What do you think of that?  It's\nquite easy to do.  Also it should stop at whitespace rather than going\nto the end of the line.\n\nPaul.\n"},{"id":"381490","messageId":"20190829012702.GB3297@blackberry","threadId":"51749","inReplyTo":"20190826221444.GB7402@blackberry","subject":"[PATCH v2] gitk: Make web links clickable","fromName":"Paul Mackerras","fromEmail":"paulus@ozlabs.org","sentAt":"2019-08-29T01:27:02Z","receivedAt":"2019-08-29T01:51:16Z","isPatch":true,"sender":{"key":"paulus@ozlabs.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"This makes gitk look for http or https URLs in the commit description\nand make the URLs clickable.  Clicking on them will invoke an external\nweb browser with the URL.\n\nThe web browser command is by default \"xdg-open\" on Linux, \"open\" on\nMacOS, and \"cmd /c start\" on Windows.  The command can be changed in\nthe preferences window, and it can include parameters as well as the\ncommand name.  If it is set to the empty string then URLs will no\nlonger be made clickable.\n\nSigned-off-by: Paul Mackerras <paulus@ozlabs.org>\n---\nv2: Match URLs anywhere, not just after [Bug]Link:.\n\n gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 50 insertions(+), 1 deletion(-)\n\ndiff --git a/gitk b/gitk\nindex a14d7a1..2a0d00c 100755\n--- a/gitk\n+++ b/gitk\n@@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {\n \n # append some text to the ctext widget, and make any SHA1 ID\n # that we know about be a clickable link.\n+# Also look for URLs of the form \"http[s]://...\" and make them web links.\n proc appendwithlinks {text tags} {\n     global ctext linknum curview\n \n@@ -7032,6 +7033,18 @@ proc appendwithlinks {text tags} {\n \tsetlink $linkid link$linknum\n \tincr linknum\n     }\n+    set wlinks [regexp -indices -all -inline -line \\\n+\t\t    {https?://[^[:space:]]+} $text]\n+    foreach l $wlinks {\n+\tset s2 [lindex $l 0]\n+\tset e2 [lindex $l 1]\n+\tset url [string range $text $s2 $e2]\n+\tincr e2\n+\t$ctext tag delete link$linknum\n+\t$ctext tag add link$linknum \"$start + $s2 c\" \"$start + $e2 c\"\n+\tsetwlink $url link$linknum\n+\tincr linknum\n+    }\n }\n \n proc setlink {id lk} {\n@@ -7064,6 +7077,18 @@ proc setlink {id lk} {\n     }\n }\n \n+proc setwlink {url lk} {\n+    global ctext\n+    global linkfgcolor\n+    global web_browser\n+\n+    if {$web_browser eq {}} return\n+    $ctext tag conf $lk -foreground $linkfgcolor -underline 1\n+    $ctext tag bind $lk <1> [list browseweb $url]\n+    $ctext tag bind $lk <Enter> {linkcursor %W 1}\n+    $ctext tag bind $lk <Leave> {linkcursor %W -1}\n+}\n+\n proc appendshortlink {id {pre {}} {post {}}} {\n     global ctext linknum\n \n@@ -7098,6 +7123,16 @@ proc linkcursor {w inc} {\n     }\n }\n \n+proc browseweb {url} {\n+    global web_browser\n+\n+    if {$web_browser eq {}} return\n+    # Use eval here in case $web_browser is a command plus some arguments\n+    if {[catch {eval exec $web_browser [list $url] &} err]} {\n+\terror_popup \"[mc \"Error starting web browser:\"] $err\"\n+    }\n+}\n+\n proc viewnextline {dir} {\n     global canv linespc\n \n@@ -11488,7 +11523,7 @@ proc create_prefs_page {w} {\n proc prefspage_general {notebook} {\n     global NS maxwidth maxgraphpct showneartags showlocalchanges\n     global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs\n-    global hideremotes want_ttk have_ttk maxrefs\n+    global hideremotes want_ttk have_ttk maxrefs web_browser\n \n     set page [create_prefs_page $notebook.general]\n \n@@ -11539,6 +11574,13 @@ proc prefspage_general {notebook} {\n     pack configure $page.extdifff.l -padx 10\n     grid x $page.extdifff $page.extdifft -sticky ew\n \n+    ${NS}::entry $page.webbrowser -textvariable web_browser\n+    ${NS}::frame $page.webbrowserf\n+    ${NS}::label $page.webbrowserf.l -text [mc \"Web browser\" ]\n+    pack $page.webbrowserf.l -side left\n+    pack configure $page.webbrowserf.l -padx 10\n+    grid x $page.webbrowserf $page.webbrowser -sticky ew\n+\n     ${NS}::label $page.lgen -text [mc \"General options\"]\n     grid $page.lgen - -sticky w -pady 10\n     ${NS}::checkbutton $page.want_ttk -variable want_ttk \\\n@@ -12310,6 +12352,7 @@ if {[tk windowingsystem] eq \"win32\"} {\n     set bgcolor SystemWindow\n     set fgcolor SystemWindowText\n     set selectbgcolor SystemHighlight\n+    set web_browser \"cmd /c start\"\n } else {\n     set uicolor grey85\n     set uifgcolor black\n@@ -12317,6 +12360,11 @@ if {[tk windowingsystem] eq \"win32\"} {\n     set bgcolor white\n     set fgcolor black\n     set selectbgcolor gray85\n+    if {[tk windowingsystem] eq \"aqua\"} {\n+\tset web_browser \"open\"\n+    } else {\n+\tset web_browser \"xdg-open\"\n+    }\n }\n set diffcolors {red \"#00a000\" blue}\n set diffcontext 3\n@@ -12390,6 +12438,7 @@ set config_variables {\n     filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor\n     linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor\n     indexcirclecolor circlecolors linkfgcolor circleoutlinecolor\n+    web_browser\n }\n foreach var $config_variables {\n     config_init_trace $var\n-- \n2.7.4\n\n"},{"id":"381492","messageId":"xmqqy2zczl9q.fsf@gitster-ct.c.googlers.com","threadId":"51749","inReplyTo":"20190829005011.GA3297@blackberry","subject":"Re: [PATCH] gitk: Make web links clickable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-29T03:46:25Z","receivedAt":"2019-08-29T03:46:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paul Mackerras <paulus@ozlabs.org> writes:\n\n> I was expecting some comments and suggestions, so I didn't push it out\n> yet.  One suggestion which seems reasonable is to match any http or\n> https URL anywhere in the commit description, not just with Link: or\n> BugLink: at the start of the line.  What do you think of that?  It's\n> quite easy to do.  Also it should stop at whitespace rather than going\n> to the end of the line.\n\nYup, that's a quite good suggestion, without little chance of false\npositive these days, as we do not have to worry about anything but\nhttp:// and https:// ;-)\n\nIn case I forgot to say in my previous message, it's been a while\nsince we heard from you the last time.  Welcome back ;)\n\n"},{"id":"381534","messageId":"20190829183207.sy66tyxnnzgvjv35@yadavpratyush.com","threadId":"51749","inReplyTo":"20190829012702.GB3297@blackberry","subject":"Re: [PATCH v2] gitk: Make web links clickable","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2019-08-29T18:32:07Z","receivedAt":"2019-08-29T18:32:15Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"On 29/08/19 11:27AM, Paul Mackerras wrote:\n> This makes gitk look for http or https URLs in the commit description\n> and make the URLs clickable.  Clicking on them will invoke an external\n> web browser with the URL.\n> \n> The web browser command is by default \"xdg-open\" on Linux, \"open\" on\n> MacOS, and \"cmd /c start\" on Windows.  The command can be changed in\n> the preferences window, and it can include parameters as well as the\n> command name.  If it is set to the empty string then URLs will no\n> longer be made clickable.\n> \n> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>\n> ---\n> v2: Match URLs anywhere, not just after [Bug]Link:.\n> \n>  gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n>  1 file changed, 50 insertions(+), 1 deletion(-)\n> \n> diff --git a/gitk b/gitk\n> index a14d7a1..2a0d00c 100755\n> --- a/gitk\n> +++ b/gitk\n> @@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {\n>  \n>  # append some text to the ctext widget, and make any SHA1 ID\n>  # that we know about be a clickable link.\n> +# Also look for URLs of the form \"http[s]://...\" and make them web links.\n>  proc appendwithlinks {text tags} {\n>      global ctext linknum curview\n>  \n> @@ -7032,6 +7033,18 @@ proc appendwithlinks {text tags} {\n>  \tsetlink $linkid link$linknum\n>  \tincr linknum\n>      }\n> +    set wlinks [regexp -indices -all -inline -line \\\n> +\t\t    {https?://[^[:space:]]+} $text]\n\nI know I suggested searching till the first non-whitespace character, \nbut thinking more about, there are some problematic cases. Say someone \nhas a commit message like:\n  \n  Foo bar baz (more details at https://example.com/hello)\n\nOr like:\n\n  Check out https://foo.com, https://bar.com\n\nIn the first example, the closing parenthesis gets included in the link, \nbut shouldn't be. In the second, the comma after foo.com would be \nincluded in the link, but shouldn't be. So maybe use a more \nsophisticated regex?\n\nA quick Google search gives out the following options [0][1].\n\n[0] gives the following regex:\n\n  https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)\n\nIt is kind of ugly to look at, and I'm not even sure if there are any \nsyntax differences with Tcl's regex library.\n\n[1] lists a bunch of regexes and which URLs they work on and which ones \nthey don't. The smallest among them I found is:\n\n  @^(https?|ftp)://[^\\s/$.?#].[^\\s]*$@iS\n\nAgain, I'm not sure how well this would work with Tcl's regex library, \nor how commonly these URL patterns appear in actual commit messages.  \nJust something to consider.\n\n[0] https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url\n[1] https://mathiasbynens.be/demo/url-regex\n\n[snip]\n\n-- \nRegards,\nPratyush Yadav\n"},{"id":"382354","messageId":"20190913233307.GA29205@blackberry","threadId":"51749","inReplyTo":"20190829183207.sy66tyxnnzgvjv35@yadavpratyush.com","subject":"Re: [PATCH v2] gitk: Make web links clickable","fromName":"Paul Mackerras","fromEmail":"paulus@ozlabs.org","sentAt":"2019-09-13T23:33:07Z","receivedAt":"2019-09-14T01:54:44Z","isPatch":true,"sender":{"key":"paulus@ozlabs.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"On Fri, Aug 30, 2019 at 12:02:07AM +0530, Pratyush Yadav wrote:\n> On 29/08/19 11:27AM, Paul Mackerras wrote:\n> > This makes gitk look for http or https URLs in the commit description\n> > and make the URLs clickable.  Clicking on them will invoke an external\n> > web browser with the URL.\n> > \n> > The web browser command is by default \"xdg-open\" on Linux, \"open\" on\n> > MacOS, and \"cmd /c start\" on Windows.  The command can be changed in\n> > the preferences window, and it can include parameters as well as the\n> > command name.  If it is set to the empty string then URLs will no\n> > longer be made clickable.\n> > \n> > Signed-off-by: Paul Mackerras <paulus@ozlabs.org>\n> > ---\n> > v2: Match URLs anywhere, not just after [Bug]Link:.\n> > \n> >  gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-\n> >  1 file changed, 50 insertions(+), 1 deletion(-)\n> > \n> > diff --git a/gitk b/gitk\n> > index a14d7a1..2a0d00c 100755\n> > --- a/gitk\n> > +++ b/gitk\n> > @@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {\n> >  \n> >  # append some text to the ctext widget, and make any SHA1 ID\n> >  # that we know about be a clickable link.\n> > +# Also look for URLs of the form \"http[s]://...\" and make them web links.\n> >  proc appendwithlinks {text tags} {\n> >      global ctext linknum curview\n> >  \n> > @@ -7032,6 +7033,18 @@ proc appendwithlinks {text tags} {\n> >  \tsetlink $linkid link$linknum\n> >  \tincr linknum\n> >      }\n> > +    set wlinks [regexp -indices -all -inline -line \\\n> > +\t\t    {https?://[^[:space:]]+} $text]\n> \n> I know I suggested searching till the first non-whitespace character, \n> but thinking more about, there are some problematic cases. Say someone \n> has a commit message like:\n>   \n>   Foo bar baz (more details at https://example.com/hello)\n> \n> Or like:\n> \n>   Check out https://foo.com, https://bar.com\n> \n> In the first example, the closing parenthesis gets included in the link, \n> but shouldn't be. In the second, the comma after foo.com would be \n> included in the link, but shouldn't be. So maybe use a more \n> sophisticated regex?\n\nI did think about that, but it seems to be impossible to get it right\nin all cases, so I went for simple and obvious.  In particular I don't\nsee how to handle the common case of a '.' immediately following the\nURL, since '.' is a legal character in a URL.\n\n> A quick Google search gives out the following options [0][1].\n> \n> [0] gives the following regex:\n> \n>   https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)\n> \n> It is kind of ugly to look at, and I'm not even sure if there are any \n> syntax differences with Tcl's regex library.\n> \n> [1] lists a bunch of regexes and which URLs they work on and which ones \n> they don't. The smallest among them I found is:\n> \n>   @^(https?|ftp)://[^\\s/$.?#].[^\\s]*$@iS\n> \n> Again, I'm not sure how well this would work with Tcl's regex library, \n> or how commonly these URL patterns appear in actual commit messages.  \n> Just something to consider.\n> \n> [0] https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url\n> [1] https://mathiasbynens.be/demo/url-regex\n\nI think I would be inclined to make the regex customizable, since that\nwould also allow the user to match ftp or other URLs if they want.\nThe only difficulty with that is if there are subexpressions, that\nwill change how we have to interpret the list returned by the\nregexp -indices -all -inline command.\n\nPaul.\n"},{"id":"382366","messageId":"20190914143050.jiax3vhm3ng7glew@yadavpratyush.com","threadId":"51749","inReplyTo":"20190913233307.GA29205@blackberry","subject":"Re: [PATCH v2] gitk: Make web links clickable","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2019-09-14T14:30:50Z","receivedAt":"2019-09-14T14:30:56Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"On 14/09/19 09:33AM, Paul Mackerras wrote:\n> On Fri, Aug 30, 2019 at 12:02:07AM +0530, Pratyush Yadav wrote:\n> > On 29/08/19 11:27AM, Paul Mackerras wrote:\n> > \n> > I know I suggested searching till the first non-whitespace character, \n> > but thinking more about, there are some problematic cases. Say someone \n> > has a commit message like:\n> >   \n> >   Foo bar baz (more details at https://example.com/hello)\n> > \n> > Or like:\n> > \n> >   Check out https://foo.com, https://bar.com\n> > \n> > In the first example, the closing parenthesis gets included in the link, \n> > but shouldn't be. In the second, the comma after foo.com would be \n> > included in the link, but shouldn't be. So maybe use a more \n> > sophisticated regex?\n> \n> I did think about that, but it seems to be impossible to get it right\n> in all cases, so I went for simple and obvious.  In particular I don't\n> see how to handle the common case of a '.' immediately following the\n> URL, since '.' is a legal character in a URL.\n> \n> > A quick Google search gives out the following options [0][1].\n> > \n> > [0] gives the following regex:\n> > \n> >   https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)\n> > \n> > It is kind of ugly to look at, and I'm not even sure if there are any \n> > syntax differences with Tcl's regex library.\n> > \n> > [1] lists a bunch of regexes and which URLs they work on and which ones \n> > they don't. The smallest among them I found is:\n> > \n> >   @^(https?|ftp)://[^\\s/$.?#].[^\\s]*$@iS\n> > \n> > Again, I'm not sure how well this would work with Tcl's regex library, \n> > or how commonly these URL patterns appear in actual commit messages.  \n> > Just something to consider.\n> > \n> > [0] https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url\n> > [1] https://mathiasbynens.be/demo/url-regex\n> \n> I think I would be inclined to make the regex customizable, since that\n> would also allow the user to match ftp or other URLs if they want.\n> The only difficulty with that is if there are subexpressions, that\n> will change how we have to interpret the list returned by the\n> regexp -indices -all -inline command.\n\nThat just puts the responsibility of parsing the URL on the user, it \ndoesn't solve the problem.\n\nI don't have any numbers, but I think most problematic cases are when \nthere are some trailing characters. We aren't dealing with malicious \nactors that want to do something bad or make gitk crash. IMO it is \nreasonable to expect legal URLs in a commit message.\n\nSo instead of trying to encompass all possible legal URLs and removing \nall illegal URLs, how about using a simple regex for basic filtering to \nweed out some false positives, and then trimming illegal trailing \ncharacters. These trailing characters would most likely be comma, \nperiod, parenthesis, question marks, quotation marks, etc. This way the \nlogic stays simple and we tackle more real world problems.\n\nSounds reasonable?\n\n-- \nRegards,\nPratyush Yadav\n"}]}