Commit 60d60e9c authored by Matt Harbison's avatar Matt Harbison
Browse files

scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns

This will make it easier to support subrepository operations.
parent fad896292e7d
......@@ -94,7 +94,8 @@ def perfaddremove(ui, repo):
try:
oldquiet = repo.ui.quiet
repo.ui.quiet = True
timer(lambda: scmutil.addremove(repo, dry_run=True))
matcher = scmutil.match(repo[None])
timer(lambda: scmutil.addremove(repo, matcher, dry_run=True))
finally:
repo.ui.quiet = oldquiet
fm.end()
......
......@@ -73,7 +73,7 @@ def restorematchandpatsfn():
scmutil.matchandpats = getattr(scmutil.matchandpats, 'oldmatchandpats',
scmutil.matchandpats)
def addlargefiles(ui, repo, *pats, **opts):
def addlargefiles(ui, repo, matcher, **opts):
large = opts.pop('large', None)
lfsize = lfutil.getminsize(
ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None))
......@@ -85,7 +85,7 @@ def addlargefiles(ui, repo, *pats, **opts):
lfmatcher = match_.match(repo.root, '', list(lfpats))
lfnames = []
m = scmutil.match(repo[None], pats, opts)
m = copy.copy(matcher)
m.bad = lambda x, y: None
wctx = repo[None]
for f in repo.walk(m):
......@@ -223,7 +223,8 @@ def overrideadd(orig, ui, repo, *pats, **opts):
if opts.get('large'):
raise util.Abort(_('--normal cannot be used with --large'))
return orig(ui, repo, *pats, **opts)
bad = addlargefiles(ui, repo, *pats, **opts)
matcher = scmutil.match(repo[None], pats, opts)
bad = addlargefiles(ui, repo, matcher, **opts)
installnormalfilesmatchfn(repo[None].manifest())
result = orig(ui, repo, *pats, **opts)
restorematchfn()
......@@ -1083,10 +1084,10 @@ def overridesummary(orig, ui, repo, *pats, **opts):
finally:
repo.lfstatus = False
def scmutiladdremove(orig, repo, pats=[], opts={}, dry_run=None,
def scmutiladdremove(orig, repo, matcher, opts={}, dry_run=None,
similarity=None):
if not lfutil.islfilesrepo(repo):
return orig(repo, pats, opts, dry_run, similarity)
return orig(repo, matcher, opts, dry_run, similarity)
# Get the list of missing largefiles so we can remove them
lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
unsure, s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [],
......@@ -1101,14 +1102,12 @@ def scmutiladdremove(orig, repo, pats=[], opts={}, dry_run=None,
removelargefiles(repo.ui, repo, True, *m, **opts)
# Call into the normal add code, and any files that *should* be added as
# largefiles will be
addlargefiles(repo.ui, repo, *pats, **opts)
addlargefiles(repo.ui, repo, matcher, **opts)
# Now that we've handled largefiles, hand off to the original addremove
# function to take care of the rest. Make sure it doesn't do anything with
# largefiles by installing a matcher that will ignore them.
installnormalfilesmatchfn(repo[None].manifest())
result = orig(repo, pats, opts, dry_run, similarity)
restorematchfn()
return result
# largefiles by passing a matcher that will ignore them.
matcher = composenormalfilematcher(matcher, repo[None].manifest())
return orig(repo, matcher, opts, dry_run, similarity)
# Calling purge with --all will cause the largefiles to be deleted.
# Override repo.status to prevent this from happening.
......
......@@ -2197,14 +2197,14 @@ def commit(ui, repo, commitfunc, pats, opts):
if date:
opts['date'] = util.parsedate(date)
message = logmessage(ui, opts)
matcher = scmutil.match(repo[None], pats, opts)
# extract addremove carefully -- this function can be called from a command
# that doesn't support addremove
if opts.get('addremove'):
scmutil.addremove(repo, pats, opts)
scmutil.addremove(repo, matcher, opts)
return commitfunc(ui, repo, message,
scmutil.match(repo[None], pats, opts), opts)
return commitfunc(ui, repo, message, matcher, opts)
def amend(ui, repo, commitfunc, old, extra, pats, opts):
# amend will reuse the existing user if not specified, but the obsolete
......
......@@ -235,7 +235,8 @@ def addremove(ui, repo, *pats, **opts):
raise util.Abort(_('similarity must be a number'))
if sim < 0 or sim > 100:
raise util.Abort(_('similarity must be between 0 and 100'))
return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0)
matcher = scmutil.match(repo[None], pats, opts)
return scmutil.addremove(repo, matcher, opts, similarity=sim / 100.0)
@command('^annotate|blame',
[('r', 'rev', '', _('annotate the specified revision'), _('REV')),
......
......@@ -713,13 +713,13 @@ def matchfiles(repo, files):
'''Return a matcher that will efficiently match exactly these files.'''
return matchmod.exact(repo.root, repo.getcwd(), files)
def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None):
def addremove(repo, matcher, opts={}, dry_run=None, similarity=None):
m = matcher
if dry_run is None:
dry_run = opts.get('dry_run')
if similarity is None:
similarity = float(opts.get('similarity') or 0)
# we'd use status here, except handling of symlinks and ignore is tricky
m = match(repo[None], pats, opts)
rejected = []
m.bad = lambda x, y: rejected.append(x)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment