/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
from bzrlib.errors import (BzrCheckError,
56
56
                           BzrError,
57
57
                           DivergedBranches,
 
58
                           WeaveRevisionNotPresent,
58
59
                           NotBranchError,
59
60
                           NotVersionedError)
60
61
from bzrlib.inventory import InventoryEntry
62
63
                            compact_date,
63
64
                            file_kind,
64
65
                            isdir,
 
66
                            getcwd,
 
67
                            pathjoin,
65
68
                            pumpfile,
66
69
                            splitpath,
67
70
                            rand_bytes,
 
71
                            abspath,
 
72
                            normpath,
68
73
                            realpath,
69
74
                            relpath,
70
75
                            rename)
 
76
from bzrlib.textui import show_status
71
77
import bzrlib.tree
72
78
from bzrlib.trace import mutter
73
79
import bzrlib.xml5
172
178
    not listed in the Inventory and vice versa.
173
179
    """
174
180
 
175
 
    def __init__(self, basedir='.', branch=None):
 
181
    def __init__(self, basedir=u'.', branch=None):
176
182
        """Construct a WorkingTree for basedir.
177
183
 
178
184
        If the branch is not supplied, it is opened automatically.
191
197
        self.branch = branch
192
198
        self.basedir = realpath(basedir)
193
199
 
194
 
        self._set_inventory(self.read_working_inventory())
195
 
 
196
200
        # update the whole cache up front and write to disk if anything changed;
197
201
        # in the future we might want to do this more selectively
198
202
        # two possible ways offer themselves : in self._unlock, write the cache
207
211
            mutter("write hc")
208
212
            hc.write()
209
213
 
 
214
        self._set_inventory(self.read_working_inventory())
 
215
 
210
216
    def _set_inventory(self, inv):
211
217
        self._inventory = inv
212
218
        self.path2id = self._inventory.path2id
223
229
        If there is one, it is returned, along with the unused portion of path.
224
230
        """
225
231
        if path is None:
226
 
            path = os.getcwdu()
 
232
            path = getcwd()
227
233
        else:
228
234
            # sanity check.
229
235
            if path.find('://') != -1:
230
236
                raise NotBranchError(path=path)
231
 
        path = os.path.abspath(path)
232
 
        tail = ''
 
237
        path = abspath(path)
 
238
        tail = u''
233
239
        while True:
234
240
            try:
235
241
                return WorkingTree(path), tail
236
242
            except NotBranchError:
237
243
                pass
238
244
            if tail:
239
 
                tail = os.path.join(os.path.basename(path), tail)
 
245
                tail = pathjoin(os.path.basename(path), tail)
240
246
            else:
241
247
                tail = os.path.basename(path)
 
248
            lastpath = path
242
249
            path = os.path.dirname(path)
243
 
            # FIXME: top in windows is indicated how ???
244
 
            if path == os.path.sep:
 
250
            if lastpath == path:
245
251
                # reached the root, whatever that may be
246
252
                raise NotBranchError(path=path)
247
253
 
261
267
                               getattr(self, 'basedir', None))
262
268
 
263
269
    def abspath(self, filename):
264
 
        return os.path.join(self.basedir, filename)
 
270
        return pathjoin(self.basedir, filename)
265
271
 
266
 
    def relpath(self, abspath):
 
272
    def relpath(self, abs):
267
273
        """Return the local path portion from a given absolute path."""
268
 
        return relpath(self.basedir, abspath)
 
274
        return relpath(self.basedir, abs)
269
275
 
270
276
    def has_filename(self, filename):
271
277
        return bzrlib.osutils.lexists(self.abspath(filename))
312
318
    def get_file_size(self, file_id):
313
319
        return os.path.getsize(self.id2abspath(file_id))
314
320
 
 
321
    @needs_read_lock
315
322
    def get_file_sha1(self, file_id):
316
323
        path = self._inventory.id2path(file_id)
317
324
        return self._hashcache.get_sha1(path)
370
377
            if len(fp) == 0:
371
378
                raise BzrError("cannot add top-level %r" % f)
372
379
 
373
 
            fullpath = os.path.normpath(self.abspath(f))
 
380
            fullpath = normpath(self.abspath(f))
374
381
 
375
382
            try:
376
383
                kind = file_kind(fullpath)
502
509
                for ff in descend(fp, f_ie.file_id, fap):
503
510
                    yield ff
504
511
 
505
 
        for f in descend('', inv.root.file_id, self.basedir):
 
512
        for f in descend(u'', inv.root.file_id, self.basedir):
506
513
            yield f
507
514
 
508
515
    @needs_write_lock
661
668
        source.lock_read()
662
669
        try:
663
670
            old_revision_history = self.branch.revision_history()
664
 
            self.branch.pull(source, overwrite)
 
671
            count = self.branch.pull(source, overwrite)
665
672
            new_revision_history = self.branch.revision_history()
666
673
            if new_revision_history != old_revision_history:
667
674
                if len(old_revision_history):
671
678
                merge_inner(self.branch,
672
679
                            self.branch.basis_tree(), 
673
680
                            self.branch.revision_tree(other_revision))
 
681
            return count
674
682
        finally:
675
683
            source.unlock()
676
684
 
776
784
        """See Branch.lock_write, and WorkingTree.unlock."""
777
785
        return self.branch.lock_write()
778
786
 
 
787
    def _basis_inventory_name(self, revision_id):
 
788
        return 'basis-inventory.%s' % revision_id
 
789
 
 
790
    def set_last_revision(self, new_revision, old_revision=None):
 
791
        if old_revision:
 
792
            try:
 
793
                path = self._basis_inventory_name(old_revision)
 
794
                path = self.branch._rel_controlfilename(path)
 
795
                self.branch._transport.delete(path)
 
796
            except:
 
797
                pass
 
798
        try:
 
799
            xml = self.branch.get_inventory_xml(new_revision)
 
800
            path = self._basis_inventory_name(new_revision)
 
801
            self.branch.put_controlfile(path, xml)
 
802
        except WeaveRevisionNotPresent:
 
803
            pass
 
804
 
 
805
    def read_basis_inventory(self, revision_id):
 
806
        """Read the cached basis inventory."""
 
807
        path = self._basis_inventory_name(revision_id)
 
808
        return self.branch.controlfile(path, 'r').read()
 
809
        
779
810
    @needs_read_lock
780
811
    def read_working_inventory(self):
781
812
        """Read the working inventory."""
883
914
        between multiple working trees, i.e. via shared storage, then we 
884
915
        would probably want to lock both the local tree, and the branch.
885
916
        """
 
917
        if self._hashcache.needs_write:
 
918
            self._hashcache.write()
886
919
        return self.branch.unlock()
887
920
 
888
921
    @needs_write_lock