Mercurial > hg
comparison mercurial/dirstate.py @ 4146:e287d61dd268
Yield directories in dirstate.statwalk()
author | Emanuele Aina <faina.mail@tiscali.it> |
---|---|
date | Tue, 06 Mar 2007 17:45:39 -0300 |
parents | e6d26e71f049 |
children | ba51a8225a60 |
comparison
equal
deleted
inserted
replaced
4145:2ebdd33fe456 | 4146:e287d61dd268 |
---|---|
355 # filter out the stat | 355 # filter out the stat |
356 for src, f, st in self.statwalk(files, match, badmatch=badmatch): | 356 for src, f, st in self.statwalk(files, match, badmatch=badmatch): |
357 yield src, f | 357 yield src, f |
358 | 358 |
359 def statwalk(self, files=None, match=util.always, ignored=False, | 359 def statwalk(self, files=None, match=util.always, ignored=False, |
360 badmatch=None): | 360 badmatch=None, directories=False): |
361 ''' | 361 ''' |
362 walk recursively through the directory tree, finding all files | 362 walk recursively through the directory tree, finding all files |
363 matched by the match function | 363 matched by the match function |
364 | 364 |
365 results are yielded in a tuple (src, filename, st), where src | 365 results are yielded in a tuple (src, filename, st), where src |
366 is one of: | 366 is one of: |
367 'f' the file was found in the directory tree | 367 'f' the file was found in the directory tree |
368 'd' the file is a directory of the tree | |
368 'm' the file was only in the dirstate and not in the tree | 369 'm' the file was only in the dirstate and not in the tree |
369 'b' file was not found and matched badmatch | 370 'b' file was not found and matched badmatch |
370 | 371 |
371 and st is the stat result if the file was found in the directory. | 372 and st is the stat result if the file was found in the directory. |
372 ''' | 373 ''' |
392 if not self.root.endswith(os.sep): | 393 if not self.root.endswith(os.sep): |
393 common_prefix_len += 1 | 394 common_prefix_len += 1 |
394 # recursion free walker, faster than os.walk. | 395 # recursion free walker, faster than os.walk. |
395 def findfiles(s): | 396 def findfiles(s): |
396 work = [s] | 397 work = [s] |
398 if directories: | |
399 yield 'd', util.normpath(s[common_prefix_len:]), os.lstat(s) | |
397 while work: | 400 while work: |
398 top = work.pop() | 401 top = work.pop() |
399 names = os.listdir(top) | 402 names = os.listdir(top) |
400 names.sort() | 403 names.sort() |
401 # nd is the top of the repository dir tree | 404 # nd is the top of the repository dir tree |
419 st = os.lstat(p) | 422 st = os.lstat(p) |
420 if stat.S_ISDIR(st.st_mode): | 423 if stat.S_ISDIR(st.st_mode): |
421 ds = util.pconvert(os.path.join(nd, f +'/')) | 424 ds = util.pconvert(os.path.join(nd, f +'/')) |
422 if imatch(ds): | 425 if imatch(ds): |
423 work.append(p) | 426 work.append(p) |
427 if directories: | |
428 yield 'd', np, st | |
424 if imatch(np) and np in dc: | 429 if imatch(np) and np in dc: |
425 yield 'm', np, st | 430 yield 'm', np, st |
426 elif imatch(np): | 431 elif imatch(np): |
427 if self.supported_type(np, st): | 432 if self.supported_type(np, st): |
428 yield 'f', np, st | 433 yield 'f', np, st |