contrib/vim/hg-menu.vim
author Brodie Rao <brodie@sf.io>
Mon, 16 Sep 2013 01:08:29 -0700
changeset 20192 38fad5e76ee8
parent 5081 ea7b982b6c08
permissions -rw-r--r--
branches: simplify with repo.branchmap().iterbranches() Running hg branches on the PyPy repo (with 996) over a busy NFS server, before this change: $ time hg --profile branches > /dev/null CallCount Recursive Total(s) Inline(s) module:lineno(function) 1069 0 1.2955 1.2955 <open> 1063 0 0.5576 0.5576 <method 'close' of 'file' objects> 4122 0 0.1993 0.0449 mercurial.repoview:161(changelog) 8240 0 0.0771 0.0299 mercurial.changelog:133(tip) 4122 0 0.0422 0.0204 mercurial.localrepo:26(__get__) 8240 0 0.0252 0.0131 <len> 4122 0 0.0060 0.0037 mercurial.repoview:112(filterrevs) 8240 0 0.0028 0.0028 <hash> 3029 0 0.2139 0.0390 mercurial.context:202(__init__) 3029 0 0.1402 0.0339 mercurial.repoview:161(changelog) 3029 0 0.0240 0.0087 mercurial.changelog:183(rev) 9087 0 0.0067 0.0067 <isinstance> 1096 0 0.0025 0.0025 <binascii.unhexlify> 4125 0 0.0015 0.0015 <len> 4229 0 0.0344 0.0344 mercurial.revlog:296(rev) 1061 0 0.0343 0.0343 <method 'seek' of 'file' objects> 1063 0 0.0339 0.0339 <method 'read' of 'file' objects> 40476 16488 0.0479 0.0311 <len> 16488 0 0.0216 0.0168 mercurial.revlog:262(__len__) 8240 0 0.0771 0.0299 mercurial.changelog:133(tip) 8240 0 0.0281 0.0203 mercurial.changelog:190(node) 8240 0 0.0191 0.0095 <len> 1342 0 0.0278 0.0278 <zlib.decompress> 1074 0 2.2143 0.0266 mercurial.changelog:270(read) 1074 0 2.1328 0.0230 mercurial.revlog:907(revision) 1073 0 0.0208 0.0108 mercurial.changelog:28(decodeextra) 2148 0 0.0072 0.0072 <method 'split' of 'str' objects> 2148 0 0.0211 0.0038 mercurial.encoding:61(tolocal) 1074 0 0.0028 0.0028 <method 'index' of 'str' objects> 1061 0 1.9811 0.0237 mercurial.revlog:817(_loadchunk) real 0m2.742s user 0m0.811s sys 0m0.188s After this change: $ time hg --profile branches > /dev/null CallCount Recursive Total(s) Inline(s) module:lineno(function) 2092 0 0.1444 0.0292 mercurial.context:202(__init__) 2092 0 0.0908 0.0216 mercurial.repoview:161(changelog) 2092 0 0.0164 0.0057 mercurial.changelog:183(rev) 6276 0 0.0045 0.0045 <isinstance> 1096 0 0.0024 0.0024 <binascii.unhexlify> 3188 0 0.0013 0.0013 <len> 2218 0 0.0230 0.0230 mercurial.revlog:296(rev) 2111 0 0.1028 0.0218 mercurial.repoview:161(changelog) 4218 0 0.0387 0.0146 mercurial.changelog:133(tip) 2111 0 0.0238 0.0104 mercurial.localrepo:26(__get__) 4218 0 0.0122 0.0062 <len> 2111 0 0.0038 0.0021 mercurial.repoview:112(filterrevs) 4218 0 0.0014 0.0014 <hash> 20240 8444 0.0233 0.0149 <len> 8444 0 0.0110 0.0084 mercurial.revlog:262(__len__) 4218 0 0.0387 0.0146 mercurial.changelog:133(tip) 4218 0 0.0144 0.0103 mercurial.changelog:190(node) 4218 0 0.0097 0.0048 <len> 2398 1 0.0271 0.0115 mercurial.localrepo:26(__get__) 2398 1 0.0146 0.0046 mercurial.scmutil:939(__get__) 2124 0 0.0009 0.0009 mercurial.localrepo:330(unfiltered) 274 0 0.0002 0.0002 mercurial.repoview:192(unfiltered) 4 0 0.1409 0.0112 mercurial.branchmap:19(read) 1096 0 0.1113 0.0028 mercurial.localrepo:407(__contains__) 1098 0 0.0020 0.0020 <method 'split' of 'str' objects> 1097 0 0.0019 0.0019 <binascii.unhexlify> 1096 0 0.0093 0.0018 mercurial.encoding:61(tolocal) 1096 0 0.0010 0.0010 <method 'append' of 'list' objects> 4349 0 0.0150 0.0105 mercurial.changelog:190(node) 4349 0 0.0045 0.0045 mercurial.revlog:317(node) real 0m0.362s user 0m0.329s sys 0m0.024s
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1414
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     1
" vim600: set foldmethod=marker:
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     2
" =============================================================================
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     3
"  Name Of File: hg-menu.vim
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     4
"   Description: Interface to Mercurial Version Control.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     5
"        Author: Steve Borho (modified Jeff Lanzarotta's RCS script)
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     6
"          Date: Wednesday, October 5, 2005
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     7
"       Version: 0.1.0
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     8
"     Copyright: None.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
     9
"         Usage: These command and gui menu displays useful hg functions
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    10
" Configuration: Your hg executable must be in your path.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    11
" =============================================================================
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2351
diff changeset
    12
1414
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    13
" Section: Init {{{1
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    14
if exists("loaded_hg_menu")
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    15
  finish
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    16
endif
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    17
let loaded_hg_menu = 1
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    18
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    19
" Section: Menu Options {{{1
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    20
if has("gui")
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    21
"  amenu H&G.Commit\ File<Tab>,ci :!hg commit %<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    22
"  amenu H&G.Commit\ All<Tab>,call :!hg commit<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    23
"  amenu H&G.-SEP1-        <nul>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    24
  amenu H&G.Add<Tab>\\add :!hg add %<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    25
  amenu H&G.Forget\ Add<Tab>\\fgt :!hg forget %<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    26
  amenu H&G.Show\ Differences<Tab>\\diff :call ShowResults("FileDiff", "hg\ diff")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    27
  amenu H&G.Revert\ to\ Last\ Version<Tab>\\revert :!hg revert %<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    28
  amenu H&G.Show\ History<Tab>\\log :call ShowResults("FileLog", "hg\ log")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    29
  amenu H&G.Annotate<Tab>\\an :call ShowResults("annotate", "hg\ annotate")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    30
  amenu H&G.-SEP1-        <nul>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    31
  amenu H&G.Repo\ Status<Tab>\\stat :call ShowResults("RepoStatus", "hg\ status")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    32
  amenu H&G.Pull<Tab>\\pull :!hg pull<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    33
  amenu H&G.Update<Tab>\\upd :!hg update<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    34
endif
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    35
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    36
" Section: Mappings {{{1
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    37
if(v:version >= 600)
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    38
  " The default Leader is \ 'backslash'
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    39
  map <Leader>add       :!hg add %<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    40
  map <Leader>fgt       :!hg forget %<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    41
  map <Leader>diff      :call ShowResults("FileDiff", "hg\ diff")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    42
  map <Leader>revert    :!hg revert %<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    43
  map <Leader>log       :call ShowResults("FileLog", "hg\ log")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    44
  map <Leader>an        :call ShowResults("annotate", "hg\ annotate")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    45
  map <Leader>stat      :call ShowResults("RepoStatus", "hg\ status")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    46
  map <Leader>upd       :!hg update<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    47
  map <Leader>pull      :!hg pull<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    48
else
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    49
  " pre 6.0, the default Leader was a comma
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    50
  map ,add          :!hg add %<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    51
  map ,fgt          :!hg forget %<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    52
  map ,diff         :call ShowResults("FileDiff", "hg\ diff")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    53
  map ,revert       :!hg revert<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    54
  map ,log          :call ShowResults("FileLog", "hg\ log")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    55
  map ,an           :call ShowResults("annotate", "hg\ annotate")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    56
  map ,stat         :call ShowResults("RepoStatus", "hg\ status")<CR><CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    57
  map ,upd          :!hg update<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    58
  map ,pull         :!hg pull<CR>:e!<CR>
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    59
endif
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    60
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    61
" Section: Functions {{{1
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    62
" Show the log results of the current file with a revision control system.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    63
function! ShowResults(bufferName, cmdName)
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    64
  " Modify the shortmess option:
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    65
  " A  don't give the "ATTENTION" message when an existing swap file is
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    66
  "    found.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    67
  set shortmess+=A
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    68
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    69
  " Get the name of the current buffer.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    70
  let currentBuffer = bufname("%")
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    71
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    72
  " If a buffer with the name rlog exists, delete it.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    73
  if bufexists(a:bufferName)
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    74
    execute 'bd! ' a:bufferName
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    75
  endif
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    76
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    77
  " Create a new buffer.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    78
  execute 'new ' a:bufferName
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    79
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    80
  " Execute the command.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    81
  execute 'r!' a:cmdName ' ' currentBuffer
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    82
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    83
  " Make is so that the file can't be edited.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    84
  setlocal nomodified
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    85
  setlocal nomodifiable
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    86
  setlocal readonly
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    87
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    88
  " Go to the beginning of the buffer.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    89
  execute "normal 1G"
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    90
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    91
  " Restore the shortmess option.
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    92
  set shortmess-=A
32fde51910c0 New vim script; provides key mappings and menus for GVIM
Steve Borho <steve@borho.org>
parents:
diff changeset
    93
endfunction