Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 42478:561cd02c58ff
cat: don't prefetch files unless the output requires it
It's a waste to cache lfs blobs when cat'ing the raw data at best, but a hassle
debugging when the blob is missing. I'm not sure if there are other commands
that have '{data}' for output, and if there's a general way to prefetch on that
keyword.
It's interesting that the verbose output seems to leak into the JSON output, but
that seems like an existing bug.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 04 Oct 2018 00:57:11 -0400 |
parents | 307f67d4aee3 |
children | 5f2f6912c9e6 |
comparison
equal
deleted
inserted
replaced
42477:e658ac39fe41 | 42478:561cd02c58ff |
---|---|
2351 for warning in warnings: | 2351 for warning in warnings: |
2352 ui.warn(warning) | 2352 ui.warn(warning) |
2353 | 2353 |
2354 return ret | 2354 return ret |
2355 | 2355 |
2356 def _catfmtneedsdata(fm): | |
2357 return not fm.datahint() or 'data' in fm.datahint() | |
2358 | |
2356 def _updatecatformatter(fm, ctx, matcher, path, decode): | 2359 def _updatecatformatter(fm, ctx, matcher, path, decode): |
2357 """Hook for adding data to the formatter used by ``hg cat``. | 2360 """Hook for adding data to the formatter used by ``hg cat``. |
2358 | 2361 |
2359 Extensions (e.g., lfs) can wrap this to inject keywords/data, but must call | 2362 Extensions (e.g., lfs) can wrap this to inject keywords/data, but must call |
2360 this method first.""" | 2363 this method first.""" |
2361 data = ctx[path].data() | 2364 |
2362 if decode: | 2365 # data() can be expensive to fetch (e.g. lfs), so don't fetch it if it |
2363 data = ctx.repo().wwritedata(path, data) | 2366 # wasn't requested. |
2367 data = b'' | |
2368 if _catfmtneedsdata(fm): | |
2369 data = ctx[path].data() | |
2370 if decode: | |
2371 data = ctx.repo().wwritedata(path, data) | |
2364 fm.startitem() | 2372 fm.startitem() |
2365 fm.context(ctx=ctx) | 2373 fm.context(ctx=ctx) |
2366 fm.write('data', '%s', data) | 2374 fm.write('data', '%s', data) |
2367 fm.data(path=path) | 2375 fm.data(path=path) |
2368 | 2376 |
2389 file = matcher.files()[0] | 2397 file = matcher.files()[0] |
2390 mfl = repo.manifestlog | 2398 mfl = repo.manifestlog |
2391 mfnode = ctx.manifestnode() | 2399 mfnode = ctx.manifestnode() |
2392 try: | 2400 try: |
2393 if mfnode and mfl[mfnode].find(file)[0]: | 2401 if mfnode and mfl[mfnode].find(file)[0]: |
2394 scmutil.prefetchfiles(repo, [ctx.rev()], matcher) | 2402 if _catfmtneedsdata(basefm): |
2403 scmutil.prefetchfiles(repo, [ctx.rev()], matcher) | |
2395 write(file) | 2404 write(file) |
2396 return 0 | 2405 return 0 |
2397 except KeyError: | 2406 except KeyError: |
2398 pass | 2407 pass |
2399 | 2408 |
2400 scmutil.prefetchfiles(repo, [ctx.rev()], matcher) | 2409 if _catfmtneedsdata(basefm): |
2410 scmutil.prefetchfiles(repo, [ctx.rev()], matcher) | |
2401 | 2411 |
2402 for abs in ctx.walk(matcher): | 2412 for abs in ctx.walk(matcher): |
2403 write(abs) | 2413 write(abs) |
2404 err = 0 | 2414 err = 0 |
2405 | 2415 |