Patchwork [stable] largefiles: use repo.wwrite for writing standins (issue3909)

login
register
mail settings
Submitter Mads Kiilerich
Date April 26, 2013, 10:47 p.m.
Message ID <2b1b707feb4faeaaa755.1367016423@xps>
Download mbox | patch
Permalink /patch/1488/
State Accepted
Commit 0509ae083ec10f0c2a35d99041efd5e4040a8ed4
Headers show

Comments

Mads Kiilerich - April 26, 2013, 10:47 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1367016102 -7200
#      Sat Apr 27 00:41:42 2013 +0200
# Branch stable
# Node ID 2b1b707feb4faeaaa75597d72168ca71057f29e0
# Parent  a8dc5cfeb82b81fdbeed8576597c11a45960d17b
largefiles: use repo.wwrite for writing standins (issue3909)
Matt Mackall - April 27, 2013, 5:18 p.m.
On Sat, 2013-04-27 at 00:47 +0200, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1367016102 -7200
> #      Sat Apr 27 00:41:42 2013 +0200
> # Branch stable
> # Node ID 2b1b707feb4faeaaa75597d72168ca71057f29e0
> # Parent  a8dc5cfeb82b81fdbeed8576597c11a45960d17b
> largefiles: use repo.wwrite for writing standins (issue3909)

Queued for stable, thanks.

Patch

diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -215,20 +215,12 @@  def _lfconvert_addchangeset(rsrc, rdst, 
                         raise util.Abort(_('largefile %s becomes symlink') % f)
 
                 # largefile was modified, update standins
-                fullpath = rdst.wjoin(f)
-                util.makedirs(os.path.dirname(fullpath))
                 m = util.sha1('')
                 m.update(ctx[f].data())
                 hash = m.hexdigest()
                 if f not in lfiletohash or lfiletohash[f] != hash:
-                    try:
-                        fd = open(fullpath, 'wb')
-                        fd.write(ctx[f].data())
-                    finally:
-                        if fd:
-                            fd.close()
+                    rdst.wwrite(f, ctx[f].data(), ctx[f].flags())
                     executable = 'x' in ctx[f].flags()
-                    os.chmod(fullpath, lfutil.getmode(executable))
                     lfutil.writestandin(rdst, lfutil.standin(f), hash,
                         executable)
                     lfiletohash[f] = hash
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -277,7 +277,7 @@  def readstandin(repo, filename, node=Non
 
 def writestandin(repo, standin, hash, executable):
     '''write hash to <repo.root>/<standin>'''
-    writehash(hash, repo.wjoin(standin), executable)
+    repo.wwrite(standin, hash + '\n', executable and 'x' or '')
 
 def copyandhash(instream, outfile):
     '''Read bytes from instream (iterable) and write them to outfile,
@@ -301,23 +301,12 @@  def hashfile(file):
     fd.close()
     return hasher.hexdigest()
 
-def writehash(hash, filename, executable):
-    util.makedirs(os.path.dirname(filename))
-    util.writefile(filename, hash + '\n')
-    os.chmod(filename, getmode(executable))
-
 def getexecutable(filename):
     mode = os.stat(filename).st_mode
     return ((mode & stat.S_IXUSR) and
             (mode & stat.S_IXGRP) and
             (mode & stat.S_IXOTH))
 
-def getmode(executable):
-    if executable:
-        return 0755
-    else:
-        return 0644
-
 def urljoin(first, second, *arg):
     def join(left, right):
         if not left.endswith('/'):