Subject: git merge failed to detect conflict

From: Juergen Kosel <[email-masked]>
Date: Sun, 19 Jun 2011 17:51:29 +0200

Hello,

I have just steped into a boarder case, where git merge fails to detect
a merge conflict:

The commit A in the remote branch was the following:

diff --git a/LoWPAN.c b/LoWPAN.c
index 3e929e5..1b768e2 100644 (file)
- --- a/LoWPAN.c
+++ b/LoWPAN.c
@@ -431,12 +431,16 @@ int main (int argc, char **argv)
       }
       printf("\n");
 #endif
- -      // forward into kernel/tap device
- -      retval=lowpan_writeout(&rx_packet,tap_fd);
- -      if(retval<0) {
- -       ERROR_OUTPUT("Failed to forward datagram into tap device: %s",
- -                    strerror(errno));
- -       break; // leave the while loop
+      // ensure that we haven't got our own multicast
+      if((rx_packet.source.pan_id != own_802154_addr.pan_id)
+        || (rx_packet.source.short_addr != own_802154_addr.short_addr)) {
+       // forward into kernel/tap device
+       retval=lowpan_writeout(&rx_packet,tap_fd);
+       if(retval<0) {
+         ERROR_OUTPUT("Failed to forward datagram into tap device: %s",
+                      strerror(errno));
+         break; // leave the while loop
+       }
       }
     }
   }

The commit B in the local branch was:
diff --git a/LoWPAN.c b/LoWPAN.c
index 3e929e5..a7c65e3 100644 (file)
- --- a/LoWPAN.c
+++ b/LoWPAN.c
@@ -438,6 +438,8 @@ int main (int argc, char **argv)
                     strerror(errno));
        break; // leave the while loop
       }
+      DEBUG_OUTPUT("Successfully forwarded %d bytes into the tap device",
+                  retval);
     }
   }

The resulting merge commit AB is:
diff --cc LoWPAN.c
index a7c65e3,1b768e2..92ec5f7
- --- 1/LoWPAN.c
- --- 2/LoWPAN.c
+++ b/LoWPAN.c
@@@ -431,15 -431,17 +431,19 @@@ int main (int argc, char **argv
        }
        printf("\n");
  #endif
- -       // forward into kernel/tap device
- -       retval=lowpan_writeout(&rx_packet,tap_fd);
- -       if(retval<0) {
- -       ERROR_OUTPUT("Failed to forward datagram into tap device: %s",
- -                    strerror(errno));
- -       break; // leave the while loop
+       // ensure that we haven't got our own multicast
+       if((rx_packet.source.pan_id != own_802154_addr.pan_id)
+        || (rx_packet.source.short_addr != own_802154_addr.short_addr)) {
+       // forward into kernel/tap device
+       retval=lowpan_writeout(&rx_packet,tap_fd);
+       if(retval<0) {
+         ERROR_OUTPUT("Failed to forward datagram into tap device: %s",
+                      strerror(errno));
+         break; // leave the while loop
+       }
        }
 +      DEBUG_OUTPUT("Successfully forwarded %d bytes into the tap device",
 +                 retval);
      }
    }

If you just look at the diff output, it is difficult to see the problem.
But if you look at the corresponding code sections, than you see that
diff has splitted the conflictiong section into two none conflicting
sections.

Code A:

 434       // ensure that we haven't got our own multicast
 435       if((rx_packet.source.pan_id != own_802154_addr.pan_id)
 436          || (rx_packet.source.short_addr !=
own_802154_addr.short_addr)) {
 437         // forward into kernel/tap device
 438         retval=lowpan_writeout(&rx_packet,tap_fd);
 439         if(retval<0) {
 440           ERROR_OUTPUT("Failed to forward datagram into tap device:
%s",
 441                        strerror(errno));
 442           break; // leave the while loop
 443         }
 444       }

Code B:

 434       // forward into kernel/tap device
 435       retval=lowpan_writeout(&rx_packet,tap_fd);
 436       if(retval<0) {
 437         ERROR_OUTPUT("Failed to forward datagram into tap device: %s",
 438                      strerror(errno));
 439         break; // leave the while loop
 440       }
 441       DEBUG_OUTPUT("Successfully forwarded %d bytes into the tap
device",
 442                    retval);
 443     }

Code AB:

 434       // ensure that we haven't got our own multicast
 435       if((rx_packet.source.pan_id != own_802154_addr.pan_id)
 436          || (rx_packet.source.short_addr !=
own_802154_addr.short_addr)) {
 437         // forward into kernel/tap device
 438         retval=lowpan_writeout(&rx_packet,tap_fd);
 439         if(retval<0) {
 440           ERROR_OUTPUT("Failed to forward datagram into tap device:
%s",
 441                        strerror(errno));
 442           break; // leave the while loop
 443         }
 444       }
 445       DEBUG_OUTPUT("Successfully forwarded %d bytes into the tap
device",
 446                    retval);
 447     }

Obviously git/diff has failed to detect that human intervention is
required here. One _workaround_ would be, to demand in the coding style,
that closing braces get unique comments.
But what would be the solution of this problem?

Greetings
	Juergen