Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 8614:573734e7e6d0
cmdutils: Take over glob expansion duties from util
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 24 May 2009 16:38:29 -0500 |
parents | 4fa1618bf495 |
children | b6511055d37b |
comparison
equal
deleted
inserted
replaced
8613:4dea46d4e3f8 | 8614:573734e7e6d0 |
---|---|
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2, incorporated herein by reference. | 6 # GNU General Public License version 2, incorporated herein by reference. |
7 | 7 |
8 from node import hex, nullid, nullrev, short | 8 from node import hex, nullid, nullrev, short |
9 from i18n import _ | 9 from i18n import _ |
10 import os, sys, bisect, stat, errno, re | 10 import os, sys, bisect, stat, errno, re, glob |
11 import mdiff, bdiff, util, templater, patch, error, encoding | 11 import mdiff, bdiff, util, templater, patch, error, encoding |
12 import match as _match | 12 import match as _match |
13 | 13 |
14 revrangesep = ':' | 14 revrangesep = ':' |
15 | 15 |
233 return pat | 233 return pat |
234 return open(make_filename(repo, pat, node, total, seqno, revwidth, | 234 return open(make_filename(repo, pat, node, total, seqno, revwidth, |
235 pathname), | 235 pathname), |
236 mode) | 236 mode) |
237 | 237 |
238 def expandpats(pats): | |
239 if not util.expandglobs: | |
240 return list(pats) | |
241 ret = [] | |
242 for p in pats: | |
243 kind, name = _match._patsplit(p, None) | |
244 if kind is None: | |
245 globbed = glob.glob(name) | |
246 if globbed: | |
247 ret.extend(globbed) | |
248 continue | |
249 ret.append(p) | |
250 return ret | |
251 | |
238 def match(repo, pats=[], opts={}, globbed=False, default='relpath'): | 252 def match(repo, pats=[], opts={}, globbed=False, default='relpath'): |
239 if not globbed and default == 'relpath': | 253 if not globbed and default == 'relpath': |
240 pats = util.expand_glob(pats or []) | 254 pats = expandpats(pats or []) |
241 m = _match.match(repo.root, repo.getcwd(), pats, | 255 m = _match.match(repo.root, repo.getcwd(), pats, |
242 opts.get('include'), opts.get('exclude'), default) | 256 opts.get('include'), opts.get('exclude'), default) |
243 def badfn(f, msg): | 257 def badfn(f, msg): |
244 repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) | 258 repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) |
245 return False | 259 return False |
485 else: | 499 else: |
486 res = lambda p: dest | 500 res = lambda p: dest |
487 return res | 501 return res |
488 | 502 |
489 | 503 |
490 pats = util.expand_glob(pats) | 504 pats = expandpats(pats) |
491 if not pats: | 505 if not pats: |
492 raise util.Abort(_('no source or destination specified')) | 506 raise util.Abort(_('no source or destination specified')) |
493 if len(pats) == 1: | 507 if len(pats) == 1: |
494 raise util.Abort(_('no destination specified')) | 508 raise util.Abort(_('no destination specified')) |
495 dest = pats.pop() | 509 dest = pats.pop() |