tags:

views:

631

answers:

4

I've always wanted to be able to get a reasonably elegant way of getting vimdiff to work with a CVS controlled file. I've found numerous (somewhat hacky) scripts around the internet (best example here) that basically check out the file you are editing from CVS to a temp file, and vimdiff the two. None of these take into account branches, and always assume you're working from MAIN, which for me is completely useless.

So, my question is this: has anyone out there found a decent solution for this that does more than this script?

Or failing that, does anyone have any ideas of how they would implement this, or suggestions for what features you would consider vital for something that does this? My intention is that, if no one can suggest an already built solution to either use or build from, we start building one from here.

A: 

You could change the call to cvs to take branches into account. That shouldn't be to hard. It bit harder would to change the whole function and make the branch your working a variable (argument, session, global or otherwise).

Peter Stuifzand
+2  A: 

I've been working on a similar script here: http://github.com/ghewgill/vim-scmdiff (in fact, they may have the same ancestry). I haven't used scmdiff with cvs, but it should do a diff against the branch you have checked out. You can also specify that you want to diff against a particular revision (with :D revision ). Hopefully this helps, and feel free to contribute if you've got improvements!

@braklet: Thanks for the changes. I was uncomfortable with C-d as a key binding choice so C-h might be doable. However, it would be super annoying if one's key mapping mapped Backspace to C-h. Any suggestions? And, I wonder why the cvs commands didn't work in relative dirs for you. That's odd.

Greg Hewgill
I suggest <Leader>d (which I changed in my fork of your script on GitHub ;).
jkramer
good idea, merged!
Greg Hewgill
Hehe, that was fast. Thanks!
jkramer
+1  A: 

@Greg Hewgill: thanks for the script! I had a couple of issues with it though, so here's what I'd change:

line 21:

< map <silent> <C-d> :call <SID>scmToggle()<CR>
--
> map <silent> <C-h> :call <SID>scmToggle()<CR>

I use Ctrl-d for page-down (too lazy to move all that way over to PdDn), so had to switch to Ctrl-h.

line 112:

<         let cmd = 'cd ' . g:scmBufPath . ' && ' . g:scmDiffCommand . ' diff ' . g:scmDiffRev . ' ' . expand('%:p') . ' > ' . tmpdiff
--
> if g:scmDiffUseAbsPaths 
>     let cmd = 'cd ' . g:scmBufPath . ' && ' . g:scmDiffCommand . ' diff ' . g:scmDiffRev . ' ' . expand('%:p') . ' > ' . tmpdiff
> else
>     let cmd = g:scmDiffCommand . ' diff ' . g:scmDiffRev . ' ' . bufname('%') . ' > ' . tmpdiff
> endif

I had issues with not being able to use absolute paths with CVS. I don't know if this is a weirdness of our local set up here, or if it's a global CVS thing. So, I've made a configurable variable that you can put in your .vimrc to use relative path instead.

It now seems to work exactly how I wanted, so I'll keep bashing away and see if I can find anything else that breaks, posting fixes as I go.

Edit: Forgot to add: please feel free to add these changes to your script on github if you feel they're worthwhile.

braklet
A: 

VCSCommand is another actively maintained vim script for VCS integration. It has support for CVS/SVN/SVK/git.

I use it all the time for SVN and never had any complaints. The shortcuts use mapleader, so it is unlikely that they will overwrite existing mappings.

0x89
I actually already use VCSCommand, and it's definitely been more reliable than scmdiff for getting diffs (eg if I'm in a directory of checked out code that I got to through a symlink from another set of checked out code), however, so I guess I need to combine the methods from VCSCommand for getting diffs with the methods from scmdiff for displaying them...
braklet
have you tried VCSVimDiff / <Leader>cv? I think it is a perfect way of displaying diffs..
0x89