1

私はこの問題を抱えています:Subversionリポジトリが与えられた場合、リポジトリhttp://svn/trunk/全体を検索して、名前が付けられたすべてのファイルexp.xml(それらのURL全体)を検索/一覧表示したいと思います。最初のオカレンスが見つかったら、URLのさらに下の検索を停止します。明確にするために、ここにいくつかの架空のURLがあります。

http://svn/trunk/pro1/sub-pro-x/exp.xml/sub-pro-x1/exp.xml
http://svn/trunk/pro2/sub-pro-y/pro-y1/exp.xml/sub-pro-y1/exp.xml
http://svn/trunk/pro3/sub-pro-z/exp.xml/sub-pro-z1/exp.xml/sub-proj/exp.xml

結果は次のようになります。

http://svn/trunk/pro1/sub-pro-x/exp.xml
http://svn/trunk/pro2/sub-pro-y/pro-y1/exp.xml
http://svn/trunk/pro3/sub-pro-z/exp.xml

今、私はすでに解決策を持っていますが、リポジトリ全体を検索したgrep exp.xml後に使用するため、あまり効率的ではありません(30〜40分)。svn -R list ---知りたい場合は、次のコマンドを使用してください。

svn list -R http://svn/trunk | grep /exp.xml

だから私の質問は、このクエリを大幅に高速化することが可能かどうかです。私が考えていることの1つは、言語、できればPerlを使用して、すべてのリンクを直接トラバースしhttp:/svn/trunk/て処理し、最初のリンクが見つかったらそれ以上のトラバースを停止することexp.xmlです。

御時間ありがとうございます。

4

2 に答える 2

1

If you want it to be faster, I would try checking out the SVN project and then searching the files on disk. You could perform a search using "find" in the checked-out sandbox (where "." assumes you are in the top directory of your project):

find . -name 'exp.xml'

but, similar to your "grep" solution, I don't think it achieves your "stop searching further" criteria. If you want a Perl script to search for "exp.xml" but stop recursing if it finds a match, try this (takes top level directory as argument):

#!/usr/bin/env perl
use warnings;
use strict;

my @dirs = $ARGV[0];

my @files;
DIR:
while (my $dir = shift @dirs) {
    opendir(my $dh, $dir) or die "Couldn't open dir $dir: $!";

    my @new_dirs;
    while (my $file = readdir($dh)) {
        # skip special directories (".", "..", and ".svn")
        next if $file =~ /^\./;

        # turn file into correct relative path
        $file = "$dir/$file";

        if (-d $file) {
            push @new_dirs, $file;
        }
        if ($file eq "$dir/exp.xml") {
            # if we matched, next outer loop so we don't recurse further
            push @files, $file;
            next DIR;
        }
    }
    # if we didn't match any files, we need to check sub-dirs
    push @dirs, @new_dirs;
}

print "$_\n" for @files;
于 2012-04-29T00:23:54.580 に答える
0

svn ls [URL]スクリプトでまたはを使用svn ls -R [URL]して、[URL] で始まる SVN リポジトリを一覧表示します。詳細については、を参照svn ls --helpしてください。

于 2012-04-29T07:44:27.220 に答える