Patchwork [3,of,3,VFS] subrepo: use vfs.walk instead of os.walk

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 11, 2015, 2:17 p.m.
Message ID <7238eab705505fc7d88d.1428761867@juju>
Download mbox | patch
Permalink /patch/8615/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - April 11, 2015, 2:17 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1428760804 -32400
#      Sat Apr 11 23:00:04 2015 +0900
# Node ID 7238eab705505fc7d88d9a24c020604d3c2f7d86
# Parent  e848285bccb2733268cea52ff5ba94705f8780e5
subrepo: use vfs.walk instead of os.walk

"dirpath" in the tuple yielded by "vfs.walk()" is relative one from
the root of specified vfs, and absolute path in the warning message is
composed by "vfs.join()".

On the other hand, target file "f" exists in "dirpath", and
"reljoin()" is needed to unlink "f" by "vfs.unlink()".
Pierre-Yves David - April 14, 2015, 8:20 p.m.
On 04/11/2015 10:17 AM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1428760804 -32400
> #      Sat Apr 11 23:00:04 2015 +0900
> # Node ID 7238eab705505fc7d88d9a24c020604d3c2f7d86
> # Parent  e848285bccb2733268cea52ff5ba94705f8780e5
> subrepo: use vfs.walk instead of os.walk

These three are pushed to the clowncopter. They appeared to make sense. 
Thanks for the detailled description.

CCing matt as he know more about the vfs plan (but patch was 3 days old)

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -303,7 +303,7 @@  def _abssource(repo, push=False, abort=T
         raise util.Abort(_("default path for subrepository not found"))
 
 def _sanitize(ui, vfs, ignore):
-    for dirname, dirs, names in os.walk(vfs.base):
+    for dirname, dirs, names in vfs.walk():
         for i, d in enumerate(dirs):
             if d.lower() == ignore:
                 del dirs[i]
@@ -313,8 +313,8 @@  def _sanitize(ui, vfs, ignore):
         for f in names:
             if f.lower() == 'hgrc':
                 ui.warn(_("warning: removing potentially hostile 'hgrc' "
-                          "in '%s'\n") % dirname)
-                os.unlink(os.path.join(dirname, f))
+                          "in '%s'\n") % vfs.join(dirname))
+                vfs.unlink(vfs.reljoin(dirname, f))
 
 def subrepo(ctx, path):
     """return instance of the right subrepo class for subrepo in path"""