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

Re: [PATCH] gitk: Fix how remote branch names with / are drawn

From
Mike Rappazzo <rappazzo@gmail.com>
Date
Apr 13, 2016, 11:35 UTC
Message-ID
<CANoM8SXixymz3=NQWgG5vSo7XDNh18_OzrNXU4+Y8CQ0LkB6sw@mail.gmail.com>
In-Reply-To
<1460512743-27100-1-git-send-email-odinguru@gmail.com>
On Tue, Apr 12, 2016 at 9:59 PM, David Holmer <odinguru@gmail.com> wrote:
Show 37 quoted lines
> Consider this example branch:
>
> remotes/origin/master
>
> gitk displays this branch with different background colors for each part:
> "remotes/origin" in orange and "master" in green. The idea is to make it
> visually easy to read the branch name separately from the remote name.
>
> However this fails when given this example branch:
>
> remotes/origin/foo/bar
>
> gitk displays this branch with "remotes/origin/foo" in orange and "bar" in
> green. This makes it hard to read the branch name "foo/bar". This is due
> to an inappropriately greedy regexp. This patch provides a fix so the same
> branch will now be displayed with "remotes/origin" in orange and "foo/bar"
> in green.
>
> Signed-off-by: David Holmer <odinguru@gmail.com>
> ---
>  gitk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gitk b/gitk
> index 805a1c7..ca2392b 100755
> --- a/gitk
> +++ b/gitk
> @@ -6640,7 +6640,7 @@ proc drawtags {id x xt y1} {
>             set xl [expr {$xl - $delta/2}]
>             $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
>                 -width 1 -outline black -fill $col -tags tag.$id
> -           if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
> +           if {[regexp {^(remotes/[^/]*/|remotes/)} $tag match remoteprefix]} {
>                 set rwid [font measure mainfont $remoteprefix]
>                 set xi [expr {$x + 1}]
>                 set yti [expr {$yt + 1}]
> --

This likely fixes the problem for most situations, but doesn't for a remote with a '/' in the name. Yet, I think this is a better state than the present.

Is the regex `[^/]*/` more efficient than '.*?/`? Or do you find the former more readable?

Previous: David HolmerNext: David Holmer
Message 2 of 4 in “gitk: Fix how remote branch names with / are drawn”
  1. gitk: Fix how remote branch names with / are drawnDavid Holmer, Apr 13, 2016
  2. Mike RappazzoApr 13, 2016
  3. David HolmerApr 13, 2016
  4. Mike RappazzoApr 13, 2016

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.