git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] gitk: Make web links clickable

From
Pratyush Yadav <me@yadavpratyush.com>
Date
Aug 29, 2019, 18:32 UTC
Message-ID
<20190829183207.sy66tyxnnzgvjv35@yadavpratyush.com>
In-Reply-To
<20190829012702.GB3297@blackberry>
On 29/08/19 11:27AM, Paul Mackerras wrote:
Show 35 quoted lines
> This makes gitk look for http or https URLs in the commit description
> and make the URLs clickable.  Clicking on them will invoke an external
> web browser with the URL.
> 
> The web browser command is by default "xdg-open" on Linux, "open" on
> MacOS, and "cmd /c start" on Windows.  The command can be changed in
> the preferences window, and it can include parameters as well as the
> command name.  If it is set to the empty string then URLs will no
> longer be made clickable.
> 
> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
> ---
> v2: Match URLs anywhere, not just after [Bug]Link:.
> 
>  gitk | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/gitk b/gitk
> index a14d7a1..2a0d00c 100755
> --- a/gitk
> +++ b/gitk
> @@ -7016,6 +7016,7 @@ proc commit_descriptor {p} {
>  
>  # append some text to the ctext widget, and make any SHA1 ID
>  # that we know about be a clickable link.
> +# Also look for URLs of the form "http[s]://..." and make them web links.
>  proc appendwithlinks {text tags} {
>      global ctext linknum curview
>  
> @@ -7032,6 +7033,18 @@ proc appendwithlinks {text tags} {
>  	setlink $linkid link$linknum
>  	incr linknum
>      }
> +    set wlinks [regexp -indices -all -inline -line \
> +		    {https?://[^[:space:]]+} $text]
I know I suggested searching till the first non-whitespace character, 
but thinking more about, there are some problematic cases. Say someone 
has a commit message like:
  
  Foo bar baz (more details at https://example.com/hello)
Or like:
  Check out https://foo.com, https://bar.com

In the first example, the closing parenthesis gets included in the link, but shouldn't be. In the second, the comma after foo.com would be included in the link, but shouldn't be. So maybe use a more sophisticated regex?

A quick Google search gives out the following options [0][1].
[0] gives the following regex:
  https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)

It is kind of ugly to look at, and I'm not even sure if there are any syntax differences with Tcl's regex library.

[1] lists a bunch of regexes and which URLs they work on and which ones they don't. The smallest among them I found is:

  @^(https?|ftp)://[^\s/$.?#].[^\s]*$@iS

Again, I'm not sure how well this would work with Tcl's regex library, or how commonly these URL patterns appear in actual commit messages. Just something to consider.

[0] https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url [1] https://mathiasbynens.be/demo/url-regex

[snip]
-- 
Regards,
Pratyush Yadav
Previous: Paul MackerrasNext: Paul Mackerras
Message 8 of 10 in “gitk: Make web links clickable”
  1. gitk: Make web links clickablePaul Mackerras, Aug 26, 2019
  2. Barret RhodenAug 27, 2019
  3. Junio C HamanoAug 27, 2019
  4. Paul MackerrasAug 29, 2019
  5. Junio C HamanoAug 29, 2019
  6. Pratyush YadavAug 27, 2019
  7. gitk: Make web links clickablePaul Mackerras, Aug 29, 2019
  8. Pratyush YadavAug 29, 2019
  9. Paul MackerrasSep 13, 2019
  10. Pratyush YadavSep 14, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.