~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

Use global osutils, otherwise it creates a local var.

Which works, but causes us to run the import on every call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from bzrlib.lazy_import import lazy_import
18
18
lazy_import(globals(), """
 
19
import cStringIO
 
20
import re
19
21
import time
20
22
 
21
23
from bzrlib import (
22
24
    bzrdir,
23
25
    check,
 
26
    chk_map,
24
27
    config,
25
28
    controldir,
26
29
    debug,
29
32
    generate_ids,
30
33
    gpg,
31
34
    graph,
 
35
    inventory,
32
36
    inventory_delta,
33
37
    lockable_files,
34
38
    lockdir,
35
39
    lru_cache,
36
40
    osutils,
 
41
    pyutils,
37
42
    revision as _mod_revision,
38
43
    static_tuple,
 
44
    trace,
39
45
    tsort,
40
46
    versionedfile,
41
47
    )
42
48
from bzrlib.bundle import serializer
43
49
from bzrlib.recordcounter import RecordCounter
44
 
from bzrlib.revisiontree import InventoryRevisionTree
 
50
from bzrlib.revisiontree import RevisionTree
45
51
from bzrlib.store.versioned import VersionedFileStore
46
52
from bzrlib.testament import Testament
47
53
""")
93
99
 
94
100
    def __init__(self, repository, parents, config, timestamp=None,
95
101
                 timezone=None, committer=None, revprops=None,
96
 
                 revision_id=None, lossy=False):
 
102
                 revision_id=None):
97
103
        """Initiate a CommitBuilder.
98
104
 
99
105
        :param repository: Repository to commit to.
100
106
        :param parents: Revision ids of the parents of the new revision.
 
107
        :param config: Configuration to use.
101
108
        :param timestamp: Optional timestamp recorded for commit.
102
109
        :param timezone: Optional timezone for timestamp.
103
110
        :param committer: Optional committer to set for commit.
104
111
        :param revprops: Optional dictionary of revision properties.
105
112
        :param revision_id: Optional revision id.
106
 
        :param lossy: Whether to discard data that can not be natively
107
 
            represented, when pushing to a foreign VCS 
108
113
        """
109
114
        self._config = config
110
 
        self._lossy = lossy
111
115
 
112
116
        if committer is None:
113
117
            self._committer = self._config.username()
236
240
    def revision_tree(self):
237
241
        """Return the tree that was just committed.
238
242
 
239
 
        After calling commit() this can be called to get a
240
 
        InventoryRevisionTree representing the newly committed tree. This is
241
 
        preferred to calling Repository.revision_tree() because that may
242
 
        require deserializing the inventory, while we already have a copy in
 
243
        After calling commit() this can be called to get a RevisionTree
 
244
        representing the newly committed tree. This is preferred to
 
245
        calling Repository.revision_tree() because that may require
 
246
        deserializing the inventory, while we already have a copy in
243
247
        memory.
244
248
        """
245
249
        if self.new_inventory is None:
246
250
            self.new_inventory = self.repository.get_inventory(
247
251
                self._new_revision_id)
248
 
        return InventoryRevisionTree(self.repository, self.new_inventory,
 
252
        return RevisionTree(self.repository, self.new_inventory,
249
253
            self._new_revision_id)
250
254
 
251
255
    def finish_inventory(self):
1163
1167
        if config is not None and config.signature_needed():
1164
1168
            if inv is None:
1165
1169
                inv = self.get_inventory(revision_id)
1166
 
            tree = InventoryRevisionTree(self, inv, revision_id)
1167
 
            testament = Testament(rev, tree)
1168
 
            plaintext = testament.as_short_text()
 
1170
            plaintext = Testament(rev, inv).as_short_text()
1169
1171
            self.store_revision_signature(
1170
1172
                gpg.GPGStrategy(config), plaintext, revision_id)
1171
1173
        # check inventory present
1787
1789
 
1788
1790
    def get_commit_builder(self, branch, parents, config, timestamp=None,
1789
1791
                           timezone=None, committer=None, revprops=None,
1790
 
                           revision_id=None, lossy=False):
 
1792
                           revision_id=None):
1791
1793
        """Obtain a CommitBuilder for this repository.
1792
1794
 
1793
1795
        :param branch: Branch to commit to.
1798
1800
        :param committer: Optional committer to set for commit.
1799
1801
        :param revprops: Optional dictionary of revision properties.
1800
1802
        :param revision_id: Optional revision id.
1801
 
        :param lossy: Whether to discard data that can not be natively
1802
 
            represented, when pushing to a foreign VCS
1803
1803
        """
1804
1804
        if self._fallback_repositories and not self._format.supports_chks:
1805
1805
            raise errors.BzrError("Cannot commit directly to a stacked branch"
1806
1806
                " in pre-2a formats. See "
1807
1807
                "https://bugs.launchpad.net/bzr/+bug/375013 for details.")
1808
1808
        result = self._commit_builder_class(self, parents, config,
1809
 
            timestamp, timezone, committer, revprops, revision_id,
1810
 
            lossy)
 
1809
            timestamp, timezone, committer, revprops, revision_id)
1811
1810
        self.start_write_group()
1812
1811
        return result
1813
1812
 
2515
2514
        # TODO: refactor this to use an existing revision object
2516
2515
        # so we don't need to read it in twice.
2517
2516
        if revision_id == _mod_revision.NULL_REVISION:
2518
 
            return InventoryRevisionTree(self,
2519
 
                Inventory(root_id=None), _mod_revision.NULL_REVISION)
 
2517
            return RevisionTree(self, Inventory(root_id=None),
 
2518
                                _mod_revision.NULL_REVISION)
2520
2519
        else:
2521
2520
            inv = self.get_inventory(revision_id)
2522
 
            return InventoryRevisionTree(self, inv, revision_id)
 
2521
            return RevisionTree(self, inv, revision_id)
2523
2522
 
2524
2523
    def revision_trees(self, revision_ids):
2525
2524
        """Return Trees for revisions in this repository.
2529
2528
        """
2530
2529
        inventories = self.iter_inventories(revision_ids)
2531
2530
        for inv in inventories:
2532
 
            yield InventoryRevisionTree(self, inv, inv.revision_id)
 
2531
            yield RevisionTree(self, inv, inv.revision_id)
2533
2532
 
2534
2533
    def _filtered_revision_trees(self, revision_ids, file_ids):
2535
2534
        """Return Tree for a revision on this branch with only some files.
2545
2544
            # Should we introduce a FilteredRevisionTree class rather
2546
2545
            # than pre-filter the inventory here?
2547
2546
            filtered_inv = inv.filter(file_ids)
2548
 
            yield InventoryRevisionTree(self, filtered_inv, filtered_inv.revision_id)
 
2547
            yield RevisionTree(self, filtered_inv, filtered_inv.revision_id)
2549
2548
 
2550
2549
    @needs_read_lock
2551
2550
    def get_ancestry(self, revision_id, topo_sorted=True):
2773
2772
                except UnicodeDecodeError:
2774
2773
                    raise errors.NonAsciiRevisionId(method, self)
2775
2774
 
2776
 
    def _find_inconsistent_revision_parents(self, revisions_iterator=None):
2777
 
        """Find revisions with different parent lists in the revision object
2778
 
        and in the index graph.
 
2775
    def revision_graph_can_have_wrong_parents(self):
 
2776
        """Is it possible for this repository to have a revision graph with
 
2777
        incorrect parents?
2779
2778
 
2780
 
        :param revisions_iterator: None, or an iterator of (revid,
2781
 
            Revision-or-None). This iterator controls the revisions checked.
2782
 
        :returns: an iterator yielding tuples of (revison-id, parents-in-index,
2783
 
            parents-in-revision).
 
2779
        If True, then this repository must also implement
 
2780
        _find_inconsistent_revision_parents so that check and reconcile can
 
2781
        check for inconsistencies before proceeding with other checks that may
 
2782
        depend on the revision index being consistent.
2784
2783
        """
2785
 
        if not self.is_locked():
2786
 
            raise AssertionError()
2787
 
        vf = self.revisions
2788
 
        if revisions_iterator is None:
2789
 
            revisions_iterator = self._iter_revisions(None)
2790
 
        for revid, revision in revisions_iterator:
2791
 
            if revision is None:
2792
 
                pass
2793
 
            parent_map = vf.get_parent_map([(revid,)])
2794
 
            parents_according_to_index = tuple(parent[-1] for parent in
2795
 
                parent_map[(revid,)])
2796
 
            parents_according_to_revision = tuple(revision.parent_ids)
2797
 
            if parents_according_to_index != parents_according_to_revision:
2798
 
                yield (revid, parents_according_to_index,
2799
 
                    parents_according_to_revision)
2800
 
 
2801
 
    def _check_for_inconsistent_revision_parents(self):
2802
 
        inconsistencies = list(self._find_inconsistent_revision_parents())
2803
 
        if inconsistencies:
2804
 
            raise errors.BzrCheckError(
2805
 
                "Revision knit has inconsistent parents.")
 
2784
        raise NotImplementedError(self.revision_graph_can_have_wrong_parents)
2806
2785
 
2807
2786
 
2808
2787
def install_revision(repository, rev, revision_tree):
2867
2846
        for revision, tree in parent_trees.iteritems():
2868
2847
            if ie.file_id not in tree:
2869
2848
                continue
2870
 
            parent_id = tree.get_file_revision(ie.file_id)
 
2849
            parent_id = tree.inventory[ie.file_id].revision
2871
2850
            if parent_id in text_parents:
2872
2851
                continue
2873
2852
            text_parents.append((ie.file_id, parent_id))
3045
3024
    supports_leaving_lock = None
3046
3025
    # Does this format support the full VersionedFiles interface?
3047
3026
    supports_full_versioned_files = None
3048
 
    # Does this format support signing revision signatures?
3049
 
    supports_revision_signatures = True
3050
 
    # Can the revision graph have incorrect parents?
3051
 
    revision_graph_can_have_wrong_parents = None
3052
3027
 
3053
3028
    def __repr__(self):
3054
3029
        return "%s()" % self.__class__.__name__
3106
3081
        """Return the short description for this format."""
3107
3082
        raise NotImplementedError(self.get_format_description)
3108
3083
 
 
3084
    # TODO: this shouldn't be in the base class, it's specific to things that
 
3085
    # use weaves or knits -- mbp 20070207
 
3086
    def _get_versioned_file_store(self,
 
3087
                                  name,
 
3088
                                  transport,
 
3089
                                  control_files,
 
3090
                                  prefixed=True,
 
3091
                                  versionedfile_class=None,
 
3092
                                  versionedfile_kwargs={},
 
3093
                                  escaped=False):
 
3094
        if versionedfile_class is None:
 
3095
            versionedfile_class = self._versionedfile_class
 
3096
        weave_transport = control_files._transport.clone(name)
 
3097
        dir_mode = control_files._dir_mode
 
3098
        file_mode = control_files._file_mode
 
3099
        return VersionedFileStore(weave_transport, prefixed=prefixed,
 
3100
                                  dir_mode=dir_mode,
 
3101
                                  file_mode=file_mode,
 
3102
                                  versionedfile_class=versionedfile_class,
 
3103
                                  versionedfile_kwargs=versionedfile_kwargs,
 
3104
                                  escaped=escaped)
 
3105
 
3109
3106
    def initialize(self, a_bzrdir, shared=False):
3110
3107
        """Initialize a repository of this format in a_bzrdir.
3111
3108
 
3252
3249
# NOTE: These are experimental in 0.92. Stable in 1.0 and above
3253
3250
format_registry.register_lazy(
3254
3251
    'Bazaar pack repository format 1 (needs bzr 0.92)\n',
3255
 
    'bzrlib.repofmt.knitpack_repo',
 
3252
    'bzrlib.repofmt.pack_repo',
3256
3253
    'RepositoryFormatKnitPack1',
3257
3254
    )
3258
3255
format_registry.register_lazy(
3259
3256
    'Bazaar pack repository format 1 with subtree support (needs bzr 0.92)\n',
3260
 
    'bzrlib.repofmt.knitpack_repo',
 
3257
    'bzrlib.repofmt.pack_repo',
3261
3258
    'RepositoryFormatKnitPack3',
3262
3259
    )
3263
3260
format_registry.register_lazy(
3264
3261
    'Bazaar pack repository format 1 with rich root (needs bzr 1.0)\n',
3265
 
    'bzrlib.repofmt.knitpack_repo',
 
3262
    'bzrlib.repofmt.pack_repo',
3266
3263
    'RepositoryFormatKnitPack4',
3267
3264
    )
3268
3265
format_registry.register_lazy(
3269
3266
    'Bazaar RepositoryFormatKnitPack5 (bzr 1.6)\n',
3270
 
    'bzrlib.repofmt.knitpack_repo',
 
3267
    'bzrlib.repofmt.pack_repo',
3271
3268
    'RepositoryFormatKnitPack5',
3272
3269
    )
3273
3270
format_registry.register_lazy(
3274
3271
    'Bazaar RepositoryFormatKnitPack5RichRoot (bzr 1.6.1)\n',
3275
 
    'bzrlib.repofmt.knitpack_repo',
 
3272
    'bzrlib.repofmt.pack_repo',
3276
3273
    'RepositoryFormatKnitPack5RichRoot',
3277
3274
    )
3278
3275
format_registry.register_lazy(
3279
3276
    'Bazaar RepositoryFormatKnitPack5RichRoot (bzr 1.6)\n',
3280
 
    'bzrlib.repofmt.knitpack_repo',
 
3277
    'bzrlib.repofmt.pack_repo',
3281
3278
    'RepositoryFormatKnitPack5RichRootBroken',
3282
3279
    )
3283
3280
format_registry.register_lazy(
3284
3281
    'Bazaar RepositoryFormatKnitPack6 (bzr 1.9)\n',
3285
 
    'bzrlib.repofmt.knitpack_repo',
 
3282
    'bzrlib.repofmt.pack_repo',
3286
3283
    'RepositoryFormatKnitPack6',
3287
3284
    )
3288
3285
format_registry.register_lazy(
3289
3286
    'Bazaar RepositoryFormatKnitPack6RichRoot (bzr 1.9)\n',
3290
 
    'bzrlib.repofmt.knitpack_repo',
 
3287
    'bzrlib.repofmt.pack_repo',
3291
3288
    'RepositoryFormatKnitPack6RichRoot',
3292
3289
    )
3293
3290
format_registry.register_lazy(
3301
3298
format_registry.register_lazy(
3302
3299
    ("Bazaar development format 2 with subtree support "
3303
3300
        "(needs bzr.dev from before 1.8)\n"),
3304
 
    'bzrlib.repofmt.knitpack_repo',
 
3301
    'bzrlib.repofmt.pack_repo',
3305
3302
    'RepositoryFormatPackDevelopment2Subtree',
3306
3303
    )
3307
3304
format_registry.register_lazy(
4176
4173
                parse_result = deserialiser.parse_text_bytes(
4177
4174
                    inventory_delta_bytes)
4178
4175
            except inventory_delta.IncompatibleInventoryDelta, err:
4179
 
                mutter("Incompatible delta: %s", err.msg)
 
4176
                trace.mutter("Incompatible delta: %s", err.msg)
4180
4177
                raise errors.IncompatibleRevision(self.target_repo._format)
4181
4178
            basis_id, new_id, rich_root, tree_refs, inv_delta = parse_result
4182
4179
            revision_id = new_id