~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Merged mailine

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
                            compact_date,
64
64
                            file_kind,
65
65
                            isdir,
 
66
                            getcwd,
 
67
                            pathjoin,
66
68
                            pumpfile,
67
69
                            splitpath,
68
70
                            rand_bytes,
 
71
                            abspath,
 
72
                            normpath,
69
73
                            realpath,
70
74
                            relpath,
71
75
                            rename)
193
197
        self.branch = branch
194
198
        self.basedir = realpath(basedir)
195
199
 
196
 
        self._set_inventory(self.read_working_inventory())
197
 
 
198
200
        # update the whole cache up front and write to disk if anything changed;
199
201
        # in the future we might want to do this more selectively
200
202
        # two possible ways offer themselves : in self._unlock, write the cache
209
211
            mutter("write hc")
210
212
            hc.write()
211
213
 
 
214
        self._set_inventory(self.read_working_inventory())
 
215
 
212
216
    def _set_inventory(self, inv):
213
217
        self._inventory = inv
214
218
        self.path2id = self._inventory.path2id
225
229
        If there is one, it is returned, along with the unused portion of path.
226
230
        """
227
231
        if path is None:
228
 
            path = os.getcwdu()
 
232
            path = getcwd()
229
233
        else:
230
234
            # sanity check.
231
235
            if path.find('://') != -1:
232
236
                raise NotBranchError(path=path)
233
 
        path = os.path.abspath(path)
 
237
        path = abspath(path)
 
238
        orig_path = path[:]
234
239
        tail = u''
235
240
        while True:
236
241
            try:
238
243
            except NotBranchError:
239
244
                pass
240
245
            if tail:
241
 
                tail = os.path.join(os.path.basename(path), tail)
 
246
                tail = pathjoin(os.path.basename(path), tail)
242
247
            else:
243
248
                tail = os.path.basename(path)
 
249
            lastpath = path
244
250
            path = os.path.dirname(path)
245
 
            # FIXME: top in windows is indicated how ???
246
 
            if path == os.path.sep:
 
251
            if lastpath == path:
247
252
                # reached the root, whatever that may be
248
 
                raise NotBranchError(path=path)
 
253
                raise NotBranchError(path=orig_path)
249
254
 
250
255
    def __iter__(self):
251
256
        """Iterate through file_ids for this tree.
263
268
                               getattr(self, 'basedir', None))
264
269
 
265
270
    def abspath(self, filename):
266
 
        return os.path.join(self.basedir, filename)
 
271
        return pathjoin(self.basedir, filename)
267
272
 
268
 
    def relpath(self, abspath):
 
273
    def relpath(self, abs):
269
274
        """Return the local path portion from a given absolute path."""
270
 
        return relpath(self.basedir, abspath)
 
275
        return relpath(self.basedir, abs)
271
276
 
272
277
    def has_filename(self, filename):
273
278
        return bzrlib.osutils.lexists(self.abspath(filename))
314
319
    def get_file_size(self, file_id):
315
320
        return os.path.getsize(self.id2abspath(file_id))
316
321
 
 
322
    @needs_read_lock
317
323
    def get_file_sha1(self, file_id):
318
324
        path = self._inventory.id2path(file_id)
319
325
        return self._hashcache.get_sha1(path)
372
378
            if len(fp) == 0:
373
379
                raise BzrError("cannot add top-level %r" % f)
374
380
 
375
 
            fullpath = os.path.normpath(self.abspath(f))
 
381
            fullpath = normpath(self.abspath(f))
376
382
 
377
383
            try:
378
384
                kind = file_kind(fullpath)
909
915
        between multiple working trees, i.e. via shared storage, then we 
910
916
        would probably want to lock both the local tree, and the branch.
911
917
        """
 
918
        if self._hashcache.needs_write and self.branch._lock_count==1:
 
919
            self._hashcache.write()
912
920
        return self.branch.unlock()
913
921
 
914
922
    @needs_write_lock