contrib/vim/hgcommand.vim
changeset 2636 733fff9b23f7
parent 2635 37bcccf8a683
child 2637 fcfd46c4a27a
equal deleted inserted replaced
2635:37bcccf8a683 2636:733fff9b23f7
   313 "
   313 "
   314 " Returns: string to be exec'd that sets the multiple return values.
   314 " Returns: string to be exec'd that sets the multiple return values.
   315 
   315 
   316 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
   316 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
   317   let hgBufferCheck=s:HGCurrentBufferCheck()
   317   let hgBufferCheck=s:HGCurrentBufferCheck()
       
   318   "echomsg "DBG : in HGGetStatusVars"
   318   if hgBufferCheck == -1 
   319   if hgBufferCheck == -1 
   319     return ""
   320     return ""
   320   endif
   321   endif
   321   let fileName=bufname(hgBufferCheck)
   322   let fileName=bufname(hgBufferCheck)
   322   let fileNameWithoutLink=s:HGResolveLink(fileName)
   323   let fileNameWithoutLink=s:HGResolveLink(fileName)
   324   let oldCwd=s:HGChangeToCurrentFileDir(fileName)
   325   let oldCwd=s:HGChangeToCurrentFileDir(fileName)
   325   try
   326   try
   326     let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root  " 
   327     let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root  " 
   327     let roottext=system(hgCommand)
   328     let roottext=system(hgCommand)
   328     " Suppress ending null char ! Does it work in window ?
   329     " Suppress ending null char ! Does it work in window ?
   329     let roottext=substitute(roottext, '.$', '', "")
   330     let roottext=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
   330     if match(getcwd()."/".fileNameWithoutLink, roottext) == -1
   331     if match(getcwd()."/".fileNameWithoutLink, roottext) == -1
   331       return ""
   332       return ""
   332     endif
   333     endif
       
   334     let returnExpression = ""
   333     let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . fileName
   335     let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . fileName
   334     let statustext=system(hgCommand)
   336     let statustext=system(hgCommand)
   335     if(v:shell_error)
   337     if(v:shell_error)
   336       return ""
   338       return ""
       
   339     endif
       
   340     if a:repositoryVar != ""
       
   341       let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . roottext . "'"
   337     endif
   342     endif
   338     if match(statustext, '^[?I]') >= 0 
   343     if match(statustext, '^[?I]') >= 0 
   339       let revision="NEW"
   344       let revision="NEW"
   340     elseif match(statustext, '^[R]') >= 0 
   345     elseif match(statustext, '^[R]') >= 0 
   341       let revision="REMOVED"
   346       let revision="REMOVED"
   342     elseif match(statustext, '^[D]') >= 0 
   347     elseif match(statustext, '^[D]') >= 0 
   343       let revision="DELETED"
   348       let revision="DELETED"
   344     elseif match(statustext, '^[A]') >= 0 
   349     elseif match(statustext, '^[A]') >= 0 
   345       let revision="ADDED"
   350       let revision="ADDED"
   346     endif
       
   347 
       
   348     let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b  " 
       
   349     let statustext=system(hgCommand)
       
   350     if(v:shell_error)
       
   351         return ""
       
   352     endif
       
   353     if exists('revision')
       
   354       let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
       
   355     else
   351     else
       
   352       " The file is tracked, we can try to get is revision number
       
   353       let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b  " 
       
   354       let statustext=system(hgCommand)
       
   355       if(v:shell_error)
       
   356 	  return ""
       
   357       endif
   356       let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
   358       let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
   357       let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
   359 
   358     endif
   360       if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
   359 
   361 	let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
   360     if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
   362 	let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
   361       let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
   363       endif
   362       let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
   364     endif
   363     endif
   365     if (exists('revision'))
   364     if a:repositoryVar != ""
   366       let returnExpression = "let " . a:revisionVar . "='" . revision . "' " . returnExpression
   365       let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root  " 
   367     endif
   366       let roottext=system(hgCommand)
       
   367       let repository=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
       
   368       let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . repository . "'"
       
   369     endif
       
   370 
       
   371 
       
   372 
   368 
   373     return returnExpression
   369     return returnExpression
   374   finally
   370   finally
   375     execute 'cd' escape(oldCwd, ' ')
   371     execute 'cd' escape(oldCwd, ' ')
   376   endtry
   372   endtry
   434     let origBuffer = s:HGBufferCheck(a:hgBuffer)
   430     let origBuffer = s:HGBufferCheck(a:hgBuffer)
   435     "This should never not work, but I'm paranoid
   431     "This should never not work, but I'm paranoid
   436     if origBuffer != a:hgBuffer
   432     if origBuffer != a:hgBuffer
   437       call setbufvar(origBuffer, "HGBufferSetup", 0)
   433       call setbufvar(origBuffer, "HGBufferSetup", 0)
   438     endif
   434     endif
       
   435   else
       
   436     "We are presumably in the original buffer
       
   437     let b:HGBufferSetup = 0
       
   438     "We do the setup now as now event will be triggered allowing it later.
       
   439     call s:HGSetupBuffer()
   439   endif
   440   endif
   440   return a:hgBuffer
   441   return a:hgBuffer
   441 endfunction
   442 endfunction
   442 
   443 
   443 " Function: s:HGOverrideOption(option, [value]) {{{2
   444 " Function: s:HGOverrideOption(option, [value]) {{{2
   610 function! HGEnableBufferSetup()
   611 function! HGEnableBufferSetup()
   611   let g:HGCommandEnableBufferSetup=1
   612   let g:HGCommandEnableBufferSetup=1
   612   augroup HGCommandPlugin
   613   augroup HGCommandPlugin
   613     au!
   614     au!
   614     au BufEnter * call s:HGSetupBuffer()
   615     au BufEnter * call s:HGSetupBuffer()
       
   616     au BufWritePost * call s:HGSetupBuffer()
   615     " Force resetting up buffer on external file change (HG update)
   617     " Force resetting up buffer on external file change (HG update)
   616     au FileChangedShell * call s:HGSetupBuffer(1)
   618     au FileChangedShell * call s:HGSetupBuffer(1)
   617   augroup END
   619   augroup END
   618 
   620 
   619   " Only auto-load if the plugin is fully loaded.  This gives other plugins a
   621   " Only auto-load if the plugin is fully loaded.  This gives other plugins a
   756           \ ':g/^HG:/d<CR>'.
   758           \ ':g/^HG:/d<CR>'.
   757           \ ':update<CR>'.
   759           \ ':update<CR>'.
   758           \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
   760           \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
   759           \                             '"' . newCwd . '",' .
   761           \                             '"' . newCwd . '",' .
   760           \                             '"' . realFileName . '",' .
   762           \                             '"' . realFileName . '",' .
   761           \                             hgBufferCheck . ')<CR>'.
   763           \                             hgBufferCheck . ')<CR>'
   762           \ ':call <SID>HGBufferSetup(1)<CR>'
       
   763 
   764 
   764     silent 0put ='HG: ----------------------------------------------------------------------'
   765     silent 0put ='HG: ----------------------------------------------------------------------'
   765     silent put =\"HG: Enter Log.  Lines beginning with `HG:' are removed automatically\"
   766     silent put =\"HG: Enter Log.  Lines beginning with `HG:' are removed automatically\"
   766     silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
   767     silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
   767 
   768 
   910 
   911 
   911 
   912 
   912 " Function: s:HGUpdate() {{{2
   913 " Function: s:HGUpdate() {{{2
   913 function! s:HGUpdate()
   914 function! s:HGUpdate()
   914   return s:HGMarkOrigBufferForSetup(s:HGDoCommand('update', 'update', ''))
   915   return s:HGMarkOrigBufferForSetup(s:HGDoCommand('update', 'update', ''))
   915   call s:HGSetupBuffer(1)
       
   916 endfunction
   916 endfunction
   917 
   917 
   918 " Function: s:HGVimDiff(...) {{{2
   918 " Function: s:HGVimDiff(...) {{{2
   919 function! s:HGVimDiff(...)
   919 function! s:HGVimDiff(...)
   920   let originalBuffer = s:HGCurrentBufferCheck()
   920   let originalBuffer = s:HGCurrentBufferCheck()