How to find all 'SVN working copies' on Wi

2019-05-21 09:42发布

I have Windows XP. I'd like to upgrade my TortoiseSVN to version 1.7. In order to do that I need to ensure that I can find all SVN working copies on my PC. So they can be updated.

I have found a similar question but it is specific to Powershell. So, I was wondering if there was a more general solution to find all 'SVN working copies' on Win XP.

If I knew the equivalent of 'linux find' on windows I could probably write it myself. But I'm hoping that there may be a bash script out there already (or maybe some solution that's even simpler) that me and others could use.

  • scans the computer
  • if it finds a directory that contains a directory called ".svn"
    • echo that name, and
    • breaks from searching that directory any more

4条回答
Root(大扎)
2楼-- · 2019-05-21 10:27

I have managed to find all 'SVN working copies' on Win XP.

I did it using the PowerSell script provided by Alexey Shcherbak.

Here is a summary of the process using the PowerShell method.

Test to see if you have PowerShell already installed.

Windows PowerShell is a command-line shell and scripting environment that brings the power of the .NET Framework to command-line users and script writers.

Test to see if it is already installed by attempting to start it.

To start Windows PowerShell from the Run box, click Start, click Run, and type:

powershell

If that does not work...

Install it

  • Download Microsoft Windows PowerShell 1.0 for Windows XP from Cnet.com
  • (PowerShell 2 for Windows XP is also available, but I did not use it. (instructions here) )

Once its installed...

Start PowerShell and have a play

Start > All Programs > Windows PowerShell 1.0 > Windows PowerShell

See a brief introduction to PowerShell on YouTube.

Create a PowerShell script

Copy Alexey Shcherbak's PowerSell script (that finds the svn working copies) into a text file and save it as something like C:\PowerShellScripts\FindSvnWorkingDirectories.ps1.

I modified it slightly to search my C drive and to suppress access denied errors :

$prev = "^$"

Get-ChildItem -ErrorAction SilentlyContinue -Recurse -Force -Include ".svn" -Path "c:\" `
| ?{$_.PSIsContainer -and $_.Fullname.StartsWith($prev)-eq $false}`
| %{ $prev=$_.Fullname.TrimEnd(".svn"); $prev}

To explain what this script does in detail:

$prev = "^$" initialises $prev to empty-matching regex; ^$ will never match any meaningful value (except startline-endline). This was needed to pass initial check.

Get-ChildItem -ErrorAction SilentlyContinue -Recurse -Force -Include ".svn" -Path "c:\" `

Gets all objects with name ".svn" (in our case - all files and folders with exact name ".svn"), started from Path, Recursively.

  • Get-ChildItem, by default, is an alias of the dir command.
  • -ErrorAction SilentlyContinue - Prevents showing errors such as Access to the path 'C:\System Volume Information' is denied as described here.
  • -Recurse means search recusively.
  • -Force ensures hidden files are found.
  • -Include ".svn" identifies the filename that we are searching for.
  • -Path "c:\" idientifies the path to search.
  • ` The backtick means continue the statement to the next line.

On the next line:

| ?{$_.PSIsContainer -and $_.Fullname.StartsWith($prev)-eq $false}`

The pipe symbol, |, pipes the output of Get-ChildItem into the next cmdlets.

?{...statements... } is shorthand for the Where-Object cmdlet.

$_ is the way to address "each" entry from pipe. It basically says "If entry is a directory" and "fullname does not start with value from $prev", then "Pass entry to next construct".

| %{ $prev=$_.Fullname.TrimEnd(".svn"); $prev}

The entry is then piped to the next statement.

%{} is shorthand for Foreach-Object. This construct does 2 things:

  • Assign the current folder's fullname to $prev (without the ".svn" tail).
  • Pass $prev to the next pipeline sink.

Allow PowerShell to run the script

By default, for security, PowerShell's ExecutionPolicy does not let you run PowerShell scripts. So, you need to allow it to do so.

See Running Windows PowerShell Scripts for more info.

I did the following:

Note: The hash symbol (#) is just shotrthand for the command prompt.

Determine the current ExecutionPolicy:

# Get-ExecutionPolicy
Restricted

If, like mine, its Restricted. Change the policy to allow a script to run:

# Set-ExecutionPolicy RemoteSigned

Run the PowerShell script

Then run the script to find the svn working copies. Note you need to specify the full path to the PowerShell script.

# C:\PowerShellScripts\FindSvnWorkingDirectories.ps1

If there are loads of directories on the PC it may take some time. The results should appear.

Copy and Paste the results to somewhere

I did this by selecting the output text with my mouse. Then, to copy it:

Click the PowerShell icon (in the top-left of the Window) > Edit > Copy

Then I pasted it into a text editor.

Revert the PowerShell Excecution Policy to its original state

Since I rarely use PowerShell and I loosened the Excecution Policy only to run this, one-off, script I am going to revert it back to its orignal state for security.

Determine the current ExecutionPolicy:

# Get-ExecutionPolicy
RemoteSigned

Change the policy to revert it to its original state:

# Set-ExecutionPolicy Restricted

So that's how I did it.

查看更多
Luminary・发光体
3楼-- · 2019-05-21 10:29

As soon as you have powershell, I could provide my full script to upgrade working copies to 1.7

$prev = "^$"
$workingCopies = Get-ChildItem -Recurse -Force -Include ".svn" -Path "d:\Projects\" |?{$_.PSIsContainer -and $_.Fullname.StartsWith($prev)-eq $false} |%{$prev=$_.Fullname.TrimEnd(".svn"); $prev}

foreach($copy in $workingCopies)
{
    &"C:\Program Files\TortoiseSVN\bin\svn.exe" upgrade $copy;
}

I dont had issues with access rights to "System Volume" dir (that was just accidentially, cause I store all my sources in one folder I have full rights to..). As for your issue with Execution Policy - here nice trick to avoid set it forth and back. You could run powershell with special options to avoid issues with execution policy, user specific profile settings (which could be broken for different reasons) etc:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -File “C:\Projects\ConvertSvnToVersion17.ps1”

Also I could clarify what exactly this script do (if you are interested):

$prev = "^$"

Initialize $prev to empty-matching regex - ^$ never match any meaning value (except startline-endline). This was needed to pass initial check

Get-ChildItem -Recurse -Force -Include ".svn" -Path "d:\Projects\" 

Get all objects with name ".svn" (in our case - all files and folders with exact name ".svn"), started from Path, Recursively. And pipe it to next construct:

?{$_.PSIsContainer -and $_.Fullname.StartsWith($prev)-eq $false} 

?{...statements... } is shortcut to "Where-Object" cmdlet, $_ is the way to address "each" entry from pipe. It could be rewritten similar to

foreach($entry in $entriesFromSomewhere)
{
    If($entry.PSIsContainer -eq $true -and $entry.Fullname.StartsWith($prev) -eq $false)
    {
        "If entry is directory" and  "fullname not start with value from $prev"
        ...Pass entry to next construct...
    }
}

But I wrote it as one-liner for the brevity

%{$prev=$_.Fullname.TrimEnd(".svn"); $prev}

%{} is shortcut for Foreach =) And this construct doing 2 things :

  1. Assign folder fullname without ".svn" tail to $prev
  2. Pass $prev further to next pipeline sink.

And entire result set assigned to $workingCopies as array (any result with more than 1 item will be array)

foreach($copy in $workingCopies)
{
    &"C:\Program Files\TortoiseSVN\bin\svn.exe" upgrade $copy;
}

Foreach element in array - execute command (& sign for "execute as command") "…\svn.exe upgrade "

All the magic here is going to that backtracking $prev element: On first ".svn" entry $prev contains non-matching value so first check in "where" will be reduced to "If entry is directory". Then assigning step will put folder parent dir. Ex. If found dir fullname is c:\projects\project1.root\trunk.svn - $prev will be assigned to "c:\projects\project1.root\trunk\". This trick will help us to filter all lower-level .svn dirs: c:\projects\project1.root\trunk\SubProject1.svn entry - will not pass check "not starts with $prev" And this way we will filter only first level .svn dirs, cause all nested .snv will be filtered by StartsWith($prev) -eq $false

So its pretty simple but appears as some magic =)

BTW Thank you for your own answer here - your efforts greatly inspired me to write this comment and clarify entire script.

Grammar geeks should be summoned to this comment for cleaning and rephrasing my "so-called-English" ;)

查看更多
小情绪 Triste *
4楼-- · 2019-05-21 10:33

For complex and powerful searches on Windows-box I can recommend (I use it in real-life)

  • Embedded search inside Total Commander (your have fair evaluation time)
  • GrepWin (with wildcard- and regexp-keywords for filenames patterns)

You miss the point. SVN-clients 1.7 can (and really must) upgrade existing working copies after installing before usage. Also nore: all dirs inside WC for pre-1.6 versions have .svn dirs, you are interested in only every top-most

And later it may be useful for you

1.6 svn-dir

.svn>dir /B
all-wcprops
entries
prop-base
props
text-base
tmp

1.7 svn-dir

.svn>dir /B
entries
format
pristine
tmp
wc.db
查看更多
爷的心禁止访问
5楼-- · 2019-05-21 10:36

To find all .svn files, you can use dir. dir .svn /s will do it (though it won't break from scanning subdirectories) or you can use Windows Explorer and ask the little doggy to find all .svn files.

or you could download unxutils and use find after all!

查看更多
登录 后发表回答