Commit 5ce0b35c authored by Martin von Zweigbergk's avatar Martin von Zweigbergk
Browse files

addremove: pass around uipathfn and use instead of m.uipath() (API)

Differential Revision: https://phab.mercurial-scm.org/D5903
parent b2df5dc3ebfb
......@@ -519,7 +519,11 @@ def perfaddremove(ui, repo, **opts):
repo.ui.quiet = True
matcher = scmutil.match(repo[None])
opts[b'dry_run'] = True
timer(lambda: scmutil.addremove(repo, matcher, b"", opts))
if b'uipathfn' in getargspec(scmutil.addremove).args:
uipathfn = scmutil.getuipathfn(repo)
timer(lambda: scmutil.addremove(repo, matcher, b"", uipathfn, opts))
else:
timer(lambda: scmutil.addremove(repo, matcher, b"", opts))
finally:
repo.ui.quiet = oldquiet
fm.end()
......
......@@ -1225,11 +1225,11 @@ def overridesummary(orig, ui, repo, *pats, **opts):
repo.lfstatus = False
@eh.wrapfunction(scmutil, 'addremove')
def scmutiladdremove(orig, repo, matcher, prefix, opts=None):
def scmutiladdremove(orig, repo, matcher, prefix, uipathfn, opts=None):
if opts is None:
opts = {}
if not lfutil.islfilesrepo(repo):
return orig(repo, matcher, prefix, opts)
return orig(repo, matcher, prefix, uipathfn, opts)
# Get the list of missing largefiles so we can remove them
lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
unsure, s = lfdirstate.status(matchmod.always(repo.root, repo.getcwd()),
......@@ -1260,7 +1260,7 @@ def scmutiladdremove(orig, repo, matcher, prefix, opts=None):
# function to take care of the rest. Make sure it doesn't do anything with
# largefiles by passing a matcher that will ignore them.
matcher = composenormalfilematcher(matcher, repo[None].manifest(), added)
return orig(repo, matcher, prefix, opts)
return orig(repo, matcher, prefix, uipathfn, opts)
# Calling purge with --all will cause the largefiles to be deleted.
# Override repo.status to prevent this from happening.
......
......@@ -2391,7 +2391,9 @@ def commit(ui, repo, commitfunc, pats, opts):
dsguard = dirstateguard.dirstateguard(repo, 'commit')
with dsguard or util.nullcontextmanager():
if dsguard:
if scmutil.addremove(repo, matcher, "", opts) != 0:
relative = scmutil.anypats(pats, opts)
uipathfn = scmutil.getuipathfn(repo, forcerelativevalue=relative)
if scmutil.addremove(repo, matcher, "", uipathfn, opts) != 0:
raise error.Abort(
_("failed to mark all new/missing files as added/removed"))
......@@ -2469,8 +2471,10 @@ def amend(ui, repo, old, extra, pats, opts):
# add/remove the files to the working copy if the "addremove" option
# was specified.
matcher = scmutil.match(wctx, pats, opts)
relative = scmutil.anypats(pats, opts)
uipathfn = scmutil.getuipathfn(repo, forcerelativevalue=relative)
if (opts.get('addremove')
and scmutil.addremove(repo, matcher, "", opts)):
and scmutil.addremove(repo, matcher, "", uipathfn, opts)):
raise error.Abort(
_("failed to mark all new/missing files as added/removed"))
......
......@@ -255,7 +255,9 @@ def addremove(ui, repo, *pats, **opts):
if not opts.get('similarity'):
opts['similarity'] = '100'
matcher = scmutil.match(repo[None], pats, opts)
return scmutil.addremove(repo, matcher, "", opts)
relative = scmutil.anypats(pats, opts)
uipathfn = scmutil.getuipathfn(repo, forcerelativevalue=relative)
return scmutil.addremove(repo, matcher, "", uipathfn, opts)
@command('annotate|blame',
[('r', 'rev', '', _('annotate the specified revision'), _('REV')),
......
......@@ -763,6 +763,14 @@ def subdiruipathfn(subpath, uipathfn):
'''Create a new uipathfn that treats the file as relative to subpath.'''
return lambda f: uipathfn(posixpath.join(subpath, f))
def anypats(pats, opts):
'''Checks if any patterns, including --include and --exclude were given.
Some commands (e.g. addremove) use this condition for deciding whether to
print absolute or relative paths.
'''
return bool(pats or opts.get('include') or opts.get('exclude'))
def expandpats(pats):
'''Expand bare globs when running on windows.
On posix we assume it already has already been done by sh.'''
......@@ -1031,7 +1039,7 @@ def cleanupnodes(repo, replacements, operation, moves=None, metadata=None,
repair.delayedstrip(repo.ui, repo, tostrip, operation,
backup=backup)
def addremove(repo, matcher, prefix, opts=None):
def addremove(repo, matcher, prefix, uipathfn, opts=None):
if opts is None:
opts = {}
m = matcher
......@@ -1052,12 +1060,13 @@ def addremove(repo, matcher, prefix, opts=None):
if opts.get('subrepos') or m.exact(subpath) or any(submatch.files()):
sub = wctx.sub(subpath)
subprefix = repo.wvfs.reljoin(prefix, subpath)
subuipathfn = subdiruipathfn(subpath, uipathfn)
try:
if sub.addremove(submatch, subprefix, opts):
if sub.addremove(submatch, subprefix, subuipathfn, opts):
ret = 1
except error.LookupError:
repo.ui.status(_("skipping missing subrepository: %s\n")
% m.uipath(subpath))
% uipathfn(subpath))
rejected = []
def badfn(f, msg):
......@@ -1075,10 +1084,10 @@ def addremove(repo, matcher, prefix, opts=None):
for abs in sorted(toprint):
if repo.ui.verbose or not m.exact(abs):
if abs in unknownset:
status = _('adding %s\n') % m.uipath(abs)
status = _('adding %s\n') % uipathfn(abs)
label = 'ui.addremove.added'
else:
status = _('removing %s\n') % m.uipath(abs)
status = _('removing %s\n') % uipathfn(abs)
label = 'ui.addremove.removed'
repo.ui.status(status, label=label)
......
......@@ -290,7 +290,7 @@ class abstractsubrepo(object):
def add(self, ui, match, prefix, uipathfn, explicitonly, **opts):
return []
def addremove(self, matcher, prefix, opts):
def addremove(self, matcher, prefix, uipathfn, opts):
self.ui.warn("%s: %s" % (prefix, _("addremove is not supported")))
return 1
......@@ -521,13 +521,13 @@ class hgsubrepo(abstractsubrepo):
explicitonly, **opts)
@annotatesubrepoerror
def addremove(self, m, prefix, opts):
def addremove(self, m, prefix, uipathfn, opts):
# In the same way as sub directories are processed, once in a subrepo,
# always entry any of its subrepos. Don't corrupt the options that will
# be used to process sibling subrepos however.
opts = copy.copy(opts)
opts['subrepos'] = True
return scmutil.addremove(self._repo, m, prefix, opts)
return scmutil.addremove(self._repo, m, prefix, uipathfn, opts)
@annotatesubrepoerror
def cat(self, match, fm, fntemplate, prefix, **opts):
......
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