diff -r 9e0f3ba4a9c2 -r 1c0c413cccdd mercurial/commands.py --- a/mercurial/commands.py Sat Jul 16 15:13:40 2005 -0800 +++ b/mercurial/commands.py Mon Jul 18 06:54:21 2005 -0800 @@ -36,6 +36,39 @@ for x in args] return args +def matchpats(ui, cwd, pats = [], opts = {}): + head = '' + if opts.get('rootless'): head = '(?:.*/|)' + def reify(name, tail): + if name.startswith('re:'): + return name[3:] + elif name.startswith('glob:'): + return head + util.globre(name[5:], '', tail) + elif name.startswith('path:'): + return '^' + re.escape(name[5:]) + '$' + return head + util.globre(name, '', tail) + cwdsep = cwd + os.sep + def under(fn): + if not cwd or fn.startswith(cwdsep): return True + def matchfn(pats, tail, ifempty = util.always): + if not pats: return ifempty + pat = '(?:%s)' % '|'.join([reify(p, tail) for p in pats]) + if cwd: pat = re.escape(cwd + os.sep) + pat + ui.debug('regexp: %s\n' % pat) + return re.compile(pat).match + patmatch = matchfn(pats, '$') + incmatch = matchfn(opts.get('include'), '(?:/|$)', under) + excmatch = matchfn(opts.get('exclude'), '(?:/|$)', util.never) + return lambda fn: (incmatch(fn) and not excmatch(fn) and + (fn.endswith('/') or patmatch(fn))) + +def walk(repo, pats, opts): + cwd = repo.getcwd() + if cwd: c = len(cwd) + 1 + for fn in repo.walk(match = matchpats(repo.ui, cwd, pats, opts)): + if cwd: yield fn, fn[c:] + else: yield fn, fn + revrangesep = ':' def revrange(ui, repo, revs, revlog=None): @@ -288,9 +321,17 @@ # Commands start here, listed alphabetically -def add(ui, repo, file1, *files): +def add(ui, repo, *pats, **opts): '''add the specified files on the next commit''' - repo.add(relpath(repo, (file1,) + files)) + names = [] + q = dict(zip(pats, pats)) + for abs, rel in walk(repo, pats, opts): + if rel in q or abs in q: + names.append(abs) + elif repo.dirstate.state(abs) == '?': + ui.status('adding %s\n' % rel) + names.append(abs) + repo.add(names) def addremove(ui, repo, *files): """add all new files, delete all missing files""" @@ -669,46 +710,15 @@ def locate(ui, repo, *pats, **opts): """locate files matching specific patterns""" - if [p for p in pats if os.sep in p]: - ui.warn("error: patterns may not contain '%s'\n" % os.sep) - ui.warn("use '-i