-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have some code here (can't share it with you, sorry) where I unified
and side-by-side diffs show up significantly differently.  Ignoring
whitespace only changes what parts of the lines are highlighted, so I
won't be discussing it further.

Here's what the original code looks like:

// Comment at line start
    if(cond && cond && cond)
    {
        stuff;
    }
// Comment at line start
    if(cond && cond && cond)
    {
        stuff;
    }

And the new:

// Comment at line start
    if (cond
     && cond
     && cond) {
        stuff;
    }

// Comment at line start
    if (cond
     && cond
     && cond) {
        stuff;
    }

The side-by-side diffs look like this:

// Comment at line start        // Comment at line start
    if(cond && cond && cond)  |     if (cond
    {                         <
                              >      && cond
                              >      && cond) {
        stuff;                          stuff;
    }                               }
// Comment at line start      <
    if(cond && cond && cond)  <
    {                         |
                              > // Comment at line start
                              >     if (cond
                              >      && cond
                              >      && cond) {
        stuff;                          stuff;
    }                               }

I find this quite odd.

The algorithm gets off to a good start, treating the first if line as a
change.  But then it deletes the "{" line and inserts the remainder of
the conditionals.  Perhaps this is because "{" alone isn't enough
context for it to decide that the third line is a change rather than a
new line.  I don't mind that part so much.

What really confuses me is the handling of the blank line that is
inserted before the second comment.  Rather than just insert a blank
line, the side-by-side diff deletes the comment and the if, then
replaces the "{" line with the blank, then reinserts the comment (even
though it's completely unchanged from the original) followed by the new
version of the if.

Wouldn't it be more efficient to say the following?  Due to having more
change lines than inserts and deletes, this presentation uses thirteen
lines whereas the above uses sixteen.

// Comment at line start        // Comment at line start
    if(cond && cond && cond)  |     if (cond
                              >      && cond
    {                         |      && cond) {
        stuff;                          stuff;
    }                               }
                              >
// Comment at line start
    if(cond && cond && cond)  |     if (cond
                              >      && cond
    {                         |      && cond) {
        stuff;                          stuff;
    }                               }

Ah well.  Meanwhile, the unified diff looks perfectly good:

 // Comment at line start
- -    if(cond && cond && cond)
- -    {
+    if (cond
+     && cond
+     && cond) {
         stuff;
     }
+
 // Comment at line start
- -    if(cond && cond && cond)
- -    {
+    if (cond
+     && cond
+     && cond) {
         stuff;
     }

- -- 
Andy Goth | <andrew.m.goth/at/gmail/dot/com>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (MingW32)

iQEcBAEBAgAGBQJUA/dUAAoJELtYwrrr47Y4KAYH/j+OouBBwNyMokfTwLfNZWWy
2aRoUMYIo7I/NsL5tJgufmMfan1U/u8frmukRyuumZ+xwNtRyQGuTpd5jpNfHzgd
uVvYk6U21Hq+zvVGlRw3HKSFg2RmzJmS9An8d2MIq4V+ZUQs22SCwtPPYtqJ+A25
QMmfaWOVIgmyRDx8u2H+EDLbP0TCjtZ1XeJJyWwTETFUSR0+s2HjNe/Y2S0enc62
4tYbkEjVYOxqAbmeb+TdDgYZkg93pOpPxATrGkX+yNIJgEBFB0+LMhjf/mxgIpyG
U9a4AEYgK5E25v5/R9YnNJdzyYMZFdUoOv+fSO+CtDf4Yt1kHJfn82+Wil5gzjg=
=jpuE
-----END PGP SIGNATURE-----
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to