How does SVN choose the BASE revision for a merge?
<p>According to the <a href="http://svnbook.red-bean.com/en/1.8/svn.branchmerge.basicmerging.html" rel="nofollow">redbook</a>, the merges from trunk to a branch are termed "<strong>sync merges</strong>".</p>

<p>How does Subversion determine the BASE revision for the <strong><em>second</em></strong> sync merge?</p>

<p>Let me explain. (This long because of the diagrams. The <em>pretty-pretty pictures</em>! So bear with me, eh?)</p>

<p>Here's how the first sync merge to a feature branch would look like:<br></p>

<pre><code>                      .........
                     .         .
 trunk  --+---------L-----------R------
           \                     \
            \                    |
             \                   v
 feature      +------------------o-----
         r10 r11   r100         r200
</code></pre>

<p>(Diagram taken from <code>svn merge --help</code>)</p>

<p>In this diagram, there are changes to the trunk in r100:200.
Since this is the first sync merge, the BASE is clearly the the point at which the feature branch was created, at r10. (The <code>+</code> on the trunk)</p>

<p>After this merge, the <code>svn:mergeinfo</code> is update to say that the feature branch is merged with the trunk up to r200. Like so:</p>

<pre><code>/trunk:1-200
</code></pre>

<p>And the output from <code>svn mergeinfo ^/trunk</code> looks like:</p>

<pre><code>  youngest common ancestor
  |         last full merge
  |         |        tip of branch
  |         |        |         repository path

  10        200      200
  |         |        |       
-------| |------------         /trunk
   \         \               
    \         \              
     --| |------------         /branches/feature
                     |       
                     WC      
</code></pre>

<p>After some more development, another sync merge is performed:</p>

<pre><code>                                   .........
                                  .         .
 trunk  --+----------------------L-----------R-------
           \                     \           \
            \                    |           |
             \                   v           v
 feature      +------------------o-----------x-------
         r10 r11   r100         r200        r300
</code></pre>

<p>This time we're merging r200:300 into the feature branch.</p>

<h1>The Question</h1>

<p>Does Subversion choose feature@r200 as the BASE for the merge, or does it choose trunk@r200 as the BASE?</p>

<p>This matters because 3-way diff/merge tools take the BASE very seriously.</p>

<p>If the BASE is feature@r200, then any changes made in the trunk before the first sync merge will be part of the base. Which means that wherever the trunk differs from them, the trunk will win out. Despite the fact that those changes should remain!</p>

<hr>

<p>That's the end of the question, the stuff below this line is an explanation why I'm asking the question.</p>

<p>Example:</p>

<p>Here's how the first sync merge went:</p>

<pre><code>BASE        LEFT           RIGHT              MERGED
trunk@r10   trunk@r200     feature@r200       sync merge result
---------   -----------    ------------       -----------------

foo         foo            foo                foo
EVIL LINE   EVIL LINE      ..deleted EVIL..   ..deleted EVIL..
bar         bar            bar                bar
</code></pre>

<p>Which correctly deleted the <code>EVIL LINE</code>.</p>

<p>Now let's look at the <strong>second</strong> sync merge:</p>

<p>Let's assume feature@r200 is the BASE. The <code>EVIL LINE</code> is still in the trunk, but gone from the feature branch:</p>

<pre><code>BASE               LEFT           RIGHT              MERGED
feature@r200       trunk@r300     feature@r300       sync merge result
------------       -----------    ------------       -----------------

foo                foo            foo                foo
..deleted EVIL..   EVIL LINE      ..deleted EVIL..   EVIL LINE
bar                bar            bar                bar
</code></pre>

<p>Why? Because a 3-way merge tool would look at that and see that <code>BASE == RIGHT</code>, and <code>BASE != LEFT</code>, and decide that the correct course of action is to take LEFT.</p>

<p>However, if we assume trunk@r200 is the BASE. There's no issue, the deleted line remains deleted:</p>

<pre><code>BASE        LEFT           RIGHT              MERGED
trunk@r200  trunk@r300     feature@r300       sync merge result
----------  -----------    ------------       -----------------

foo         foo            foo                foo
EVIL LINE   EVIL LINE      ..deleted EVIL..   ..deleted EVIL..
bar         bar            bar                bar
</code></pre>

<p>I guess my problem is that I don't know how the BASE is chosen, and I don't see any documentation that explains how it is decided.</p>

<p>I want to know this to answer a more complex question:</p>

<ul>
<li>After a sync merge (trunk into branch), <strong>and a reintegrate merge</strong> (branch into trunk), assuming I did the reintegrate correctly for re-use, what will be the BASE for the next sync merge and the next reintegrate merge?</li>
</ul>