/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: Aaron Bentley
  • Date: 2005-10-06 03:15:08 UTC
  • mto: (1185.12.13)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: aaron.bentley@utoronto.ca-20051006031508-35ad4e5af9f9aff7
Added test_commit.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
# it's not predictable when it will be written out.
22
22
 
23
23
import os
24
 
    
 
24
import stat
 
25
import fnmatch
 
26
        
25
27
import bzrlib.tree
26
 
from errors import BzrCheckError
27
 
from trace import mutter
 
28
from bzrlib.osutils import appendpath, file_kind, isdir, splitpath
 
29
from bzrlib.errors import BzrCheckError
 
30
from bzrlib.trace import mutter
28
31
 
29
32
class WorkingTree(bzrlib.tree.Tree):
30
33
    """Working copy tree.
67
70
        """
68
71
        inv = self._inventory
69
72
        for path, ie in inv.iter_entries():
70
 
            if os.path.exists(self.abspath(path)):
 
73
            if bzrlib.osutils.lexists(self.abspath(path)):
71
74
                yield ie.file_id
72
75
 
73
76
 
81
84
        return os.path.join(self.basedir, filename)
82
85
 
83
86
    def has_filename(self, filename):
84
 
        return os.path.exists(self.abspath(filename))
 
87
        return bzrlib.osutils.lexists(self.abspath(filename))
85
88
 
86
89
    def get_file(self, file_id):
87
90
        return self.get_file_byname(self.id2path(file_id))
93
96
        ## XXX: badly named; this isn't in the store at all
94
97
        return self.abspath(self.id2path(file_id))
95
98
 
 
99
 
 
100
    def id2abspath(self, file_id):
 
101
        return self.abspath(self.id2path(file_id))
 
102
 
96
103
                
97
104
    def has_id(self, file_id):
98
105
        # files that have been deleted are excluded
100
107
        if not inv.has_id(file_id):
101
108
            return False
102
109
        path = inv.id2path(file_id)
103
 
        return os.path.exists(self.abspath(path))
 
110
        return bzrlib.osutils.lexists(self.abspath(path))
104
111
 
105
112
 
106
113
    __contains__ = has_id
107
114
    
108
115
 
109
116
    def get_file_size(self, file_id):
110
 
        # is this still called?
111
 
        raise NotImplementedError()
112
 
 
 
117
        return os.path.getsize(self.id2abspath(file_id))
113
118
 
114
119
    def get_file_sha1(self, file_id):
115
120
        path = self._inventory.id2path(file_id)
116
121
        return self._hashcache.get_sha1(path)
117
122
 
118
123
 
 
124
    def is_executable(self, file_id):
 
125
        if os.name == "nt":
 
126
            return self._inventory[file_id].executable
 
127
        else:
 
128
            path = self._inventory.id2path(file_id)
 
129
            mode = os.lstat(self.abspath(path)).st_mode
 
130
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC&mode)
 
131
 
 
132
    def get_symlink_target(self, file_id):
 
133
        return os.readlink(self.id2path(file_id))
 
134
 
119
135
    def file_class(self, filename):
120
136
        if self.path2id(filename):
121
137
            return 'V'
135
151
 
136
152
        Skips the control directory.
137
153
        """
138
 
        from osutils import appendpath, file_kind
139
 
        import os
140
 
 
141
154
        inv = self._inventory
142
155
 
143
156
        def descend(from_dir_relpath, from_dir_id, dp):
194
207
            if not self.is_ignored(subp):
195
208
                yield subp
196
209
 
 
210
    def iter_conflicts(self):
 
211
        conflicted = set()
 
212
        for path in (s[0] for s in self.list_files()):
 
213
            stem = get_conflicted_stem(path)
 
214
            if stem is None:
 
215
                continue
 
216
            if stem not in conflicted:
 
217
                conflicted.add(stem)
 
218
                yield stem
197
219
 
198
220
    def extras(self):
199
221
        """Yield all unknown files in this WorkingTree.
205
227
        Currently returned depth-first, sorted by name within directories.
206
228
        """
207
229
        ## TODO: Work from given directory downwards
208
 
        from osutils import isdir, appendpath
209
 
        
210
230
        for path, dir_entry in self.inventory.directories():
211
231
            mutter("search for unknowns in %r" % path)
212
232
            dirabs = self.abspath(path)
269
289
        # Eventually it should be replaced with something more
270
290
        # accurate.
271
291
        
272
 
        import fnmatch
273
 
        from osutils import splitpath
274
 
        
275
292
        for pat in self.get_ignore_list():
276
293
            if '/' in pat or '\\' in pat:
277
294
                
290
307
                    return pat
291
308
        else:
292
309
            return None
293
 
        
 
 
b'\\ No newline at end of file'
 
310
 
 
311
CONFLICT_SUFFIXES = ('.THIS', '.BASE', '.OTHER')
 
312
def get_conflicted_stem(path):
 
313
    for suffix in CONFLICT_SUFFIXES:
 
314
        if path.endswith(suffix):
 
315
            return path[:-len(suffix)]