diff hgext/largefiles/lfcommands.py @ 16439:290850e7aa43

largefiles: fix cat for largefiles (issue3352) This is a fix to largefiles so that 'hg cat' will work correctly when a largefile is specified. As per discussion on Issue 3352: 1) The file will be printed regardless if it is binary or large. 2) The file is downloaded if it is not readily available (not found in the system cache), so that it can be printed. If the download fails, then we abort.
author Na'Tosha Bard <natosha@unity3d.com>
date Mon, 16 Apr 2012 17:03:39 +0200
parents d87d9d8a8e03
children ebf6d38c9063
line wrap: on
line diff
--- a/hgext/largefiles/lfcommands.py	Mon Apr 16 08:50:40 2012 -0700
+++ b/hgext/largefiles/lfcommands.py	Mon Apr 16 17:03:39 2012 +0200
@@ -11,7 +11,7 @@
 import os
 import shutil
 
-from mercurial import util, match as match_, hg, node, context, error
+from mercurial import util, match as match_, hg, node, context, error, cmdutil
 from mercurial.i18n import _
 
 import lfutil
@@ -485,6 +485,23 @@
         lfdirstate.drop(lfile)
     return ret
 
+def catlfile(repo, lfile, rev, filename):
+    hash = lfutil.readstandin(repo, lfile, rev)
+    if not lfutil.inusercache(repo.ui, hash):
+        store = basestore._openstore(repo)
+        success, missing = store.get([(lfile, hash)])
+        if len(success) != 1:
+            raise util.Abort(
+                _('largefile %s is not in cache and could not be downloaded')
+                    % lfile)
+    path = lfutil.usercachepath(repo.ui, hash)
+    fpout = cmdutil.makefileobj(repo, filename)
+    fpin = open(path, "rb")
+    fpout.write(fpin.read())
+    fpout.close()
+    fpin.close()
+    return 0
+
 # -- hg commands declarations ------------------------------------------------
 
 cmdtable = {