Patchwork [2,of,7] vfs: factor out "rename and avoid ambiguity" to reuse

login
register
mail settings
Submitter Katsunori FUJIWARA
Date June 9, 2017, 4:08 a.m.
Message ID <5ae5c4d392374e41d489.1496981302@speaknoevil>
Download mbox | patch
Permalink /patch/21261/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - June 9, 2017, 4:08 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1496980698 -32400
#      Fri Jun 09 12:58:18 2017 +0900
# Node ID 5ae5c4d392374e41d489d87a9d7c1a85920e0702
# Parent  eff387e5c445cb7270dc72e5140dcb96e9a07bf9
vfs: factor out "rename and avoid ambiguity" to reuse

This makes subsequent patch simple.

Patch

diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -177,11 +177,14 @@  class abstractvfs(object):
         dstpath = self.join(dst)
         oldstat = checkambig and util.filestat(dstpath)
         if oldstat and oldstat.stat:
-            ret = util.rename(self.join(src), dstpath)
-            newstat = util.filestat(dstpath)
-            if newstat.isambig(oldstat):
-                # stat of renamed file is ambiguous to original one
-                newstat.avoidambig(dstpath, oldstat)
+            def dorename(spath, dpath):
+                ret = util.rename(spath, dpath)
+                newstat = util.filestat(dpath)
+                if newstat.isambig(oldstat):
+                    # stat of renamed file is ambiguous to original one
+                    return ret, newstat.avoidambig(dpath, oldstat)
+                return ret, True
+            ret, avoided = dorename(self.join(src), dstpath)
             return ret
         return util.rename(self.join(src), dstpath)