comparison mercurial/commands.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
38 38
39 def matchpats(repo, cwd, pats = [], opts = {}, head = ''): 39 def matchpats(repo, cwd, pats = [], opts = {}, head = ''):
40 return util.matcher(repo, cwd, pats or ['.'], opts.get('include'), 40 return util.matcher(repo, cwd, pats or ['.'], opts.get('include'),
41 opts.get('exclude'), head) 41 opts.get('exclude'), head)
42 42
43 def pathto(n1, n2):
44 '''return the relative path from one place to another'''
45 if not n1: return n2
46 a, b = n1.split(os.sep), n2.split(os.sep)
47 a.reverse(), b.reverse()
48 while a and b and a[-1] == b[-1]:
49 a.pop(), b.pop()
50 b.reverse()
51 return os.sep.join((['..'] * len(a)) + b)
52
53 def makewalk(repo, pats, opts, head = ''): 43 def makewalk(repo, pats, opts, head = ''):
54 cwd = repo.getcwd() 44 cwd = repo.getcwd()
55 files, matchfn = matchpats(repo, cwd, pats, opts, head) 45 files, matchfn = matchpats(repo, cwd, pats, opts, head)
56 def walk(): 46 def walk():
57 for src, fn in repo.walk(files = files, match = matchfn): 47 for src, fn in repo.walk(files = files, match = matchfn):
58 yield src, fn, pathto(cwd, fn) 48 yield src, fn, util.pathto(cwd, fn)
59 return files, matchfn, walk() 49 return files, matchfn, walk()
60 50
61 def walk(repo, pats, opts, head = ''): 51 def walk(repo, pats, opts, head = ''):
62 files, matchfn, results = makewalk(repo, pats, opts, head) 52 files, matchfn, results = makewalk(repo, pats, opts, head)
63 for r in results: yield r 53 for r in results: yield r
1076 ? = not tracked 1066 ? = not tracked
1077 ''' 1067 '''
1078 1068
1079 cwd = repo.getcwd() 1069 cwd = repo.getcwd()
1080 files, matchfn = matchpats(repo, cwd, pats, opts) 1070 files, matchfn = matchpats(repo, cwd, pats, opts)
1081 (c, a, d, u) = [[pathto(cwd, x) for x in n] 1071 (c, a, d, u) = [[util.pathto(cwd, x) for x in n]
1082 for n in repo.changes(files=files, match=matchfn)] 1072 for n in repo.changes(files=files, match=matchfn)]
1083 1073
1084 changetypes = [('modified', 'M', c), 1074 changetypes = [('modified', 'M', c),
1085 ('added', 'A', a), 1075 ('added', 'A', a),
1086 ('removed', 'R', d), 1076 ('removed', 'R', d),