# HG changeset patch # User Ludovic Chabant # Date 1406676857 25200 # Node ID e5ac6464a76793097719808cf5f1987073c66c89 # Parent e8b115e595d178f2cef8456d6130440be92888a8 Handle absolute/relative paths properly. diff -r e8b115e595d1 -r e5ac6464a767 plugin/lawrencium.vim --- a/plugin/lawrencium.vim Fri Jul 25 09:46:00 2014 -0700 +++ b/plugin/lawrencium.vim Tue Jul 29 16:34:17 2014 -0700 @@ -62,6 +62,11 @@ return '"' . a:str . '"' endfunction +" Returns whether a path is absolute. +function! s:isabspath(path) + return a:path =~# '\v^(\w\:)?[/\\]' +endfunction + " Normalizes the slashes in a path. function! s:normalizepath(path) if exists('+shellslash') && &shellslash @@ -291,16 +296,17 @@ " Gets a full path given a repo-relative path. function! s:HgRepo.GetFullPath(path) abort let l:root_dir = self.root_dir - if a:path =~# '\v^[/\\]' - let l:root_dir = s:stripslash(l:root_dir) + if s:isabspath(a:path) + call s:throw("Expected relative path, got absolute path: " . a:path)` endif return l:root_dir . a:path endfunction +" Gets a repo-relative path given any path. function! s:HgRepo.GetRelativePath(path) abort - execute 'cd! ' . self.root_dir + execute 'lcd! ' . self.root_dir let l:relative_path = fnamemodify(a:path, ':.') - execute 'cd! -' + execute 'lcd! -' return l:relative_path endfunction