3

Here's the problem: I want to query subversion for the revision number of a repository, and then create a new directory with the revision number in its name (for example, "Build763").

The command "svn info" outputs a number of label\value pairs, delimited by colons. For example

Path: c#
URL: file:///%5Copdy-doo/Archive%20(H)/Development/CodeRepositories/datmedia/Development/c%23
Repository UUID: b1d03fca-1949-a747-a1a0-046c2429f46a
Revision: 58
Last Changed Rev: 58
Last Changed Date: 2011-01-12 11:36:12 +1000 (Wed, 12 Jan 2011)

Here is my current code which solves the problem. Is there a way to do this with less code? I'm thinking that with the use of piping you could do this with one or two lines. I certainly shouldn't have to use a temporary file.

$RepositoryRoot = "file:///%5Cdat-ftp/Archive%20(H)/Development/CodeRepositories/datmedia"
$BuildBase="/Development/c%23"
$RepositoryPath=$RepositoryRoot + $BuildBase

# Outputing the info into a file
svn info $RepositoryPath | Out-File -FilePath svn_info.txt

$regex = [regex] '^Revision: (\d{1,4})'

foreach($info_line in get-content "svn_info.txt")
    {
        $match = $regex.Match($info_line);
        if($match.Success)
        {
            $revisionNumber = $match.Groups[1];
            break;
        }
    }


"Revision number = " + $revisionNumber;

4 Answers 4

3

Here's one way:

    $revisionNumber = svn info $RepositoryPath |
     select-string "^revision" |
      foreach {$_.line.split(":")[1].trim()}

    if ($revisionNumber){"Revision number = " + $revisionNumber

}
Sign up to request clarification or add additional context in comments.

Comments

2

Taking mjolinor's suggestion, I'm finally going with:

$revisionNumber = (svn info $RepositoryPath | select-string '^Revision: (\d+)$').Matches[0].Groups[1].Value

Cool! One line of code. (It took two hours to write, but hey)

6 Comments

They make you dig for that capture, don't they?
Well, you could just use (svn info $RepositoryPath) -Replace '^Revision: (\d+)$','$1' to get at the capture ;)
That's better. I'll have to remember that.
@Jaykul: That only works if "(svn info $RepositoryPath)" returns one line. I've tried this and you get the revision line with just the number, but you get all of the other lines (URL, repository ID etc) as well.
You could simplify this even more: (svn info $RepositoryPath | select-string "^Revision").ToString().Split(":")[1].Trim()
|
2

For what it's worth, you could use ConvertFrom-PropertyString

Comments

0

If you can create and use Working Copy of URL (WC), you can

  • svnversion WC: will output clean number of WC-revision

    > svnversion trunk

    34

  • With SubWCRrev convert template-file with SubWCRrev-keywords into bat-file (subwcrev WC tpl-file bat-file) with RevNo, substituted in needed place (inside mkdir options) and call resulted bat for performing operation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.