如何在 SubVersion 存储库中搜索文件的所有修订版? [英] How do I search all revisions of a file in a SubVersion repository?

查看:29
本文介绍了如何在 SubVersion 存储库中搜索文件的所有修订版?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想grep 一个字符串的文件的所有修订.例如查找何时添加或删除功能.

I'd like to grep all revisions of a file for a string. e.g. to find when a function was added or removed.

有没有简单"的方法来做到这一点?(即单个 bash 命令行会很好.)通过检查修订和单独测试来进行手动二进制搜索似乎太乏味且容易出错.

Is there a "simple" way to do this? (i.e. a single bash command line would be nice.) Doing a manual binary search by checking out revisions and testing individually seems too tedious and error prone.

如果我足够聪明,可以用有用的描述提交更改,那么我可以grep 使用以下内容grep 日志:

If I was smart enough to commit the change with a useful description then I can grep the log with something like:

svn log myfile.c | grep my_func

虽然这并没有提供修订号,所以我怀疑还有更好的方法可以做到这一点.

This doesn't provide a revision number though, so I suspect there's a better way to do that too.

推荐答案

我写了一个脚本来做到这一点

I wrote a script to do it

典型用法:

perl searchrev.pl Import.php setImportStatus

----------------------------------------------------------------------
r19565 | johnf | 2009-06-24 14:33:00 +0100 (Wed, 24 Jun 2009) | 1 line
----------------------------------------------------------------------
line 60 $this->setImportStatus($entity_id, $entity_attr_id);
---------------------------------------------------------------------
r13722 | john | 2008-03-10 17:06:14 +0000 (Mon, 10 Mar 2008) | 1 line
---------------------------------------------------------------------
line 70 $this->setImportStatus($entity_id, $entity_attr_id);
---------------------------------------------------------------------
r11692 | paul | 2007-05-23 10:55:45 +0100 (Wed, 23 May 2007) | 1 line
---------------------------------------------------------------------
Not found
---------------------------------------------------------------------
r11691 | paul | 2007-05-23 10:36:26 +0100 (Wed, 23 May 2007) | 1 line
---------------------------------------------------------------------
Not found
---------------------------------------------------------------------
r11683 | paul | 2007-05-23 09:04:29 +0100 (Wed, 23 May 2007) | 1 line
---------------------------------------------------------------------
Not found

这是脚本,很容易为你自己的目的而破解

Here's the script, easy to hack for your own purposes

#!/usr/bin/perl -w

my $file=$ARGV[0];
my $pattern=$ARGV[1];

my @history=`svn log $file`;
foreach (@history)
{
    chomp;
    if (m/^r(\d+)/)
    {
        my $revision=$1;
        my $sep='-' x length($_);

        print "$sep\n$_\n$sep\n";

        my @code=`svn cat -r $revision $file`;
        my $lineno=0;
        my $found=0;
        foreach my $line (@code)
        {
            $lineno++;
            if ($line=~m/$pattern/)
            {
                $line=~s/^\s+//;
                print "line $lineno $line";
                 $found=1;
            }
        }

        print "Not found\n" unless ($found);
    }
}

这篇关于如何在 SubVersion 存储库中搜索文件的所有修订版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆