D5901: add: pass around uipathfn and use instead of m.rel() (API)
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Sat Feb 9 22:23:26 UTC 2019
martinvonz updated this revision to Diff 13968.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D5901?vs=13921&id=13968
REVISION DETAIL
https://phab.mercurial-scm.org/D5901
AFFECTED FILES
hgext/largefiles/overrides.py
mercurial/cmdutil.py
mercurial/commands.py
mercurial/scmutil.py
mercurial/subrepo.py
CHANGE DETAILS
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -287,7 +287,7 @@
"""
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 @@
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 @@
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 @@
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 @@
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
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -11,6 +11,7 @@
import glob
import hashlib
import os
+import posixpath
import re
import subprocess
import weakref
@@ -758,6 +759,10 @@
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/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -180,7 +180,8 @@
"""
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/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2027,7 +2027,7 @@
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,21 +2051,24 @@
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):
sub = wctx.sub(subpath)
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/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -235,15 +235,15 @@
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
To: martinvonz, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list