~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/codeimport/worker.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-03 05:01:52 UTC
  • mfrom: (13081.2.20 newer-bzr)
  • Revision ID: launchpad@pqm.canonical.com-20110603050152-qvu17gaqkvalj1hv
[r=allenap][bug=660790, 670870, 674581, 688459, 691994,
        709539] Update Bazaar to 2.3.3 and bzr-svn, bzr-hg,
        bzr-git and bzr-loom to their current tips.

Show diffs side-by-side

added added

removed removed

Lines of Context:
545
545
class PullingImportWorker(ImportWorker):
546
546
    """An import worker for imports that can be done by a bzr plugin.
547
547
 
548
 
    Subclasses need to implement `format_classes`.
 
548
    Subclasses need to implement `probers`.
549
549
    """
550
550
 
551
551
    needs_bzr_tree = False
552
552
 
553
553
    @property
554
 
    def format_classes(self):
555
 
        """The format classes that should be tried for this import."""
 
554
    def probers(self):
 
555
        """The probers that should be tried for this import."""
556
556
        raise NotImplementedError
557
557
 
558
 
    def getExtraPullArgs(self):
559
 
        """Return extra arguments to `InterBranch.pull`.
560
 
 
561
 
        This method only really exists because only bzr-git and bzr-svn
562
 
        support the 'limit' argument to this method.  When bzr-hg plugin does
563
 
        too, this method can go away.
 
558
    def getRevisionLimit(self):
 
559
        """Return maximum number of revisions to fetch (None for no limit).
564
560
        """
565
 
        return {}
 
561
        return None
566
562
 
567
563
    def _doImport(self):
568
564
        self._logger.info("Starting job.")
574
570
                "Getting exising bzr branch from central store.")
575
571
            bazaar_branch = self.getBazaarBranch()
576
572
            transport = get_transport(self.source_details.url)
577
 
            for format_class in self.format_classes:
 
573
            for prober_kls in self.probers:
 
574
                prober = prober_kls()
578
575
                try:
579
 
                    format = format_class.probe_transport(transport)
 
576
                    format = prober.probe_transport(transport)
580
577
                    break
581
578
                except NotBranchError:
582
579
                    pass
586
583
            remote_branch_tip = remote_branch.last_revision()
587
584
            inter_branch = InterBranch.get(remote_branch, bazaar_branch)
588
585
            self._logger.info("Importing branch.")
589
 
            pull_result = inter_branch.pull(
590
 
                overwrite=True, **self.getExtraPullArgs())
 
586
            inter_branch.fetch(limit=self.getRevisionLimit())
 
587
            if bazaar_branch.repository.has_revision(remote_branch_tip):
 
588
                pull_result = inter_branch.pull(overwrite=True)
 
589
                if pull_result.old_revid != pull_result.new_revid:
 
590
                    result = CodeImportWorkerExitCode.SUCCESS
 
591
                else:
 
592
                    result = CodeImportWorkerExitCode.SUCCESS_NOCHANGE
 
593
            else:
 
594
                result = CodeImportWorkerExitCode.SUCCESS_PARTIAL
591
595
            self._logger.info("Pushing local import branch to central store.")
592
596
            self.pushBazaarBranch(bazaar_branch)
593
 
            last_imported_revison = bazaar_branch.last_revision()
594
597
            self._logger.info("Job complete.")
595
 
            if last_imported_revison == remote_branch_tip:
596
 
                if pull_result.old_revid != pull_result.new_revid:
597
 
                    return CodeImportWorkerExitCode.SUCCESS
598
 
                else:
599
 
                    return CodeImportWorkerExitCode.SUCCESS_NOCHANGE
600
 
            else:
601
 
                return CodeImportWorkerExitCode.SUCCESS_PARTIAL
 
598
            return result
602
599
        finally:
603
600
            bzrlib.ui.ui_factory = saved_factory
604
601
 
610
607
    """
611
608
 
612
609
    @property
613
 
    def format_classes(self):
614
 
        """See `PullingImportWorker.opening_format`."""
615
 
        # We only return LocalGitBzrDirFormat for tests.
 
610
    def probers(self):
 
611
        """See `PullingImportWorker.probers`."""
616
612
        from bzrlib.plugins.git import (
617
 
            LocalGitBzrDirFormat, RemoteGitBzrDirFormat)
618
 
        return [LocalGitBzrDirFormat, RemoteGitBzrDirFormat]
 
613
            LocalGitProber, RemoteGitProber)
 
614
        return [LocalGitProber, RemoteGitProber]
619
615
 
620
 
    def getExtraPullArgs(self):
621
 
        """See `PullingImportWorker.getExtraPullArgs`."""
622
 
        return {'limit': config.codeimport.git_revisions_import_limit}
 
616
    def getRevisionLimit(self):
 
617
        """See `PullingImportWorker.getRevisionLimit`."""
 
618
        return config.codeimport.git_revisions_import_limit
623
619
 
624
620
    def getBazaarBranch(self):
625
621
        """See `ImportWorker.getBazaarBranch`.
666
662
    """
667
663
 
668
664
    @property
669
 
    def format_classes(self):
670
 
        """See `PullingImportWorker.opening_format`."""
671
 
        # We only return HgLocalRepository for tests.
672
 
        from bzrlib.plugins.hg import HgBzrDirFormat
673
 
        return [HgBzrDirFormat]
 
665
    def probers(self):
 
666
        """See `PullingImportWorker.probers`."""
 
667
        from bzrlib.plugins.hg import HgProber
 
668
        return [HgProber]
 
669
 
 
670
    def getRevisionLimit(self):
 
671
        """See `PullingImportWorker.getRevisionLimit`."""
 
672
        return config.codeimport.hg_revisions_import_limit
674
673
 
675
674
    def getBazaarBranch(self):
676
675
        """See `ImportWorker.getBazaarBranch`.
714
713
class BzrSvnImportWorker(PullingImportWorker):
715
714
    """An import worker for importing Subversion via bzr-svn."""
716
715
 
717
 
    def getExtraPullArgs(self):
718
 
        """See `PullingImportWorker.getExtraPullArgs`."""
719
 
        return {'limit': config.codeimport.svn_revisions_import_limit}
 
716
    def getRevisionLimit(self):
 
717
        """See `PullingImportWorker.getRevisionLimit`."""
 
718
        return config.codeimport.svn_revisions_import_limit
720
719
 
721
720
    @property
722
 
    def format_classes(self):
723
 
        """See `PullingImportWorker.opening_format`."""
724
 
        from bzrlib.plugins.svn.format import SvnRemoteFormat
725
 
        return [SvnRemoteFormat]
 
721
    def probers(self):
 
722
        """See `PullingImportWorker.probers`."""
 
723
        from bzrlib.plugins.svn import SvnRemoteProber
 
724
        return [SvnRemoteProber]