git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pat Thoyts <patthoyts@googlemail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Kirill <kirillathome@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	msysgit@googlegroups.com, git@vger.kernel.org
Subject: Re: [GITK PATCH 2/3] gitk: support path filters even in  subdirectories
Date: Thu, 25 Feb 2010 01:51:31 +0000	[thread overview]
Message-ID: <a5b261831002241751v5294af48rac8b5f52ba6cb045@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.1.00.1002232122110.3980@intel-tinevez-2-302>

On 23 February 2010 20:22, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> Hi,
>
> On Tue, 23 Feb 2010, Kirill wrote:
>
>> I believe the fact that pathprefix is set only under several conditions,
>> the invocation without arguments is broken.
>
> You are absolutely correct!
>
> Will fix and push to work/gitk-dashdash-dot,
> Dscho

This doesn't seem to work for me. We are trying to have the file tree
window display filenames when 'gitk -- .' is used and with your patch
this isn't happening when I apply this to gitk. I broke out the
path_filter function into a separate test to play with it a bit. It
seems this function is trying to match a path prefix to the provided
file name so here is a test script with three implementations. The
original, dscho's new one (git rev-parse --show-prefix returns an
empty string when run in the toplevel directory so I force the
'pathprefix' variable for the tests).

With this script I get the following results:
C:\src\gitk>tclsh told.tcl
original-2 failed . gitk expected 1 got 0
original-3 failed ./ gitk expected 1 got 0
original-5 failed ./po po/de.po expected 1 got 0
dscho-2 failed . gitk expected 1 got 0
dscho-3 failed ./ gitk expected 1 got 0
dscho-5 failed ./po po/de.po expected 1 got 0

So it looks like a simple string match on a normalized path works ok.
[file normalize $name] doesn't require the target file to exists btw.

--- test script begins ---

proc path_filter_orig {filter name} {
    foreach p $filter {
        set l [string length $p]
	if {[string index $p end] eq "/"} {
	    if {[string compare -length $l $p $name] == 0} {
		return 1
	    }
	} else {
	    if {[string compare -length $l $p $name] == 0 &&
		([string length $name] == $l ||
		 [string index $name $l] eq "/")} {
		return 1
	    }
	}
    }
    return 0
}

proc path_filter_dscho {filter name} {
    set pathprefix ""
    foreach p $filter {
        if {$p == "."} {
            set p $pathprefix
        } else {
            set p $pathprefix$p
        }
        set l [string length $p]
	if {[string index $p end] eq "/"} {
	    if {[string compare -length $l $p $name] == 0} {
		return 1
	    }
	} else {
	    if {[string compare -length $l $p $name] == 0 &&
		([string length $name] == $l ||
		 [string index $name $l] eq "/")} {
		return 1
	    }
	}
    }
    return 0
}

proc path_filter {filter name} {
    set name [file normalize $name]
    foreach p $filter {
        set p [file normalize $p]
        if {[string equal $p $name] || [string match $p* $name]} {
            return 1
        }
    }
    return 0
}

set tests {
    1  ""   gitk   0
    2  .    gitk   1
    3  ./   gitk   1
    4  po   po/de.po  1
    5  ./po po/de.po 1
    6  po   gitk   0
    7  po   a/b    0
    8  a    a/b/c  1
}

foreach {id filter name result} $tests {
    set testresult [path_filter_orig $filter $name]
    if {$testresult != $result} {
        puts "original-$id failed $filter $name expected $result got
$testresult"
    }
}

foreach {id filter name result} $tests {
    set testresult [path_filter_dscho $filter $name]
    if {$testresult != $result} {
        puts "dscho-$id failed $filter $name expected $result got $testresult"
    }
}

foreach {id filter name result} $tests {
    set testresult [path_filter $filter $name]
    if {$testresult != $result} {
        puts "new-$id failed $filter $name expected $result got $testresult"
    }
}

  reply	other threads:[~2010-02-25  1:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f579dd581002200847o340a3eb9l50d0f1329d4e2c23@mail.gmail.com>
     [not found] ` <alpine.DEB.1.00.1002201847290.20986@pacific.mpi-cbg.de>
     [not found]   ` <a5b261831002200948v3c01708dv3e42d08d42e3119@mail.gmail.com>
     [not found]     ` <alpine.DEB.1.00.1002201920350.20986@pacific.mpi-cbg.de>
2010-02-23 16:51       ` [GITK PATCH] gitk: support "gitk <tracheophyte> -- ." Johannes Schindelin
2010-02-23 17:10         ` [GITK PATCH 2/3] gitk: support path filters even in subdirectories Johannes Schindelin
2010-02-23 17:12           ` [GITK PATCH 3/3] gitk: strip prefix from filenames " Johannes Schindelin
2010-02-23 19:42             ` Kirill
2010-02-23 20:50               ` Johannes Schindelin
2010-02-23 22:20                 ` Kirill
2010-02-23 19:37           ` [GITK PATCH 2/3] gitk: support path filters even " Kirill
2010-02-23 20:22             ` Johannes Schindelin
2010-02-25  1:51               ` Pat Thoyts [this message]
2010-02-25 14:22                 ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a5b261831002241751v5294af48rac8b5f52ba6cb045@mail.gmail.com \
    --to=patthoyts@googlemail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=kirillathome@gmail.com \
    --cc=msysgit@googlegroups.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).