Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Eliminating merge conflicts for adjacent/contiguous blocks?

I'm getting merge conflicts for a case that I don't think should be a conflict.  In the end, it comes down to code in the merge( ) method of MergeAlgorithm.java.  The code is as follows (around line 150 in the Java file):

   if (oursEdit.getEndA() < theirsEdit.getBeginA()) {
   ...

   } else if (theirsEdit.getEndA() < oursEdit.getBeginA()) {
    ...

   } else {
    ...

The checks for the begin/end of the Edits looks for strictly less-than, so the begin/ends have to differ by at least one line.  I think it would be okay if the check was for less-than-or-equal, allowing the Edit blocks to be contiguous.

As an example, consider a document like this in a master branch:

    0: master
    1:
    2:
    3: master

Next, assume that there are branches called "branch1" and "branch2" based on the initial version of master, but with the following changes:

In branch "branch1":

    0: master
    1: branch1 change
    2:
    3: master

In branch "branch2":

    0: master
    1:
    2: branch2 change
    3: master

Merging these should result in the following, IMHO:

    0: master
    1: branch1 change
    2: branch2 change
    3: master

With the current merge( ) implementation, merging "branch1" into master is fine, but then merging "branch2" into master warns of a conflict.

I've changed the check to less-than-or-equal in my local copy, and it seems to work well with the testing I've been doing.  Of course, some of the JUnit tests in the JGit source tree now fail because they include tests that relied on contiguous merges failing, and now those merges work cleanly.


So, does that change make sense?  Or is the contiguous merge conflict a feature, not a bug?  (If so, I'd love to hear the reason why it's correct behaviour.)


And if that does make sense, then what's the best way to get that changed?  Submit a bug report with all these details?  I guess I could submit a patch, though the instructions on the wiki for submitting a patch are discouragingly complicated!

Back to the top