445a446 > exec 'command! -buffer -bang -nargs=0 RenSVK :call '.s:sid.'_PerformSVKMove()' 655a657,739 > function! PerformSVKMove() "{{{1 > " The function to do the renaming > > " Prevent a report of our actions from showing up > let oldRep=&report > let save_sc = &sc > set report=10000 nosc > > " Get the current lines, except the first > let saved_z = @z > normal 1GVG"zy > let bufferText = @z > let @z = saved_z > > let splitBufferText = split(bufferText, "\n") > let modifiedFileList = [] > for line in splitBufferText > if line !~ '^#' > let line = substitute(line, s:linkPrefix.'.*','','') > let line = substitute(line, '\/$','','') > let modifiedFileList += [ b:renamerDirectory . '/' . line ] > endif > endfor > > let numOriginalFiles = len(b:renamerOriginalPathfileList) > let numModifiedFiles = len(modifiedFileList) > > if numModifiedFiles != numOriginalFiles > echoe 'Dir contains '.numOriginalFiles.' writeable files, but there are '.numModifiedFiles.' listed in buffer. These numbers should be equal' > return > endif > > " The actual renaming process is a hard one to do reliably. Consider a few cases: > " 1. a -> c > " b -> c > " => This should give an error, else a will be deleted. > " 2. a -> b > " b -> c > " This should be okay, but basic sequential processing would give > " a -> c, and b is deleted - not at all what was asked for! > " 3. a -> b > " b -> a > " This should be okay, but basic sequential processing would give > " a remains unchanged and b is deleted!! > " So - first check that all destination files are unique. > " If yes, then for all files that are changing, rename them to > " _GOING_TO_ > " Then finally rename them to . > > " Check for duplicates > let sortedModifiedFileList = sort(copy(modifiedFileList)) > let lastFile = '' > for thisFile in sortedModifiedFileList > if thisFile == lastFile > echoe "Duplicate final file name found, '".thisFile."'" > return > end > let lastFile = thisFile > endfor > > " SVK Move > let i = 0 > while i < numOriginalFiles > if b:renamerOriginalPathfileList[i] != modifiedFileList[i] > "echom "PWD=".b:renamerDirectory." svk ".b:renamerOriginalPathfileList[i]." ".modifiedFileList[i] > let oldName = b:renamerOriginalPathfileList[i] > let newName = modifiedFileList[i] > call system("svk mv ".oldName." ".newName) > if v:shell_error != 0 > echoe "Unable to svk mv ".oldName." ".newName > " Continue anyway with the other files since we've already started renaming > endif > endif > let i += 1 > endwhile > > let &report=oldRep > let &sc = save_sc > > exec 'call '.s:sid.'_StartRenamer(0,b:renamerDirectory)' > > endfunction >