/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Andrew Bennetts
  • Date: 2008-09-14 10:23:29 UTC
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080914102329-2nvv40h7fljpvcxt
Tidy imports in bzrlib/msgeditor.py as suggested by John's review.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2009 Canonical Ltd
 
1
#! /usr/bin/python
 
2
 
 
3
# Copyright (C) 2005 Canonical Ltd
2
4
#
3
5
# This program is free software; you can redistribute it and/or modify
4
6
# it under the terms of the GNU General Public License as published by
12
14
#
13
15
# You should have received a copy of the GNU General Public License
14
16
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
18
 
17
19
# Author: Martin Pool <mbp@canonical.com>
18
20
 
59
61
# where the basis and destination are unchanged.
60
62
 
61
63
# FIXME: Sometimes we will be given a parents list for a revision
62
 
# that includes some redundant parents (i.e. already a parent of
63
 
# something in the list.)  We should eliminate them.  This can
 
64
# that includes some redundant parents (i.e. already a parent of 
 
65
# something in the list.)  We should eliminate them.  This can 
64
66
# be done fairly efficiently because the sequence numbers constrain
65
67
# the possible relationships.
66
68
 
69
71
from copy import copy
70
72
from cStringIO import StringIO
71
73
import os
 
74
import sha
 
75
import time
 
76
import warnings
72
77
 
73
78
from bzrlib.lazy_import import lazy_import
74
79
lazy_import(globals(), """
75
80
from bzrlib import tsort
76
81
""")
77
82
from bzrlib import (
78
 
    errors,
79
 
    osutils,
 
83
    progress,
80
84
    )
81
85
from bzrlib.errors import (WeaveError, WeaveFormatError, WeaveParentMismatch,
82
86
        RevisionAlreadyPresent,
83
87
        RevisionNotPresent,
84
88
        UnavailableRepresentation,
 
89
        WeaveRevisionAlreadyPresent,
 
90
        WeaveRevisionNotPresent,
85
91
        )
86
 
from bzrlib.osutils import dirname, sha, sha_strings, split_lines
 
92
import bzrlib.errors as errors
 
93
from bzrlib.osutils import dirname, sha_strings, split_lines
87
94
import bzrlib.patiencediff
88
95
from bzrlib.revision import NULL_REVISION
89
96
from bzrlib.symbol_versioning import *
90
97
from bzrlib.trace import mutter
 
98
from bzrlib.tsort import topo_sort
91
99
from bzrlib.versionedfile import (
92
100
    AbsentContentFactory,
93
101
    adapter_registry,
94
102
    ContentFactory,
95
 
    sort_groupcompress,
96
103
    VersionedFile,
97
104
    )
98
105
from bzrlib.weavefile import _read_weave_v5, write_weave_v5
117
124
    def get_bytes_as(self, storage_kind):
118
125
        if storage_kind == 'fulltext':
119
126
            return self._weave.get_text(self.key[-1])
120
 
        elif storage_kind == 'chunked':
121
 
            return self._weave.get_lines(self.key[-1])
122
127
        else:
123
128
            raise UnavailableRepresentation(self.key, storage_kind, 'fulltext')
124
129
 
125
130
 
126
131
class Weave(VersionedFile):
127
132
    """weave - versioned text file storage.
128
 
 
 
133
    
129
134
    A Weave manages versions of line-based text files, keeping track
130
135
    of the originating version for each line.
131
136
 
177
182
 
178
183
    * It doesn't seem very useful to have an active insertion
179
184
      inside an inactive insertion, but it might happen.
180
 
 
 
185
      
181
186
    * Therefore, all instructions are always"considered"; that
182
187
      is passed onto and off the stack.  An outer inactive block
183
188
      doesn't disable an inner block.
214
219
 
215
220
    __slots__ = ['_weave', '_parents', '_sha1s', '_names', '_name_map',
216
221
                 '_weave_name', '_matcher', '_allow_reserved']
217
 
 
 
222
    
218
223
    def __init__(self, weave_name=None, access_mode='w', matcher=None,
219
224
                 get_scope=None, allow_reserved=False):
220
225
        """Create a weave.
223
228
            for detecting when this weave goes out of scope (should stop
224
229
            answering requests or allowing mutation).
225
230
        """
226
 
        super(Weave, self).__init__()
 
231
        super(Weave, self).__init__(access_mode)
227
232
        self._weave = []
228
233
        self._parents = []
229
234
        self._sha1s = []
253
258
 
254
259
    def copy(self):
255
260
        """Return a deep copy of self.
256
 
 
 
261
        
257
262
        The copy can be modified without affecting the original weave."""
258
263
        other = Weave()
259
264
        other._weave = self._weave[:]
269
274
            return False
270
275
        return self._parents == other._parents \
271
276
               and self._weave == other._weave \
272
 
               and self._sha1s == other._sha1s
273
 
 
 
277
               and self._sha1s == other._sha1s 
 
278
    
274
279
    def __ne__(self, other):
275
280
        return not self.__eq__(other)
276
281
 
312
317
        versions = [version[-1] for version in versions]
313
318
        if ordering == 'topological':
314
319
            parents = self.get_parent_map(versions)
315
 
            new_versions = tsort.topo_sort(parents)
316
 
            new_versions.extend(set(versions).difference(set(parents)))
317
 
            versions = new_versions
318
 
        elif ordering == 'groupcompress':
319
 
            parents = self.get_parent_map(versions)
320
 
            new_versions = sort_groupcompress(parents)
 
320
            new_versions = topo_sort(parents)
321
321
            new_versions.extend(set(versions).difference(set(parents)))
322
322
            versions = new_versions
323
323
        for version in versions:
348
348
    def insert_record_stream(self, stream):
349
349
        """Insert a record stream into this versioned file.
350
350
 
351
 
        :param stream: A stream of records to insert.
 
351
        :param stream: A stream of records to insert. 
352
352
        :return: None
353
353
        :seealso VersionedFile.get_record_stream:
354
354
        """
359
359
                raise RevisionNotPresent([record.key[0]], self)
360
360
            # adapt to non-tuple interface
361
361
            parents = [parent[0] for parent in record.parents]
362
 
            if (record.storage_kind == 'fulltext'
363
 
                or record.storage_kind == 'chunked'):
 
362
            if record.storage_kind == 'fulltext':
364
363
                self.add_lines(record.key[0], parents,
365
 
                    osutils.chunks_to_lines(record.get_bytes_as('chunked')))
 
364
                    split_lines(record.get_bytes_as('fulltext')))
366
365
            else:
367
366
                adapter_key = record.storage_kind, 'fulltext'
368
367
                try:
371
370
                    adapter_factory = adapter_registry.get(adapter_key)
372
371
                    adapter = adapter_factory(self)
373
372
                    adapters[adapter_key] = adapter
374
 
                lines = split_lines(adapter.get_bytes(record))
 
373
                lines = split_lines(adapter.get_bytes(
 
374
                    record, record.get_bytes_as(record.storage_kind)))
375
375
                try:
376
376
                    self.add_lines(record.key[0], parents, lines)
377
377
                except RevisionAlreadyPresent:
397
397
 
398
398
    def _add(self, version_id, lines, parents, sha1=None, nostore_sha=None):
399
399
        """Add a single text on top of the weave.
400
 
 
 
400
  
401
401
        Returns the index number of the newly added version.
402
402
 
403
403
        version_id
404
404
            Symbolic name for this version.
405
405
            (Typically the revision-id of the revision that added it.)
406
 
            If None, a name will be allocated based on the hash. (sha1:SHAHASH)
407
406
 
408
407
        parents
409
408
            List or set of direct parent version numbers.
410
 
 
 
409
            
411
410
        lines
412
411
            Sequence of lines to be added in the new version.
413
412
 
419
418
            sha1 = sha_strings(lines)
420
419
        if sha1 == nostore_sha:
421
420
            raise errors.ExistingContent
422
 
        if version_id is None:
423
 
            version_id = "sha1:" + sha1
424
421
        if version_id in self._name_map:
425
422
            return self._check_repeated_add(version_id, parents, lines, sha1)
426
423
 
437
434
        self._names.append(version_id)
438
435
        self._name_map[version_id] = new_version
439
436
 
440
 
 
 
437
            
441
438
        if not parents:
442
439
            # special case; adding with no parents revision; can do
443
440
            # this more quickly by just appending unconditionally.
454
451
            if sha1 == self._sha1s[pv]:
455
452
                # special case: same as the single parent
456
453
                return new_version
457
 
 
 
454
            
458
455
 
459
456
        ancestors = self._inclusions(parents)
460
457
 
509
506
                # i2; we want to insert after this region to make sure
510
507
                # we don't destroy ourselves
511
508
                i = i2 + offset
512
 
                self._weave[i:i] = ([('{', new_version)]
513
 
                                    + lines[j1:j2]
 
509
                self._weave[i:i] = ([('{', new_version)] 
 
510
                                    + lines[j1:j2] 
514
511
                                    + [('}', None)])
515
512
                offset += 2 + (j2 - j1)
516
513
        return new_version
543
540
            if not isinstance(l, basestring):
544
541
                raise ValueError("text line should be a string or unicode, not %s"
545
542
                                 % type(l))
546
 
 
 
543
        
547
544
 
548
545
 
549
546
    def _check_versions(self, indexes):
557
554
    def _compatible_parents(self, my_parents, other_parents):
558
555
        """During join check that other_parents are joinable with my_parents.
559
556
 
560
 
        Joinable is defined as 'is a subset of' - supersets may require
 
557
        Joinable is defined as 'is a subset of' - supersets may require 
561
558
        regeneration of diffs, but subsets do not.
562
559
        """
563
560
        return len(other_parents.difference(my_parents)) == 0
577
574
            version_ids = self.versions()
578
575
        version_ids = set(version_ids)
579
576
        for lineno, inserted, deletes, line in self._walk_internal(version_ids):
580
 
            if inserted not in version_ids: continue
 
577
            # if inserted not in version_ids then it was inserted before the
 
578
            # versions we care about, but because weaves cannot represent ghosts
 
579
            # properly, we do not filter down to that
 
580
            # if inserted not in version_ids: continue
581
581
            if line[-1] != '\n':
582
582
                yield line + '\n', inserted
583
583
            else:
585
585
 
586
586
    def _walk_internal(self, version_ids=None):
587
587
        """Helper method for weave actions."""
588
 
 
 
588
        
589
589
        istack = []
590
590
        dset = set()
591
591
 
672
672
        for i in versions:
673
673
            if not isinstance(i, int):
674
674
                raise ValueError(i)
675
 
 
 
675
            
676
676
        included = self._inclusions(versions)
677
677
 
678
678
        istack = []
687
687
 
688
688
        WFE = WeaveFormatError
689
689
 
690
 
        # wow.
 
690
        # wow. 
691
691
        #  449       0   4474.6820   2356.5590   bzrlib.weave:556(_extract)
692
692
        #  +285282   0   1676.8040   1676.8040   +<isinstance>
693
693
        # 1.6 seconds in 'isinstance'.
699
699
        # we're still spending ~1/4 of the method in isinstance though.
700
700
        # so lets hard code the acceptable string classes we expect:
701
701
        #  449       0   1202.9420    786.2930   bzrlib.weave:556(_extract)
702
 
        # +71352     0    377.5560    377.5560   +<method 'append' of 'list'
 
702
        # +71352     0    377.5560    377.5560   +<method 'append' of 'list' 
703
703
        #                                          objects>
704
704
        # yay, down to ~1/4 the initial extract time, and our inline time
705
705
        # has shrunk again, with isinstance no longer dominating.
706
706
        # tweaking the stack inclusion test to use a set gives:
707
707
        #  449       0   1122.8030    713.0080   bzrlib.weave:556(_extract)
708
 
        # +71352     0    354.9980    354.9980   +<method 'append' of 'list'
 
708
        # +71352     0    354.9980    354.9980   +<method 'append' of 'list' 
709
709
        #                                          objects>
710
710
        # - a 5% win, or possibly just noise. However with large istacks that
711
711
        # 'in' test could dominate, so I'm leaving this change in place -
712
712
        # when its fast enough to consider profiling big datasets we can review.
713
713
 
714
 
 
715
 
 
 
714
              
 
715
             
716
716
 
717
717
        for l in self._weave:
718
718
            if l.__class__ == tuple:
747
747
 
748
748
    def _maybe_lookup(self, name_or_index):
749
749
        """Convert possible symbolic name to index, or pass through indexes.
750
 
 
 
750
        
751
751
        NOT FOR PUBLIC USE.
752
752
        """
753
753
        if isinstance(name_or_index, (int, long)):
763
763
        measured_sha1 = sha_strings(result)
764
764
        if measured_sha1 != expected_sha1:
765
765
            raise errors.WeaveInvalidChecksum(
766
 
                    'file %s, revision %s, expected: %s, measured %s'
 
766
                    'file %s, revision %s, expected: %s, measured %s' 
767
767
                    % (self._weave_name, version_id,
768
768
                       expected_sha1, measured_sha1))
769
769
        return result
803
803
            # For creating the ancestry, IntSet is much faster (3.7s vs 0.17s)
804
804
            # The problem is that set membership is much more expensive
805
805
            name = self._idx_to_name(i)
806
 
            sha1s[name] = sha()
 
806
            sha1s[name] = sha.new()
807
807
            texts[name] = []
808
808
            new_inc = set([name])
809
809
            for p in self._parents[i]:
811
811
 
812
812
            if set(new_inc) != set(self.get_ancestry(name)):
813
813
                raise AssertionError(
814
 
                    'failed %s != %s'
 
814
                    'failed %s != %s' 
815
815
                    % (set(new_inc), set(self.get_ancestry(name))))
816
816
            inclusions[name] = new_inc
817
817
 
855
855
            parent_name = other._names[parent_idx]
856
856
            if parent_name not in self._name_map:
857
857
                # should not be possible
858
 
                raise WeaveError("missing parent {%s} of {%s} in %r"
 
858
                raise WeaveError("missing parent {%s} of {%s} in %r" 
859
859
                                 % (parent_name, other._name_map[other_idx], self))
860
860
            new_parents.append(self._name_map[parent_name])
861
861
        return new_parents
868
868
         * the same text
869
869
         * the same direct parents (by name, not index, and disregarding
870
870
           order)
871
 
 
 
871
        
872
872
        If present & correct return True;
873
 
        if not present in self return False;
 
873
        if not present in self return False; 
874
874
        if inconsistent raise error."""
875
875
        this_idx = self._name_map.get(name, -1)
876
876
        if this_idx != -1:
909
909
    """A WeaveFile represents a Weave on disk and writes on change."""
910
910
 
911
911
    WEAVE_SUFFIX = '.weave'
912
 
 
 
912
    
913
913
    def __init__(self, name, transport, filemode=None, create=False, access_mode='w', get_scope=None):
914
914
        """Create a WeaveFile.
915
 
 
 
915
        
916
916
        :param create: If not True, only open an existing knit.
917
917
        """
918
918
        super(WeaveFile, self).__init__(name, access_mode, get_scope=get_scope,
968
968
        super(WeaveFile, self).insert_record_stream(stream)
969
969
        self._save()
970
970
 
 
971
    @deprecated_method(one_five)
 
972
    def join(self, other, pb=None, msg=None, version_ids=None,
 
973
             ignore_missing=False):
 
974
        """Join other into self and save."""
 
975
        super(WeaveFile, self).join(other, pb, msg, version_ids, ignore_missing)
 
976
        self._save()
 
977
 
971
978
 
972
979
def _reweave(wa, wb, pb=None, msg=None):
973
980
    """Combine two weaves and return the result.
974
981
 
975
 
    This works even if a revision R has different parents in
 
982
    This works even if a revision R has different parents in 
976
983
    wa and wb.  In the resulting weave all the parents are given.
977
984
 
978
 
    This is done by just building up a new weave, maintaining ordering
 
985
    This is done by just building up a new weave, maintaining ordering 
979
986
    of the versions in the two inputs.  More efficient approaches
980
 
    might be possible but it should only be necessary to do
981
 
    this operation rarely, when a new previously ghost version is
 
987
    might be possible but it should only be necessary to do 
 
988
    this operation rarely, when a new previously ghost version is 
982
989
    inserted.
983
990
 
984
991
    :param pb: An optional progress bar, indicating how far done we are
1018
1025
        wr._add(name, lines, [wr._lookup(i) for i in combined_parents[name]])
1019
1026
    return wr
1020
1027
 
1021
 
 
1022
1028
def _reweave_parent_graphs(wa, wb):
1023
1029
    """Return combined parent ancestry for two weaves.
1024
 
 
 
1030
    
1025
1031
    Returned as a list of (version_name, set(parent_names))"""
1026
1032
    combined = {}
1027
1033
    for weave in [wa, wb]:
1029
1035
            p = combined.setdefault(name, set())
1030
1036
            p.update(map(weave._idx_to_name, weave._parents[idx]))
1031
1037
    return combined
 
1038
 
 
1039
 
 
1040
def weave_toc(w):
 
1041
    """Show the weave's table-of-contents"""
 
1042
    print '%6s %50s %10s %10s' % ('ver', 'name', 'sha1', 'parents')
 
1043
    for i in (6, 50, 10, 10):
 
1044
        print '-' * i,
 
1045
    print
 
1046
    for i in range(w.num_versions()):
 
1047
        sha1 = w._sha1s[i]
 
1048
        name = w._names[i]
 
1049
        parent_str = ' '.join(map(str, w._parents[i]))
 
1050
        print '%6d %-50.50s %10.10s %s' % (i, name, sha1, parent_str)
 
1051
 
 
1052
 
 
1053
 
 
1054
def weave_stats(weave_file, pb):
 
1055
    from bzrlib.weavefile import read_weave
 
1056
 
 
1057
    wf = file(weave_file, 'rb')
 
1058
    w = read_weave(wf)
 
1059
    # FIXME: doesn't work on pipes
 
1060
    weave_size = wf.tell()
 
1061
 
 
1062
    total = 0
 
1063
    vers = len(w)
 
1064
    for i in range(vers):
 
1065
        pb.update('checking sizes', i, vers)
 
1066
        for origin, lineno, line in w._extract([i]):
 
1067
            total += len(line)
 
1068
 
 
1069
    pb.clear()
 
1070
 
 
1071
    print 'versions          %9d' % vers
 
1072
    print 'weave file        %9d bytes' % weave_size
 
1073
    print 'total contents    %9d bytes' % total
 
1074
    print 'compression ratio %9.2fx' % (float(total) / float(weave_size))
 
1075
    if vers:
 
1076
        avg = total/vers
 
1077
        print 'average size      %9d bytes' % avg
 
1078
        print 'relative size     %9.2fx' % (float(weave_size) / float(avg))
 
1079
 
 
1080
 
 
1081
def usage():
 
1082
    print """bzr weave tool
 
1083
 
 
1084
Experimental tool for weave algorithm.
 
1085
 
 
1086
usage:
 
1087
    weave init WEAVEFILE
 
1088
        Create an empty weave file
 
1089
    weave get WEAVEFILE VERSION
 
1090
        Write out specified version.
 
1091
    weave check WEAVEFILE
 
1092
        Check consistency of all versions.
 
1093
    weave toc WEAVEFILE
 
1094
        Display table of contents.
 
1095
    weave add WEAVEFILE NAME [BASE...] < NEWTEXT
 
1096
        Add NEWTEXT, with specified parent versions.
 
1097
    weave annotate WEAVEFILE VERSION
 
1098
        Display origin of each line.
 
1099
    weave merge WEAVEFILE VERSION1 VERSION2 > OUT
 
1100
        Auto-merge two versions and display conflicts.
 
1101
    weave diff WEAVEFILE VERSION1 VERSION2 
 
1102
        Show differences between two versions.
 
1103
 
 
1104
example:
 
1105
 
 
1106
    % weave init foo.weave
 
1107
    % vi foo.txt
 
1108
    % weave add foo.weave ver0 < foo.txt
 
1109
    added version 0
 
1110
 
 
1111
    (create updated version)
 
1112
    % vi foo.txt
 
1113
    % weave get foo.weave 0 | diff -u - foo.txt
 
1114
    % weave add foo.weave ver1 0 < foo.txt
 
1115
    added version 1
 
1116
 
 
1117
    % weave get foo.weave 0 > foo.txt       (create forked version)
 
1118
    % vi foo.txt
 
1119
    % weave add foo.weave ver2 0 < foo.txt
 
1120
    added version 2
 
1121
 
 
1122
    % weave merge foo.weave 1 2 > foo.txt   (merge them)
 
1123
    % vi foo.txt                            (resolve conflicts)
 
1124
    % weave add foo.weave merged 1 2 < foo.txt     (commit merged version)     
 
1125
    
 
1126
"""
 
1127
    
 
1128
 
 
1129
 
 
1130
def main(argv):
 
1131
    import sys
 
1132
    import os
 
1133
    try:
 
1134
        import bzrlib
 
1135
    except ImportError:
 
1136
        # in case we're run directly from the subdirectory
 
1137
        sys.path.append('..')
 
1138
        import bzrlib
 
1139
    from bzrlib.weavefile import write_weave, read_weave
 
1140
    from bzrlib.progress import ProgressBar
 
1141
 
 
1142
    try:
 
1143
        import psyco
 
1144
        psyco.full()
 
1145
    except ImportError:
 
1146
        pass
 
1147
 
 
1148
    if len(argv) < 2:
 
1149
        usage()
 
1150
        return 0
 
1151
 
 
1152
    cmd = argv[1]
 
1153
 
 
1154
    def readit():
 
1155
        return read_weave(file(argv[2], 'rb'))
 
1156
    
 
1157
    if cmd == 'help':
 
1158
        usage()
 
1159
    elif cmd == 'add':
 
1160
        w = readit()
 
1161
        # at the moment, based on everything in the file
 
1162
        name = argv[3]
 
1163
        parents = map(int, argv[4:])
 
1164
        lines = sys.stdin.readlines()
 
1165
        ver = w.add(name, parents, lines)
 
1166
        write_weave(w, file(argv[2], 'wb'))
 
1167
        print 'added version %r %d' % (name, ver)
 
1168
    elif cmd == 'init':
 
1169
        fn = argv[2]
 
1170
        if os.path.exists(fn):
 
1171
            raise IOError("file exists")
 
1172
        w = Weave()
 
1173
        write_weave(w, file(fn, 'wb'))
 
1174
    elif cmd == 'get': # get one version
 
1175
        w = readit()
 
1176
        sys.stdout.writelines(w.get_iter(int(argv[3])))
 
1177
        
 
1178
    elif cmd == 'diff':
 
1179
        w = readit()
 
1180
        fn = argv[2]
 
1181
        v1, v2 = map(int, argv[3:5])
 
1182
        lines1 = w.get(v1)
 
1183
        lines2 = w.get(v2)
 
1184
        diff_gen = bzrlib.patiencediff.unified_diff(lines1, lines2,
 
1185
                                '%s version %d' % (fn, v1),
 
1186
                                '%s version %d' % (fn, v2))
 
1187
        sys.stdout.writelines(diff_gen)
 
1188
            
 
1189
    elif cmd == 'annotate':
 
1190
        w = readit()
 
1191
        # newline is added to all lines regardless; too hard to get
 
1192
        # reasonable formatting otherwise
 
1193
        lasto = None
 
1194
        for origin, text in w.annotate(int(argv[3])):
 
1195
            text = text.rstrip('\r\n')
 
1196
            if origin == lasto:
 
1197
                print '      | %s' % (text)
 
1198
            else:
 
1199
                print '%5d | %s' % (origin, text)
 
1200
                lasto = origin
 
1201
                
 
1202
    elif cmd == 'toc':
 
1203
        weave_toc(readit())
 
1204
 
 
1205
    elif cmd == 'stats':
 
1206
        weave_stats(argv[2], ProgressBar())
 
1207
        
 
1208
    elif cmd == 'check':
 
1209
        w = readit()
 
1210
        pb = ProgressBar()
 
1211
        w.check(pb)
 
1212
        pb.clear()
 
1213
        print '%d versions ok' % w.num_versions()
 
1214
 
 
1215
    elif cmd == 'inclusions':
 
1216
        w = readit()
 
1217
        print ' '.join(map(str, w.inclusions([int(argv[3])])))
 
1218
 
 
1219
    elif cmd == 'parents':
 
1220
        w = readit()
 
1221
        print ' '.join(map(str, w._parents[int(argv[3])]))
 
1222
 
 
1223
    elif cmd == 'plan-merge':
 
1224
        # replaced by 'bzr weave-plan-merge'
 
1225
        w = readit()
 
1226
        for state, line in w.plan_merge(int(argv[3]), int(argv[4])):
 
1227
            if line:
 
1228
                print '%14s | %s' % (state, line),
 
1229
    elif cmd == 'merge':
 
1230
        # replaced by 'bzr weave-merge-text'
 
1231
        w = readit()
 
1232
        p = w.plan_merge(int(argv[3]), int(argv[4]))
 
1233
        sys.stdout.writelines(w.weave_merge(p))
 
1234
    else:
 
1235
        raise ValueError('unknown command %r' % cmd)
 
1236
    
 
1237
 
 
1238
if __name__ == '__main__':
 
1239
    import sys
 
1240
    sys.exit(main(sys.argv))