/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

  • Committer: Martin Pool
  • Date: 2005-06-28 03:02:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050628030231-d311e4ebcd467ef4
Merge John's import-speedup branch:

                                                                                         
  777 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:32 -0500
      revision-id: john@arbash-meinel.com-20050627032031-e82a50db3863b18e
      bzr selftest was not using the correct bzr

  776 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:22 -0500
      revision-id: john@arbash-meinel.com-20050627032021-c9f21fde989ddaee
      Add was using an old mutter

  775 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:02:33 -0500
      revision-id: john@arbash-meinel.com-20050627030233-9165cfe98fc63298
      Cleaned up to be less different

  774 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:54:53 -0500
      revision-id: john@arbash-meinel.com-20050627025452-4260d0e744edef43
      Allow BZR_PLUGIN_PATH='' to negate plugin loading.

  773 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:49:34 -0500
      revision-id: john@arbash-meinel.com-20050627024933-b7158f67b7b9eae5
      Finished the previous cleanup (allowing load_plugins to be called twice)

  772 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:45:08 -0500
      revision-id: john@arbash-meinel.com-20050627024508-723b1df510d196fc
      Work on making the tests pass. versioning.py is calling run_cmd directly, but plugins have been loaded.

  771 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:32:29 -0500
      revision-id: john@arbash-meinel.com-20050627023228-79972744d7c53e15
      Got it down a little bit more by removing import of tree and inventory.

  770 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:26:05 -0500
      revision-id: john@arbash-meinel.com-20050627022604-350b9773ef622f95
      Reducing the number of import from bzrlib/__init__.py and bzrlib/branch.py

  769 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:32:25 -0500
      revision-id: john@arbash-meinel.com-20050627013225-32dd044f10d23948
      Updated revision.py and xml.py to include SubElement.

  768 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:56 -0500
      revision-id: john@arbash-meinel.com-20050627010356-ee66919e1c377faf
      Minor typo

  767 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:13 -0500
      revision-id: john@arbash-meinel.com-20050627010312-40d024007eb85051
      Caching the import

  766 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:51:47 -0500
      revision-id: john@arbash-meinel.com-20050627005147-5281c99e48ed1834
      Created wrapper functions for lazy import of ElementTree

  765 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:46:37 -0500
      revision-id: john@arbash-meinel.com-20050627004636-bf432902004a94c5
      Removed all of the test imports of cElementTree

  764 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:43:59 -0500
      revision-id: john@arbash-meinel.com-20050627004358-d137fbe9570dd71b
      Trying to make bzr startup faster.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
# TODO: Don't allow WorkingTrees to be constructed for remote branches.
18
 
 
19
 
# FIXME: I don't know if writing out the cache from the destructor is really a
20
 
# good idea, because destructors are considered poor taste in Python, and
21
 
# it's not predictable when it will be written out.
22
17
 
23
18
import os
24
19
    
25
20
import bzrlib.tree
26
21
from errors import BzrCheckError
27
22
from trace import mutter
 
23
import statcache
28
24
 
29
25
class WorkingTree(bzrlib.tree.Tree):
30
26
    """Working copy tree.
35
31
    It is possible for a `WorkingTree` to have a filename which is
36
32
    not listed in the Inventory and vice versa.
37
33
    """
 
34
    _statcache = None
 
35
    
38
36
    def __init__(self, basedir, inv):
39
 
        from bzrlib.hashcache import HashCache
40
 
        from bzrlib.trace import note, mutter
41
 
 
42
37
        self._inventory = inv
43
38
        self.basedir = basedir
44
39
        self.path2id = inv.path2id
45
 
 
46
 
        # update the whole cache up front and write to disk if anything changed;
47
 
        # in the future we might want to do this more selectively
48
 
        hc = self._hashcache = HashCache(basedir)
49
 
        hc.read()
50
 
        hc.scan()
51
 
 
52
 
        if hc.needs_write:
53
 
            mutter("write hc")
54
 
            hc.write()
55
 
            
56
 
            
57
 
    def __del__(self):
58
 
        if self._hashcache.needs_write:
59
 
            self._hashcache.write()
60
 
 
 
40
        self._update_statcache()
61
41
 
62
42
    def __iter__(self):
63
43
        """Iterate through file_ids for this tree.
66
46
        and the working file exists.
67
47
        """
68
48
        inv = self._inventory
69
 
        for path, ie in inv.iter_entries():
70
 
            if os.path.exists(self.abspath(path)):
71
 
                yield ie.file_id
 
49
        for file_id in self._inventory:
 
50
            # TODO: This is slightly redundant; we should be able to just
 
51
            # check the statcache but it only includes regular files.
 
52
            # only include files which still exist on disk
 
53
            ie = inv[file_id]
 
54
            if ie.kind == 'file':
 
55
                if ((file_id in self._statcache)
 
56
                    or (os.path.exists(self.abspath(inv.id2path(file_id))))):
 
57
                    yield file_id
 
58
 
72
59
 
73
60
 
74
61
    def __repr__(self):
75
62
        return "<%s of %s>" % (self.__class__.__name__,
76
 
                               getattr(self, 'basedir', None))
77
 
 
78
 
 
 
63
                               self.basedir)
79
64
 
80
65
    def abspath(self, filename):
81
66
        return os.path.join(self.basedir, filename)
96
81
                
97
82
    def has_id(self, file_id):
98
83
        # files that have been deleted are excluded
99
 
        inv = self._inventory
100
 
        if not inv.has_id(file_id):
 
84
        if not self.inventory.has_id(file_id):
101
85
            return False
102
 
        path = inv.id2path(file_id)
103
 
        return os.path.exists(self.abspath(path))
 
86
        if file_id in self._statcache:
 
87
            return True
 
88
        return os.path.exists(self.abspath(self.id2path(file_id)))
104
89
 
105
90
 
106
91
    __contains__ = has_id
107
92
    
108
93
 
 
94
    def _update_statcache(self):
 
95
        import statcache
 
96
        if not self._statcache:
 
97
            self._statcache = statcache.update_cache(self.basedir, self.inventory)
 
98
 
109
99
    def get_file_size(self, file_id):
110
 
        # is this still called?
111
 
        raise NotImplementedError()
 
100
        import os, stat
 
101
        return os.stat(self._get_store_filename(file_id))[stat.ST_SIZE]
112
102
 
113
103
 
114
104
    def get_file_sha1(self, file_id):
115
 
        path = self._inventory.id2path(file_id)
116
 
        return self._hashcache.get_sha1(path)
 
105
        return self._statcache[file_id][statcache.SC_SHA1]
117
106
 
118
107
 
119
108
    def file_class(self, filename):
138
127
        from osutils import appendpath, file_kind
139
128
        import os
140
129
 
141
 
        inv = self._inventory
 
130
        inv = self.inventory
142
131
 
143
132
        def descend(from_dir_relpath, from_dir_id, dp):
144
133
            ls = os.listdir(dp)
290
279
                    return pat
291
280
        else:
292
281
            return None
293
 
        
 
 
b'\\ No newline at end of file'
 
282
        
 
283
 
 
284
        
 
285
        
 
286