# HG changeset patch # User Na'Tosha Bard # Date 1334588619 -7200 # Node ID 290850e7aa436d04662eec5f4990d82dc9f2d0f6 # Parent 28a90cdf0ca00df1de2e7afdd8a0f2c86b7162a3 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. diff -r 28a90cdf0ca0 -r 290850e7aa43 hgext/largefiles/lfcommands.py --- 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 = { diff -r 28a90cdf0ca0 -r 290850e7aa43 hgext/largefiles/overrides.py --- a/hgext/largefiles/overrides.py Mon Apr 16 08:50:40 2012 -0700 +++ b/hgext/largefiles/overrides.py Mon Apr 16 17:03:39 2012 +0200 @@ -966,3 +966,10 @@ finally: repo._istransplanting = False return result + +def overridecat(orig, ui, repo, file1, *pats, **opts): + rev = opts.get('rev') + if not lfutil.standin(file1) in repo[rev]: + result = orig(ui, repo, file1, *pats, **opts) + return result + return lfcommands.catlfile(repo, file1, opts.get('rev'), opts.get('output')) diff -r 28a90cdf0ca0 -r 290850e7aa43 hgext/largefiles/uisetup.py --- a/hgext/largefiles/uisetup.py Mon Apr 16 08:50:40 2012 -0700 +++ b/hgext/largefiles/uisetup.py Mon Apr 16 17:03:39 2012 +0200 @@ -64,6 +64,8 @@ overrides.overrideupdate) entry = extensions.wrapcommand(commands.table, 'pull', overrides.overridepull) + entry = extensions.wrapcommand(commands.table, 'cat', + overrides.overridecat) entry = extensions.wrapfunction(merge, '_checkunknownfile', overrides.overridecheckunknownfile) entry = extensions.wrapfunction(merge, 'manifestmerge', diff -r 28a90cdf0ca0 -r 290850e7aa43 tests/test-largefiles.t --- a/tests/test-largefiles.t Mon Apr 16 08:50:40 2012 -0700 +++ b/tests/test-largefiles.t Mon Apr 16 17:03:39 2012 +0200 @@ -761,6 +761,19 @@ $ cat sub2/large7 large7 +Cat a largefile + $ hg cat normal3 + normal3-modified + $ hg cat sub/large4 + large4-modified + $ rm ${USERCACHE}/* + $ hg cat -r a381d2c8c80e -o cat.out sub/large4 + $ cat cat.out + large4-modified + $ rm cat.out + $ hg cat -r a381d2c8c80e normal3 + normal3-modified + Test that renaming a largefile results in correct output for status $ hg rename sub/large4 large4-renamed