Patchwork [3,of,3] purge: prefer util.unlink instead over own removefile

login
register
mail settings
Submitter Christian Ebert
Date Aug. 2, 2014, 8:48 a.m.
Message ID <3703e7ec0657059cb741.1406969313@1.0.0.127.in-addr.arpa>
Download mbox | patch
Permalink /patch/5226/
State Accepted
Headers show

Comments

Christian Ebert - Aug. 2, 2014, 8:48 a.m.
# HG changeset patch
# User Christian Ebert <blacktrash@gmx.net>
# Date 1406969121 -3600
#      Sat Aug 02 09:45:21 2014 +0100
# Node ID 3703e7ec0657059cb741236dac1b6b1e4075e7d5
# Parent  76feb88784ff48008b95faa339f3717debc41137
purge: prefer util.unlink instead over own removefile
Matt Mackall - Aug. 3, 2014, 2:16 a.m.
On Sat, 2014-08-02 at 09:48 +0100, Christian Ebert wrote:
> # HG changeset patch
> # User Christian Ebert <blacktrash@gmx.net>
> # Date 1406969121 -3600
> #      Sat Aug 02 09:45:21 2014 +0100
> # Node ID 3703e7ec0657059cb741236dac1b6b1e4075e7d5
> # Parent  76feb88784ff48008b95faa339f3717debc41137
> purge: prefer util.unlink instead over own removefile

Queued for default, thanks.

Patch

diff -r 76feb88784ff -r 3703e7ec0657 hgext/purge.py
--- a/hgext/purge.py	Sat Aug 02 09:44:45 2014 +0100
+++ b/hgext/purge.py	Sat Aug 02 09:45:21 2014 +0100
@@ -95,17 +95,6 @@  def purge(ui, repo, *dirs, **opts):
         else:
             ui.write('%s%s' % (name, eol))
 
-    def removefile(path):
-        try:
-            os.remove(path)
-        except OSError:
-            # read-only files cannot be unlinked under Windows
-            s = os.stat(path)
-            if (s.st_mode & stat.S_IWRITE) != 0:
-                raise
-            os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE)
-            os.remove(path)
-
     directories = []
     match = scmutil.match(repo[None], dirs, opts)
     match.explicitdir = match.traversedir = directories.append
@@ -115,7 +104,7 @@  def purge(ui, repo, *dirs, **opts):
         for f in sorted(status[4] + status[5]):
             if act:
                 ui.note(_('removing file %s\n') % f)
-            remove(removefile, f)
+            remove(util.unlink, f)
 
     if removedirs:
         for f in sorted(directories, reverse=True):