Patchwork [2,of,3] narrowmatcher: propagate the rel() method

login
register
mail settings
Submitter Matt Harbison
Date Dec. 30, 2014, 1:38 a.m.
Message ID <1f18e86a4d081a4d5217.1419903491@Envy>
Download mbox | patch
Permalink /patch/7259/
State Accepted
Delegated to: Matt Mackall
Headers show

Comments

Matt Harbison - Dec. 30, 2014, 1:38 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1417101416 18000
#      Thu Nov 27 10:16:56 2014 -0500
# Node ID 1f18e86a4d081a4d5217cd78cd9d92d060996be4
# Parent  1b2a6db6a8a039aa6d1a69e5e7e4b73e9c9bc50f
narrowmatcher: propagate the rel() method

The full path is propagated to the original match object since this is often
used directly for printing a file name to the user.  This is cleaner than
requiring each caller to join the prefix with the file name prior to calling it,
and will lead to not having to pass the prefix around separately.  It is also
consistent with the bad() and abs() methods in terms of the required input.  The
uipath() method now inherits this path building property.

There is no visible change in path style for rel() because it ultimately calls
util.pathto(), which returns an os.sep based path.  (The previous os.path.join()
was violating the documented usage of util.pathto(), that its third parameter be
'/' separated.)  The doctest needed to be normalized to '/' separators to avoid
test differences on Windows, now that a full path is returned for a short
filename.

The test changes are to drop globs that are no longer necessary when printing an
absolute file in a subrepo, as returned from match.uipath().  Previously when
os.path.join() was used to add the prefix, the absolute path to a file in a
subrepo was printed with a mix of '/' and '\'.  The absolute path for a file not
in a subrepo, as returned from match.uipath(), is still purely '/' based.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1991,7 +1991,7 @@ 
                 cca(f)
             names.append(f)
             if ui.verbose or not exact:
-                ui.status(_('adding %s\n') % match.rel(join(f)))
+                ui.status(_('adding %s\n') % match.rel(f))
 
     for subpath in sorted(wctx.substate):
         sub = wctx.sub(subpath)
@@ -2042,12 +2042,12 @@ 
                     if repo.wvfs.exists(f):
                         ui.warn(_('not removing %s: '
                                   'file is already untracked\n')
-                                % match.rel(join(f)))
+                                % match.rel(f))
                     bad.append(f)
 
     for f in forget:
         if ui.verbose or not match.exact(f):
-            ui.status(_('removing %s\n') % match.rel(join(f)))
+            ui.status(_('removing %s\n') % match.rel(f))
 
     rejected = wctx.forget(forget, prefix)
     bad.extend(f for f in rejected if f in match.files())
@@ -2095,10 +2095,10 @@ 
         if repo.wvfs.exists(f):
             if repo.wvfs.isdir(f):
                 ui.warn(_('not removing %s: no tracked files\n')
-                        % m.rel(join(f)))
+                        % m.rel(f))
             else:
                 ui.warn(_('not removing %s: file is untracked\n')
-                        % m.rel(join(f)))
+                        % m.rel(f))
         # missing files will generate a warning elsewhere
         ret = 1
 
@@ -2107,22 +2107,22 @@ 
     elif after:
         list = deleted
         for f in modified + added + clean:
-            ui.warn(_('not removing %s: file still exists\n') % m.rel(join(f)))
+            ui.warn(_('not removing %s: file still exists\n') % m.rel(f))
             ret = 1
     else:
         list = deleted + clean
         for f in modified:
             ui.warn(_('not removing %s: file is modified (use -f'
-                      ' to force removal)\n') % m.rel(join(f)))
+                      ' to force removal)\n') % m.rel(f))
             ret = 1
         for f in added:
             ui.warn(_('not removing %s: file has been marked for add'
-                      ' (use forget to undo)\n') % m.rel(join(f)))
+                      ' (use forget to undo)\n') % m.rel(f))
             ret = 1
 
     for f in sorted(list):
         if ui.verbose or not m.exact(f):
-            ui.status(_('removing %s\n') % m.rel(join(f)))
+            ui.status(_('removing %s\n') % m.rel(f))
 
     wlock = repo.wlock()
     try:
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -138,7 +138,7 @@ 
         '''Convert repo path to a display path.  If patterns or -I/-X were used
         to create this matcher, the display path will be relative to cwd.
         Otherwise it is relative to the root of the repo.'''
-        return (self._pathrestricted and self.rel(f)) or f
+        return (self._pathrestricted and self.rel(f)) or self.abs(f)
 
     def files(self):
         '''Explicitly listed files or patterns or roots:
@@ -186,8 +186,8 @@ 
     ['b.txt']
     >>> m2.exact('b.txt')
     True
-    >>> m2.rel('b.txt')
-    'b.txt'
+    >>> util.pconvert(m2.rel('b.txt'))
+    'sub/b.txt'
     >>> def bad(f, msg):
     ...     print "%s: %s" % (f, msg)
     >>> m1.bad = bad
@@ -217,6 +217,9 @@ 
     def bad(self, f, msg):
         self._matcher.bad(self._path + "/" + f, msg)
 
+    def rel(self, f):
+        return self._matcher.rel(self._path + "/" + f)
+
 def patkind(pattern, default=None):
     '''If pattern is 'kind:pat' with a known kind, return kind.'''
     return _patsplit(pattern, default)[0]
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -773,9 +773,9 @@ 
     for abs in sorted(toprint):
         if repo.ui.verbose or not m.exact(abs):
             if abs in unknownset:
-                status = _('adding %s\n') % m.uipath(join(abs))
+                status = _('adding %s\n') % m.uipath(abs)
             else:
-                status = _('removing %s\n') % m.uipath(join(abs))
+                status = _('removing %s\n') % m.uipath(abs)
             repo.ui.status(status)
 
     renames = _findrenames(repo, m, added + unknown, removed + deleted,
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -107,7 +107,7 @@ 
   $ mkdir sub1/sub2/folder
   $ echo 'subfolder' > sub1/sub2/folder/test.txt
   $ hg ci -ASm "add test.txt"
-  adding sub1/sub2/folder/test.txt (glob)
+  adding sub1/sub2/folder/test.txt
   committing subrepository sub1
   committing subrepository sub1/sub2 (glob)
 
@@ -162,10 +162,10 @@ 
   $ rm sub1/sub2/folder/test.txt
   $ rm sub1/sub2/test.txt
   $ hg ci -ASm "remove test.txt"
-  adding sub1/sub2/folder/bar (glob)
-  removing sub1/sub2/folder/test.txt (glob)
-  removing sub1/sub2/test.txt (glob)
-  adding sub1/foo (glob)
+  adding sub1/sub2/folder/bar
+  removing sub1/sub2/folder/test.txt
+  removing sub1/sub2/test.txt
+  adding sub1/foo
   adding foo/bar/abc
   committing subrepository sub1
   committing subrepository sub1/sub2 (glob)