[p4] PowerShell Integration

mancaus.40868864 at bloglines.com mancaus.40868864 at bloglines.com
Thu Nov 30 01:49:06 PST 2006


Yes, that's sort of what I was thinking too. 



I'll have a look at the Ruby
implementation - it's probably a good starting point and, as much as it will
grate with many, powershell does pay quite a homage to Ruby.



Ideally I'd
like to be able to do a 

# Revert open changelists with comments beginning
"Temp"

Get-P4Changes ... | ?{

  $_.Comment.StartsWith( "Temp" } -and $_.IsOpen
| %{

    $_.Revert()

  }

}



... i.e. have commands matching the perforce
commands that return objects with meaningful methods.



This would probably
involve writing a .NET object hierarchy to represent perforce entities (change,
connection, client, spec, file, etc.) that uses the C++ API... a lot of work.



The other option is a simple set of functions that parse p4 output into
data objects.



For example, I've appended a very naive function that will
get all changes in the depot. This would allow things like:

Get-P4Changes
<spec> | ?{ $_.Date.DayOfWeek -eq [DayOfWeek]::Friday } | format-table

...
to catch those changelists that might need a bit more review.



Cheers,

  Blake



function Get-P4Changes

{

  $changeRegex = new-object "System.Text.RegularExpressions.Regex"
"^Change (\d+) on (\d{4})/(\d{2})/(\d{2}) by (\S+)@(\S+) (\*pending\* |)'(.*)'$"



  p4 changes $args | %{ 



    $match = $changeRegex.Match($_)



   
$date = new-object "System.DateTime" ($match.Groups[2].Value, $match.Groups[3].Value,
$match.Groups[4].Value)



    trap { echo ("Error matching "+$_) } 



 
  $pending = ($match.Groups[7].Value.Length -gt 0)



    $change = new-object
psobject

    $change | add-member NoteProperty "Change" $match.Groups[1].Value

    $change | add-member NoteProperty "Date" $date 

    $change | add-member
NoteProperty "User" $match.Groups[5].Value

    $change | add-member NoteProperty
"Workspace" $match.Groups[6].Value

    $change | add-member NoteProperty
"Pending" $pending 

    $change | add-member NoteProperty "ShortComment"
$match.Groups[8].Value



    $change



  }

}





--- Bennett wrote:

The
ideal would be a 'p4' command that was a native powershell object.

> That
way you could pipe complete Perforce objects between powershell

> functions
and act on them as structured types (sorting on changelist #,

> user, exporting
to xml, etc. etc. etc.).  There are definitely a lot of

> possibility.

>





More information about the perforce-user mailing list