##// END OF EJS Templates
fix handling of files of unsupported type in the walk code...
Benoit Boissinot -
r1487:2bc6cd62 default
parent child Browse files
Show More
@@ -241,6 +241,22 b' class dirstate:'
241 bs += 1
241 bs += 1
242 return ret
242 return ret
243
243
244 def supported_type(self, f, st, verbose=True):
245 if stat.S_ISREG(st.st_mode):
246 return True
247 if verbose:
248 kind = 'unknown'
249 if stat.S_ISCHR(st.st_mode): kind = _('character device')
250 elif stat.S_ISBLK(st.st_mode): kind = _('block device')
251 elif stat.S_ISFIFO(st.st_mode): kind = _('fifo')
252 elif stat.S_ISLNK(st.st_mode): kind = _('symbolic link')
253 elif stat.S_ISSOCK(st.st_mode): kind = _('socket')
254 elif stat.S_ISDIR(st.st_mode): kind = _('directory')
255 self.ui.warn(_('%s: unsupported file type (type is %s)\n') % (
256 util.pathto(self.getcwd(), f),
257 kind))
258 return False
259
244 def statwalk(self, files=None, match=util.always, dc=None):
260 def statwalk(self, files=None, match=util.always, dc=None):
245 self.read()
261 self.read()
246
262
@@ -278,22 +294,6 b' class dirstate:'
278 # directly by this function, but might be modified by your statmatch call.
294 # directly by this function, but might be modified by your statmatch call.
279 #
295 #
280 def walkhelper(self, files, statmatch, dc):
296 def walkhelper(self, files, statmatch, dc):
281 def supported_type(f, st):
282 if stat.S_ISREG(st.st_mode):
283 return True
284 else:
285 kind = 'unknown'
286 if stat.S_ISCHR(st.st_mode): kind = _('character device')
287 elif stat.S_ISBLK(st.st_mode): kind = _('block device')
288 elif stat.S_ISFIFO(st.st_mode): kind = _('fifo')
289 elif stat.S_ISLNK(st.st_mode): kind = _('symbolic link')
290 elif stat.S_ISSOCK(st.st_mode): kind = _('socket')
291 elif stat.S_ISDIR(st.st_mode): kind = _('directory')
292 self.ui.warn(_('%s: unsupported file type (type is %s)\n') % (
293 util.pathto(self.getcwd(), f),
294 kind))
295 return False
296
297 # recursion free walker, faster than os.walk.
297 # recursion free walker, faster than os.walk.
298 def findfiles(s):
298 def findfiles(s):
299 retfiles = []
299 retfiles = []
@@ -316,9 +316,13 b' class dirstate:'
316 ds = os.path.join(nd, f +'/')
316 ds = os.path.join(nd, f +'/')
317 if statmatch(ds, st):
317 if statmatch(ds, st):
318 work.append(p)
318 work.append(p)
319 elif statmatch(np, st) and supported_type(np, st):
319 if statmatch(np, st) and np in dc:
320 yield util.pconvert(np), st
320 yield 'm', util.pconvert(np), st
321
321 elif statmatch(np, st):
322 if self.supported_type(np, st):
323 yield 'f', util.pconvert(np), st
324 elif np in dc:
325 yield 'm', util.pconvert(np), st
322
326
323 known = {'.hg': 1}
327 known = {'.hg': 1}
324 def seen(fn):
328 def seen(fn):
@@ -337,22 +341,22 b' class dirstate:'
337 inst.strerror))
341 inst.strerror))
338 continue
342 continue
339 if stat.S_ISDIR(st.st_mode):
343 if stat.S_ISDIR(st.st_mode):
340 cmp0 = (lambda x, y: cmp(x[0], y[0]))
344 cmp1 = (lambda x, y: cmp(x[1], y[1]))
341 sorted = [ x for x in findfiles(f) ]
345 sorted = [ x for x in findfiles(f) ]
342 sorted.sort(cmp0)
346 sorted.sort(cmp1)
343 for fl, stl in sorted:
347 for e in sorted:
344 yield 'f', fl, stl
348 yield e
345 else:
349 else:
346 ff = util.normpath(ff)
350 ff = util.normpath(ff)
347 if seen(ff):
351 if seen(ff):
348 continue
352 continue
349 found = False
350 self.blockignore = True
353 self.blockignore = True
351 if statmatch(ff, st) and supported_type(ff, st):
354 if statmatch(ff, st):
352 found = True
355 if self.supported_type(ff, st):
356 yield 'f', ff, st
357 elif ff in dc:
358 yield 'm', ff, st
353 self.blockignore = False
359 self.blockignore = False
354 if found:
355 yield 'f', ff, st
356
360
357 # step two run through anything left in the dc hash and yield
361 # step two run through anything left in the dc hash and yield
358 # if we haven't already seen it
362 # if we haven't already seen it
@@ -373,13 +377,20 b' class dirstate:'
373 unknown.append(fn)
377 unknown.append(fn)
374 continue
378 continue
375 if src == 'm':
379 if src == 'm':
376 try:
380 nonexistent = True
377 st = os.stat(fn)
381 if not st:
378 except OSError, inst:
382 try:
383 st = os.lstat(fn)
384 except OSError, inst:
385 if inst.errno != errno.ENOENT:
386 raise
387 st = None
388 # We need to re-check that it is a valid file
389 if st and self.supported_type(fn, st):
390 nonexistent = False
379 # XXX: what to do with file no longer present in the fs
391 # XXX: what to do with file no longer present in the fs
380 # who are not removed in the dirstate ?
392 # who are not removed in the dirstate ?
381 if inst.errno != errno.ENOENT:
393 if nonexistent:
382 raise
383 deleted.append(fn)
394 deleted.append(fn)
384 continue
395 continue
385 # check the common case first
396 # check the common case first
@@ -6,19 +6,27 b' echo 123 > c'
6 hg add a c
6 hg add a c
7 hg commit -m "first" -d "0 0" a c
7 hg commit -m "first" -d "0 0" a c
8 echo 123 > b
8 echo 123 > b
9 echo %% should show b unknown
9 hg status
10 hg status
10 echo 12 > c
11 echo 12 > c
12 echo %% should show b unknown and c modified
11 hg status
13 hg status
12 hg add b
14 hg add b
15 echo %% should show b added and c modified
13 hg status
16 hg status
14 hg rm a
17 hg rm a
18 echo %% should show a removed, b added and c modified
15 hg status
19 hg status
16 hg revert a
20 hg revert a
21 echo %% should show b added and c modified
17 hg status
22 hg status
18 hg revert b
23 hg revert b
24 echo %% should show b unknown and c modified
19 hg status
25 hg status
20 hg revert c
26 hg revert c
27 echo %% should show b unknown
21 hg status
28 hg status
29 echo %% should show a b and c
22 ls
30 ls
23
31
24 true
32 true
@@ -1,16 +1,24 b''
1 %% should show b unknown
1 ? b
2 ? b
3 %% should show b unknown and c modified
2 M c
4 M c
3 ? b
5 ? b
6 %% should show b added and c modified
4 M c
7 M c
5 A b
8 A b
9 %% should show a removed, b added and c modified
6 M c
10 M c
7 A b
11 A b
8 R a
12 R a
13 %% should show b added and c modified
9 M c
14 M c
10 A b
15 A b
16 %% should show b unknown and c modified
11 M c
17 M c
12 ? b
18 ? b
19 %% should show b unknown
13 ? b
20 ? b
21 %% should show a b and c
14 a
22 a
15 b
23 b
16 c
24 c
@@ -4,3 +4,12 b' bar: unsupported file type (type is symb'
4 bar: unsupported file type (type is symbolic link)
4 bar: unsupported file type (type is symbolic link)
5 adding bomb
5 adding bomb
6 bar: unsupported file type (type is symbolic link)
6 bar: unsupported file type (type is symbolic link)
7 adding a.c
8 adding dir/a.o
9 adding dir/b.o
10 a.c: unsupported file type (type is fifo)
11 dir/b.o: unsupported file type (type is symbolic link)
12 R a.c
13 R dir/a.o
14 R dir/b.o
15 ? .hgignore
General Comments 0
You need to be logged in to leave comments. Login now