tags:

views:

234

answers:

4

Our team uses svn to manage our source. When performing a re-factor on a C file, I occasionally both change functions and move them within the file. Generally I try to avoid moving functions, because it makes the default svn diff get a bit addled about what's going on, and it often provides a diff which is more confusing than it needs to be.

None the less, occasionally I do make both function file-location changes, and function internal code changes. Another place this comes up is in branch merging, when the file is in conflict, and either or both branches have moves as well as intra-function changes.

So, what I am looking for is a semantically aware diff tool that could tell me diffs at two levels - function arrangement, and detail (intra-function). I tried using the "-p" option to diff (-x -p to svn diff), but that's not what it's intended for, it certainly didn't do what I wanted.

Another option I just thought of is using a diff program designed to catch code-copying such as a university might use for checking assignments, but nothing obvious came up in a quick search.

+1  A: 

One way to do it with the tools you have is to move the functions first, check them in, then change them. Or have two enlistments, and when you see this happening move them in one, svn up the other, resolve the merge issue. It moves the work to you, but makes code reviews easier.

jeffamaphone
It makes it easier because it avoids the problem I am trying to solve. I already know how to do that.I added another example situation (merging) to the question, to clarify that this question is for the case where separating the two actions is a serious pain.
Peter
Oh yeah, that sucks. We switched away from SVN for precisely that reason. And others.
jeffamaphone
There are better diff tools, odd is one that is pretty good (but not free). However, I don't recall using any that explicitly do what you want. Very unfortunate. If possible, it would be a great feature.
jeffamaphone
A: 

you could try to do that refactoring with git:

And when using git, the whole 'keep code movement separate from changes' has an even more fundamental reason: git can track code movement (again, whether moving a whole file or just a function between files), and doing a 'git blame -C' will actually follow code movement between files. It does that by similarity analysis, but it does mean that if you both move the code and change it at the same time, git cannot see that 'oh, that function came originally from that other file', and now you get worse annotations about where code actually originated.

so, the idea would be to initialize a git repository and replay all the relevant svn-commits to that repository. after that, use git to find out which content moved to where.

akira
whats the downvote for?
akira
It wasn't me, but I suspect it was probably because the question is asking specifically about how to accomplish function-based diffs in svn.
Martin
A: 

since you increased the level of difficulty of the problem a bit with your last edit:

there are limits of what svn can do, thats the reason why git was written. the answer to your problem is basically "no, there are no tools which can track code on a semantic level with svn"

(actually there are no semantic tracking tools available for git as well, it tracks content)

akira
stackoverflow is not a forum, please put comments below the original question or answer.
Justicle
AFAIK you can use any diff tool you like with SVN. If you happen to have one that does function-level comparison, then so does SVN. So this is _not_ a git vs. SVN issue. -1
sbi
A: 

I make cosmetic changes (moving functions around) and functional changes in different commits, and put "cosmetics" in the commit message. That way, the huge and uninteresting diff for cosmetics work is ignored, and you have a concise diff for the functional changes.

orip