~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to knit.py

  • Committer: Martin Pool
  • Date: 2005-06-27 08:02:41 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050627080241-935a5feb5476850e
Handle insertion of new weave layers that insert text on top of the basis 
versions.

Knit.add takes a list of basis versions.

Turn on test for this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
    included = frozenset()
15
15
    def __init__(self, included=None):
16
16
        if included:
17
 
            self.included = set(included)
 
17
            self.included = frozenset(included)
18
18
 
19
19
    def __repr__(self):
20
20
        s = self.__class__.__name__ + '('
56
56
        self._v = []
57
57
 
58
58
        
59
 
    def add(self, text):
 
59
    def add(self, text, basis=None):
60
60
        """Add a single text on top of the weave.
61
61
 
62
62
        Returns the index number of the newly added version."""
65
65
 
66
66
        idx = len(self._v)
67
67
 
68
 
        # all of the previous texts are turned off; just append lines at the bottom
69
 
        for line in text:
70
 
            self._l.append((idx, line))
71
 
 
72
 
        vi = VerInfo()
73
 
        self._v.append(vi)
 
68
        if basis:
 
69
            basis = frozenset(basis)
 
70
            delta = self._delta(basis, text)
 
71
 
 
72
            for i1, i2, newlines in delta:
 
73
                # TODO: handle lines being offset as we insert stuff
 
74
                if i1 != i2:
 
75
                    raise NotImplementedError("can't handle replacing weave lines %d-%d yet"
 
76
                                              % (i1, i2))
 
77
 
 
78
                # a pure insertion
 
79
                to_insert = []
 
80
                for line in newlines:
 
81
                    to_insert.append((idx, line))
 
82
                
 
83
                self._l[i1:i1] = to_insert
 
84
 
 
85
            self._v.append(VerInfo(basis))
 
86
        else:
 
87
            # special case; adding with no basis revision; can do this
 
88
            # more quickly by just appending unconditionally
 
89
            for line in text:
 
90
                self._l.append((idx, line))
 
91
 
 
92
            self._v.append(VerInfo())
 
93
            
74
94
        return idx
75
95
 
76
96
    
82
102
        """Yield list of (index-id, line) pairs for the specified version.
83
103
 
84
104
        The index indicates when the line originated in the weave."""
85
 
        vi = self._v[index]
 
105
        try:
 
106
            vi = self._v[index]
 
107
        except IndexError:
 
108
            raise IndexError('version index %d out of range' % index)
86
109
        included = set(vi.included)
87
110
        included.add(index)
88
111
        return iter(self._extract(included))