comparison plugin/lawrencium.vim @ 122:a9136d95cf47

Escape paths to fix issues with repository paths with spaces in them.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 06 Oct 2015 23:13:43 -0700
parents 5168645017dd
children 860e6502b239 47209552ec46 098222a17b1f f9328d486624 3f1c7af69b43
comparison
equal deleted inserted replaced
121:5168645017dd 122:a9136d95cf47
177 let l:action = strpart(l:action, 0, l:equalidx) 177 let l:action = strpart(l:action, 0, l:equalidx)
178 endif 178 endif
179 endif 179 endif
180 180
181 if a:0 > 0 181 if a:0 > 0
182 execute 'cd! ' . l:root_dir 182 execute 'cd! ' . fnameescape(l:root_dir)
183 if a:1 == 'relative' 183 if a:1 == 'relative'
184 let l:repo_path = fnamemodify(l:repo_path, ':.') 184 let l:repo_path = fnamemodify(l:repo_path, ':.')
185 elseif a:1 == 'absolute' 185 elseif a:1 == 'absolute'
186 let l:repo_path = fnamemodify(l:repo_path, ':p') 186 let l:repo_path = fnamemodify(l:repo_path, ':p')
187 endif 187 endif
306 return s:normalizepath(l:root_dir . a:path) 306 return s:normalizepath(l:root_dir . a:path)
307 endfunction 307 endfunction
308 308
309 " Gets a repo-relative path given any path. 309 " Gets a repo-relative path given any path.
310 function! s:HgRepo.GetRelativePath(path) abort 310 function! s:HgRepo.GetRelativePath(path) abort
311 execute 'lcd! ' . self.root_dir 311 execute 'lcd! ' . fnameescape(self.root_dir)
312 let l:relative_path = fnamemodify(a:path, ':.') 312 let l:relative_path = fnamemodify(a:path, ':.')
313 execute 'lcd! -' 313 execute 'lcd! -'
314 return l:relative_path 314 return l:relative_path
315 endfunction 315 endfunction
316 316
871 function! s:Hg(bang, ...) abort 871 function! s:Hg(bang, ...) abort
872 let l:repo = s:hg_repo() 872 let l:repo = s:hg_repo()
873 if g:lawrencium_auto_cd 873 if g:lawrencium_auto_cd
874 " Temporary set the current directory to the root of the repo 874 " Temporary set the current directory to the root of the repo
875 " to make auto-completed paths work magically. 875 " to make auto-completed paths work magically.
876 execute 'cd! ' . l:repo.root_dir 876 execute 'cd! ' . fnameescape(l:repo.root_dir)
877 endif 877 endif
878 let l:output = call(l:repo.RunCommand, a:000, l:repo) 878 let l:output = call(l:repo.RunCommand, a:000, l:repo)
879 if g:lawrencium_auto_cd 879 if g:lawrencium_auto_cd
880 execute 'cd! -' 880 execute 'cd! -'
881 endif 881 endif
882 silent doautocmd User HgCmdPost 882 silent doautocmd User HgCmdPost
883 if a:bang 883 if a:bang
884 " Open the output of the command in a temp file. 884 " Open the output of the command in a temp file.
885 let l:temp_file = s:tempname('hg-output-', '.txt') 885 let l:temp_file = s:tempname('hg-output-', '.txt')
886 split 886 split
887 execute 'edit ' . l:temp_file 887 execute 'edit ' . fnameescape(l:temp_file)
888 call append(0, split(l:output, '\n')) 888 call append(0, split(l:output, '\n'))
889 call cursor(1, 1) 889 call cursor(1, 1)
890 890
891 " Make it a temp buffer 891 " Make it a temp buffer
892 setlocal bufhidden=delete 892 setlocal bufhidden=delete
982 let l:repo = s:hg_repo() 982 let l:repo = s:hg_repo()
983 let l:status_path = l:repo.GetLawrenciumPath('', 'status', '') 983 let l:status_path = l:repo.GetLawrenciumPath('', 'status', '')
984 984
985 " Open the Lawrencium buffer in a new split window of the right size. 985 " Open the Lawrencium buffer in a new split window of the right size.
986 if g:lawrencium_status_win_split_above 986 if g:lawrencium_status_win_split_above
987 execute "keepalt leftabove split " . l:status_path 987 execute "keepalt leftabove split " . fnameescape(l:status_path)
988 else 988 else
989 execute "keepalt rightbelow split " . l:status_path 989 execute "keepalt rightbelow split " . fnameescape(l:status_path)
990 endif 990 endif
991 991
992 if (line('$') == 1 && getline(1) == '') 992 if (line('$') == 1 && getline(1) == '')
993 " Buffer is empty, which means there are not changes... 993 " Buffer is empty, which means there are not changes...
994 " Quit and display a message. 994 " Quit and display a message.
1260 " Hgedit {{{ 1260 " Hgedit {{{
1261 1261
1262 function! s:HgEdit(bang, filename) abort 1262 function! s:HgEdit(bang, filename) abort
1263 let l:full_path = s:hg_repo().GetFullPath(a:filename) 1263 let l:full_path = s:hg_repo().GetFullPath(a:filename)
1264 if a:bang 1264 if a:bang
1265 execute "edit! " . l:full_path 1265 execute "edit! " . fnameescape(l:full_path)
1266 else 1266 else
1267 execute "edit " . l:full_path 1267 execute "edit " . fnameescape(l:full_path)
1268 endif 1268 endif
1269 endfunction 1269 endfunction
1270 1270
1271 call s:AddMainCommand("-bang -nargs=1 -complete=customlist,s:ListRepoFiles Hgedit :call s:HgEdit(<bang>0, <f-args>)") 1271 call s:AddMainCommand("-bang -nargs=1 -complete=customlist,s:ListRepoFiles Hgedit :call s:HgEdit(<bang>0, <f-args>)")
1272 1272
1542 1542
1543 " All good now, proceed. 1543 " All good now, proceed.
1544 if l:target_winnr > 0 1544 if l:target_winnr > 0
1545 execute l:target_winnr . "wincmd w" 1545 execute l:target_winnr . "wincmd w"
1546 endif 1546 endif
1547 execute 'keepalt ' . l:cmd . l:special 1547 execute 'keepalt ' . l:cmd . fnameescape(l:special)
1548 1548
1549 " Set the reuse ID if we had one. 1549 " Set the reuse ID if we had one.
1550 if l:reuse_id != '' 1550 if l:reuse_id != ''
1551 call s:trace("Setting reuse ID '".l:reuse_id."' on buffer: ".bufnr('%')) 1551 call s:trace("Setting reuse ID '".l:reuse_id."' on buffer: ".bufnr('%'))
1552 call setbufvar('%', l:reuse_id, 1) 1552 call setbufvar('%', l:reuse_id, 1)
1626 let l:msg .= "HG: Write and quit buffer to proceed.\n" 1626 let l:msg .= "HG: Write and quit buffer to proceed.\n"
1627 let l:msg .= "HG: --\n" 1627 let l:msg .= "HG: --\n"
1628 let l:msg .= "HG: user: " . split(a:repo.RunCommand('showconfig ui.username'), '\n')[0] . "\n" 1628 let l:msg .= "HG: user: " . split(a:repo.RunCommand('showconfig ui.username'), '\n')[0] . "\n"
1629 let l:msg .= "HG: branch '" . split(a:repo.RunCommand('branch'), '\n')[0] . "'\n" 1629 let l:msg .= "HG: branch '" . split(a:repo.RunCommand('branch'), '\n')[0] . "'\n"
1630 1630
1631 execute 'lcd ' . a:repo.root_dir 1631 execute 'lcd ' . fnameescape(a:repo.root_dir)
1632 if len(a:filenames) 1632 if len(a:filenames)
1633 let l:status_lines = split(a:repo.RunCommand('status', a:filenames), "\n") 1633 let l:status_lines = split(a:repo.RunCommand('status', a:filenames), "\n")
1634 else 1634 else
1635 let l:status_lines = split(a:repo.RunCommand('status'), "\n") 1635 let l:status_lines = split(a:repo.RunCommand('status'), "\n")
1636 endif 1636 endif
1770 let l:log_opts = join(a:000, ',') 1770 let l:log_opts = join(a:000, ',')
1771 endif 1771 endif
1772 1772
1773 let l:log_path = l:repo.GetLawrenciumPath(l:path, 'log', l:log_opts) 1773 let l:log_path = l:repo.GetLawrenciumPath(l:path, 'log', l:log_opts)
1774 if a:vertical 1774 if a:vertical
1775 execute 'vertical pedit ' . l:log_path 1775 execute 'vertical pedit ' . fnameescape(l:log_path)
1776 else 1776 else
1777 execute 'pedit ' . l:log_path 1777 execute 'pedit ' . fnameescape(l:log_path)
1778 endif 1778 endif
1779 wincmd P 1779 wincmd P
1780 1780
1781 " Add some other nice commands and mappings. 1781 " Add some other nice commands and mappings.
1782 let l:is_file = (l:path != '' && filereadable(l:repo.GetFullPath(l:path))) 1782 let l:is_file = (l:path != '' && filereadable(l:repo.GetFullPath(l:path)))
1950 endif 1950 endif
1951 1951
1952 if l:has_local_edits 1952 if l:has_local_edits
1953 " Just open the output of the command. 1953 " Just open the output of the command.
1954 echom "Local edits found, will show the annotations for the parent revision." 1954 echom "Local edits found, will show the annotations for the parent revision."
1955 execute 'edit ' . l:annotation_path 1955 execute 'edit ' . fnameescape(l:annotation_path)
1956 setlocal nowrap nofoldenable 1956 setlocal nowrap nofoldenable
1957 setlocal filetype=hgannotate 1957 setlocal filetype=hgannotate
1958 else 1958 else
1959 " Store some info about the current buffer. 1959 " Store some info about the current buffer.
1960 let l:cur_topline = line('w0') + &scrolloff 1960 let l:cur_topline = line('w0') + &scrolloff
1964 1964
1965 " Open the annotated file in a split buffer on the left, after 1965 " Open the annotated file in a split buffer on the left, after
1966 " having disabled wrapping and folds on the current file. 1966 " having disabled wrapping and folds on the current file.
1967 " Make both windows scroll-bound. 1967 " Make both windows scroll-bound.
1968 setlocal scrollbind nowrap nofoldenable 1968 setlocal scrollbind nowrap nofoldenable
1969 execute 'keepalt leftabove vsplit ' . l:annotation_path 1969 execute 'keepalt leftabove vsplit ' . fnameescape(l:annotation_path)
1970 setlocal nonumber 1970 setlocal nonumber
1971 setlocal scrollbind nowrap nofoldenable foldcolumn=0 1971 setlocal scrollbind nowrap nofoldenable foldcolumn=0
1972 setlocal filetype=hgannotate 1972 setlocal filetype=hgannotate
1973 1973
1974 " When the annotated buffer is deleted, restore the settings we 1974 " When the annotated buffer is deleted, restore the settings we
2067 2067
2068 function! s:HgQSeries() abort 2068 function! s:HgQSeries() abort
2069 " Open the MQ series in the preview window and jump to it. 2069 " Open the MQ series in the preview window and jump to it.
2070 let l:repo = s:hg_repo() 2070 let l:repo = s:hg_repo()
2071 let l:path = l:repo.GetLawrenciumPath('', 'qseries', '') 2071 let l:path = l:repo.GetLawrenciumPath('', 'qseries', '')
2072 execute 'pedit ' . l:path 2072 execute 'pedit ' . fnameescape(l:path)
2073 wincmd P 2073 wincmd P
2074 2074
2075 " Make the series buffer a Lawrencium buffer. 2075 " Make the series buffer a Lawrencium buffer.
2076 let b:mercurial_dir = l:repo.root_dir 2076 let b:mercurial_dir = l:repo.root_dir
2077 call s:DefineMainCommands() 2077 call s:DefineMainCommands()
2125 let l:current = split(l:repo.RunCommand('qheader', l:patchname), '\n') 2125 let l:current = split(l:repo.RunCommand('qheader', l:patchname), '\n')
2126 2126
2127 " Open a temp file to write the commit message. 2127 " Open a temp file to write the commit message.
2128 let l:temp_file = s:tempname('hg-qrefedit-', '.txt') 2128 let l:temp_file = s:tempname('hg-qrefedit-', '.txt')
2129 split 2129 split
2130 execute 'edit ' . l:temp_file 2130 execute 'edit ' . fnameescape(l:temp_file)
2131 call append(0, 'HG: Enter the new commit message for patch "' . l:patchname . '" here.\n') 2131 call append(0, 'HG: Enter the new commit message for patch "' . l:patchname . '" here.\n')
2132 call append(0, '') 2132 call append(0, '')
2133 call append(0, l:current) 2133 call append(0, l:current)
2134 call cursor(1, 1) 2134 call cursor(1, 1)
2135 2135