~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to multiparent/__init__.py

  • Committer: Aaron Bentley
  • Date: 2007-04-11 20:39:57 UTC
  • mto: (2520.4.1 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070411203957-j7uadxym4214p6ly
Implement from_patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
            for line in hunk.to_patch():
85
85
                yield line
86
86
 
 
87
    @staticmethod
 
88
    def from_patch(lines):
 
89
        line_iter = iter(lines)
 
90
        hunks = []
 
91
        cur_line = None
 
92
        while(True):
 
93
            try:
 
94
                cur_line = line_iter.next()
 
95
            except StopIteration:
 
96
                break
 
97
            if cur_line[0] == 'i':
 
98
                num_lines = int(cur_line.split(' ')[1])
 
99
                hunk_lines = [line_iter.next() for x in xrange(num_lines)]
 
100
                hunk_lines[-1] = hunk_lines[-1][:-1]
 
101
                hunks.append(NewText(hunk_lines))
 
102
            elif cur_line[0] == '\n':
 
103
                hunks[-1].lines[-1] += '\n'
 
104
            else:
 
105
                assert cur_line[0] == 'c', cur_line[0]
 
106
                parent, parent_pos, child_pos, num_lines =\
 
107
                    [int(v) for v in cur_line.split(' ')[1:]]
 
108
                hunks.append(ParentText(parent, parent_pos, child_pos,
 
109
                                        num_lines))
 
110
        return MultiParent(hunks)
 
111
 
87
112
    def range_iterator(self):
88
113
        """Iterate through the hunks, with range indicated
89
114