~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Martin Packman
  • Date: 2011-12-08 18:58:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6359.
  • Revision ID: martin.packman@canonical.com-20111208185827-rnav0jtrbp1none0
Add export-pot --include-duplicates option for permitting multiple entries with the same msgid

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
 
173
173
    def __init__(self, basedir='.',
174
174
                 branch=DEPRECATED_PARAMETER,
175
 
                 _control_files=None,
176
175
                 _internal=False,
 
176
                 _transport=None,
177
177
                 _format=None,
178
178
                 _bzrdir=None):
179
179
        """Construct a WorkingTree instance. This is not a public API.
192
192
        else:
193
193
            self._branch = self.bzrdir.open_branch()
194
194
        self.basedir = realpath(basedir)
195
 
        self._control_files = _control_files
196
 
        self._transport = self._control_files._transport
 
195
        self._transport = _transport
197
196
        self._rules_searcher = None
198
197
        self.views = self._make_views()
199
198
 
237
236
 
238
237
        This will probe the repository for its lock as well.
239
238
        """
240
 
        self._control_files.break_lock()
241
 
        self.branch.break_lock()
 
239
        raise NotImplementedError(self.break_lock)
242
240
 
243
241
    def requires_rich_root(self):
244
242
        return self._format.requires_rich_root
522
520
            # TODO now merge from tree.last_revision to revision (to preserve
523
521
            # user local changes)
524
522
            merge.transform_tree(tree, self)
525
 
            tree.set_parent_ids([revision_id])
 
523
            if revision_id == _mod_revision.NULL_REVISION:
 
524
                new_parents = []
 
525
            else:
 
526
                new_parents = [revision_id]
 
527
            tree.set_parent_ids(new_parents)
526
528
 
527
529
    def id2abspath(self, file_id):
528
530
        return self.abspath(self.id2path(file_id))
737
739
 
738
740
    @needs_tree_write_lock
739
741
    def set_merge_modified(self, modified_hashes):
740
 
        def iter_stanzas():
741
 
            for file_id, hash in modified_hashes.iteritems():
742
 
                yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
743
 
                    hash=hash)
744
 
        self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
 
742
        """Set the merge modified hashes."""
 
743
        raise NotImplementedError(self.set_merge_modified)
745
744
 
746
745
    def _sha_from_stat(self, path, stat_result):
747
746
        """Get a sha digest from the tree's stat cache.
753
752
        """
754
753
        return None
755
754
 
756
 
    def _put_rio(self, filename, stanzas, header):
757
 
        self._must_be_locked()
758
 
        my_file = _mod_rio.rio_file(stanzas, header)
759
 
        self._transport.put_file(filename, my_file,
760
 
            mode=self.bzrdir._get_file_mode())
761
 
 
762
755
    @needs_write_lock # because merge pulls data into the branch.
763
756
    def merge_from_branch(self, branch, to_revision=None, from_revision=None,
764
757
                          merge_type=None, force=False):
1004
997
                                show_base=show_base)
1005
998
                    basis_root_id = basis_tree.get_root_id()
1006
999
                    new_root_id = new_basis_tree.get_root_id()
1007
 
                    if basis_root_id != new_root_id:
 
1000
                    if new_root_id is not None and basis_root_id != new_root_id:
1008
1001
                        self.set_root_id(new_root_id)
1009
1002
                finally:
1010
1003
                    basis_tree.unlock()
1011
1004
                # TODO - dedup parents list with things merged by pull ?
1012
1005
                # reuse the revisiontree we merged against to set the new
1013
1006
                # tree data.
1014
 
                parent_trees = [(self.branch.last_revision(), new_basis_tree)]
 
1007
                parent_trees = []
 
1008
                if self.branch.last_revision() != _mod_revision.NULL_REVISION:
 
1009
                    parent_trees.append(
 
1010
                        (self.branch.last_revision(), new_basis_tree))
1015
1011
                # we have to pull the merge trees out again, because
1016
1012
                # merge_inner has set the ids. - this corner is not yet
1017
1013
                # layered well enough to prevent double handling.
1141
1137
        return _mod_revision.ensure_null(self.branch.last_revision())
1142
1138
 
1143
1139
    def is_locked(self):
1144
 
        return self._control_files.is_locked()
1145
 
 
1146
 
    def _must_be_locked(self):
1147
 
        if not self.is_locked():
1148
 
            raise errors.ObjectNotLocked(self)
 
1140
        """Check if this tree is locked."""
 
1141
        raise NotImplementedError(self.is_locked)
1149
1142
 
1150
1143
    def lock_read(self):
1151
1144
        """Lock the tree for reading.
1154
1147
 
1155
1148
        :return: A bzrlib.lock.LogicalLockResult.
1156
1149
        """
1157
 
        if not self.is_locked():
1158
 
            self._reset_data()
1159
 
        self.branch.lock_read()
1160
 
        try:
1161
 
            self._control_files.lock_read()
1162
 
            return LogicalLockResult(self.unlock)
1163
 
        except:
1164
 
            self.branch.unlock()
1165
 
            raise
 
1150
        raise NotImplementedError(self.lock_read)
1166
1151
 
1167
1152
    def lock_tree_write(self):
1168
1153
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
1169
1154
 
1170
1155
        :return: A bzrlib.lock.LogicalLockResult.
1171
1156
        """
1172
 
        if not self.is_locked():
1173
 
            self._reset_data()
1174
 
        self.branch.lock_read()
1175
 
        try:
1176
 
            self._control_files.lock_write()
1177
 
            return LogicalLockResult(self.unlock)
1178
 
        except:
1179
 
            self.branch.unlock()
1180
 
            raise
 
1157
        raise NotImplementedError(self.lock_tree_write)
1181
1158
 
1182
1159
    def lock_write(self):
1183
1160
        """See MutableTree.lock_write, and WorkingTree.unlock.
1184
1161
 
1185
1162
        :return: A bzrlib.lock.LogicalLockResult.
1186
1163
        """
1187
 
        if not self.is_locked():
1188
 
            self._reset_data()
1189
 
        self.branch.lock_write()
1190
 
        try:
1191
 
            self._control_files.lock_write()
1192
 
            return LogicalLockResult(self.unlock)
1193
 
        except:
1194
 
            self.branch.unlock()
1195
 
            raise
 
1164
        raise NotImplementedError(self.lock_write)
1196
1165
 
1197
1166
    def get_physical_lock_status(self):
1198
 
        return self._control_files.get_physical_lock_status()
1199
 
 
1200
 
    def _reset_data(self):
1201
 
        """Reset transient data that cannot be revalidated."""
1202
 
        raise NotImplementedError(self._reset_data)
 
1167
        raise NotImplementedError(self.get_physical_lock_status)
1203
1168
 
1204
1169
    def set_last_revision(self, new_revision):
1205
1170
        """Change the last revision in the working tree."""
1781
1746
        :param branch: A branch to override probing for the branch.
1782
1747
        """
1783
1748
        super(InventoryWorkingTree, self).__init__(basedir=basedir,
1784
 
            branch=branch, _control_files=_control_files, _internal=_internal,
1785
 
            _format=_format, _bzrdir=_bzrdir)
 
1749
            branch=branch, _transport=_control_files._transport,
 
1750
            _internal=_internal, _format=_format, _bzrdir=_bzrdir)
1786
1751
 
 
1752
        self._control_files = _control_files
1787
1753
        self._detect_case_handling()
1788
1754
 
1789
1755
        if _inventory is None:
1828
1794
    def _deserialize(selt, in_file):
1829
1795
        return xml5.serializer_v5.read_inventory(in_file)
1830
1796
 
 
1797
    def break_lock(self):
 
1798
        """Break a lock if one is present from another instance.
 
1799
 
 
1800
        Uses the ui factory to ask for confirmation if the lock may be from
 
1801
        an active process.
 
1802
 
 
1803
        This will probe the repository for its lock as well.
 
1804
        """
 
1805
        self._control_files.break_lock()
 
1806
        self.branch.break_lock()
 
1807
 
 
1808
    def is_locked(self):
 
1809
        return self._control_files.is_locked()
 
1810
 
 
1811
    def _must_be_locked(self):
 
1812
        if not self.is_locked():
 
1813
            raise errors.ObjectNotLocked(self)
 
1814
 
 
1815
    def lock_read(self):
 
1816
        """Lock the tree for reading.
 
1817
 
 
1818
        This also locks the branch, and can be unlocked via self.unlock().
 
1819
 
 
1820
        :return: A bzrlib.lock.LogicalLockResult.
 
1821
        """
 
1822
        if not self.is_locked():
 
1823
            self._reset_data()
 
1824
        self.branch.lock_read()
 
1825
        try:
 
1826
            self._control_files.lock_read()
 
1827
            return LogicalLockResult(self.unlock)
 
1828
        except:
 
1829
            self.branch.unlock()
 
1830
            raise
 
1831
 
 
1832
    def lock_tree_write(self):
 
1833
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
1834
 
 
1835
        :return: A bzrlib.lock.LogicalLockResult.
 
1836
        """
 
1837
        if not self.is_locked():
 
1838
            self._reset_data()
 
1839
        self.branch.lock_read()
 
1840
        try:
 
1841
            self._control_files.lock_write()
 
1842
            return LogicalLockResult(self.unlock)
 
1843
        except:
 
1844
            self.branch.unlock()
 
1845
            raise
 
1846
 
 
1847
    def lock_write(self):
 
1848
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
1849
 
 
1850
        :return: A bzrlib.lock.LogicalLockResult.
 
1851
        """
 
1852
        if not self.is_locked():
 
1853
            self._reset_data()
 
1854
        self.branch.lock_write()
 
1855
        try:
 
1856
            self._control_files.lock_write()
 
1857
            return LogicalLockResult(self.unlock)
 
1858
        except:
 
1859
            self.branch.unlock()
 
1860
            raise
 
1861
 
 
1862
    def get_physical_lock_status(self):
 
1863
        return self._control_files.get_physical_lock_status()
 
1864
 
1831
1865
    @needs_tree_write_lock
1832
1866
    def _write_inventory(self, inv):
1833
1867
        """Write inventory as the current inventory."""
2252
2286
                       for key, line in annotator.annotate_flat(this_key)]
2253
2287
        return annotations
2254
2288
 
 
2289
    def _put_rio(self, filename, stanzas, header):
 
2290
        self._must_be_locked()
 
2291
        my_file = _mod_rio.rio_file(stanzas, header)
 
2292
        self._transport.put_file(filename, my_file,
 
2293
            mode=self.bzrdir._get_file_mode())
 
2294
 
 
2295
    @needs_tree_write_lock
 
2296
    def set_merge_modified(self, modified_hashes):
 
2297
        def iter_stanzas():
 
2298
            for file_id, hash in modified_hashes.iteritems():
 
2299
                yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
 
2300
                    hash=hash)
 
2301
        self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
 
2302
 
2255
2303
    @needs_read_lock
2256
2304
    def merge_modified(self):
2257
2305
        """Return a dictionary of files modified by a merge.