Commits

Anton Afanasyev committed 385af28

Fixed all functionality of posh-hg (bar mq, as veracity doesnt have that) to work with vv
Not all of tab expansions for commands work yet (e.g. diff, etc. have hg syntax still)

  • Participants
  • Parent commits 13dd9f6

Comments (0)

Files changed (5)

File Settings.ps1

     TagBackgroundColor        = $Host.UI.RawUI.BackgroundColor
     TagSeparator              = ", "
     TagSeparatorColor         = [ConsoleColor]::White
-    
-    # MQ Integration
-    ShowPatches                   = $false
-    BeforePatchText               = ' patches: '
-    UnappliedPatchForegroundColor = [ConsoleColor]::DarkGray
-    UnappliedPatchBackgroundColor = $Host.UI.RawUI.BackgroundColor
-    AppliedPatchForegroundColor   = [ConsoleColor]::DarkYellow
-    AppliedPatchBackgroundColor   = $Host.UI.RawUI.BackgroundColor
-    PatchSeparator                = ' › '
-    PatchSeparatorColor           = [ConsoleColor]::White    
 }

File VvPrompt.ps1

          
           $tagCounter=0
           $status.Tags | % {
-            $color = $s.TagForegroundColor
-                
-              write-host $_ -NoNewLine -ForegroundColor $color -BackgroundColor $s.TagBackgroundColor 
+              write-host $_ -NoNewLine -ForegroundColor $s.TagForegroundColor -BackgroundColor $s.TagBackgroundColor 
           
               if($tagCounter -lt ($status.Tags.Length -1)) {
                 write-host ", " -NoNewLine -ForegroundColor $s.TagSeparatorColor -BackgroundColor $s.TagBackgroundColor
           }        
         }
         
-        if($s.ShowPatches) {
-          $patches = Get-MqPatches
-          if($patches.All.Length) {
-            write-host $s.BeforePatchText -NoNewLine
-  
-            $patchCounter = 0
-            
-            $patches.Applied | % {
-              write-host $_ -NoNewLine -ForegroundColor $s.AppliedPatchForegroundColor -BackgroundColor $s.AppliedPatchBackgroundColor
-              if($patchCounter -lt ($patches.All.Length -1)) {
-                write-host $s.PatchSeparator -NoNewLine -ForegroundColor $s.PatchSeparatorColor
-              }
-              $patchCounter++;
-            }
-            
-            $patches.Unapplied | % {
-               write-host $_ -NoNewLine -ForegroundColor $s.UnappliedPatchForegroundColor -BackgroundColor $s.UnappliedPatchBackgroundColor
-               if($patchCounter -lt ($patches.All.Length -1)) {
-                  write-host $s.PatchSeparator -NoNewLine -ForegroundColor $s.PatchSeparatorColor
-               }
-               $patchCounter++;
-            }
-          }
-        }
-        
        Write-Host $s.AfterText -NoNewline -BackgroundColor $s.AfterBackgroundColor -ForegroundColor $s.AfterForegroundColor
     }
 }

File VvTabExpansion.ps1

 
 function VvTabExpansion($lastBlock) {
   switch -regex ($lastBlock) { 
-    
-   #handles hgtk help <cmd>
-   #handles hgtk <cmd>
-   'thg (help )?(\S*)$' {
-     thgCommands($matches[2]);
+
+   #handles vv (up|update|merge|checkout) (-b|--branch) <branch name>
+   'vv (up|update|merge|checkout) (-b|--branch) (\S*)$' {
+      findBranch($matches[3])
    }
-    
-   #handles vv update <branch name>
-   #handles vv merge <branch name>
-   'vv (up|update|merge|co|checkout) (\S*)$' {
-      findBranchOrBookmark($matches[2])
+   #handles vv (up|update|merge|checkout) --tag <tag name>
+   'vv (up|update|merge|checkout) --tag (\S*)$' {
+      findTag($matches[2])
+   }
+   #handles vv (up|update|merge|checkout) (-r|--rev) <rev num>
+   'vv (up|update|merge|checkout) (-r|--rev) (\S*)$' {
+      findRevision($matches[3])
    }
        
    #Handles vv pull -B <bookmark>   
    'vv pull (-\S* )*-(B) (\S*)$' {
      vvRemoteBookmarks($matches[3])
-     vvLocalBookmarks($matches[3])
+     vvLocalStamps($matches[3])
    }
     
    #Handles vv push -B <bookmark>   
    'vv push (-\S* )*-(B) (\S*)$' {
-     vvLocalBookmarks($matches[3])
+     vvLocalStamps($matches[3])
    }
    
-   #Handles vv bookmark <bookmark>
-   'vv (book|bookmark) (\S*)$' {
-      vvLocalBookmarks($matches[2])
+   #Handles vv stamps <bookmark>
+   'vv (stamps) (\S*)$' {
+      vvLocalStamps($matches[2])
    }
     
     #Handles vv push <path>
     }
 
     #handles vv <cmd> --<option>
-    'vv (\S+) (-\S* )*--(\S*)$' {
-      vvOptions $matches[1] $matches[3];
+    #handles vv <cmd> -<opt>
+    'vv (\S+) (-\S* )*(--|-)(\S*)$' {
+      vvOptions $matches[1] $matches[3] $matches[4];
     }
     
+    
     #handles vv revert <path>
     'vv revert (\S*)$' {
-      vvFiles $matches[1] 'M|A|R|!'
+      vvFiles $matches[1] 'Modified|Added|Removed|Lost'
     }
     
     #handles vv add <path>
     'vv add (\S*)$' {
-      vvFiles $matches[1] '\?'
+      vvFiles $matches[1] 'Found'
     }
     
     # handles vv diff <path>
     'vv diff (\S*)$' {
-      vvFiles $matches[1] 'M'
+      vvFiles $matches[1] 'Modified'
     }
     
     # handles vv commit -(I|X) <path>
     'vv commit (\S* )*-(I|X) (\S*)$' {
-      vvFiles $matches[3] 'M|A|R|!'
+      vvFiles $matches[3] 'Modified|Added|Removed|Lost'
     }    
   }
 }
 function vvFiles($filter, $pattern) {
    vv status | 
     foreach { 
-      if($_ -match "($pattern){1} (.*)") { 
+      if($_ -match "($pattern){1}:  (.*)") { 
         $matches[2] 
       } 
     } |
       break
     }
     
-    if($cmd -match '^ (\S+) (.*)') {
+    if($cmd -match '^(\S+) (.*)') {
         $matches[1]
      }
   }
 
-  if($global:PoshVvSettings.ShowPatches) {
-    # MQ integration must be explicitly enabled as the user may not have the extension
-    $vvCommands += (vv help mq) | % {
-      if($_ -match '^ (\S+) (.*)') {
-          $matches[1]
-       }
-    }
-  }
-  
   $script:vvCommands = $vvCommands
 }
 
-function findBranchOrBookmark($filter){
+function findBranch($filter){
     vvLocalBranches($filter)
-    vvLocalBookmarks($filter)
+}
+function findTag($filter){
+    VvLocalTags($filter)
+}
+
+function findRevision($filter){
+    VvLocalRevisions($filter)
 }
 
 function vvLocalBranches($filter) {
-  vv branches -a | foreach {
-    if($_ -match "(\S+) .*") {
+  vv branches --all | foreach {
+    if($_ -match "^(\S+)$") {
       if($filter -and $matches[1].StartsWith($filter)) {
         $matches[1]
       }
   }
 }
 
-function bookmarkName($bookmark) {
-    $split = $bookmark.Split(" ");
+function tagName($tag) {
+    $split = $tag.Split(" ");
         
-    if($bookmark.StartsWith("*")) {
+    if($tag.StartsWith("*")) {
         $split[1]
     }
     else{
     }
 }
 
-function vvLocalBookmarks($filter) {
-  vv bookmarks | foreach {
+function vvLocalTags($filter) {
+  vv tag  list | foreach {
     if($_ -match "(\S+) .*") {
-      $bookmark = bookmarkName($matches[0])  
-      if($filter -and $bookmark.StartsWith($filter)) {
-        $bookmark
+      $tag = tagName($matches[0])  
+      if($filter -and $tag.StartsWith($filter)) {
+        $tag
       }
       elseif(-not $filter) {
-        $bookmark
+        $tag
+      }
+    }
+  }
+}
+
+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 vvOptions($cmd, $filter) {
+function vvOptions($cmd, $prefix, $filter) {
 	$optList = @()
 	$output = vv help $cmd
+  $matchIdx = 1
+  $seq = '^(?:-\b(\S) )?(?:(?:\[)?--(\b\S+\b)(?:\])?)?( ARG)?.*$'
+  if($prefix -eq '--') {
+    $matchIdx = 2
+  }
 	foreach($line in $output) {
-		if($line -match '^ ((-\S)|  ) --(\S+) .*$') {
-			$opt = $matches[3]
-			if($filter -and $opt.StartsWith($filter)) {
-				$optList += '--' + $opt.Trim()
-			}
-			elseif(-not $filter) {
-				$optList += '--' + $opt.Trim()
-			}
+		if($line -match $seq) {
+      $opt=$matches[$matchIdx]
+      if($filter -and $opt.StartsWith($filter)) {
+        $optList += $prefix+$opt.Trim()
+      }
+      elseif(-not $filter) {
+        $optList += $prefix+$opt.Trim()
+      }
 		}
 	}
 
 	$optList | sort
 }
 
-function thgCommands($filter) {
-  $cmdList = @()
-  $output = thg help
-  foreach($line in $output) {
-    if($line -match '^ (\S+) (.*)') {
-      $cmd = $matches[1]
-      if($filter -and $cmd.StartsWith($filter)) {
-        $cmdList += $cmd.Trim()
-      }
-      elseif(-not $filter) {
-        $cmdList += $cmd.Trim()
-      }
-    }
-  }
-  
-  $cmdList | sort 
-}
-
-if(-not (Test-Path Function:\DefaultTabExpansion)) {
-   Rename-Item Function:\TabExpansion DefaultTabExpansion
+#if(-not (Test-Path Function:\DefaultTabExpansion)) {
+if(Test-Path Function:\TabExpansion) {
+   Rename-Item Function:\TabExpansion PoshVvDefaultTabExpansion
 }
 
 # Set up tab expansion and include vv expansion
        # veracity tab expansion
        '(vv) (.*)' { VvTabExpansion($lastBlock) }
        # Fall back on existing tab expansion
-       default { DefaultTabExpansion $line $lastWord }
+       default { PoshVvDefaultTabExpansion $line $lastWord }
    }
-}
+}
     $modified = 0
     $deleted = 0
     $missing = 0
-	$renamed = 0
+    $renamed = 0
     $tags = @()
     $commit = ""
     $behind = $false
    
   
-       vv summary | foreach {   
-      switch -regex ($_) {
-        'parent: (\S*) ?(.*)' { $commit = $matches[1]; $tags = $matches[2].Replace("(empty repository)", "").Split(" ", [StringSplitOptions]::RemoveEmptyEntries) } 
-        'branch: ([\S ]*)' { $branch = $matches[1] }
-        'update: (\d+)' { $behind = $true }
-        'pmerge: (\d+) pending' { $behind = $true }
-        'commit: (.*)' {
-          $matches[1].Split(",") | foreach {
-            switch -regex ($_.Trim()) {
-              '(\d+) modified' { $modified = $matches[1] }
-              '(\d+) added' { $added = $matches[1] }
-              '(\d+) removed' { $deleted = $matches[1] }
-              '(\d+) deleted' { $missing = $matches[1] }
-              '(\d+) unknown' { $untracked = $matches[1] }
-              '(\d+) renamed' { $renamed = $matches[1] }
-            }
-          } 
-        } 
-      } 
+    $status = vscript -e "print(sg.to_json(sg.pending_tree.status()));" | ConvertFrom-Json
+    $status | Get-Member | Select-Object -ExpandProperty Name | foreach {
+      switch ($_) {
+        'Found' { $untracked = $status.Found.length }
+        'Added' { $added = $status.Added.length }
+        'Modified' { $modified = $status.Modified.length }
+        'Deleted' { $deleted = $status.Deleted.length }
+        'Lost' { $missing = $status.Lost.length }
+        'Renamed' { $renamed = $status.Renamed.length }
+      }
     }
+
+    $branch = vv branch
+    # get info about newest changeset in current branch
+    $lastChset = vscript -e ("print(sg.to_json(sg.pending_tree.history(['branch=" + $branch + "','max=1'])));") | ConvertFrom-Json
+    $lastChset = $lastChset[0]
+    # get info about workingdir changeset
+    $curChset = vscript -e "print(sg.to_json(sg.pending_tree.history(['rev='+sg.pending_tree.parents()]))); " | ConvertFrom-Json
+    $curChset = $curChset[0]
+
+    $tags = $curChset.tags
+    $commit = $curChset.revno
+    if($lastChset.changeset_id -eq $curChset.changeset_id) {
+      $tags += "tip"
+    } else {
+      $behind = $true
+    }
+
+    # hg summary | foreach {   
+    #   switch -regex ($_) {
+    #     'pmerge: (\d+) pending' { $behind = $true }
+    #   } 
+    # }
     
     $active = ""
-    vv bookmarks | ?{$_}  | foreach {
+    vv stamps | ?{$_}  | foreach {
         if($_.Trim().StartsWith("*")) {
            $split = $_.Split(" ");
            $active= $split[2]
         }
     }
    
-    return @{"Untracked" = $untracked;
-               "Added" = $added;
-               "Modified" = $modified;
-               "Deleted" = $deleted;
-               "Missing" = $missing;
-			   "Renamed" = $renamed;
-               "Tags" = $tags;
-               "Commit" = $commit;
-               "Behind" = $behind;
-               "ActiveBookmark" = $active;
-               "Branch" = $branch}
+    return @{
+              "Untracked" = $untracked;
+              "Added" = $added;
+              "Modified" = $modified;
+              "Deleted" = $deleted;
+              "Missing" = $missing;
+              "Renamed" = $renamed;
+              "Tags" = $tags;
+              "Commit" = $commit;
+              "Behind" = $behind;
+              "ActiveBookmark" = $active;
+              "Branch" = $branch}
    }
 }
-
-function Get-MqPatches($filter) {
-  $applied = @()
-  $unapplied = @()
-  
-  vv qseries -v | % {
-    $bits = $_.Split(" ")
-    $status = $bits[1]
-    $name = $bits[2]
-    
-    if($status -eq "A") {
-      $applied += $name
-    } else {
-      $unapplied += $name
-    }
-  }
-  
-  $all = $unapplied + $applied
-  
-  if($filter) {
-    $all = $all | ? { $_.StartsWith($filter) }
-  }
-  
-  return @{
-    "All" = $all;
-    "Unapplied" = $unapplied;
-    "Applied" = $applied
-  }
-}

File posh-vv.psm1

 Export-ModuleMember -Function @(
   'Get-VvStatus',
   'TabExpansion',
-  'Get-MqPatches',
   'PopulateVvCommands'
  )