Mercurial > vim-lawrencium
comparison plugin/lawrencium.vim @ 98:e5ac6464a767
Handle absolute/relative paths properly.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 29 Jul 2014 16:34:17 -0700 |
parents | 1ea783dd06dd |
children | 001b341ab8ad |
comparison
equal
deleted
inserted
replaced
97:e8b115e595d1 | 98:e5ac6464a767 |
---|---|
58 endfunction | 58 endfunction |
59 | 59 |
60 " Surrounds the given string with double quotes. | 60 " Surrounds the given string with double quotes. |
61 function! s:addquotes(str) | 61 function! s:addquotes(str) |
62 return '"' . a:str . '"' | 62 return '"' . a:str . '"' |
63 endfunction | |
64 | |
65 " Returns whether a path is absolute. | |
66 function! s:isabspath(path) | |
67 return a:path =~# '\v^(\w\:)?[/\\]' | |
63 endfunction | 68 endfunction |
64 | 69 |
65 " Normalizes the slashes in a path. | 70 " Normalizes the slashes in a path. |
66 function! s:normalizepath(path) | 71 function! s:normalizepath(path) |
67 if exists('+shellslash') && &shellslash | 72 if exists('+shellslash') && &shellslash |
289 endfunction | 294 endfunction |
290 | 295 |
291 " Gets a full path given a repo-relative path. | 296 " Gets a full path given a repo-relative path. |
292 function! s:HgRepo.GetFullPath(path) abort | 297 function! s:HgRepo.GetFullPath(path) abort |
293 let l:root_dir = self.root_dir | 298 let l:root_dir = self.root_dir |
294 if a:path =~# '\v^[/\\]' | 299 if s:isabspath(a:path) |
295 let l:root_dir = s:stripslash(l:root_dir) | 300 call s:throw("Expected relative path, got absolute path: " . a:path)` |
296 endif | 301 endif |
297 return l:root_dir . a:path | 302 return l:root_dir . a:path |
298 endfunction | 303 endfunction |
299 | 304 |
305 " Gets a repo-relative path given any path. | |
300 function! s:HgRepo.GetRelativePath(path) abort | 306 function! s:HgRepo.GetRelativePath(path) abort |
301 execute 'cd! ' . self.root_dir | 307 execute 'lcd! ' . self.root_dir |
302 let l:relative_path = fnamemodify(a:path, ':.') | 308 let l:relative_path = fnamemodify(a:path, ':.') |
303 execute 'cd! -' | 309 execute 'lcd! -' |
304 return l:relative_path | 310 return l:relative_path |
305 endfunction | 311 endfunction |
306 | 312 |
307 " Gets a list of files matching a root-relative pattern. | 313 " Gets a list of files matching a root-relative pattern. |
308 " If a flag is passed and is TRUE, a slash will be appended to all | 314 " If a flag is passed and is TRUE, a slash will be appended to all |