diff --git a/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -519,7 +519,11 @@ 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() diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py --- a/hgext/largefiles/overrides.py +++ b/hgext/largefiles/overrides.py @@ -1225,11 +1225,11 @@ 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 @@ # 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. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2391,7 +2391,9 @@ 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 @@ # 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")) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -255,7 +255,9 @@ 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')), diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -763,6 +763,14 @@ '''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 @@ 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 @@ 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 @@ 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) diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -290,7 +290,7 @@ 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 @@ 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):