Patchwork [5,of,5] largefiles: don't store whole file in memory for 'cat'

login
register
mail settings
Submitter Mads Kiilerich
Date April 16, 2013, 5:49 p.m.
Message ID <4fdc08a65d5d500ccd52.1366134551@mk-desktop>
Download mbox | patch
Permalink /patch/1356/
State Changes Requested, archived
Headers show

Comments

Mads Kiilerich - April 16, 2013, 5:49 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1365982909 -7200
#      Mon Apr 15 01:41:49 2013 +0200
# Node ID 4fdc08a65d5d500ccd52654354bcae669afdd25a
# Parent  8e823f137a686b159fb67633d161032e53f0dc3c
largefiles: don't store whole file in memory for 'cat'
Mads Kiilerich - April 16, 2013, 10:39 p.m.
Bah - an off-by-one error when patchbombing, revealing a rebase merge error.

The rest of the series still apply.

/Mads

Patch

diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -565,6 +565,24 @@ 
         numcached += len(cached)
     ui.status(_("%d largefiles cached\n") % numcached)
 
+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")
+    for chunk in lfutil.blockstream(fpin):
+        fpout.write(chunk)
+    fpout.close()
+    fpin.close()
+    return 0
+
 # -- hg commands declarations ------------------------------------------------
 
 cmdtable = {