comparison mercurial/hg.py @ 884:087771ebe2e6

Fix walk code for files that do not exist anywhere, and unhandled types. Prior to this, a file that did not exist was reported as showing up in the filesystem, as were files of unsupported types (such as fifos). Now, an error message is printed and nothing is returned in such cases. This change also moves the commands.pathto function to the util module, as the walk code needs it to print non-confusing error messages.
author Bryan O'Sullivan <bos@serpentine.com>
date Fri, 12 Aug 2005 11:16:58 -0800
parents 63ca8a68d59e
children 6594ba2a0f51 509de8ab6f31
comparison
equal deleted inserted replaced
883:63ca8a68d59e 884:087771ebe2e6
9 import util 9 import util
10 from revlog import * 10 from revlog import *
11 from demandload import * 11 from demandload import *
12 demandload(globals(), "re lock urllib urllib2 transaction time socket") 12 demandload(globals(), "re lock urllib urllib2 transaction time socket")
13 demandload(globals(), "tempfile httprangereader bdiff urlparse") 13 demandload(globals(), "tempfile httprangereader bdiff urlparse")
14 demandload(globals(), "bisect select") 14 demandload(globals(), "bisect errno select stat")
15 15
16 class filelog(revlog): 16 class filelog(revlog):
17 def __init__(self, opener, path): 17 def __init__(self, opener, path):
18 revlog.__init__(self, opener, 18 revlog.__init__(self, opener,
19 os.path.join("data", self.encodedir(path + ".i")), 19 os.path.join("data", self.encodedir(path + ".i")),
487 known = {'.hg': 1} 487 known = {'.hg': 1}
488 def seen(fn): 488 def seen(fn):
489 if fn in known: return True 489 if fn in known: return True
490 known[fn] = 1 490 known[fn] = 1
491 def traverse(): 491 def traverse():
492 for f in util.unique(files): 492 for ff in util.unique(files):
493 f = os.path.join(self.root, f) 493 f = os.path.join(self.root, ff)
494 if os.path.isdir(f): 494 try:
495 st = os.stat(f)
496 except OSError, inst:
497 if ff not in dc: self.ui.warn('%s: %s\n' % (
498 util.pathto(self.getcwd(), ff),
499 inst.strerror))
500 continue
501 if stat.S_ISDIR(st.st_mode):
495 for dir, subdirs, fl in os.walk(f): 502 for dir, subdirs, fl in os.walk(f):
496 d = dir[len(self.root) + 1:] 503 d = dir[len(self.root) + 1:]
497 nd = os.path.normpath(d) 504 nd = os.path.normpath(d)
498 if seen(nd): 505 if seen(nd):
499 subdirs[:] = [] 506 subdirs[:] = []
505 subdirs.sort() 512 subdirs.sort()
506 fl.sort() 513 fl.sort()
507 for fn in fl: 514 for fn in fl:
508 fn = util.pconvert(os.path.join(d, fn)) 515 fn = util.pconvert(os.path.join(d, fn))
509 yield 'f', fn 516 yield 'f', fn
517 elif stat.S_ISREG(st.st_mode):
518 yield 'f', ff
510 else: 519 else:
511 yield 'f', f[len(self.root) + 1:] 520 kind = 'unknown'
521 if stat.S_ISCHR(st.st_mode): kind = 'character device'
522 elif stat.S_ISBLK(st.st_mode): kind = 'block device'
523 elif stat.S_ISFIFO(st.st_mode): kind = 'fifo'
524 elif stat.S_ISLNK(st.st_mode): kind = 'symbolic link'
525 elif stat.S_ISSOCK(st.st_mode): kind = 'socket'
526 self.ui.warn('%s: unsupported file type (type is %s)\n' % (
527 util.pathto(self.getcwd(), ff),
528 kind))
512 529
513 ks = dc.keys() 530 ks = dc.keys()
514 ks.sort() 531 ks.sort()
515 for k in ks: 532 for k in ks:
516 yield 'm', k 533 yield 'm', k