~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Martin Pool
  • Date: 2010-02-25 06:17:27 UTC
  • mfrom: (5055 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5057.
  • Revision ID: mbp@sourcefrog.net-20100225061727-4sd9lt0qmdc6087t
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1027
1027
 
1028
1028
        :seealso: add_inventory, for the contract.
1029
1029
        """
1030
 
        inv_lines = self._serialise_inventory_to_lines(inv)
 
1030
        inv_lines = self._serializer.write_inventory_to_lines(inv)
1031
1031
        return self._inventory_add_lines(revision_id, parents,
1032
1032
            inv_lines, check_content=False)
1033
1033
 
1484
1484
        :param using: If True, list only branches using this repository.
1485
1485
        """
1486
1486
        if using and not self.is_shared():
1487
 
            try:
1488
 
                return [self.bzrdir.open_branch()]
1489
 
            except errors.NotBranchError:
1490
 
                return []
 
1487
            return self.bzrdir.list_branches()
1491
1488
        class Evaluator(object):
1492
1489
 
1493
1490
            def __init__(self):
1502
1499
                    except errors.NoRepositoryPresent:
1503
1500
                        pass
1504
1501
                    else:
1505
 
                        return False, (None, repository)
 
1502
                        return False, ([], repository)
1506
1503
                self.first_call = False
1507
 
                try:
1508
 
                    value = (bzrdir.open_branch(), None)
1509
 
                except errors.NotBranchError:
1510
 
                    value = (None, None)
 
1504
                value = (bzrdir.list_branches(), None)
1511
1505
                return True, value
1512
1506
 
1513
 
        branches = []
1514
 
        for branch, repository in bzrdir.BzrDir.find_bzrdirs(
 
1507
        ret = []
 
1508
        for branches, repository in bzrdir.BzrDir.find_bzrdirs(
1515
1509
                self.bzrdir.root_transport, evaluate=Evaluator()):
1516
 
            if branch is not None:
1517
 
                branches.append(branch)
 
1510
            if branches is not None:
 
1511
                ret.extend(branches)
1518
1512
            if not using and repository is not None:
1519
 
                branches.extend(repository.find_branches())
1520
 
        return branches
 
1513
                ret.extend(repository.find_branches())
 
1514
        return ret
1521
1515
 
1522
1516
    @needs_read_lock
1523
1517
    def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):
1901
1895
                rev = self._serializer.read_revision_from_string(text)
1902
1896
                yield (revid, rev)
1903
1897
 
1904
 
    @needs_read_lock
1905
 
    def get_revision_xml(self, revision_id):
1906
 
        # TODO: jam 20070210 This shouldn't be necessary since get_revision
1907
 
        #       would have already do it.
1908
 
        # TODO: jam 20070210 Just use _serializer.write_revision_to_string()
1909
 
        # TODO: this can't just be replaced by:
1910
 
        # return self._serializer.write_revision_to_string(
1911
 
        #     self.get_revision(revision_id))
1912
 
        # as cStringIO preservers the encoding unlike write_revision_to_string
1913
 
        # or some other call down the path.
1914
 
        rev = self.get_revision(revision_id)
1915
 
        rev_tmp = cStringIO.StringIO()
1916
 
        # the current serializer..
1917
 
        self._serializer.write_revision(rev, rev_tmp)
1918
 
        rev_tmp.seek(0)
1919
 
        return rev_tmp.getvalue()
1920
 
 
1921
1898
    def get_deltas_for_revisions(self, revisions, specific_fileids=None):
1922
1899
        """Produce a generator of revision deltas.
1923
1900
 
2165
2142
        """
2166
2143
        selected_keys = set((revid,) for revid in revision_ids)
2167
2144
        w = _inv_weave or self.inventories
2168
 
        pb = ui.ui_factory.nested_progress_bar()
2169
 
        try:
2170
 
            return self._find_file_ids_from_xml_inventory_lines(
2171
 
                w.iter_lines_added_or_present_in_keys(
2172
 
                    selected_keys, pb=pb),
2173
 
                selected_keys)
2174
 
        finally:
2175
 
            pb.finished()
 
2145
        return self._find_file_ids_from_xml_inventory_lines(
 
2146
            w.iter_lines_added_or_present_in_keys(
 
2147
                selected_keys, pb=None),
 
2148
            selected_keys)
2176
2149
 
2177
2150
    def iter_files_bytes(self, desired_files):
2178
2151
        """Iterate through file versions.
2440
2413
                result.revision_id, revision_id))
2441
2414
        return result
2442
2415
 
2443
 
    def _serialise_inventory(self, inv):
2444
 
        return self._serializer.write_inventory_to_string(inv)
2445
 
 
2446
 
    def _serialise_inventory_to_lines(self, inv):
2447
 
        return self._serializer.write_inventory_to_lines(inv)
2448
 
 
2449
2416
    def get_serializer_format(self):
2450
2417
        return self._serializer.format_num
2451
2418
 
2515
2482
            else:
2516
2483
                next_id = parents[0]
2517
2484
 
2518
 
    @needs_read_lock
2519
 
    def get_revision_inventory(self, revision_id):
2520
 
        """Return inventory of a past revision."""
2521
 
        # TODO: Unify this with get_inventory()
2522
 
        # bzr 0.0.6 and later imposes the constraint that the inventory_id
2523
 
        # must be the same as its revision, so this is trivial.
2524
 
        if revision_id is None:
2525
 
            # This does not make sense: if there is no revision,
2526
 
            # then it is the current tree inventory surely ?!
2527
 
            # and thus get_root_id() is something that looks at the last
2528
 
            # commit on the branch, and the get_root_id is an inventory check.
2529
 
            raise NotImplementedError
2530
 
            # return Inventory(self.get_root_id())
2531
 
        else:
2532
 
            return self.get_inventory(revision_id)
2533
 
 
2534
2485
    def is_shared(self):
2535
2486
        """Return True if this repository is flagged as a shared repository."""
2536
2487
        raise NotImplementedError(self.is_shared)
2570
2521
            return RevisionTree(self, Inventory(root_id=None),
2571
2522
                                _mod_revision.NULL_REVISION)
2572
2523
        else:
2573
 
            inv = self.get_revision_inventory(revision_id)
 
2524
            inv = self.get_inventory(revision_id)
2574
2525
            return RevisionTree(self, inv, revision_id)
2575
2526
 
2576
2527
    def revision_trees(self, revision_ids):
3079
3030
    pack_compresses = False
3080
3031
    # Does the repository inventory storage understand references to trees?
3081
3032
    supports_tree_reference = None
 
3033
    # Is the format experimental ?
 
3034
    experimental = False
3082
3035
 
3083
3036
    def __str__(self):
3084
3037
        return "<%s>" % self.__class__.__name__
3415
3368
 
3416
3369
        :param revision_id: if None all content is copied, if NULL_REVISION no
3417
3370
                            content is copied.
3418
 
        :param pb: optional progress bar to use for progress reports. If not
3419
 
                   provided a default one will be created.
 
3371
        :param pb: ignored.
3420
3372
        :return: None.
3421
3373
        """
 
3374
        ui.ui_factory.warn_experimental_format_fetch(self)
3422
3375
        f = _mod_fetch.RepoFetcher(to_repository=self.target,
3423
3376
                               from_repository=self.source,
3424
3377
                               last_revision=revision_id,
3425
3378
                               fetch_spec=fetch_spec,
3426
 
                               pb=pb, find_ghosts=find_ghosts)
 
3379
                               find_ghosts=find_ghosts)
3427
3380
 
3428
3381
    def _walk_to_common_revisions(self, revision_ids):
3429
3382
        """Walk out from revision_ids in source to revisions target has.
4009
3962
        # streaming.
4010
3963
        ui.ui_factory.warn_cross_format_fetch(self.source._format,
4011
3964
            self.target._format)
 
3965
        ui.ui_factory.warn_experimental_format_fetch(self)
4012
3966
        if (not self.source.supports_rich_root()
4013
3967
            and self.target.supports_rich_root()):
4014
3968
            self._converting_to_rich_root = True
4089
4043
        :param to_convert: The disk object to convert.
4090
4044
        :param pb: a progress bar to use for progress information.
4091
4045
        """
4092
 
        self.pb = pb
 
4046
        pb = ui.ui_factory.nested_progress_bar()
4093
4047
        self.count = 0
4094
4048
        self.total = 4
4095
4049
        # this is only useful with metadir layouts - separated repo content.
4096
4050
        # trigger an assertion if not such
4097
4051
        repo._format.get_format_string()
4098
4052
        self.repo_dir = repo.bzrdir
4099
 
        self.step('Moving repository to repository.backup')
 
4053
        pb.update('Moving repository to repository.backup')
4100
4054
        self.repo_dir.transport.move('repository', 'repository.backup')
4101
4055
        backup_transport =  self.repo_dir.transport.clone('repository.backup')
4102
4056
        repo._format.check_conversion_target(self.target_format)
4103
4057
        self.source_repo = repo._format.open(self.repo_dir,
4104
4058
            _found=True,
4105
4059
            _override_transport=backup_transport)
4106
 
        self.step('Creating new repository')
 
4060
        pb.update('Creating new repository')
4107
4061
        converted = self.target_format.initialize(self.repo_dir,
4108
4062
                                                  self.source_repo.is_shared())
4109
4063
        converted.lock_write()
4110
4064
        try:
4111
 
            self.step('Copying content')
 
4065
            pb.update('Copying content')
4112
4066
            self.source_repo.copy_content_into(converted)
4113
4067
        finally:
4114
4068
            converted.unlock()
4115
 
        self.step('Deleting old repository content')
 
4069
        pb.update('Deleting old repository content')
4116
4070
        self.repo_dir.transport.delete_tree('repository.backup')
4117
4071
        ui.ui_factory.note('repository converted')
4118
 
 
4119
 
    def step(self, message):
4120
 
        """Update the pb by a step."""
4121
 
        self.count +=1
4122
 
        self.pb.update(message, self.count, self.total)
 
4072
        pb.finished()
4123
4073
 
4124
4074
 
4125
4075
_unescape_map = {