Loading ...
Sorry, an error occurred while loading the content.
 

Re: diff bug in vim?

Expand Messages
  • Bram Moolenaar
    ... Right, that s a bug. The problem is that Vim first deletes the existing lines and then adds the lines from the other buffer. When the buffer is empty in
    Message 1 of 3 , Jan 28, 2006
      Malahal wrote:

      > I have two files, say x, y. They both are only 1 line files. I open them
      > using "vim -d x y" and use 'do' (diff obtain) to make them same. Vim
      > actually gets the changes from the other buffer, but it also get an
      > empty line as a BONUS. Is this a bug? Why an extra empty line? Samething
      > happens even if use 'dp'

      Right, that's a bug. The problem is that Vim first deletes the existing
      lines and then adds the lines from the other buffer. When the buffer is
      empty in between a dummy line gets added which should be deleted
      afterwards. The dummy line is there because a buffer must always have
      at least one line.

      This patch will fix it:

      Index: diff.c
      ===================================================================
      RCS file: /cvsroot/vim/vim7/src/diff.c,v
      retrieving revision 1.10
      diff -u -r1.10 diff.c
      --- diff.c 22 Jan 2006 23:21:24 -0000 1.10
      +++ diff.c 28 Jan 2006 12:11:54 -0000
      @@ -1893,6 +1893,7 @@
      buf_T *buf;
      int start_skip, end_skip;
      int new_count;
      + int buf_empty;

      /* Find the current buffer in the list of diff buffers. */
      idx_cur = diff_buf_idx(curbuf);
      @@ -2047,9 +2048,12 @@
      end_skip = 0;
      }

      + buf_empty = FALSE;
      added = 0;
      for (i = 0; i < count; ++i)
      {
      + /* remember deleting the last line of the buffer */
      + buf_empty = curbuf->b_ml.ml_line_count == 1;
      ml_delete(lnum, FALSE);
      --added;
      }
      @@ -2066,6 +2070,13 @@
      ml_append(lnum + i - 1, p, 0, FALSE);
      vim_free(p);
      ++added;
      + if (buf_empty && curbuf->b_ml.ml_line_count == 2)
      + {
      + /* Added the first line into an empty buffer, need to
      + * delete the dummy empty line. */
      + buf_empty = FALSE;
      + ml_delete((linenr_T)2, FALSE);
      + }
      }
      }
      new_count = dp->df_count[idx_to] + added;

      --
      hundred-and-one symptoms of being an internet addict:
      193. You ask your girlfriend to drive home so you can sit back with
      your PDA and download the information to your laptop

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ download, build and distribute -- http://www.A-A-P.org ///
      \\\ help me help AIDS victims -- http://www.ICCF.nl ///
    Your message has been successfully submitted and would be delivered to recipients shortly.