~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: John Arbash Meinel
  • Date: 2008-09-05 02:29:34 UTC
  • mto: (3697.7.4 1.7)
  • mto: This revision was merged to the branch mainline in revision 3748.
  • Revision ID: john@arbash-meinel.com-20080905022934-s8692mbwpkdwi106
Cleanups to the algorithm documentation.

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
72
75
import time
73
76
import warnings
74
77
 
75
 
from bzrlib.lazy_import import lazy_import
76
 
lazy_import(globals(), """
77
 
from bzrlib import tsort
78
 
""")
79
78
from bzrlib import (
80
 
    errors,
81
 
    osutils,
82
79
    progress,
83
80
    )
84
81
from bzrlib.errors import (WeaveError, WeaveFormatError, WeaveParentMismatch,
88
85
        WeaveRevisionAlreadyPresent,
89
86
        WeaveRevisionNotPresent,
90
87
        )
91
 
from bzrlib.osutils import dirname, sha, sha_strings, split_lines
 
88
import bzrlib.errors as errors
 
89
from bzrlib.osutils import dirname, sha_strings, split_lines
92
90
import bzrlib.patiencediff
93
91
from bzrlib.revision import NULL_REVISION
94
92
from bzrlib.symbol_versioning import *
95
93
from bzrlib.trace import mutter
 
94
from bzrlib.tsort import topo_sort
96
95
from bzrlib.versionedfile import (
97
96
    AbsentContentFactory,
98
97
    adapter_registry,
99
98
    ContentFactory,
100
 
    sort_groupcompress,
101
99
    VersionedFile,
102
100
    )
103
101
from bzrlib.weavefile import _read_weave_v5, write_weave_v5
122
120
    def get_bytes_as(self, storage_kind):
123
121
        if storage_kind == 'fulltext':
124
122
            return self._weave.get_text(self.key[-1])
125
 
        elif storage_kind == 'chunked':
126
 
            return self._weave.get_lines(self.key[-1])
127
123
        else:
128
124
            raise UnavailableRepresentation(self.key, storage_kind, 'fulltext')
129
125
 
130
126
 
131
127
class Weave(VersionedFile):
132
128
    """weave - versioned text file storage.
133
 
 
 
129
    
134
130
    A Weave manages versions of line-based text files, keeping track
135
131
    of the originating version for each line.
136
132
 
182
178
 
183
179
    * It doesn't seem very useful to have an active insertion
184
180
      inside an inactive insertion, but it might happen.
185
 
 
 
181
      
186
182
    * Therefore, all instructions are always"considered"; that
187
183
      is passed onto and off the stack.  An outer inactive block
188
184
      doesn't disable an inner block.
219
215
 
220
216
    __slots__ = ['_weave', '_parents', '_sha1s', '_names', '_name_map',
221
217
                 '_weave_name', '_matcher', '_allow_reserved']
222
 
 
 
218
    
223
219
    def __init__(self, weave_name=None, access_mode='w', matcher=None,
224
220
                 get_scope=None, allow_reserved=False):
225
221
        """Create a weave.
228
224
            for detecting when this weave goes out of scope (should stop
229
225
            answering requests or allowing mutation).
230
226
        """
231
 
        super(Weave, self).__init__()
 
227
        super(Weave, self).__init__(access_mode)
232
228
        self._weave = []
233
229
        self._parents = []
234
230
        self._sha1s = []
258
254
 
259
255
    def copy(self):
260
256
        """Return a deep copy of self.
261
 
 
 
257
        
262
258
        The copy can be modified without affecting the original weave."""
263
259
        other = Weave()
264
260
        other._weave = self._weave[:]
274
270
            return False
275
271
        return self._parents == other._parents \
276
272
               and self._weave == other._weave \
277
 
               and self._sha1s == other._sha1s
278
 
 
 
273
               and self._sha1s == other._sha1s 
 
274
    
279
275
    def __ne__(self, other):
280
276
        return not self.__eq__(other)
281
277
 
317
313
        versions = [version[-1] for version in versions]
318
314
        if ordering == 'topological':
319
315
            parents = self.get_parent_map(versions)
320
 
            new_versions = tsort.topo_sort(parents)
321
 
            new_versions.extend(set(versions).difference(set(parents)))
322
 
            versions = new_versions
323
 
        elif ordering == 'groupcompress':
324
 
            parents = self.get_parent_map(versions)
325
 
            new_versions = sort_groupcompress(parents)
 
316
            new_versions = topo_sort(parents)
326
317
            new_versions.extend(set(versions).difference(set(parents)))
327
318
            versions = new_versions
328
319
        for version in versions:
353
344
    def insert_record_stream(self, stream):
354
345
        """Insert a record stream into this versioned file.
355
346
 
356
 
        :param stream: A stream of records to insert.
 
347
        :param stream: A stream of records to insert. 
357
348
        :return: None
358
349
        :seealso VersionedFile.get_record_stream:
359
350
        """
364
355
                raise RevisionNotPresent([record.key[0]], self)
365
356
            # adapt to non-tuple interface
366
357
            parents = [parent[0] for parent in record.parents]
367
 
            if (record.storage_kind == 'fulltext'
368
 
                or record.storage_kind == 'chunked'):
 
358
            if record.storage_kind == 'fulltext':
369
359
                self.add_lines(record.key[0], parents,
370
 
                    osutils.chunks_to_lines(record.get_bytes_as('chunked')))
 
360
                    split_lines(record.get_bytes_as('fulltext')))
371
361
            else:
372
362
                adapter_key = record.storage_kind, 'fulltext'
373
363
                try:
376
366
                    adapter_factory = adapter_registry.get(adapter_key)
377
367
                    adapter = adapter_factory(self)
378
368
                    adapters[adapter_key] = adapter
379
 
                lines = split_lines(adapter.get_bytes(record))
 
369
                lines = split_lines(adapter.get_bytes(
 
370
                    record, record.get_bytes_as(record.storage_kind)))
380
371
                try:
381
372
                    self.add_lines(record.key[0], parents, lines)
382
373
                except RevisionAlreadyPresent:
402
393
 
403
394
    def _add(self, version_id, lines, parents, sha1=None, nostore_sha=None):
404
395
        """Add a single text on top of the weave.
405
 
 
 
396
  
406
397
        Returns the index number of the newly added version.
407
398
 
408
399
        version_id
409
400
            Symbolic name for this version.
410
401
            (Typically the revision-id of the revision that added it.)
411
 
            If None, a name will be allocated based on the hash. (sha1:SHAHASH)
412
402
 
413
403
        parents
414
404
            List or set of direct parent version numbers.
415
 
 
 
405
            
416
406
        lines
417
407
            Sequence of lines to be added in the new version.
418
408
 
424
414
            sha1 = sha_strings(lines)
425
415
        if sha1 == nostore_sha:
426
416
            raise errors.ExistingContent
427
 
        if version_id is None:
428
 
            version_id = "sha1:" + sha1
429
417
        if version_id in self._name_map:
430
418
            return self._check_repeated_add(version_id, parents, lines, sha1)
431
419
 
442
430
        self._names.append(version_id)
443
431
        self._name_map[version_id] = new_version
444
432
 
445
 
 
 
433
            
446
434
        if not parents:
447
435
            # special case; adding with no parents revision; can do
448
436
            # this more quickly by just appending unconditionally.
459
447
            if sha1 == self._sha1s[pv]:
460
448
                # special case: same as the single parent
461
449
                return new_version
462
 
 
 
450
            
463
451
 
464
452
        ancestors = self._inclusions(parents)
465
453
 
514
502
                # i2; we want to insert after this region to make sure
515
503
                # we don't destroy ourselves
516
504
                i = i2 + offset
517
 
                self._weave[i:i] = ([('{', new_version)]
518
 
                                    + lines[j1:j2]
 
505
                self._weave[i:i] = ([('{', new_version)] 
 
506
                                    + lines[j1:j2] 
519
507
                                    + [('}', None)])
520
508
                offset += 2 + (j2 - j1)
521
509
        return new_version
548
536
            if not isinstance(l, basestring):
549
537
                raise ValueError("text line should be a string or unicode, not %s"
550
538
                                 % type(l))
551
 
 
 
539
        
552
540
 
553
541
 
554
542
    def _check_versions(self, indexes):
562
550
    def _compatible_parents(self, my_parents, other_parents):
563
551
        """During join check that other_parents are joinable with my_parents.
564
552
 
565
 
        Joinable is defined as 'is a subset of' - supersets may require
 
553
        Joinable is defined as 'is a subset of' - supersets may require 
566
554
        regeneration of diffs, but subsets do not.
567
555
        """
568
556
        return len(other_parents.difference(my_parents)) == 0
582
570
            version_ids = self.versions()
583
571
        version_ids = set(version_ids)
584
572
        for lineno, inserted, deletes, line in self._walk_internal(version_ids):
585
 
            if inserted not in version_ids: continue
 
573
            # if inserted not in version_ids then it was inserted before the
 
574
            # versions we care about, but because weaves cannot represent ghosts
 
575
            # properly, we do not filter down to that
 
576
            # if inserted not in version_ids: continue
586
577
            if line[-1] != '\n':
587
578
                yield line + '\n', inserted
588
579
            else:
590
581
 
591
582
    def _walk_internal(self, version_ids=None):
592
583
        """Helper method for weave actions."""
593
 
 
 
584
        
594
585
        istack = []
595
586
        dset = set()
596
587
 
677
668
        for i in versions:
678
669
            if not isinstance(i, int):
679
670
                raise ValueError(i)
680
 
 
 
671
            
681
672
        included = self._inclusions(versions)
682
673
 
683
674
        istack = []
692
683
 
693
684
        WFE = WeaveFormatError
694
685
 
695
 
        # wow.
 
686
        # wow. 
696
687
        #  449       0   4474.6820   2356.5590   bzrlib.weave:556(_extract)
697
688
        #  +285282   0   1676.8040   1676.8040   +<isinstance>
698
689
        # 1.6 seconds in 'isinstance'.
704
695
        # we're still spending ~1/4 of the method in isinstance though.
705
696
        # so lets hard code the acceptable string classes we expect:
706
697
        #  449       0   1202.9420    786.2930   bzrlib.weave:556(_extract)
707
 
        # +71352     0    377.5560    377.5560   +<method 'append' of 'list'
 
698
        # +71352     0    377.5560    377.5560   +<method 'append' of 'list' 
708
699
        #                                          objects>
709
700
        # yay, down to ~1/4 the initial extract time, and our inline time
710
701
        # has shrunk again, with isinstance no longer dominating.
711
702
        # tweaking the stack inclusion test to use a set gives:
712
703
        #  449       0   1122.8030    713.0080   bzrlib.weave:556(_extract)
713
 
        # +71352     0    354.9980    354.9980   +<method 'append' of 'list'
 
704
        # +71352     0    354.9980    354.9980   +<method 'append' of 'list' 
714
705
        #                                          objects>
715
706
        # - a 5% win, or possibly just noise. However with large istacks that
716
707
        # 'in' test could dominate, so I'm leaving this change in place -
717
708
        # when its fast enough to consider profiling big datasets we can review.
718
709
 
719
 
 
720
 
 
 
710
              
 
711
             
721
712
 
722
713
        for l in self._weave:
723
714
            if l.__class__ == tuple:
752
743
 
753
744
    def _maybe_lookup(self, name_or_index):
754
745
        """Convert possible symbolic name to index, or pass through indexes.
755
 
 
 
746
        
756
747
        NOT FOR PUBLIC USE.
757
748
        """
758
749
        if isinstance(name_or_index, (int, long)):
768
759
        measured_sha1 = sha_strings(result)
769
760
        if measured_sha1 != expected_sha1:
770
761
            raise errors.WeaveInvalidChecksum(
771
 
                    'file %s, revision %s, expected: %s, measured %s'
 
762
                    'file %s, revision %s, expected: %s, measured %s' 
772
763
                    % (self._weave_name, version_id,
773
764
                       expected_sha1, measured_sha1))
774
765
        return result
808
799
            # For creating the ancestry, IntSet is much faster (3.7s vs 0.17s)
809
800
            # The problem is that set membership is much more expensive
810
801
            name = self._idx_to_name(i)
811
 
            sha1s[name] = sha()
 
802
            sha1s[name] = sha.new()
812
803
            texts[name] = []
813
804
            new_inc = set([name])
814
805
            for p in self._parents[i]:
816
807
 
817
808
            if set(new_inc) != set(self.get_ancestry(name)):
818
809
                raise AssertionError(
819
 
                    'failed %s != %s'
 
810
                    'failed %s != %s' 
820
811
                    % (set(new_inc), set(self.get_ancestry(name))))
821
812
            inclusions[name] = new_inc
822
813
 
860
851
            parent_name = other._names[parent_idx]
861
852
            if parent_name not in self._name_map:
862
853
                # should not be possible
863
 
                raise WeaveError("missing parent {%s} of {%s} in %r"
 
854
                raise WeaveError("missing parent {%s} of {%s} in %r" 
864
855
                                 % (parent_name, other._name_map[other_idx], self))
865
856
            new_parents.append(self._name_map[parent_name])
866
857
        return new_parents
873
864
         * the same text
874
865
         * the same direct parents (by name, not index, and disregarding
875
866
           order)
876
 
 
 
867
        
877
868
        If present & correct return True;
878
 
        if not present in self return False;
 
869
        if not present in self return False; 
879
870
        if inconsistent raise error."""
880
871
        this_idx = self._name_map.get(name, -1)
881
872
        if this_idx != -1:
914
905
    """A WeaveFile represents a Weave on disk and writes on change."""
915
906
 
916
907
    WEAVE_SUFFIX = '.weave'
917
 
 
 
908
    
918
909
    def __init__(self, name, transport, filemode=None, create=False, access_mode='w', get_scope=None):
919
910
        """Create a WeaveFile.
920
 
 
 
911
        
921
912
        :param create: If not True, only open an existing knit.
922
913
        """
923
914
        super(WeaveFile, self).__init__(name, access_mode, get_scope=get_scope,
973
964
        super(WeaveFile, self).insert_record_stream(stream)
974
965
        self._save()
975
966
 
 
967
    @deprecated_method(one_five)
 
968
    def join(self, other, pb=None, msg=None, version_ids=None,
 
969
             ignore_missing=False):
 
970
        """Join other into self and save."""
 
971
        super(WeaveFile, self).join(other, pb, msg, version_ids, ignore_missing)
 
972
        self._save()
 
973
 
976
974
 
977
975
def _reweave(wa, wb, pb=None, msg=None):
978
976
    """Combine two weaves and return the result.
979
977
 
980
 
    This works even if a revision R has different parents in
 
978
    This works even if a revision R has different parents in 
981
979
    wa and wb.  In the resulting weave all the parents are given.
982
980
 
983
 
    This is done by just building up a new weave, maintaining ordering
 
981
    This is done by just building up a new weave, maintaining ordering 
984
982
    of the versions in the two inputs.  More efficient approaches
985
 
    might be possible but it should only be necessary to do
986
 
    this operation rarely, when a new previously ghost version is
 
983
    might be possible but it should only be necessary to do 
 
984
    this operation rarely, when a new previously ghost version is 
987
985
    inserted.
988
986
 
989
987
    :param pb: An optional progress bar, indicating how far done we are
997
995
    # map from version name -> all parent names
998
996
    combined_parents = _reweave_parent_graphs(wa, wb)
999
997
    mutter("combined parents: %r", combined_parents)
1000
 
    order = tsort.topo_sort(combined_parents.iteritems())
 
998
    order = topo_sort(combined_parents.iteritems())
1001
999
    mutter("order to reweave: %r", order)
1002
1000
 
1003
1001
    if pb and not msg:
1023
1021
        wr._add(name, lines, [wr._lookup(i) for i in combined_parents[name]])
1024
1022
    return wr
1025
1023
 
1026
 
 
1027
1024
def _reweave_parent_graphs(wa, wb):
1028
1025
    """Return combined parent ancestry for two weaves.
1029
 
 
 
1026
    
1030
1027
    Returned as a list of (version_name, set(parent_names))"""
1031
1028
    combined = {}
1032
1029
    for weave in [wa, wb]:
1034
1031
            p = combined.setdefault(name, set())
1035
1032
            p.update(map(weave._idx_to_name, weave._parents[idx]))
1036
1033
    return combined
 
1034
 
 
1035
 
 
1036
def weave_toc(w):
 
1037
    """Show the weave's table-of-contents"""
 
1038
    print '%6s %50s %10s %10s' % ('ver', 'name', 'sha1', 'parents')
 
1039
    for i in (6, 50, 10, 10):
 
1040
        print '-' * i,
 
1041
    print
 
1042
    for i in range(w.num_versions()):
 
1043
        sha1 = w._sha1s[i]
 
1044
        name = w._names[i]
 
1045
        parent_str = ' '.join(map(str, w._parents[i]))
 
1046
        print '%6d %-50.50s %10.10s %s' % (i, name, sha1, parent_str)
 
1047
 
 
1048
 
 
1049
 
 
1050
def weave_stats(weave_file, pb):
 
1051
    from bzrlib.weavefile import read_weave
 
1052
 
 
1053
    wf = file(weave_file, 'rb')
 
1054
    w = read_weave(wf)
 
1055
    # FIXME: doesn't work on pipes
 
1056
    weave_size = wf.tell()
 
1057
 
 
1058
    total = 0
 
1059
    vers = len(w)
 
1060
    for i in range(vers):
 
1061
        pb.update('checking sizes', i, vers)
 
1062
        for origin, lineno, line in w._extract([i]):
 
1063
            total += len(line)
 
1064
 
 
1065
    pb.clear()
 
1066
 
 
1067
    print 'versions          %9d' % vers
 
1068
    print 'weave file        %9d bytes' % weave_size
 
1069
    print 'total contents    %9d bytes' % total
 
1070
    print 'compression ratio %9.2fx' % (float(total) / float(weave_size))
 
1071
    if vers:
 
1072
        avg = total/vers
 
1073
        print 'average size      %9d bytes' % avg
 
1074
        print 'relative size     %9.2fx' % (float(weave_size) / float(avg))
 
1075
 
 
1076
 
 
1077
def usage():
 
1078
    print """bzr weave tool
 
1079
 
 
1080
Experimental tool for weave algorithm.
 
1081
 
 
1082
usage:
 
1083
    weave init WEAVEFILE
 
1084
        Create an empty weave file
 
1085
    weave get WEAVEFILE VERSION
 
1086
        Write out specified version.
 
1087
    weave check WEAVEFILE
 
1088
        Check consistency of all versions.
 
1089
    weave toc WEAVEFILE
 
1090
        Display table of contents.
 
1091
    weave add WEAVEFILE NAME [BASE...] < NEWTEXT
 
1092
        Add NEWTEXT, with specified parent versions.
 
1093
    weave annotate WEAVEFILE VERSION
 
1094
        Display origin of each line.
 
1095
    weave merge WEAVEFILE VERSION1 VERSION2 > OUT
 
1096
        Auto-merge two versions and display conflicts.
 
1097
    weave diff WEAVEFILE VERSION1 VERSION2 
 
1098
        Show differences between two versions.
 
1099
 
 
1100
example:
 
1101
 
 
1102
    % weave init foo.weave
 
1103
    % vi foo.txt
 
1104
    % weave add foo.weave ver0 < foo.txt
 
1105
    added version 0
 
1106
 
 
1107
    (create updated version)
 
1108
    % vi foo.txt
 
1109
    % weave get foo.weave 0 | diff -u - foo.txt
 
1110
    % weave add foo.weave ver1 0 < foo.txt
 
1111
    added version 1
 
1112
 
 
1113
    % weave get foo.weave 0 > foo.txt       (create forked version)
 
1114
    % vi foo.txt
 
1115
    % weave add foo.weave ver2 0 < foo.txt
 
1116
    added version 2
 
1117
 
 
1118
    % weave merge foo.weave 1 2 > foo.txt   (merge them)
 
1119
    % vi foo.txt                            (resolve conflicts)
 
1120
    % weave add foo.weave merged 1 2 < foo.txt     (commit merged version)     
 
1121
    
 
1122
"""
 
1123
    
 
1124
 
 
1125
 
 
1126
def main(argv):
 
1127
    import sys
 
1128
    import os
 
1129
    try:
 
1130
        import bzrlib
 
1131
    except ImportError:
 
1132
        # in case we're run directly from the subdirectory
 
1133
        sys.path.append('..')
 
1134
        import bzrlib
 
1135
    from bzrlib.weavefile import write_weave, read_weave
 
1136
    from bzrlib.progress import ProgressBar
 
1137
 
 
1138
    try:
 
1139
        import psyco
 
1140
        psyco.full()
 
1141
    except ImportError:
 
1142
        pass
 
1143
 
 
1144
    if len(argv) < 2:
 
1145
        usage()
 
1146
        return 0
 
1147
 
 
1148
    cmd = argv[1]
 
1149
 
 
1150
    def readit():
 
1151
        return read_weave(file(argv[2], 'rb'))
 
1152
    
 
1153
    if cmd == 'help':
 
1154
        usage()
 
1155
    elif cmd == 'add':
 
1156
        w = readit()
 
1157
        # at the moment, based on everything in the file
 
1158
        name = argv[3]
 
1159
        parents = map(int, argv[4:])
 
1160
        lines = sys.stdin.readlines()
 
1161
        ver = w.add(name, parents, lines)
 
1162
        write_weave(w, file(argv[2], 'wb'))
 
1163
        print 'added version %r %d' % (name, ver)
 
1164
    elif cmd == 'init':
 
1165
        fn = argv[2]
 
1166
        if os.path.exists(fn):
 
1167
            raise IOError("file exists")
 
1168
        w = Weave()
 
1169
        write_weave(w, file(fn, 'wb'))
 
1170
    elif cmd == 'get': # get one version
 
1171
        w = readit()
 
1172
        sys.stdout.writelines(w.get_iter(int(argv[3])))
 
1173
        
 
1174
    elif cmd == 'diff':
 
1175
        w = readit()
 
1176
        fn = argv[2]
 
1177
        v1, v2 = map(int, argv[3:5])
 
1178
        lines1 = w.get(v1)
 
1179
        lines2 = w.get(v2)
 
1180
        diff_gen = bzrlib.patiencediff.unified_diff(lines1, lines2,
 
1181
                                '%s version %d' % (fn, v1),
 
1182
                                '%s version %d' % (fn, v2))
 
1183
        sys.stdout.writelines(diff_gen)
 
1184
            
 
1185
    elif cmd == 'annotate':
 
1186
        w = readit()
 
1187
        # newline is added to all lines regardless; too hard to get
 
1188
        # reasonable formatting otherwise
 
1189
        lasto = None
 
1190
        for origin, text in w.annotate(int(argv[3])):
 
1191
            text = text.rstrip('\r\n')
 
1192
            if origin == lasto:
 
1193
                print '      | %s' % (text)
 
1194
            else:
 
1195
                print '%5d | %s' % (origin, text)
 
1196
                lasto = origin
 
1197
                
 
1198
    elif cmd == 'toc':
 
1199
        weave_toc(readit())
 
1200
 
 
1201
    elif cmd == 'stats':
 
1202
        weave_stats(argv[2], ProgressBar())
 
1203
        
 
1204
    elif cmd == 'check':
 
1205
        w = readit()
 
1206
        pb = ProgressBar()
 
1207
        w.check(pb)
 
1208
        pb.clear()
 
1209
        print '%d versions ok' % w.num_versions()
 
1210
 
 
1211
    elif cmd == 'inclusions':
 
1212
        w = readit()
 
1213
        print ' '.join(map(str, w.inclusions([int(argv[3])])))
 
1214
 
 
1215
    elif cmd == 'parents':
 
1216
        w = readit()
 
1217
        print ' '.join(map(str, w._parents[int(argv[3])]))
 
1218
 
 
1219
    elif cmd == 'plan-merge':
 
1220
        # replaced by 'bzr weave-plan-merge'
 
1221
        w = readit()
 
1222
        for state, line in w.plan_merge(int(argv[3]), int(argv[4])):
 
1223
            if line:
 
1224
                print '%14s | %s' % (state, line),
 
1225
    elif cmd == 'merge':
 
1226
        # replaced by 'bzr weave-merge-text'
 
1227
        w = readit()
 
1228
        p = w.plan_merge(int(argv[3]), int(argv[4]))
 
1229
        sys.stdout.writelines(w.weave_merge(p))
 
1230
    else:
 
1231
        raise ValueError('unknown command %r' % cmd)
 
1232
    
 
1233
 
 
1234
if __name__ == '__main__':
 
1235
    import sys
 
1236
    sys.exit(main(sys.argv))