~jelmer/brz/zsh-completion

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

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
 
1240
1240
        """Check a single text from this repository."""
1241
1241
        if kind == 'inventories':
1242
1242
            rev_id = record.key[0]
1243
 
            inv = self.deserialise_inventory(rev_id,
 
1243
            inv = self._deserialise_inventory(rev_id,
1244
1244
                record.get_bytes_as('fulltext'))
1245
1245
            if last_object is not None:
1246
1246
                delta = inv._make_delta(last_object)
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.
2388
2361
        """single-document based inventory iteration."""
2389
2362
        inv_xmls = self._iter_inventory_xmls(revision_ids, ordering)
2390
2363
        for text, revision_id in inv_xmls:
2391
 
            yield self.deserialise_inventory(revision_id, text)
 
2364
            yield self._deserialise_inventory(revision_id, text)
2392
2365
 
2393
2366
    def _iter_inventory_xmls(self, revision_ids, ordering):
2394
2367
        if ordering is None:
2426
2399
                        next_key = None
2427
2400
                        break
2428
2401
 
2429
 
    def deserialise_inventory(self, revision_id, xml):
 
2402
    def _deserialise_inventory(self, revision_id, xml):
2430
2403
        """Transform the xml into an inventory object.
2431
2404
 
2432
2405
        :param revision_id: The expected revision id of the inventory.
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
 
2452
2419
    @needs_read_lock
2453
 
    def get_inventory_xml(self, revision_id):
2454
 
        """Get inventory XML as a file object."""
 
2420
    def _get_inventory_xml(self, revision_id):
 
2421
        """Get serialized inventory as a string."""
2455
2422
        texts = self._iter_inventory_xmls([revision_id], 'unordered')
2456
2423
        try:
2457
2424
            text, revision_id = texts.next()
2459
2426
            raise errors.HistoryMissing(self, 'inventory', revision_id)
2460
2427
        return text
2461
2428
 
2462
 
    @needs_read_lock
2463
 
    def get_inventory_sha1(self, revision_id):
2464
 
        """Return the sha1 hash of the inventory entry
2465
 
        """
2466
 
        return self.get_revision(revision_id).inventory_sha1
2467
 
 
2468
2429
    def get_rev_id_for_revno(self, revno, known_pair):
2469
2430
        """Return the revision id of a revno, given a later (revno, revid)
2470
2431
        pair in the same history.
2521
2482
            else:
2522
2483
                next_id = parents[0]
2523
2484
 
2524
 
    @needs_read_lock
2525
 
    def get_revision_inventory(self, revision_id):
2526
 
        """Return inventory of a past revision."""
2527
 
        # TODO: Unify this with get_inventory()
2528
 
        # bzr 0.0.6 and later imposes the constraint that the inventory_id
2529
 
        # must be the same as its revision, so this is trivial.
2530
 
        if revision_id is None:
2531
 
            # This does not make sense: if there is no revision,
2532
 
            # then it is the current tree inventory surely ?!
2533
 
            # and thus get_root_id() is something that looks at the last
2534
 
            # commit on the branch, and the get_root_id is an inventory check.
2535
 
            raise NotImplementedError
2536
 
            # return Inventory(self.get_root_id())
2537
 
        else:
2538
 
            return self.get_inventory(revision_id)
2539
 
 
2540
2485
    def is_shared(self):
2541
2486
        """Return True if this repository is flagged as a shared repository."""
2542
2487
        raise NotImplementedError(self.is_shared)
2576
2521
            return RevisionTree(self, Inventory(root_id=None),
2577
2522
                                _mod_revision.NULL_REVISION)
2578
2523
        else:
2579
 
            inv = self.get_revision_inventory(revision_id)
 
2524
            inv = self.get_inventory(revision_id)
2580
2525
            return RevisionTree(self, inv, revision_id)
2581
2526
 
2582
2527
    def revision_trees(self, revision_ids):
3085
3030
    pack_compresses = False
3086
3031
    # Does the repository inventory storage understand references to trees?
3087
3032
    supports_tree_reference = None
 
3033
    # Is the format experimental ?
 
3034
    experimental = False
3088
3035
 
3089
3036
    def __repr__(self):
3090
3037
        return "%s()" % self.__class__.__name__
3421
3368
 
3422
3369
        :param revision_id: if None all content is copied, if NULL_REVISION no
3423
3370
                            content is copied.
3424
 
        :param pb: optional progress bar to use for progress reports. If not
3425
 
                   provided a default one will be created.
 
3371
        :param pb: ignored.
3426
3372
        :return: None.
3427
3373
        """
 
3374
        ui.ui_factory.warn_experimental_format_fetch(self)
3428
3375
        from bzrlib.fetch import RepoFetcher
3429
3376
        # See <https://launchpad.net/bugs/456077> asking for a warning here
3430
3377
        if self.source._format.network_name() != self.target._format.network_name():
3435
3382
                               from_repository=self.source,
3436
3383
                               last_revision=revision_id,
3437
3384
                               fetch_spec=fetch_spec,
3438
 
                               pb=pb, find_ghosts=find_ghosts)
 
3385
                               find_ghosts=find_ghosts)
3439
3386
 
3440
3387
    def _walk_to_common_revisions(self, revision_ids):
3441
3388
        """Walk out from revision_ids in source to revisions target has.
4015
3962
        """See InterRepository.fetch()."""
4016
3963
        if fetch_spec is not None:
4017
3964
            raise AssertionError("Not implemented yet...")
 
3965
        ui.ui_factory.warn_experimental_format_fetch(self)
4018
3966
        if (not self.source.supports_rich_root()
4019
3967
            and self.target.supports_rich_root()):
4020
3968
            self._converting_to_rich_root = True
4100
4048
        :param to_convert: The disk object to convert.
4101
4049
        :param pb: a progress bar to use for progress information.
4102
4050
        """
4103
 
        self.pb = pb
 
4051
        pb = ui.ui_factory.nested_progress_bar()
4104
4052
        self.count = 0
4105
4053
        self.total = 4
4106
4054
        # this is only useful with metadir layouts - separated repo content.
4107
4055
        # trigger an assertion if not such
4108
4056
        repo._format.get_format_string()
4109
4057
        self.repo_dir = repo.bzrdir
4110
 
        self.step('Moving repository to repository.backup')
 
4058
        pb.update('Moving repository to repository.backup')
4111
4059
        self.repo_dir.transport.move('repository', 'repository.backup')
4112
4060
        backup_transport =  self.repo_dir.transport.clone('repository.backup')
4113
4061
        repo._format.check_conversion_target(self.target_format)
4114
4062
        self.source_repo = repo._format.open(self.repo_dir,
4115
4063
            _found=True,
4116
4064
            _override_transport=backup_transport)
4117
 
        self.step('Creating new repository')
 
4065
        pb.update('Creating new repository')
4118
4066
        converted = self.target_format.initialize(self.repo_dir,
4119
4067
                                                  self.source_repo.is_shared())
4120
4068
        converted.lock_write()
4121
4069
        try:
4122
 
            self.step('Copying content')
 
4070
            pb.update('Copying content')
4123
4071
            self.source_repo.copy_content_into(converted)
4124
4072
        finally:
4125
4073
            converted.unlock()
4126
 
        self.step('Deleting old repository content')
 
4074
        pb.update('Deleting old repository content')
4127
4075
        self.repo_dir.transport.delete_tree('repository.backup')
4128
4076
        ui.ui_factory.note('repository converted')
4129
 
 
4130
 
    def step(self, message):
4131
 
        """Update the pb by a step."""
4132
 
        self.count +=1
4133
 
        self.pb.update(message, self.count, self.total)
 
4077
        pb.finished()
4134
4078
 
4135
4079
 
4136
4080
_unescape_map = {