emacsrcsvcdiff

How to make vc-diff output more compact


I am doing C-x v = to inspect the current differences of a file under RCS control (that is, it has an associated file with ,v suffix). However, the output is barely readable because I changed every, say, 12th line. So I get these giant chunks of diffs, where I cannot easily deduce which line was changed to what other.

Is there a way to make this diff-output more readable and still usable (so that I can jump to the source rapidly)?

(I could

  1. C-x v l to see the old versions, then
  2. do f on the last one to check it out.
  3. M-x ediff the files

but that is not very handy)


Solution

  • When running vc-diff on a file in RCS, the diff output is a "context diff" by default. That means that the old and new chunks are displayed one above the other, with the differences highlighted. More modern version control systems produce "unified diffs", where the old and new version of each group of changed lines are adjacent.

    Emacs' diff-mode can convert diffs from one format to another. Type C-c C-u to convert a context diff to a unified diff, and C-c C-d to do the opposite.

    For example, this context diff:

    *** bar.txt 2013/11/19 14:00:03 1.1
    --- bar.txt 2013/11/19 14:00:11 1.2
    ***************
    *** 1,5 ****
      one
      two
    ! tree
      four
      five
    --- 1,5 ----
      one
      two
    ! three
      four
      five
    

    would be transformed to this unified diff:

    --- bar.txt 2013/11/19 14:00:03 1.1
    +++ bar.txt 2013/11/19 14:00:11 1.2
    @@ -1,5 +1,5 @@
     one
     two
    -tree
    +three
     four
     five
    

    Regardless of which format the diff is currently in, you can jump to the corresponding line in the source file with C-c C-c. If it doesn't find the correct file, use M-x diff-tell-file-name.