largefiles: simplify lfutil.writehash
authorMartin Geisler <mg@aragost.com>
Thu, 24 Nov 2011 18:22:45 +0100
changeset 15574 c9328c829cd9
parent 15573 a5e5c64cd90b
child 15577 ad686c818e1c
largefiles: simplify lfutil.writehash This was unnecessarily verbose: there is no need to unlink the file when we open it for write anyway, and there is no need to check if the file exists after we created it.
hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py	Thu Nov 24 18:22:44 2011 +0100
+++ b/hgext/largefiles/lfutil.py	Thu Nov 24 18:22:45 2011 +0100
@@ -393,17 +393,8 @@
 
 def writehash(hash, filename, executable):
     util.makedirs(os.path.dirname(filename))
-    if os.path.exists(filename):
-        os.unlink(filename)
-    wfile = open(filename, 'wb')
-
-    try:
-        wfile.write(hash)
-        wfile.write('\n')
-    finally:
-        wfile.close()
-    if os.path.exists(filename):
-        os.chmod(filename, getmode(executable))
+    util.writefile(filename, hash + '\n')
+    os.chmod(filename, getmode(executable))
 
 def getexecutable(filename):
     mode = os.stat(filename).st_mode