tests/test-cat.t
author Pierre-Yves David <pierre-yves.david@octobus.net>
Sun, 14 Apr 2024 02:33:36 +0200
changeset 51587 8cd317c033b8
parent 49621 55c6ebd11cb9
permissions -rw-r--r--
stream-clone: disable gc for the entry listing section for the v2 format This is similar to the change we did for the v3 format in 6e4c8366c5ce. The benchmark bellow show this gives us a notable gains, especially on larger repositories. ### benchmark.name = hg.perf.stream-locked-section # benchmark.name = hg.perf.stream-locked-section # bin-env-vars.hg.flavor = default # bin-env-vars.hg.py-re2-module = default # benchmark.variants.version = v2 ## data-env-vars.name = pypy-2018-08-01-zstd-sparse-revlog 5e931bf8707c: 0.503820 ~~~~~ 1106d1bf695e: 0.470078 (-6.70%, -0.03) ## data-env-vars.name = pypy-2024-03-22-zstd-sparse-revlog 5e931bf8707c: 0.535756 ~~~~~ 1106d1bf695e: 0.490249 (-8.49%, -0.05) ## data-env-vars.name = heptapod-public-2024-03-25-zstd-sparse-revlog 5e931bf8707c: 1.327041 ~~~~~ 1106d1bf695e: 1.174636 (-11.48%, -0.15) ## data-env-vars.name = netbeans-2018-08-01-zstd-sparse-revlog 5e931bf8707c: 2.439158 ~~~~~ 1106d1bf695e: 2.220515 (-8.96%, -0.22) ## data-env-vars.name = netbeans-2019-11-07-zstd-sparse-revlog 5e931bf8707c: 2.630794 ~~~~~ 1106d1bf695e: 2.261473 (-14.04%, -0.37) ## data-env-vars.name = mozilla-central-2018-08-01-zstd-sparse-revlog 5e931bf8707c: 5.769002 ~~~~~ 1106d1bf695e: 5.062000 (-12.26%, -0.71) ## data-env-vars.name = mozilla-try-2019-02-18-zstd-sparse-revlog 5e931bf8707c: 13.351750 ~~~~~ 1106d1bf695e: 12.346655 (-7.53%, -1.01) ## data-env-vars.name = mozilla-central-2024-03-22-zstd-sparse-revlog 5e931bf8707c: 10.772939 ~~~~~ 1106d1bf695e: 9.495407 (-11.86%, -1.28) ## data-env-vars.name = mozilla-unified-2024-03-22-zstd-sparse-revlog 5e931bf8707c: 10.864297 ~~~~~ 1106d1bf695e: 9.475597 (-12.78%, -1.39) ## data-env-vars.name = mozilla-try-2023-03-22-zstd-sparse-revlog 5e931bf8707c: 17.448335 ~~~~~ 1106d1bf695e: 16.027474 (-8.14%, -1.42)

  $ hg init repo
  $ cd repo
  $ echo 0 > a
  $ echo 0 > b
  $ hg ci -A -m m
  adding a
  adding b
  $ hg rm a
  $ hg cat a
  0
  $ hg cat --decode a # more tests in test-encode
  0
  $ echo 1 > b
  $ hg ci -m m
  $ echo 2 > b
  $ hg cat -r 0 a
  0
  $ hg cat -r 0 b
  0
  $ hg cat -r 1 a
  a: no such file in rev 7040230c159c
  [1]
  $ hg cat -r 1 b
  1

Test multiple files

  $ echo 3 > c
  $ hg ci -Am addmore c
  $ hg cat b c
  1
  3
  $ hg cat .
  1
  3
  $ hg cat . c
  1
  3

Test fileset

  $ hg cat 'set:not(b) or a'
  3
  $ hg cat 'set:c or b'
  1
  3

  $ mkdir tmp
  $ hg cat --output tmp/HH_%H c
  $ hg cat --output tmp/RR_%R c
  $ hg cat --output tmp/h_%h c
  $ hg cat --output tmp/r_%r c
  $ hg cat --output tmp/%s_s c
  $ hg cat --output tmp/%d%%_d c
  $ hg cat --output tmp/%p_p c
  $ hg log -r . --template "{rev}: {node|short}\n"
  2: 45116003780e
  $ find tmp -type f | sort
  tmp/.%_d
  tmp/HH_45116003780e3678b333fb2c99fa7d559c8457e9
  tmp/RR_2
  tmp/c_p
  tmp/c_s
  tmp/h_45116003780e
  tmp/r_2

Test template output

  $ hg --cwd tmp cat ../b ../c -T '== {path|relpath} ({path}) r{rev} ==\n{data}'
  == ../b (b) r2 ==
  1
  == ../c (c) r2 ==
  3

  $ hg cat b c -Tjson --output -
  [
   {
    "data": "1\n",
    "path": "b"
   },
   {
    "data": "3\n",
    "path": "c"
   }
  ]

  $ hg cat b c -Tjson --output 'tmp/%p.json'
  $ cat tmp/b.json
  [
   {
    "data": "1\n",
    "path": "b"
   }
  ]
  $ cat tmp/c.json
  [
   {
    "data": "3\n",
    "path": "c"
   }
  ]

Test working directory

  $ echo b-wdir > b
  $ hg cat -r 'wdir()' b
  b-wdir

Environment variables are not visible by default

  $ PATTERN='t4' hg log -r '.' -T "{ifcontains('PATTERN', envvars, 'yes', 'no')}\n"
  no

Environment variable visibility can be explicit

  $ PATTERN='t4' hg log -r '.' -T "{envvars % '{key} -> {value}\n'}" \
  >                 --config "experimental.exportableenviron=PATTERN"
  PATTERN -> t4

Test behavior of output when directory structure does not already exist

  $ mkdir foo
  $ echo a > foo/a
  $ hg add foo/a
  $ hg commit -qm "add foo/a"
  $ hg cat --output "output/%p" foo/a
  $ cat output/foo/a
  a