~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-16 14:01:20 UTC
  • mfrom: (3280.2.5 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080316140120-i3yq8yr1l66m11h7
Start 1.4 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
# mbp: "you know that thing where cvs gives you conflict markers?"
36
36
    >>> intersect((0, 9), (7, 15))
37
37
    (7, 9)
38
38
    """
39
 
    # preconditions: (ra[0] <= ra[1]) and (rb[0] <= rb[1])
40
 
 
 
39
    assert ra[0] <= ra[1]
 
40
    assert rb[0] <= rb[1]
 
41
    
41
42
    sa = max(ra[0], rb[0])
42
43
    sb = min(ra[1], rb[1])
43
44
    if sa < sb:
56
57
            return False
57
58
    else:
58
59
        return True
59
 
 
 
60
        
60
61
 
61
62
 
62
63
 
132
133
    def merge_annotated(self):
133
134
        """Return merge with conflicts, showing origin of lines.
134
135
 
135
 
        Most useful for debugging merge.
 
136
        Most useful for debugging merge.        
136
137
        """
137
138
        for t in self.merge_regions():
138
139
            what = t[0]
219
220
 
220
221
        # section a[0:ia] has been disposed of, etc
221
222
        iz = ia = ib = 0
222
 
 
 
223
        
223
224
        for zmatch, zend, amatch, aend, bmatch, bend in self.find_sync_regions():
 
225
            #print 'match base [%d:%d]' % (zmatch, zend)
 
226
            
224
227
            matchlen = zend - zmatch
225
 
            # invariants:
226
 
            #   matchlen >= 0
227
 
            #   matchlen == (aend - amatch)
228
 
            #   matchlen == (bend - bmatch)
 
228
            assert matchlen >= 0
 
229
            assert matchlen == (aend - amatch)
 
230
            assert matchlen == (bend - bmatch)
 
231
            
229
232
            len_a = amatch - ia
230
233
            len_b = bmatch - ib
231
234
            len_base = zmatch - iz
232
 
            # invariants:
233
 
            # assert len_a >= 0
234
 
            # assert len_b >= 0
235
 
            # assert len_base >= 0
 
235
            assert len_a >= 0
 
236
            assert len_b >= 0
 
237
            assert len_base >= 0
236
238
 
237
239
            #print 'unmatched a=%d, b=%d' % (len_a, len_b)
238
240
 
271
273
            # that's OK, we can just skip it.
272
274
 
273
275
            if matchlen > 0:
274
 
                # invariants:
275
 
                # assert ia == amatch
276
 
                # assert ib == bmatch
277
 
                # assert iz == zmatch
278
 
 
 
276
                assert ia == amatch
 
277
                assert ib == bmatch
 
278
                assert iz == zmatch
 
279
                
279
280
                yield 'unchanged', zmatch, zend
280
281
                iz = zend
281
282
                ia = aend
324
325
    def reprocess_merge_regions(self, merge_regions):
325
326
        """Where there are conflict regions, remove the agreed lines.
326
327
 
327
 
        Lines where both A and B have made the same changes are
 
328
        Lines where both A and B have made the same changes are 
328
329
        eliminated.
329
330
        """
330
331
        for region in merge_regions:
388
389
 
389
390
                # found a match of base[i[0], i[1]]; this may be less than
390
391
                # the region that matches in either one
391
 
                # assert intlen <= alen
392
 
                # assert intlen <= blen
393
 
                # assert abase <= intbase
394
 
                # assert bbase <= intbase
 
392
                assert intlen <= alen
 
393
                assert intlen <= blen
 
394
                assert abase <= intbase
 
395
                assert bbase <= intbase
395
396
 
396
397
                asub = amatch + (intbase - abase)
397
398
                bsub = bmatch + (intbase - bbase)
398
399
                aend = asub + intlen
399
400
                bend = bsub + intlen
400
401
 
401
 
                # assert self.base[intbase:intend] == self.a[asub:aend], \
402
 
                #       (self.base[intbase:intend], self.a[asub:aend])
403
 
                # assert self.base[intbase:intend] == self.b[bsub:bend]
 
402
                assert self.base[intbase:intend] == self.a[asub:aend], \
 
403
                       (self.base[intbase:intend], self.a[asub:aend])
 
404
 
 
405
                assert self.base[intbase:intend] == self.b[bsub:bend]
404
406
 
405
407
                sl.append((intbase, intend,
406
408
                           asub, aend,
407
409
                           bsub, bend))
 
410
 
408
411
            # advance whichever one ends first in the base text
409
412
            if (abase + alen) < (bbase + blen):
410
413
                ia += 1
411
414
            else:
412
415
                ib += 1
413
 
 
 
416
            
414
417
        intbase = len(self.base)
415
418
        abase = len(self.a)
416
419
        bbase = len(self.b)
442
445
                del am[0]
443
446
            else:
444
447
                del bm[0]
445
 
 
 
448
                
446
449
        return unc
447
450
 
448
451