2016-09-12 23 views
2

有沒有一種簡單的方法來找到一個特定文件存在的svn倉庫中的所有路徑(標籤和分支)?如何在svn中查找一個文件的所有副本?

我知道在trunk上檢查了文件的修訂版本,當它被刪除時,我需要在這兩個修訂版本之間找到所有分支,標籤和可能的其他路徑副本。

+0

簡單的辦法:去你的build文件夾>>右鍵點擊>>進入了TortoiseSVN >>點擊庫瀏覽器。在這裏你將得到所有文件存在的路徑。 – UDID

+0

你嘗試過svn責備嗎?它在你的情況下工作嗎?你也可以使用'svn log --search'。 – bahrep

+0

@bahrep'svn blame'只顯示關於什麼版本改變了我文件的哪一部分的信息。我需要找到包含(或曾經包含)一些特定文件的所有分支和標籤。 'svn log --search'可能已經可以使用,但我不確定我是否能夠搜索文件的重命名,或者只是原始文件名,並希望所有副本都使用該名稱。 –

回答

2

我終於實現了整個日誌的處理在PowerShell中:

$repository = 'http://REPOSITORY/url' 
$badPaths = @('/paths/to/first/commit/of/files/to/track') 
function Delete-Nodes 
{ 
    param([xml]$xml, [string]$xpath) 
    $nodes = $xml.SelectNodes($xpath); 

    for ($i = $nodes.Count -1; $i -ge 0; $i--) 
    { 
     $nodes[$i].ParentNode.RemoveChild($nodes[$i]) *>$null 
    } 
} 

[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding 
Measure-Command { [xml]$all_revs = svn log $repository -r1:HEAD -v --xml } 

$all_revs.SelectNodes('//logentry').Count 
$badPathXpath=[string]::Join(' or ', ($badPaths | % { "text()='$_'" })) 

Delete-Nodes -xml $all_revs -xpath "//path[@action='M']" 
Delete-Nodes -xml $all_revs -xpath "//path[@action='A' and not($badPathXpath) and not(@copyfrom-path)]" # For additions we only care about our bad paths or any copies (from those) 
Delete-Nodes -xml $all_revs -xpath "/log/logentry/paths[not(descendant::path)]" 
Delete-Nodes -xml $all_revs -xpath "/log/logentry[not(descendant::paths)]" 

$monitoredPaths = @{} 

foreach ($logentry in $all_revs.log.logentry) 
{ 
    foreach ($path in $logentry.paths.path) 
    { 
     $used = $true 
     $action = $path.action 
     $from_path = $path.Attributes['copyfrom-path'].Value 
     $from_rev = $path.Attributes['copyfrom-rev'].Value 
     $revision = $logentry.revision 
     $value = $path.InnerText 

     if ($action -eq 'A' -and -not $from_path) 
     {    
      if (($badPaths | % { $value.StartsWith($_) } | Where { $_ }).Count -gt 0) 
      { 
       $monitoredPaths[$value] = New-Object PSObject -Property (@{ 'Added' = $revision; 'Deleted' = $null }) 
      } 
      else 
      { 
       $used = $false 
      } 
     } 
     elseif ($monitoredPaths.Count -gt 0 -and $from_path -and -not $monitoredPaths.ContainsKey($value)) 
     { 
      $paths = $monitoredPaths.Keys | Where-Object { $val = $monitoredPaths[$_]; ($from_path -eq $_ -or $_.StartsWith("$from_path/") -or $from_path.StartsWith("$_/")) -and ($from_rev -ge $val.Added -and (-not $val.Deleted -or $val.Deleted -gt $from_rev)) } 
      if ($paths.Count -gt 0) 
      { 
       foreach ($copied_path in $paths) 
       { 
        if ($copied_path.StartsWith("$from_path/")) 
        { 
         $sub_directory = $copied_path.SubString($from_path.Length) 
         $newPath = "$value$sub_directory" 
        } 
        else 
        { 
         $newPath = "$value" 
        } 

        if (($monitoredPaths.Keys | Where-Object { $newPath.StartsWith("$_/") -and -not $monitoredPaths[$_].Deleted }).Count -eq 0) 
        { 
         $monitoredPaths[$newPath] = New-Object PSObject -Property (@{ 'Added' = $revision; 'Deleted' = $null }) 
        } 
        else 
        { 
         $used = $false 
        } 
       } 
      } 
      else 
      { 
       $used = $false 
      } 
     } 
     elseif ($action -eq 'D' -and $monitoredPaths.ContainsKey($value)) 
     { 
      $monitoredPaths[$value].Deleted = $revision 
     } 
     elseif ($action -eq 'D') 
     { 
      $used = $false 
      foreach ($path in ($monitoredPaths.Keys | Where-Object { $_.StartsWith("$value/") -and -not $monitoredPaths[$_].Deleted })) 
      { 
       $monitoredPaths[$path].Deleted = $revision 
       $used = $true 
      } 
     } 
     else 
     { 
      $used = $false 
     } 

     if (-not $used) 
     { 
      $logentry.paths.RemoveChild($path) *>$null 
     } 
    } 
} 
相關問題