# HG changeset patch # User Martin von Zweigbergk # Date 2019-02-07 19:15:30 # Node ID f8b18583049fbb9445f019ae818c260c85bb049f # Parent 799e156785f728fe99a28119314ef556b42baa9c add: pass around uipathfn and use instead of m.rel() (API) For now, the uipathfn we pass around always prints relative paths just like before, so this should have no effect. Well, there's one little change: I also made the "skipping missing subrepository: %s\n" message relative. Differential Revision: https://phab.mercurial-scm.org/D5901 diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py --- a/hgext/largefiles/overrides.py +++ b/hgext/largefiles/overrides.py @@ -235,15 +235,15 @@ def overrideadd(orig, ui, repo, *pats, * return orig(ui, repo, *pats, **opts) @eh.wrapfunction(cmdutil, 'add') -def cmdutiladd(orig, ui, repo, matcher, prefix, explicitonly, **opts): +def cmdutiladd(orig, ui, repo, matcher, prefix, uipathfn, explicitonly, **opts): # The --normal flag short circuits this override if opts.get(r'normal'): - return orig(ui, repo, matcher, prefix, explicitonly, **opts) + return orig(ui, repo, matcher, prefix, uipathfn, explicitonly, **opts) ladded, lbad = addlargefiles(ui, repo, False, matcher, **opts) normalmatcher = composenormalfilematcher(matcher, repo[None].manifest(), ladded) - bad = orig(ui, repo, normalmatcher, prefix, explicitonly, **opts) + bad = orig(ui, repo, normalmatcher, prefix, uipathfn, explicitonly, **opts) bad.extend(f for f in lbad) return bad diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2027,7 +2027,7 @@ def walkchangerevs(repo, match, opts, pr return iterate() -def add(ui, repo, match, prefix, explicitonly, **opts): +def add(ui, repo, match, prefix, uipathfn, explicitonly, **opts): bad = [] badfn = lambda x, y: bad.append(x) or match.bad(x, y) @@ -2051,7 +2051,7 @@ def add(ui, repo, match, prefix, explici cca(f) names.append(f) if ui.verbose or not exact: - ui.status(_('adding %s\n') % match.rel(f), + ui.status(_('adding %s\n') % uipathfn(f), label='ui.addremove.added') for subpath in sorted(wctx.substate): @@ -2059,13 +2059,16 @@ def add(ui, repo, match, prefix, explici try: submatch = matchmod.subdirmatcher(subpath, match) subprefix = repo.wvfs.reljoin(prefix, subpath) + subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) if opts.get(r'subrepos'): - bad.extend(sub.add(ui, submatch, subprefix, False, **opts)) + bad.extend(sub.add(ui, submatch, subprefix, subuipathfn, False, + **opts)) else: - bad.extend(sub.add(ui, submatch, subprefix, True, **opts)) + bad.extend(sub.add(ui, submatch, subprefix, subuipathfn, True, + **opts)) except error.LookupError: ui.status(_("skipping missing subrepository: %s\n") - % match.rel(subpath)) + % uipathfn(subpath)) if not opts.get(r'dry_run'): rejected = wctx.add(names, prefix) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -180,7 +180,8 @@ def add(ui, repo, *pats, **opts): """ m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts)) - rejected = cmdutil.add(ui, repo, m, "", False, **opts) + uipathfn = scmutil.getuipathfn(repo, forcerelativevalue=True) + rejected = cmdutil.add(ui, repo, m, "", uipathfn, False, **opts) return rejected and 1 or 0 @command('addremove', diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -11,6 +11,7 @@ import errno import glob import hashlib import os +import posixpath import re import subprocess import weakref @@ -758,6 +759,10 @@ def getuipathfn(repo, legacyrelativevalu else: return lambda f: f +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 expandpats(pats): '''Expand bare globs when running on windows. On posix we assume it already has already been done by sh.''' diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -287,7 +287,7 @@ class abstractsubrepo(object): """ raise NotImplementedError - def add(self, ui, match, prefix, explicitonly, **opts): + def add(self, ui, match, prefix, uipathfn, explicitonly, **opts): return [] def addremove(self, matcher, prefix, opts): @@ -516,8 +516,9 @@ class hgsubrepo(abstractsubrepo): self._repo.vfs.write('hgrc', util.tonativeeol(''.join(lines))) @annotatesubrepoerror - def add(self, ui, match, prefix, explicitonly, **opts): - return cmdutil.add(ui, self._repo, match, prefix, explicitonly, **opts) + def add(self, ui, match, prefix, uipathfn, explicitonly, **opts): + return cmdutil.add(ui, self._repo, match, prefix, uipathfn, + explicitonly, **opts) @annotatesubrepoerror def addremove(self, m, prefix, opts): @@ -1590,7 +1591,7 @@ class gitsubrepo(abstractsubrepo): return False @annotatesubrepoerror - def add(self, ui, match, prefix, explicitonly, **opts): + def add(self, ui, match, prefix, uipathfn, explicitonly, **opts): if self._gitmissing(): return [] @@ -1614,7 +1615,7 @@ class gitsubrepo(abstractsubrepo): if exact: command.append("-f") #should be added, even if ignored if ui.verbose or not exact: - ui.status(_('adding %s\n') % match.rel(f)) + ui.status(_('adding %s\n') % uipathfn(f)) if f in tracked: # hg prints 'adding' even if already tracked if exact: @@ -1624,7 +1625,7 @@ class gitsubrepo(abstractsubrepo): self._gitcommand(command + [f]) for f in rejected: - ui.warn(_("%s already tracked!\n") % match.rel(f)) + ui.warn(_("%s already tracked!\n") % uipathfn(f)) return rejected