本文整理汇总了Python中mercurial.scmutil.match函数的典型用法代码示例。如果您正苦于以下问题:Python match函数的具体用法?Python match怎么用?Python match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了match函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: perfwalk
def perfwalk(ui, repo, *pats):
try:
m = scmutil.match(repo[None], pats, {})
timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
except Exception:
try:
m = scmutil.match(repo[None], pats, {})
timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
except Exception:
timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
示例2: _get_files
def _get_files(repo, patterns, options):
"""Return all files in the working directory that match the
patterns and are tracked (clean, modified or added). Ignored or
unknown files are only matched when given literally.
If patterns is empty, match all tracked files.
Supports options['include'] and options['exclude'] which work like
the --include and --exclude options of hg status.
"""
ctx = repo[None]
match = match_func(repo, ctx, patterns, options)
try:
ctx.status(listclean=True, listignored=True, listunknown=True)
except TypeError:
# Compatibility with older Mercurial versions.
ctx.status(clean=True, ignored=True, unknown=True)
files = []
for file_list in [ctx.clean(), ctx.modified(), ctx.added()]:
for filename in file_list:
if match(filename):
files.append(filename)
for file_list in [ctx.ignored(), ctx.unknown()]:
for filename in file_list:
if match.exact(filename):
files.append(filename)
return files
示例3: getstandinmatcher
def getstandinmatcher(repo, rmatcher=None):
'''Return a match object that applies rmatcher to the standin directory'''
standindir = repo.wjoin(shortname)
# no warnings about missing files or directories
badfn = lambda f, msg: None
if rmatcher and not rmatcher.always():
pats = [os.path.join(standindir, pat) for pat in rmatcher.files()]
match = scmutil.match(repo[None], pats, badfn=badfn)
# if pats is empty, it would incorrectly always match, so clear _always
match._always = False
else:
# no patterns: relative to repo root
match = scmutil.match(repo[None], [standindir], badfn=badfn)
return match
示例4: badd
def badd(ui, repo, *pats, **opts):
"""add the specified files to big files repo
If no names are given, add all files to the repository.
"""
setignores(ui)
ds = read_bigfiledirstate(ui, repo)
bigfiles = parse_bigfiles(repo)
bad = []
exacts = {}
names = []
m = scmutil.match(repo[None], pats, opts)
oldbad = m.bad
m.bad = lambda x,y: bad.append(x) or oldbad(x,y)
for f in repo.walk(m):
exact = m.exact(f)
if exact or f not in repo.dirstate:
names.append(f)
if ui.verbose or not exact:
ui.status(_('adding %s\n') % m.rel(f))
if not opts.get('dry_run'):
brepo = bigfiles_repo(ui)
_updatebigrepo(ui, repo, names, brepo, bigfiles, ds)
write_dotbigfilesfile(repo, bigfiles)
write_bigfiledirstate(ui, repo, ds)
return bad and 1 or 0
示例5: _nothingtoshelvemessaging
def _nothingtoshelvemessaging(ui, repo, pats, opts):
stat = repo.status(match=scmutil.match(repo[None], pats, opts))
if stat.deleted:
ui.status(_("nothing changed (%d missing files, see "
"'hg status')\n") % len(stat.deleted))
else:
ui.status(_("nothing changed\n"))
示例6: autodiff
def autodiff(ui, repo, *pats, **opts):
diffopts = patch.diffopts(ui, opts)
git = opts.get('git', 'no')
brokenfiles = set()
losedatafn = None
if git in ('yes', 'no'):
diffopts.git = git == 'yes'
diffopts.upgrade = False
elif git == 'auto':
diffopts.git = False
diffopts.upgrade = True
elif git == 'warn':
diffopts.git = False
diffopts.upgrade = True
def losedatafn(fn=None, **kwargs):
brokenfiles.add(fn)
return True
elif git == 'abort':
diffopts.git = False
diffopts.upgrade = True
def losedatafn(fn=None, **kwargs):
raise util.Abort('losing data for %s' % fn)
else:
raise util.Abort('--git must be yes, no or auto')
node1, node2 = scmutil.revpair(repo, [])
m = scmutil.match(repo[node2], pats, opts)
it = patch.diff(repo, node1, node2, match=m, opts=diffopts,
losedatafn=losedatafn)
for chunk in it:
ui.write(chunk)
for fn in sorted(brokenfiles):
ui.write(('data lost for: %s\n' % fn))
示例7: _modified_regions
def _modified_regions(repo, patterns, **kwargs):
opt_all = kwargs.get('all', False)
opt_no_ignore = kwargs.get('no_ignore', False)
# Import the match (repository file name matching helper)
# function. Different versions of Mercurial keep it in different
# modules and implement them differently.
try:
from mercurial import scmutil
m = scmutil.match(repo[None], patterns, kwargs)
except ImportError:
from mercurial import cmdutil
m = cmdutil.match(repo, patterns, kwargs)
modified, added, removed, deleted, unknown, ignore, clean = \
repo.status(match=m, clean=opt_all)
if not opt_all:
try:
wctx = repo.workingctx()
except:
from mercurial import context
wctx = context.workingctx(repo)
files = [ (fn, all_regions) for fn in added ] + \
[ (fn, modregions(wctx, fn)) for fn in modified ]
else:
files = [ (fn, all_regions) for fn in added + modified + clean ]
for fname, mod_regions in files:
if opt_no_ignore or not check_ignores(fname):
yield fname, mod_regions
示例8: _amend
def _amend(orig, ui, repo, old, extra, pats, opts):
# Only wrap if not disabled and repo is instance of
# localrepo.localrepository
if _disabled[0] or not isinstance(repo, localrepo.localrepository):
return orig(ui, repo, old, extra, pats, opts)
with repo.wlock(), repo.lock(), repo.transaction('dirsyncamend'):
wctx = repo[None]
matcher = scmutil.match(wctx, pats, opts)
if (opts.get('addremove')
and scmutil.addremove(repo, matcher, "", opts)):
raise error.Abort(
_("failed to mark all new/missing files as added/removed"))
mirroredfiles = _updateworkingcopy(repo, matcher)
if mirroredfiles and not matcher.always():
# Ensure that all the files to be amended (original + synced) are
# under consideration during the amend operation. We do so by
# setting the value against 'include' key in opts as the only source
# of truth.
pats = ()
opts['include'] = [
f for f in wctx.files() if matcher(f)] + list(mirroredfiles)
return orig(ui, repo, old, extra, pats, opts)
示例9: casecheck
def casecheck(ui, repo, *pats, **opts):
if not repo.local():
ui.note(_('Only local repositories can be checked'))
return
'''check an existing local repository for filename issues (caseguard)'''
try:
# Mercurial >= 1.9
m = scmutil.match(repo[0], pats, opts)
except ImportError:
# Mercurial <= 1.8
m = cmdutil.match(repo, pats, opts)
seen = dict()
def dostatus(msg):
ui.status('%s\n' % msg)
for f in repo.walk(m):
if f in repo.dirstate:
badname = _wincheck(ui, f, dostatus) or \
_charcheck(ui, f, dostatus)
if f.lower() in seen:
dostatus(_('%s collides with %s') % (f, seen[f.lower()]))
else:
seen[f.lower()] = f
if not badname:
ui.note(_('\t[OK] %s\n') % f)
示例10: archive
def archive(web, req, tmpl):
type_ = req.form.get('type', [None])[0]
allowed = web.configlist("web", "allow_archive")
key = req.form['node'][0]
if type_ not in web.archives:
msg = 'Unsupported archive type: %s' % type_
raise ErrorResponse(HTTP_NOT_FOUND, msg)
if not ((type_ in allowed or
web.configbool("web", "allow" + type_, False))):
msg = 'Archive type not allowed: %s' % type_
raise ErrorResponse(HTTP_FORBIDDEN, msg)
reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame))
cnode = web.repo.lookup(key)
arch_version = key
if cnode == key or key == 'tip':
arch_version = short(cnode)
name = "%s-%s" % (reponame, arch_version)
ctx = webutil.changectx(web.repo, req)
pats = []
matchfn = scmutil.match(ctx, [])
file = req.form.get('file', None)
if file:
pats = ['path:' + file[0]]
matchfn = scmutil.match(ctx, pats, default='path')
if pats:
files = [f for f in ctx.manifest().keys() if matchfn(f)]
if not files:
raise ErrorResponse(HTTP_NOT_FOUND,
'file(s) not found: %s' % file[0])
mimetype, artype, extension, encoding = web.archive_specs[type_]
headers = [
('Content-Disposition', 'attachment; filename=%s%s' % (name, extension))
]
if encoding:
headers.append(('Content-Encoding', encoding))
req.headers.extend(headers)
req.respond(HTTP_OK, mimetype)
archival.archive(web.repo, req, cnode, artype, prefix=name,
matchfn=matchfn,
subrepos=web.configbool("web", "archivesubrepos"))
return []
示例11: override_remove
def override_remove(orig, ui, repo, *pats, **opts):
manifest = repo[None].manifest()
installnormalfilesmatchfn(manifest)
orig(ui, repo, *pats, **opts)
restorematchfn()
after, force = opts.get('after'), opts.get('force')
if not pats and not after:
raise util.Abort(_('no files specified'))
m = scmutil.match(repo[None], pats, opts)
try:
repo.lfstatus = True
s = repo.status(match=m, clean=True)
finally:
repo.lfstatus = False
modified, added, deleted, clean = [[f for f in list
if lfutil.standin(f) in manifest]
for list in [s[0], s[1], s[3], s[6]]]
def warn(files, reason):
for f in files:
ui.warn(_('not removing %s: %s (use -f to force removal)\n')
% (m.rel(f), reason))
if force:
remove, forget = modified + deleted + clean, added
elif after:
remove, forget = deleted, []
warn(modified + added + clean, _('file still exists'))
else:
remove, forget = deleted + clean, []
warn(modified, _('file is modified'))
warn(added, _('file has been marked for add'))
for f in sorted(remove + forget):
if ui.verbose or not m.exact(f):
ui.status(_('removing %s\n') % m.rel(f))
# Need to lock because standin files are deleted then removed from the
# repository and we could race inbetween.
wlock = repo.wlock()
try:
lfdirstate = lfutil.openlfdirstate(ui, repo)
for f in remove:
if not after:
os.unlink(repo.wjoin(f))
currentdir = os.path.split(f)[0]
while currentdir and not os.listdir(repo.wjoin(currentdir)):
os.rmdir(repo.wjoin(currentdir))
currentdir = os.path.split(currentdir)[0]
lfdirstate.remove(f)
lfdirstate.write()
forget = [lfutil.standin(f) for f in forget]
remove = [lfutil.standin(f) for f in remove]
lfutil.repo_forget(repo, forget)
lfutil.repo_remove(repo, remove, unlink=True)
finally:
wlock.release()
示例12: foamdiff
def foamdiff(ui, repo, *files, **opts):
'''
Compare two OpenFOAM-dictionaries for semantic differences
Very simple. Uses pyFoamCompareDictionary.py and does not pass
options along to it
'''
revs = opts.get('rev')
change = opts.get('change')
if len(files)==0:
raise util.Abort("No files specified")
if revs and change:
msg = _('cannot specify --rev and --change at the same time')
raise util.Abort(msg)
elif change:
node2 = repo.lookup(change)
node1a, node1b = repo.changelog.parents(node2)
else:
node1a, node2 = scmutil.revpair(repo, revs)
if not revs:
node1b = repo.dirstate.parents()[1]
else:
node1b = nullid
if node1b!=nullid:
raise util.Abort("Can't do 3-way comparisons")
matcher = scmutil.match(repo[node2], files, opts)
mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher)[:3])
modadd = mod_a | add_a
common = modadd | rem_a
if not common:
return 0
tmproot = tempfile.mkdtemp(prefix='foamdiff.')
ui.debug("Writing temporary files to %s\n" %tmproot)
try:
dir1a_files = mod_a | rem_a
dir1a=snapshot(ui, repo, dir1a_files, node1a, tmproot)[0]
dir2root = tmproot
if node2:
dir2=snapshot(ui, repo, modadd, node2, tmproot)[0]
else:
dir2=''
dir2root=repo.root
for f in common:
ui.write("\n Comparing: %s\n" %f)
f1=path.join(tmproot,dir1a,f)
f2=path.join(dir2root,dir2,f)
CompareDictionary(args=[f1,f2])
finally:
ui.note(_('cleaning up temp directory\n'))
shutil.rmtree(tmproot)
示例13: getmatcher
def getmatcher(repo, pats=[], opts={}, showbad=True):
'''Wrapper around scmutil.match() that adds showbad: if false,
neuter the match object's bad() method so it does not print any
warnings about missing files or directories.'''
match = scmutil.match(repo[None], pats, opts)
if not showbad:
match.bad = lambda f, msg: None
return match
示例14: _status
def _status(ui, repo, wctx, kwt, *pats, **opts):
'''Bails out if [keyword] configuration is not active.
Returns status of working directory.'''
if kwt:
return repo.status(match=scmutil.match(wctx, pats, opts), clean=True,
unknown=opts.get('unknown') or opts.get('all'))
if ui.configitems('keyword'):
raise util.Abort(_('[keyword] patterns cannot match'))
raise util.Abort(_('no [keyword] patterns configured'))
示例15: remove_largefiles
def remove_largefiles(ui, repo, *pats, **opts):
after = opts.get('after')
if not pats and not after:
raise util.Abort(_('no files specified'))
m = scmutil.match(repo[None], pats, opts)
try:
repo.lfstatus = True
s = repo.status(match=m, clean=True)
finally:
repo.lfstatus = False
manifest = repo[None].manifest()
modified, added, deleted, clean = [[f for f in list
if lfutil.standin(f) in manifest]
for list in [s[0], s[1], s[3], s[6]]]
def warn(files, reason):
for f in files:
ui.warn(_('not removing %s: %s (use forget to undo)\n')
% (m.rel(f), reason))
if after:
remove, forget = deleted, []
warn(modified + added + clean, _('file still exists'))
else:
remove, forget = deleted + clean, []
warn(modified, _('file is modified'))
warn(added, _('file has been marked for add'))
for f in sorted(remove + forget):
if ui.verbose or not m.exact(f):
ui.status(_('removing %s\n') % m.rel(f))
# Need to lock because standin files are deleted then removed from the
# repository and we could race inbetween.
wlock = repo.wlock()
try:
lfdirstate = lfutil.openlfdirstate(ui, repo)
for f in remove:
if not after:
# If this is being called by addremove, notify the user that we
# are removing the file.
if getattr(repo, "_isaddremove", False):
ui.status(_('removing %s\n' % f))
if os.path.exists(repo.wjoin(f)):
util.unlinkpath(repo.wjoin(f))
lfdirstate.remove(f)
lfdirstate.write()
forget = [lfutil.standin(f) for f in forget]
remove = [lfutil.standin(f) for f in remove]
lfutil.repo_forget(repo, forget)
# If this is being called by addremove, let the original addremove
# function handle this.
if not getattr(repo, "_isaddremove", False):
lfutil.repo_remove(repo, remove, unlink=True)
finally:
wlock.release()