~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_directive.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
        return klass(revision_id, t.as_sha1(), time, timezone, target_branch,
137
137
            patch, patch_type, public_branch, message)
138
138
 
 
139
    def get_disk_name(self, branch):
 
140
        """Generate a suitable basename for storing this directive on disk
 
141
 
 
142
        :param branch: The Branch this merge directive was generated fro
 
143
        :return: A string
 
144
        """
 
145
        revno, revision_id = branch.last_revision_info()
 
146
        if self.revision_id == revision_id:
 
147
            revno = [revno]
 
148
        else:
 
149
            revno = branch.get_revision_id_to_revno_map().get(self.revision_id,
 
150
                ['merge'])
 
151
        nick = re.sub('(\W+)', '-', branch.nick).strip('-')
 
152
        return '%s-%s' % (nick, '.'.join(str(n) for n in revno))
 
153
 
139
154
    @staticmethod
140
155
    def _generate_diff(repository, revision_id, ancestor_id):
141
156
        tree_1 = repository.revision_tree(ancestor_id)
190
205
                    StringIO(self.get_raw_bundle()))
191
206
                # We don't use the bundle's target revision, because
192
207
                # MergeDirective.revision_id is authoritative.
193
 
                info.install_revisions(target_repo, stream_input=False)
 
208
                try:
 
209
                    info.install_revisions(target_repo, stream_input=False)
 
210
                except errors.RevisionNotPresent:
 
211
                    # At least one dependency isn't present.  Try installing
 
212
                    # missing revisions from the submit branch
 
213
                    try:
 
214
                        submit_branch = \
 
215
                            _mod_branch.Branch.open(self.target_branch)
 
216
                    except errors.NotBranchError:
 
217
                        raise errors.TargetNotBranch(self.target_branch)
 
218
                    missing_revisions = []
 
219
                    bundle_revisions = set(r.revision_id for r in
 
220
                                           info.real_revisions)
 
221
                    for revision in info.real_revisions:
 
222
                        for parent_id in revision.parent_ids:
 
223
                            if (parent_id not in bundle_revisions and
 
224
                                not target_repo.has_revision(parent_id)):
 
225
                                missing_revisions.append(parent_id)
 
226
                    # reverse missing revisions to try to get heads first
 
227
                    unique_missing = []
 
228
                    unique_missing_set = set()
 
229
                    for revision in reversed(missing_revisions):
 
230
                        if revision in unique_missing_set:
 
231
                            continue
 
232
                        unique_missing.append(revision)
 
233
                        unique_missing_set.add(revision)
 
234
                    for missing_revision in unique_missing:
 
235
                        target_repo.fetch(submit_branch.repository,
 
236
                                          missing_revision)
 
237
                    info.install_revisions(target_repo, stream_input=False)
194
238
            else:
195
239
                source_branch = _mod_branch.Branch.open(self.source_branch)
196
240
                target_repo.fetch(source_branch.repository, self.revision_id)
234
278
        """
235
279
        _BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
236
280
            timezone, target_branch, patch, source_branch, message)
237
 
        assert patch_type in (None, 'diff', 'bundle'), patch_type
 
281
        if patch_type not in (None, 'diff', 'bundle'):
 
282
            raise ValueError(patch_type)
238
283
        if patch_type != 'bundle' and source_branch is None:
239
284
            raise errors.NoMergeSource()
240
285
        if patch_type is not None and patch is None: