~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Martin Pool
  • Date: 2005-07-11 03:12:34 UTC
  • Revision ID: mbp@sourcefrog.net-20050711031233-e5cc726bc78362e1
- fix typo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
# Copyright (C) 2005 Canonical Ltd
 
4
 
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
 
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
 
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
# Author: Martin Pool <mbp@canonical.com>
 
20
 
 
21
 
 
22
"""Weave - storage of related text file versions"""
 
23
 
 
24
# TODO: Perhaps have copy method for Weave instances?
 
25
 
 
26
# XXX: If we do weaves this way, will a merge still behave the same
 
27
# way if it's done in a different order?  That's a pretty desirable
 
28
# property.
 
29
 
 
30
# TODO: How to write these to disk?  One option is cPickle, which
 
31
# would be fast but less friendly to C, and perhaps not portable.  Another is
 
32
 
 
33
# TODO: Nothing here so far assumes the lines are really \n newlines,
 
34
# rather than being split up in some other way.  We could accomodate
 
35
# binaries, perhaps by naively splitting on \n or perhaps using
 
36
# something like a rolling checksum.
 
37
 
 
38
# TODO: Perhaps track SHA-1 in the header for protection?  This would
 
39
# be redundant with it being stored in the inventory, but perhaps
 
40
# usefully so?
 
41
 
 
42
# TODO: Track version names as well as indexes. 
 
43
 
 
44
# TODO: Probably do transitive expansion when specifying parents?
 
45
 
 
46
# TODO: Separate out some code to read and write weaves.
 
47
 
 
48
# TODO: End marker for each version so we can stop reading?
 
49
 
 
50
# TODO: Check that no insertion occurs inside a deletion that was
 
51
# active in the version of the insertion.
 
52
 
 
53
# TODO: Perhaps a special slower check() method that verifies more
 
54
# nesting constraints and the MD5 of each version?
 
55
 
 
56
 
 
57
 
 
58
try:
 
59
    set
 
60
    frozenset
 
61
except NameError:
 
62
    from sets import Set, ImmutableSet
 
63
    set = Set
 
64
    frozenset = ImmutableSet
 
65
    del Set, ImmutableSet
 
66
 
 
67
 
 
68
class WeaveError(Exception):
 
69
    """Exception in processing weave"""
 
70
 
 
71
 
 
72
class WeaveFormatError(WeaveError):
 
73
    """Weave invariant violated"""
 
74
    
 
75
 
 
76
class Weave(object):
 
77
    """weave - versioned text file storage.
 
78
    
 
79
    A Weave manages versions of line-based text files, keeping track
 
80
    of the originating version for each line.
 
81
 
 
82
    To clients the "lines" of the file are represented as a list of strings.
 
83
    These strings  will typically have terminal newline characters, but
 
84
    this is not required.  In particular files commonly do not have a newline
 
85
    at the end of the file.
 
86
 
 
87
    Texts can be identified in either of two ways:
 
88
 
 
89
    * a nonnegative index number.
 
90
 
 
91
    * a version-id string.
 
92
 
 
93
    Typically the index number will be valid only inside this weave and
 
94
    the version-id is used to reference it in the larger world.
 
95
 
 
96
    The weave is represented as a list mixing edit instructions and
 
97
    literal text.  Each entry in _l can be either a string (or
 
98
    unicode), or a tuple.  If a string, it means that the given line
 
99
    should be output in the currently active revisions.
 
100
 
 
101
    If a tuple, it gives a processing instruction saying in which
 
102
    revisions the enclosed lines are active.  The tuple has the form
 
103
    (instruction, version).
 
104
 
 
105
    The instruction can be '{' or '}' for an insertion block, and '['
 
106
    and ']' for a deletion block respectively.  The version is the
 
107
    integer version index.  There is no replace operator, only deletes
 
108
    and inserts.
 
109
 
 
110
    Constraints/notes:
 
111
 
 
112
    * A later version can delete lines that were introduced by any
 
113
      number of ancestor versions; this implies that deletion
 
114
      instructions can span insertion blocks without regard to the
 
115
      insertion block's nesting.
 
116
 
 
117
    * Similarly, deletions need not be properly nested with regard to
 
118
      each other, because they might have been generated by
 
119
      independent revisions.
 
120
 
 
121
    * Insertions are always made by inserting a new bracketed block
 
122
      into a single point in the previous weave.  This implies they
 
123
      can nest but not overlap, and the nesting must always have later
 
124
      insertions on the inside.
 
125
 
 
126
    * It doesn't seem very useful to have an active insertion
 
127
      inside an inactive insertion, but it might happen.
 
128
      
 
129
    * Therefore, all instructions are always"considered"; that
 
130
      is passed onto and off the stack.  An outer inactive block
 
131
      doesn't disable an inner block.
 
132
 
 
133
    * Lines are enabled if the most recent enclosing insertion is
 
134
      active and none of the enclosing deletions are active.
 
135
 
 
136
    * There is no point having a deletion directly inside its own
 
137
      insertion; you might as well just not write it.  And there
 
138
      should be no way to get an earlier version deleting a later
 
139
      version.
 
140
 
 
141
    _l
 
142
        Text of the weave. 
 
143
 
 
144
    _v
 
145
        List of versions, indexed by index number.
 
146
 
 
147
        For each version we store the set (included_versions), which
 
148
        lists the previous versions also considered active; the
 
149
        versions included in those versions are included transitively.
 
150
        So new versions created from nothing list []; most versions
 
151
        have a single entry; some have more.
 
152
 
 
153
    _sha1s
 
154
        List of hex SHA-1 of each version, or None if not recorded.
 
155
    """
 
156
    def __init__(self):
 
157
        self._l = []
 
158
        self._v = []
 
159
        self._sha1s = []
 
160
 
 
161
 
 
162
    def __eq__(self, other):
 
163
        if not isinstance(other, Weave):
 
164
            return False
 
165
        return self._v == other._v \
 
166
               and self._l == other._l
 
167
    
 
168
 
 
169
    def __ne__(self, other):
 
170
        return not self.__eq__(other)
 
171
 
 
172
        
 
173
    def add(self, parents, text):
 
174
        """Add a single text on top of the weave.
 
175
  
 
176
        Returns the index number of the newly added version.
 
177
 
 
178
        parents
 
179
            List or set of parent version numbers.  This must normally include
 
180
            the parents and the parent's parents, or wierd things might happen.
 
181
 
 
182
        text
 
183
            Sequence of lines to be added in the new version."""
 
184
        ## self._check_versions(parents)
 
185
        ## self._check_lines(text)
 
186
        idx = len(self._v)
 
187
 
 
188
        import sha
 
189
        s = sha.new()
 
190
        for l in text:
 
191
            s.update(l)
 
192
        sha1 = s.hexdigest()
 
193
        del s
 
194
 
 
195
        if parents:
 
196
            delta = self._delta(self.inclusions(parents), text)
 
197
 
 
198
            # offset gives the number of lines that have been inserted
 
199
            # into the weave up to the current point; if the original edit instruction
 
200
            # says to change line A then we actually change (A+offset)
 
201
            offset = 0
 
202
 
 
203
            for i1, i2, newlines in delta:
 
204
                assert 0 <= i1
 
205
                assert i1 <= i2
 
206
                assert i2 <= len(self._l)
 
207
 
 
208
                # the deletion and insertion are handled separately.
 
209
                # first delete the region.
 
210
                if i1 != i2:
 
211
                    self._l.insert(i1+offset, ('[', idx))
 
212
                    self._l.insert(i2+offset+1, (']', idx))
 
213
                    offset += 2
 
214
                    # is this OK???
 
215
 
 
216
                if newlines:
 
217
                    # there may have been a deletion spanning up to
 
218
                    # i2; we want to insert after this region to make sure
 
219
                    # we don't destroy ourselves
 
220
                    i = i2 + offset
 
221
                    self._l[i:i] = [('{', idx)] \
 
222
                                   + newlines \
 
223
                                   + [('}', idx)]
 
224
                    offset += 2 + len(newlines)
 
225
 
 
226
            self._addversion(parents)
 
227
        else:
 
228
            # special case; adding with no parents revision; can do this
 
229
            # more quickly by just appending unconditionally
 
230
            self._l.append(('{', idx))
 
231
            self._l += text
 
232
            self._l.append(('}', idx))
 
233
 
 
234
            self._addversion(None)
 
235
 
 
236
        self._sha1s.append(sha1)
 
237
            
 
238
        return idx
 
239
 
 
240
 
 
241
    def inclusions(self, versions):
 
242
        """Expand out everything included by versions."""
 
243
        i = set(versions)
 
244
        for v in versions:
 
245
            try:
 
246
                i.update(self._v[v])
 
247
            except IndexError:
 
248
                raise ValueError("version %d not present in weave" % v)
 
249
        return i
 
250
 
 
251
 
 
252
    def _addversion(self, parents):
 
253
        if parents:
 
254
            self._v.append(frozenset(parents))
 
255
        else:
 
256
            self._v.append(frozenset())
 
257
 
 
258
 
 
259
    def _check_lines(self, text):
 
260
        if not isinstance(text, list):
 
261
            raise ValueError("text should be a list, not %s" % type(text))
 
262
 
 
263
        for l in text:
 
264
            if not isinstance(l, basestring):
 
265
                raise ValueError("text line should be a string or unicode, not %s"
 
266
                                 % type(l))
 
267
        
 
268
 
 
269
 
 
270
    def _check_versions(self, indexes):
 
271
        """Check everything in the sequence of indexes is valid"""
 
272
        for i in indexes:
 
273
            try:
 
274
                self._v[i]
 
275
            except IndexError:
 
276
                raise IndexError("invalid version number %r" % i)
 
277
 
 
278
    
 
279
    def annotate(self, index):
 
280
        return list(self.annotate_iter(index))
 
281
 
 
282
 
 
283
    def annotate_iter(self, version):
 
284
        """Yield list of (index-id, line) pairs for the specified version.
 
285
 
 
286
        The index indicates when the line originated in the weave."""
 
287
        included = self.inclusions([version])
 
288
        for origin, lineno, text in self._extract(included):
 
289
            yield origin, text
 
290
 
 
291
 
 
292
    def _extract(self, included):
 
293
        """Yield annotation of lines in included set.
 
294
 
 
295
        Yields a sequence of tuples (origin, lineno, text), where
 
296
        origin is the origin version, lineno the index in the weave,
 
297
        and text the text of the line.
 
298
 
 
299
        The set typically but not necessarily corresponds to a version.
 
300
        """
 
301
        istack = []          # versions for which an insertion block is current
 
302
 
 
303
        dset = set()         # versions for which a deletion block is current
 
304
 
 
305
        isactive = None
 
306
 
 
307
        lineno = 0         # line of weave, 0-based
 
308
 
 
309
        # TODO: Probably only need to put included revisions in the istack
 
310
 
 
311
        # TODO: Could split this into two functions, one that updates
 
312
        # the stack and the other that processes the results -- but
 
313
        # I'm not sure it's really needed.
 
314
 
 
315
        # TODO: In fact, I think we only need to store the *count* of
 
316
        # active insertions and deletions, and we can maintain that by
 
317
        # just by just counting as we go along.
 
318
 
 
319
        WFE = WeaveFormatError
 
320
 
 
321
        for l in self._l:
 
322
            if isinstance(l, tuple):
 
323
                isactive = None         # recalculate
 
324
                c, v = l
 
325
                if c == '{':
 
326
                    if istack and (istack[-1] >= v):
 
327
                        raise WFE("improperly nested insertions %d>=%d on line %d" 
 
328
                                  % (istack[-1], v, lineno))
 
329
                    istack.append(v)
 
330
                elif c == '}':
 
331
                    try:
 
332
                        oldv = istack.pop()
 
333
                    except IndexError:
 
334
                        raise WFE("unmatched close of insertion %d on line %d"
 
335
                                  % (v, lineno))
 
336
                    if oldv != v:
 
337
                        raise WFE("mismatched close of insertion %d!=%d on line %d"
 
338
                                  % (oldv, v, lineno))
 
339
                elif c == '[':
 
340
                    # block deleted in v
 
341
                    if v in dset:
 
342
                        raise WFE("repeated deletion marker for version %d on line %d"
 
343
                                  % (v, lineno))
 
344
                    if istack:
 
345
                        if istack[-1] == v:
 
346
                            raise WFE("version %d deletes own text on line %d"
 
347
                                      % (v, lineno))
 
348
                        # XXX
 
349
                        dset.add(v)
 
350
                elif c == ']':
 
351
                    if v in dset:
 
352
                        dset.remove(v)
 
353
                    else:
 
354
                        raise WFE("unmatched close of deletion %d on line %d"
 
355
                                  % (v, lineno))
 
356
                else:
 
357
                    raise WFE("invalid processing instruction %r on line %d"
 
358
                              % (l, lineno))
 
359
            else:
 
360
                assert isinstance(l, basestring)
 
361
                if not istack:
 
362
                    raise WFE("literal at top level on line %d"
 
363
                              % lineno)
 
364
                if isactive == None:
 
365
                    isactive = (istack[-1] in included) \
 
366
                               and not included.intersection(dset)
 
367
                if isactive:
 
368
                    origin = istack[-1]
 
369
                    yield origin, lineno, l
 
370
            lineno += 1
 
371
 
 
372
        if istack:
 
373
            raise WFE("unclosed insertion blocks at end of weave",
 
374
                                   istack)
 
375
        if dset:
 
376
            raise WFE("unclosed deletion blocks at end of weave",
 
377
                                   dset)
 
378
 
 
379
 
 
380
    def get_iter(self, version):
 
381
        """Yield lines for the specified version."""
 
382
        for origin, lineno, line in self._extract(self.inclusions([version])):
 
383
            yield line
 
384
 
 
385
 
 
386
    def get(self, index):
 
387
        return list(self.get_iter(index))
 
388
 
 
389
 
 
390
    def mash_iter(self, included):
 
391
        """Return composed version of multiple included versions."""
 
392
        included = frozenset(included)
 
393
        for origin, lineno, text in self._extract(included):
 
394
            yield text
 
395
 
 
396
 
 
397
    def dump(self, to_file):
 
398
        from pprint import pprint
 
399
        print >>to_file, "Weave._l = ",
 
400
        pprint(self._l, to_file)
 
401
        print >>to_file, "Weave._v = ",
 
402
        pprint(self._v, to_file)
 
403
 
 
404
 
 
405
 
 
406
    def numversions(self):
 
407
        l = len(self._v)
 
408
        assert l == len(self._sha1s)
 
409
        return l
 
410
 
 
411
 
 
412
    def check(self):
 
413
        # check no circular inclusions
 
414
        for version in range(self.numversions()):
 
415
            inclusions = list(self._v[version])
 
416
            if inclusions:
 
417
                inclusions.sort()
 
418
                if inclusions[-1] >= version:
 
419
                    raise WeaveFormatError("invalid included version %d for index %d"
 
420
                                           % (inclusions[-1], version))
 
421
 
 
422
        # try extracting all versions; this is a bit slow and parallel
 
423
        # extraction could be used
 
424
        import sha
 
425
        for version in range(self.numversions()):
 
426
            s = sha.new()
 
427
            for l in self.get_iter(version):
 
428
                s.update(l)
 
429
            hd = s.hexdigest()
 
430
            expected = self._sha1s[version]
 
431
            if hd != expected:
 
432
                raise WeaveError("mismatched sha1 for version %d; "
 
433
                                 "got %s, expected %s"
 
434
                                 % (version, hd, expected))
 
435
 
 
436
 
 
437
 
 
438
    def merge(self, merge_versions):
 
439
        """Automerge and mark conflicts between versions.
 
440
 
 
441
        This returns a sequence, each entry describing alternatives
 
442
        for a chunk of the file.  Each of the alternatives is given as
 
443
        a list of lines.
 
444
 
 
445
        If there is a chunk of the file where there's no diagreement,
 
446
        only one alternative is given.
 
447
        """
 
448
 
 
449
        # approach: find the included versions common to all the
 
450
        # merged versions
 
451
        raise NotImplementedError()
 
452
 
 
453
 
 
454
 
 
455
    def _delta(self, included, lines):
 
456
        """Return changes from basis to new revision.
 
457
 
 
458
        The old text for comparison is the union of included revisions.
 
459
 
 
460
        This is used in inserting a new text.
 
461
 
 
462
        Delta is returned as a sequence of
 
463
        (weave1, weave2, newlines).
 
464
 
 
465
        This indicates that weave1:weave2 of the old weave should be
 
466
        replaced by the sequence of lines in newlines.  Note that
 
467
        these line numbers are positions in the total weave and don't
 
468
        correspond to the lines in any extracted version, or even the
 
469
        extracted union of included versions.
 
470
 
 
471
        If line1=line2, this is a pure insert; if newlines=[] this is a
 
472
        pure delete.  (Similar to difflib.)
 
473
        """
 
474
        # basis a list of (origin, lineno, line)
 
475
        basis_lineno = []
 
476
        basis_lines = []
 
477
        for origin, lineno, line in self._extract(included):
 
478
            basis_lineno.append(lineno)
 
479
            basis_lines.append(line)
 
480
 
 
481
        # add a sentinal, because we can also match against the final line
 
482
        basis_lineno.append(len(self._l))
 
483
 
 
484
        # XXX: which line of the weave should we really consider
 
485
        # matches the end of the file?  the current code says it's the
 
486
        # last line of the weave?
 
487
 
 
488
        from difflib import SequenceMatcher
 
489
        s = SequenceMatcher(None, basis_lines, lines)
 
490
 
 
491
        # TODO: Perhaps return line numbers from composed weave as well?
 
492
 
 
493
        for tag, i1, i2, j1, j2 in s.get_opcodes():
 
494
            ##print tag, i1, i2, j1, j2
 
495
 
 
496
            if tag == 'equal':
 
497
                continue
 
498
 
 
499
            # i1,i2 are given in offsets within basis_lines; we need to map them
 
500
            # back to offsets within the entire weave
 
501
            real_i1 = basis_lineno[i1]
 
502
            real_i2 = basis_lineno[i2]
 
503
 
 
504
            assert 0 <= j1
 
505
            assert j1 <= j2
 
506
            assert j2 <= len(lines)
 
507
 
 
508
            yield real_i1, real_i2, lines[j1:j2]
 
509
 
 
510
 
 
511
 
 
512
def weave_info(filename, out):
 
513
    """Show some text information about the weave."""
 
514
    from weavefile import read_weave
 
515
    wf = file(filename, 'rb')
 
516
    w = read_weave(wf)
 
517
    # FIXME: doesn't work on pipes
 
518
    weave_size = wf.tell()
 
519
    print >>out, "weave file size %d bytes" % weave_size
 
520
    print >>out, "weave contains %d versions" % len(w._v)
 
521
 
 
522
    total = 0
 
523
    print '%6s %6s %8s %40s %20s' % ('ver', 'lines', 'bytes', 'sha1', 'parents')
 
524
    for i in (6, 6, 8, 40, 20):
 
525
        print '-' * i,
 
526
    print
 
527
    for i in range(len(w._v)):
 
528
        text = w.get(i)
 
529
        lines = len(text)
 
530
        bytes = sum((len(a) for a in text))
 
531
        sha1 = w._sha1s[i]
 
532
        print '%6d %6d %8d %40s' % (i, lines, bytes, sha1),
 
533
        print ', '.join(map(str, w._v[i]))
 
534
        total += bytes
 
535
 
 
536
    print >>out, "versions total %d bytes" % total
 
537
    print >>out, "compression ratio %.3f" % (float(total)/float(weave_size))
 
538
 
 
539
 
 
540
def usage():
 
541
    print """bzr weave tool
 
542
 
 
543
Experimental tool for weave algorithm.
 
544
 
 
545
usage:
 
546
    weave init WEAVEFILE
 
547
        Create an empty weave file
 
548
    weave get WEAVEFILE VERSION
 
549
        Write out specified version.
 
550
    weave check WEAVEFILE
 
551
        Check consistency of all versions.
 
552
    weave info WEAVEFILE
 
553
        Display table of contents.
 
554
    weave add WEAVEFILE [BASE...] < NEWTEXT
 
555
        Add NEWTEXT, with specified parent versions.
 
556
    weave annotate WEAVEFILE VERSION
 
557
        Display origin of each line.
 
558
    weave mash WEAVEFILE VERSION...
 
559
        Display composite of all selected versions.
 
560
    weave merge WEAVEFILE VERSION1 VERSION2 > OUT
 
561
        Auto-merge two versions and display conflicts.
 
562
 
 
563
example:
 
564
 
 
565
    % weave init foo.weave
 
566
    % vi foo.txt
 
567
    % weave add foo.weave < foo.txt
 
568
    added version 0
 
569
 
 
570
    (create updated version)
 
571
    % vi foo.txt
 
572
    % weave get foo.weave 0 | diff -u - foo.txt
 
573
    % weave add foo.weave 0 < foo.txt
 
574
    added version 1
 
575
 
 
576
    % weave get foo.weave 0 > foo.txt       (create forked version)
 
577
    % vi foo.txt
 
578
    % weave add foo.weave 0 < foo.txt
 
579
    added version 2
 
580
 
 
581
    % weave merge foo.weave 1 2 > foo.txt   (merge them)
 
582
    % vi foo.txt                            (resolve conflicts)
 
583
    % weave add foo.weave 1 2 < foo.txt     (commit merged version)     
 
584
    
 
585
"""
 
586
    
 
587
 
 
588
 
 
589
def main(argv):
 
590
    import sys
 
591
    import os
 
592
    from weavefile import write_weave, read_weave
 
593
    cmd = argv[1]
 
594
 
 
595
    def readit():
 
596
        return read_weave(file(argv[2], 'rb'))
 
597
    
 
598
    if cmd == 'help':
 
599
        usage()
 
600
    elif cmd == 'add':
 
601
        w = readit()
 
602
        # at the moment, based on everything in the file
 
603
        parents = map(int, argv[3:])
 
604
        lines = sys.stdin.readlines()
 
605
        ver = w.add(parents, lines)
 
606
        write_weave(w, file(argv[2], 'wb'))
 
607
        print 'added version %d' % ver
 
608
    elif cmd == 'init':
 
609
        fn = argv[2]
 
610
        if os.path.exists(fn):
 
611
            raise IOError("file exists")
 
612
        w = Weave()
 
613
        write_weave(w, file(fn, 'wb'))
 
614
    elif cmd == 'get': # get one version
 
615
        w = readit()
 
616
        sys.stdout.writelines(w.get_iter(int(argv[3])))
 
617
        
 
618
    elif cmd == 'mash': # get composite
 
619
        w = readit()
 
620
        sys.stdout.writelines(w.mash_iter(map(int, argv[3:])))
 
621
 
 
622
    elif cmd == 'annotate':
 
623
        w = readit()
 
624
        # newline is added to all lines regardless; too hard to get
 
625
        # reasonable formatting otherwise
 
626
        lasto = None
 
627
        for origin, text in w.annotate(int(argv[3])):
 
628
            text = text.rstrip('\r\n')
 
629
            if origin == lasto:
 
630
                print '      | %s' % (text)
 
631
            else:
 
632
                print '%5d | %s' % (origin, text)
 
633
                lasto = origin
 
634
                
 
635
    elif cmd == 'info':
 
636
        weave_info(argv[2], sys.stdout)
 
637
        
 
638
    elif cmd == 'check':
 
639
        w = readit()
 
640
        w.check()
 
641
 
 
642
    elif cmd == 'merge':
 
643
        if len(argv) != 5:
 
644
            usage()
 
645
            return 1
 
646
 
 
647
        w = readit()
 
648
        v1, v2 = map(int, argv[3:5])
 
649
 
 
650
        basis = w.inclusions([v1]).intersection(w.inclusions([v2]))
 
651
 
 
652
        base_lines = list(w.mash_iter(basis))
 
653
        a_lines = list(w.get(v1))
 
654
        b_lines = list(w.get(v2))
 
655
 
 
656
        from bzrlib.merge3 import Merge3
 
657
        m3 = Merge3(base_lines, a_lines, b_lines)
 
658
 
 
659
        name_a = 'version %d' % v1
 
660
        name_b = 'version %d' % v2
 
661
        sys.stdout.writelines(m3.merge_lines(name_a=name_a, name_b=name_b))
 
662
    else:
 
663
        raise ValueError('unknown command %r' % cmd)
 
664
    
 
665
 
 
666
if __name__ == '__main__':
 
667
    import sys
 
668
    sys.exit(main(sys.argv))