##// END OF EJS Templates
cat: don't prefetch files unless the output requires it...
Matt Harbison -
r42678:561cd02c default
parent child Browse files
Show More
@@ -2353,14 +2353,22 b' def remove(ui, repo, m, prefix, uipathfn'
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)
@@ -2391,13 +2399,15 b' def cat(ui, repo, ctx, matcher, basefm, '
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)
@@ -537,8 +537,55 b' Misc: process dies early if a requiremen'
537
537
538 $ hg clone -qU http://localhost:$HGPORT $TESTTMP/bulkfetch
538 $ hg clone -qU http://localhost:$HGPORT $TESTTMP/bulkfetch
539
539
540 Cat doesn't prefetch unless data is needed (e.g. '-T {rawdata}' doesn't need it)
541
542 $ hg --cwd $TESTTMP/bulkfetch cat -vr tip lfspair1.bin -T '{rawdata}\n{path}\n'
543 lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
544 version https://git-lfs.github.com/spec/v1
545 oid sha256:cf1b2787b74e66547d931b6ebe28ff63303e803cb2baa14a8f57c4383d875782
546 size 20
547 x-is-binary 0
548
549 lfspair1.bin
550
551 $ hg --cwd $TESTTMP/bulkfetch cat -vr tip lfspair1.bin -T json
552 lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
553 [lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
554 lfs: downloading cf1b2787b74e66547d931b6ebe28ff63303e803cb2baa14a8f57c4383d875782 (20 bytes)
555 lfs: processed: cf1b2787b74e66547d931b6ebe28ff63303e803cb2baa14a8f57c4383d875782
556 lfs: downloaded 1 files (20 bytes)
557 lfs: found cf1b2787b74e66547d931b6ebe28ff63303e803cb2baa14a8f57c4383d875782 in the local lfs store
558
559 {
560 "data": "this is an lfs file\n",
561 "path": "lfspair1.bin",
562 "rawdata": "version https://git-lfs.github.com/spec/v1\noid sha256:cf1b2787b74e66547d931b6ebe28ff63303e803cb2baa14a8f57c4383d875782\nsize 20\nx-is-binary 0\n"
563 }
564 ]
565
566 $ rm -r $TESTTMP/bulkfetch/.hg/store/lfs
567
568 $ hg --cwd $TESTTMP/bulkfetch cat -vr tip lfspair1.bin -T '{data}\n'
569 lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
570 lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
571 lfs: downloading cf1b2787b74e66547d931b6ebe28ff63303e803cb2baa14a8f57c4383d875782 (20 bytes)
572 lfs: processed: cf1b2787b74e66547d931b6ebe28ff63303e803cb2baa14a8f57c4383d875782
573 lfs: downloaded 1 files (20 bytes)
574 lfs: found cf1b2787b74e66547d931b6ebe28ff63303e803cb2baa14a8f57c4383d875782 in the local lfs store
575 this is an lfs file
576
577 $ hg --cwd $TESTTMP/bulkfetch cat -vr tip lfspair2.bin
578 lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
579 lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
580 lfs: downloading d96eda2c74b56e95cfb5ffb66b6503e198cc6fc4a09dc877de925feebc65786e (24 bytes)
581 lfs: processed: d96eda2c74b56e95cfb5ffb66b6503e198cc6fc4a09dc877de925feebc65786e
582 lfs: downloaded 1 files (24 bytes)
583 lfs: found d96eda2c74b56e95cfb5ffb66b6503e198cc6fc4a09dc877de925feebc65786e in the local lfs store
584 this is an lfs file too
585
540 Export will prefetch all needed files across all needed revisions
586 Export will prefetch all needed files across all needed revisions
541
587
588 $ rm -r $TESTTMP/bulkfetch/.hg/store/lfs
542 $ hg -R $TESTTMP/bulkfetch -v export -r 0:tip -o all.export
589 $ hg -R $TESTTMP/bulkfetch -v export -r 0:tip -o all.export
543 lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
590 lfs: assuming remote store: http://localhost:$HGPORT/.git/info/lfs
544 exporting patches:
591 exporting patches:
General Comments 0
You need to be logged in to leave comments. Login now