~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_directive.py

  • Committer: Robert Collins
  • Date: 2007-07-25 00:52:21 UTC
  • mfrom: (2650 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2651.
  • Revision ID: robertc@robertcollins.net-20070725005221-0ysm6il5mqnme3wz
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
from StringIO import StringIO
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
 
 
154
139
    @staticmethod
155
140
    def _generate_diff(repository, revision_id, ancestor_id):
156
141
        tree_1 = repository.revision_tree(ancestor_id)
205
190
                    StringIO(self.get_raw_bundle()))
206
191
                # We don't use the bundle's target revision, because
207
192
                # MergeDirective.revision_id is authoritative.
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)
 
193
                info.install_revisions(target_repo)
238
194
            else:
239
195
                source_branch = _mod_branch.Branch.open(self.source_branch)
240
196
                target_repo.fetch(source_branch.repository, self.revision_id)
278
234
        """
279
235
        _BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
280
236
            timezone, target_branch, patch, source_branch, message)
281
 
        if patch_type not in (None, 'diff', 'bundle'):
282
 
            raise ValueError(patch_type)
 
237
        assert patch_type in (None, 'diff', 'bundle'), patch_type
283
238
        if patch_type != 'bundle' and source_branch is None:
284
239
            raise errors.NoMergeSource()
285
240
        if patch_type is not None and patch is None:
370
325
 
371
326
class MergeDirective2(_BaseMergeDirective):
372
327
 
373
 
    _format_string = 'Bazaar merge directive format 2 (Bazaar 0.90)'
 
328
    _format_string = 'Bazaar merge directive format 2 (Bazaar 0.19)'
374
329
 
375
330
    def __init__(self, revision_id, testament_sha1, time, timezone,
376
331
                 target_branch, patch=None, source_branch=None, message=None,
531
486
                                               self.base_revision_id)
532
487
        # Convert line-endings to UNIX
533
488
        stored_patch = re.sub('\r\n?', '\n', self.patch)
534
 
        calculated_patch = re.sub('\r\n?', '\n', calculated_patch)
535
489
        # Strip trailing whitespace
536
490
        calculated_patch = re.sub(' *\n', '\n', calculated_patch)
537
491
        stored_patch = re.sub(' *\n', '\n', stored_patch)
557
511
 
558
512
class MergeDirectiveFormatRegistry(registry.Registry):
559
513
 
560
 
    def register(self, directive, format_string=None):
561
 
        if format_string is None:
562
 
            format_string = directive._format_string
563
 
        registry.Registry.register(self, format_string, directive)
 
514
    def register(self, directive):
 
515
        registry.Registry.register(self, directive._format_string, directive)
564
516
 
565
517
 
566
518
_format_registry = MergeDirectiveFormatRegistry()
567
519
_format_registry.register(MergeDirective)
568
520
_format_registry.register(MergeDirective2)
569
 
_format_registry.register(MergeDirective2,
570
 
                          'Bazaar merge directive format 2 (Bazaar 0.19)')