changeset 41661:f8b18583049f

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
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 07 Feb 2019 11:15:30 -0800
parents 799e156785f7
children b2df5dc3ebfb
files hgext/largefiles/overrides.py mercurial/cmdutil.py mercurial/commands.py mercurial/scmutil.py mercurial/subrepo.py
diffstat 5 files changed, 25 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/overrides.py	Fri Feb 08 10:32:48 2019 -0800
+++ b/hgext/largefiles/overrides.py	Thu Feb 07 11:15:30 2019 -0800
@@ -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
--- a/mercurial/cmdutil.py	Fri Feb 08 10:32:48 2019 -0800
+++ b/mercurial/cmdutil.py	Thu Feb 07 11:15:30 2019 -0800
@@ -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,7 +2051,7 @@
                 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 @@
         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)
--- a/mercurial/commands.py	Fri Feb 08 10:32:48 2019 -0800
+++ b/mercurial/commands.py	Thu Feb 07 11:15:30 2019 -0800
@@ -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',
--- a/mercurial/scmutil.py	Fri Feb 08 10:32:48 2019 -0800
+++ b/mercurial/scmutil.py	Thu Feb 07 11:15:30 2019 -0800
@@ -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.'''
--- a/mercurial/subrepo.py	Fri Feb 08 10:32:48 2019 -0800
+++ b/mercurial/subrepo.py	Thu Feb 07 11:15:30 2019 -0800
@@ -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