~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_directive.py

Fix WorkingTree4._iter_changes with pending merges and deleted files

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    testament,
29
29
    timestamp,
30
30
    )
31
 
from bzrlib.bundle import (
32
 
    serializer as bundle_serializer,
33
 
    )
 
31
from bzrlib.bundle import serializer as bundle_serializer
34
32
 
35
33
 
36
34
class MergeDirective(object):
90
88
        :param lines: An iterable of lines
91
89
        :return: a MergeRequest
92
90
        """
93
 
        line_iter = iter(lines)
94
 
        for line in line_iter:
95
 
            if line.startswith('# ' + klass._format_string):
96
 
                break
97
 
        else:
98
 
            if len(lines) > 0:
99
 
                raise errors.NotAMergeDirective(lines[0])
100
 
            else:
101
 
                raise errors.NotAMergeDirective('')
 
91
        assert lines[0].startswith('# ' + klass._format_string + '\n')
 
92
        line_iter = iter(lines[1:])
102
93
        stanza = rio.read_patch_stanza(line_iter)
103
94
        patch_lines = list(line_iter)
104
95
        if len(patch_lines) == 0:
105
96
            patch = None
106
 
            patch_type = None
107
97
        else:
108
98
            patch = ''.join(patch_lines)
109
 
            try:
110
 
                bundle_serializer.read_bundle(StringIO(patch))
111
 
            except errors.NotABundle:
112
 
                patch_type = 'diff'
113
 
            else:
114
 
                patch_type = 'bundle'
 
99
        try:
 
100
            bundle_serializer.read_bundle(StringIO(patch))
 
101
        except errors.NotABundle:
 
102
            patch_type = 'diff'
 
103
        else:
 
104
            patch_type = 'bundle'
115
105
        time, timezone = timestamp.parse_patch_date(stanza.get('timestamp'))
116
106
        kwargs = {}
117
107
        for key in ('revision_id', 'testament_sha1', 'target_branch',
120
110
                kwargs[key] = stanza.get(key)
121
111
            except KeyError:
122
112
                pass
123
 
        kwargs['revision_id'] = kwargs['revision_id'].encode('utf-8')
124
113
        return MergeDirective(time=time, timezone=timezone,
125
114
                              patch_type=patch_type, patch=patch, **kwargs)
126
115
 
203
192
        used for the commit.
204
193
        """
205
194
        t = testament.StrictTestament3.from_revision(repository, revision_id)
206
 
        submit_branch = _mod_branch.Branch.open(target_branch)
207
 
        if submit_branch.get_public_branch() is not None:
208
 
            target_branch = submit_branch.get_public_branch()
209
195
        if patch_type is None:
210
196
            patch = None
211
197
        else:
 
198
            submit_branch = _mod_branch.Branch.open(target_branch)
212
199
            submit_revision_id = submit_branch.last_revision()
213
200
            repository.fetch(submit_branch.repository, submit_revision_id)
214
201
            ancestor_id = _mod_revision.common_ancestor(revision_id,
252
239
        bundle_serializer.write_bundle(repository, revision_id,
253
240
                                       ancestor_id, s)
254
241
        return s.getvalue()
255
 
 
256
 
    def install_revisions(self, target_repo):
257
 
        """Install revisions and return the target revision"""
258
 
        if not target_repo.has_revision(self.revision_id):
259
 
            if self.patch_type == 'bundle':
260
 
                info = bundle_serializer.read_bundle(StringIO(self.patch))
261
 
                # We don't use the bundle's target revision, because
262
 
                # MergeDirective.revision_id is authoritative.
263
 
                info.install_revisions(target_repo)
264
 
            else:
265
 
                source_branch = _mod_branch.Branch.open(self.source_branch)
266
 
                target_repo.fetch(source_branch.repository, self.revision_id)
267
 
        return self.revision_id