6 # of the GNU General Public License, incorporated herein by reference. |
6 # of the GNU General Public License, incorporated herein by reference. |
7 |
7 |
8 from demandload import demandload |
8 from demandload import demandload |
9 from node import * |
9 from node import * |
10 from i18n import gettext as _ |
10 from i18n import gettext as _ |
|
11 demandload(globals(), 'util') |
11 demandload(globals(), 'os sys') |
12 demandload(globals(), 'os sys') |
12 |
13 |
13 def make_filename(repo, pat, node, |
14 def make_filename(repo, pat, node, |
14 total=None, seqno=None, revwidth=None, pathname=None): |
15 total=None, seqno=None, revwidth=None, pathname=None): |
15 node_expander = { |
16 node_expander = { |
64 if hasattr(pat, 'read') and 'r' in mode: |
65 if hasattr(pat, 'read') and 'r' in mode: |
65 return pat |
66 return pat |
66 return open(make_filename(repo, pat, node, total, seqno, revwidth, |
67 return open(make_filename(repo, pat, node, total, seqno, revwidth, |
67 pathname), |
68 pathname), |
68 mode) |
69 mode) |
|
70 |
|
71 def matchpats(repo, pats=[], opts={}, head=''): |
|
72 cwd = repo.getcwd() |
|
73 if not pats and cwd: |
|
74 opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
|
75 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
|
76 cwd = '' |
|
77 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
78 opts.get('exclude'), head) |
|
79 |
|
80 def makewalk(repo, pats, opts, node=None, head='', badmatch=None): |
|
81 files, matchfn, anypats = matchpats(repo, pats, opts, head) |
|
82 exact = dict(zip(files, files)) |
|
83 def walk(): |
|
84 for src, fn in repo.walk(node=node, files=files, match=matchfn, |
|
85 badmatch=badmatch): |
|
86 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
87 return files, matchfn, walk() |
|
88 |
|
89 def walk(repo, pats, opts, node=None, head='', badmatch=None): |
|
90 files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) |
|
91 for r in results: |
|
92 yield r |