Commits

Anton Afanasyev committed 81789ab

Better vvFiles based on vscript
Better vvLocalRevisions based on vscript
minor code style cleanup
Fxied vv commit suggestions

Comments (0)

Files changed (1)

VvTabExpansion.ps1

 function VvTabExpansion($lastBlock) {
   switch -regex ($lastBlock) { 
 
-   #handles vv (up|update|merge|checkout) (-b|--branch) <branch name>
-   'vv (up|update|merge|checkout) (-b|--branch) (\S*)$' {
+   #handles vv (up|update|merge) (-b|--branch) <branch name>
+   'vv (up|update|merge) (-b|--branch) (\S*)$' {
       findBranch($matches[3])
    }
-   #handles vv (up|update|merge|checkout) --tag <tag name>
-   'vv (up|update|merge|checkout) --tag (\S*)$' {
+   #handles vv (up|update|merge) --tag <tag name>
+   'vv (up|update|merge) --tag (\S*)$' {
       findTag($matches[2])
    }
-   #handles vv (up|update|merge|checkout) (-r|--rev) <rev num>
-   'vv (up|update|merge|checkout) (-r|--rev) (\S*)$' {
+   #handles vv (up|update|merge) (-r|--rev) <rev num>
+   'vv (up|update|merge) (-r|--rev) (\S*)$' {
       findRevision($matches[3])
    }
+
+   #handles vv checkout <repo name>
+   'vv checkout (\S*)$' {
+    findRepo($matches[1])
+   }
+
        
    #Handles vv pull -B <bookmark>   
    'vv pull (-\S* )*-(B) (\S*)$' {
     }
     
     # handles vv commit -(I|X) <path>
-    'vv commit (\S* )*-(I|X) (\S*)$' {
-      vvFiles $matches[3] 'Modified|Added|Removed|Lost'
+    'vv commit (\S* )*(\S*)$' {
+      vvFiles $matches[2] 'Modified|Added|Removed|Lost'
     }    
   }
 }
 
 function vvFiles($filter, $pattern) {
-   vv status | 
-    foreach { 
-      if($_ -match "($pattern){1}:  (.*)") { 
-        $matches[2] 
-      } 
-    } |
-    where { $_ -like "*$filter*" } |
-    foreach { if($_ -like '* *') {  "'$_'"  } else { $_ } }
+  $rawStatus = vscript -e "print(sg.to_json(sg.pending_tree.status()))" | ConvertFrom-Json
+  # get the relevant properties from which to get the files
+  $props = $rawStatus | Get-Member -MemberType NoteProperty | where {$_.Name -match $pattern }
+  $allFiles = $props | foreach { $rawStatus | select -ExpandProperty $_.Name | %{$_.path} | where {$_ -like "*$filter*"} }
+  $allFiles
+  
+  # vv status | 
+  #   foreach { 
+  #     if($_ -match "($pattern){1}:  (.*)") { 
+  #       $matches[2] 
+  #     } 
+  # } |
+  #   where { $_ -like "*$filter*" } |
+  #   foreach { if($_ -like '* *') {  "'$_'"  } else { $_ } }
 }
 
 function vvRemotes($filter) {
   $script:vvCommands = $vvCommands
 }
 
+function findRepo($filter) {
+  vvRepositories($filter)
+}
 function findBranch($filter){
     vvLocalBranches($filter)
 }
 function findTag($filter){
-    VvLocalTags($filter)
+    vvLocalTags($filter)
 }
 
 function findRevision($filter){
-    VvLocalRevisions($filter)
+    vvLocalRevisions($filter)
 }
 
 function vvLocalBranches($filter) {
     }
   }
 }
+function vvRepositories($filter) {
+  vv repo list | %{$_} | where {$_.StartsWith($filter)}
+}
 
 function tagName($tag) {
     $split = $tag.Split(" ");
 }
 
 function vvLocalTags($filter) {
-  vv tag  list | foreach {
+  vv tag list | foreach {
     if($_ -match "(\S+) .*") {
       $tag = tagName($matches[0])  
       if($filter -and $tag.StartsWith($filter)) {
   }
 }
 
-function revNum($rev) {
-    $split = $rev.Split(" ");
-        
-    if($rev.StartsWith("*")) {
-        $split[1]
-    }
-    else{
-        $split[0]
-    }
-}
-
-function VvLocalRevisions($filter) {
-  vv history | foreach {
-    if($_ -match "revision:  (\d+):(\S+)") {
-      foreach($m in $matches[1],$matches[2]) {
-        $revnum = revNum($m)
-
-        if($filter -and $revnum.StartsWith($filter)) {
-          $revnum
-        }
-        elseif(-not $filter) {
-          $revnum
-        }
-      }
-    }
+function vvLocalRevisions($filter) {
+  $history = vscript -e "print(sg.to_json(sg.pending_tree.history()))" | ConvertFrom-Json
+  if(-not $filter){
+    $history | %{$_.revno}
+  } elseif($filter.StartsWith("*")) {
+    $history | where {$_.changeset_id.StartsWith($filter.Substring(1))} | %{$_.changeset_id}
+  } else {
+    $history | where {$_.revno.ToString().StartsWith($filter)} | %{$_.revno}
   }
 }
 
-function vvRemoteBookmarks($filter) {
-  vv incoming -B | foreach {
-    if($_ -match "(\S+) .*") {
-      if($filter -and $matches[1].StartsWith($filter)) {
-        $matches[1]
-      }
-      elseif(-not $filter) {
-        $matches[1]
-      }
-    }
-  }
-}
-
+# shows all options for specific command
 function vvOptions($cmd, $prefix, $filter) {
 	$optList = @()
 	$output = vv help $cmd