问题
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:
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.
回答2:
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.
回答3:
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)
回答4:
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.
来源:https://stackoverflow.com/questions/1464098/how-can-i-get-c-function-based-diffs