2012-06-15 34 views
1

如何獲取svn --xml list命令的輸出,並使用PowerShell將其轉換爲按提交日期時間排序的表?按上次提交時間排序`svn --xml list`輸出

我使用這個命令輸出的每個文件的摘要在我的工作區:

svn --xml list svn://svn.example.com/Database 

我收到以下輸出:

<?xml version="1.0" encoding="UTF-8"?> 
<lists> 
<list 
    path="svn://svn.skyscanner.co.uk/SkyscannerDatabase/INT/Flightstore"> 
<entry 
    kind="dir"> 
<name>Assemblies</name> 
<commit 
    revision="10768"> 
<author>sam</author> 
<date>2011-03-03T17:35:40.705575Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Data</name> 
<commit 
    revision="15118"> 
<author>yann</author> 
<date>2012-06-07T17:52:46.028463Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Database Triggers</name> 
<commit 
    revision="10764"> 
<author>sam</author> 
<date>2011-03-03T16:31:50.399811Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Defaults</name> 
<commit 
    revision="10764"> 
<author>sam</author> 
<date>2011-03-03T16:31:50.399811Z</date> 
</commit> 
</entry> 
<entry 
    kind="file"> 
<name>Filter.scpf</name> 
<size>4396</size> 
<commit 
    revision="14955"> 
<author>yann</author> 
<date>2012-05-30T10:08:54.064942Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Functions</name> 
<commit 
    revision="13994"> 
<author>sam</author> 
<date>2012-03-12T10:41:18.173561Z</date> 
</commit> 
</entry> 
<entry 
    kind="file"> 
<name>RedGate.ssc</name> 
<size>0</size> 
<commit 
    revision="10764"> 
<author>sam</author> 
<date>2011-03-03T16:31:50.399811Z</date> 
</commit> 
</entry> 
<entry 
    kind="file"> 
<name>RedGateDatabaseInfo.xml</name> 
<size>2491</size> 
<commit 
    revision="14546"> 
<author>david</author> 
<date>2012-05-02T10:23:19.811375Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Rules</name> 
<commit 
    revision="10768"> 
<author>sam</author> 
<date>2011-03-03T17:35:40.705575Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Security</name> 
<commit 
    revision="14956"> 
<author>yann</author> 
<date>2012-05-30T10:11:38.387808Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Service Broker</name> 
<commit 
    revision="10764"> 
<author>sam</author> 
<date>2011-03-03T16:31:50.399811Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Storage</name> 
<commit 
    revision="10764"> 
<author>sam</author> 
<date>2011-03-03T16:31:50.399811Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Stored Procedures</name> 
<commit 
    revision="15194"> 
<author>sam</author> 
<date>2012-06-12T16:50:16.105896Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Synonyms</name> 
<commit 
    revision="10764"> 
<author>sam</author> 
<date>2011-03-03T16:31:50.399811Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Tables</name> 
<commit 
    revision="15224"> 
<author>yann</author> 
<date>2012-06-13T15:38:11.018172Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Types</name> 
<commit 
    revision="10768"> 
<author>sam</author> 
<date>2011-03-03T17:35:40.705575Z</date> 
</commit> 
</entry> 
<entry 
    kind="dir"> 
<name>Views</name> 
<commit 
    revision="15142"> 
<author>yann</author> 
<date>2012-06-08T17:28:48.067359Z</date> 
</commit> 
</entry> 
</list> 
</lists> 

表應包含相同的列輸出的svn --verbose list命令。該命令輸出五列:版本,用戶,大小,日期時間和文件名。這裏是svn --verbose list svn://svn.example.com/Database輸出:

15224 yann     Jun 13 16:38 ./ 
10768 sam     Mar 03 2011 Assemblies/ 
15118 yann     Jun 07 18:52 Data/ 
10764 sam     Mar 03 2011 Database Triggers/ 
10764 sam     Mar 03 2011 Defaults/ 
14955 yann    4396 May 30 11:08 Filter.scpf 
13994 sam     Mar 12 10:41 Functions/ 
10764 sam     0 Mar 03 2011 RedGate.ssc 
14546 david   2491 May 02 11:23 RedGateDatabaseInfo.xml 
10768 sam     Mar 03 2011 Rules/ 
14956 yann     May 30 11:11 Security/ 
10764 sam     Mar 03 2011 Service Broker/ 
10764 sam     Mar 03 2011 Storage/ 
15194 sam     Jun 12 17:50 Stored Procedures/ 
10764 sam     Mar 03 2011 Synonyms/ 
15224 yann     Jun 13 16:38 Tables/ 
10768 sam     Mar 03 2011 Types/ 
15142 yann     Jun 08 18:28 Views/ 

我曾嘗試以下簡單的代碼:

[Xml] $Output = svn --xml list svn://svn.example.com/Database 
$Output.Lists.List.Entry 

與三列產生輸出:善良,名稱和提交。這裏是輸出:

kind   name       commit 
----   ----       ------ 
dir   Assemblies      commit 
dir   Data       commit 
dir   Database Triggers    commit 
dir   Defaults      commit 
file   Filter.scpf      commit 
dir   Functions      commit 
file   RedGate.ssc      commit 
file   RedGateDatabaseInfo.xml   commit 
dir   Rules       commit 
dir   Security      commit 
dir   Service Broker     commit 
dir   Storage       commit 
dir   Stored Procedures    commit 
dir   Synonyms      commit 
dir   Tables       commit 
dir   Types       commit 
dir   Views       commit 

我失去了什麼轉換?

回答

1

我適應JPBlanc's answer得到這個解決方案:

([Xml] (svn list --xml svn://svn.example.com/Database)).Lists.List.Entry | 
Select -Property @(
    @{N='revision';E={$_.commit.GetAttribute('revision')}}, 
    @{N='author'; E={$_.commit.author}}, 
    'size', 
    @{N='date'; E={$_.commit.date}}, 
    'name' 
) | 
Sort -Property date | 
Format-Table -Auto 

它產生以下輸出:

revision author size date      name     
-------- ------ ---- ----      ----     
10764 sam 0 2011-03-03T16:31:50.399811Z RedGate.ssc    
10764 sam  2011-03-03T16:31:50.399811Z Storage     
10764 sam  2011-03-03T16:31:50.399811Z Service Broker   
10764 sam  2011-03-03T16:31:50.399811Z Defaults    
10764 sam  2011-03-03T16:31:50.399811Z Synonyms    
10764 sam  2011-03-03T16:31:50.399811Z Database Triggers  
10768 sam  2011-03-03T17:35:40.705575Z Rules     
10768 sam  2011-03-03T17:35:40.705575Z Types     
10768 sam  2011-03-03T17:35:40.705575Z Assemblies    
13994 sam  2012-03-12T10:41:18.173561Z Functions    
14546 david 2491 2012-05-02T10:23:19.811375Z RedGateDatabaseInfo.xml 
14955 yann 4396 2012-05-30T10:08:54.064942Z Filter.scpf    
14956 yann  2012-05-30T10:11:38.387808Z Security    
15118 yann  2012-06-07T17:52:46.028463Z Data     
15142 yann  2012-06-08T17:28:48.067359Z Views     
15194 sam  2012-06-12T16:50:16.105896Z Stored Procedures  
15224 yann  2012-06-13T15:38:11.018172Z Tables     
1

你可以試試:

$a = $Output.lists.list.entry | select name,kind,@{N="author";E={$_.commit.author}},@{N="date";E={$_.commit.date}} 

然後

$a | Sort-Object -Property date 
+0

這產生一個表格格式,但包括'kind','name','size'和'commit'列。我已經調整了你的答案,以找到我最終會接受的解決方案。感謝您的貢獻。 –

+0

對不起,但在我的解決方案中,我有作者和日期,但不再提交!我可以按日期排序,這就是你要求的。 – JPBlanc