| 1 |
#require no-windows |
| 2 |
|
| 3 |
$ . "$TESTDIR/remotefilelog-library.sh" |
| 4 |
|
| 5 |
$ hg init master |
| 6 |
$ cd master |
| 7 |
$ cat >> .hg/hgrc <<EOF |
| 8 |
> [remotefilelog] |
| 9 |
> server=True |
| 10 |
> EOF |
| 11 |
$ echo x > x |
| 12 |
$ echo z > z |
| 13 |
$ hg commit -qAm x |
| 14 |
$ echo x2 > x |
| 15 |
$ echo y > y |
| 16 |
$ hg commit -qAm y |
| 17 |
$ hg bookmark foo |
| 18 |
|
| 19 |
$ cd .. |
| 20 |
|
| 21 |
# prefetch a revision |
| 22 |
|
| 23 |
$ hgcloneshallow ssh://user@dummy/master shallow --noupdate |
| 24 |
streaming all changes |
| 25 |
3 files to transfer, 528 bytes of data (no-zstd !) |
| 26 |
stream-cloned 3 files / 528 bytes in * seconds (* */sec) (glob) (no-zstd !) |
| 27 |
3 files to transfer, 533 bytes of data (zstd no-rust !) |
| 28 |
stream-cloned 3 files / 533 bytes in * seconds (* */sec) (glob) (zstd no-rust !) |
| 29 |
5 files to transfer, 659 bytes of data (zstd rust !) |
| 30 |
stream-cloned 5 files / 659 bytes in * seconds (*/sec) (glob) (zstd rust !) |
| 31 |
searching for changes |
| 32 |
no changes found |
| 33 |
$ cd shallow |
| 34 |
|
| 35 |
$ hg prefetch -r 0 |
| 36 |
2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) |
| 37 |
|
| 38 |
$ hg cat -r 0 x |
| 39 |
x |
| 40 |
|
| 41 |
# prefetch with base |
| 42 |
|
| 43 |
$ clearcache |
| 44 |
$ hg prefetch -r 0::1 -b 0 |
| 45 |
2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) |
| 46 |
|
| 47 |
$ hg cat -r 1 x |
| 48 |
x2 |
| 49 |
$ hg cat -r 1 y |
| 50 |
y |
| 51 |
|
| 52 |
$ hg cat -r 0 x |
| 53 |
x |
| 54 |
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
| 55 |
|
| 56 |
$ hg cat -r 0 z |
| 57 |
z |
| 58 |
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
| 59 |
|
| 60 |
$ hg prefetch -r 0::1 --base 0 |
| 61 |
$ hg prefetch -r 0::1 -b 1 |
| 62 |
$ hg prefetch -r 0::1 |
| 63 |
|
| 64 |
# prefetch a range of revisions |
| 65 |
|
| 66 |
$ clearcache |
| 67 |
$ hg prefetch -r 0::1 |
| 68 |
4 files fetched over 1 fetches - (4 misses, 0.00% hit ratio) over *s (glob) |
| 69 |
|
| 70 |
$ hg cat -r 0 x |
| 71 |
x |
| 72 |
$ hg cat -r 1 x |
| 73 |
x2 |
| 74 |
|
| 75 |
# prefetch certain files |
| 76 |
|
| 77 |
$ clearcache |
| 78 |
$ hg prefetch -r 1 x |
| 79 |
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
| 80 |
|
| 81 |
$ hg cat -r 1 x |
| 82 |
x2 |
| 83 |
|
| 84 |
$ hg cat -r 1 y |
| 85 |
y |
| 86 |
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
| 87 |
|
| 88 |
# prefetch on pull when configured |
| 89 |
|
| 90 |
$ printf "[remotefilelog]\npullprefetch=bookmark()\n" >> .hg/hgrc |
| 91 |
$ hg strip tip |
| 92 |
saved backup bundle to $TESTTMP/shallow/.hg/strip-backup/109c3a557a73-3f43405e-backup.hg (glob) |
| 93 |
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
| 94 |
|
| 95 |
$ clearcache |
| 96 |
$ hg pull |
| 97 |
pulling from ssh://user@dummy/master |
| 98 |
searching for changes |
| 99 |
adding changesets |
| 100 |
adding manifests |
| 101 |
adding file changes |
| 102 |
updating bookmark foo |
| 103 |
added 1 changesets with 0 changes to 0 files |
| 104 |
new changesets 109c3a557a73 |
| 105 |
(run 'hg update' to get a working copy) |
| 106 |
prefetching file contents |
| 107 |
3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over *s (glob) |
| 108 |
|
| 109 |
$ hg up tip |
| 110 |
3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 111 |
|
| 112 |
# prefetch only fetches changes not in working copy |
| 113 |
|
| 114 |
$ hg strip tip |
| 115 |
1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 116 |
saved backup bundle to $TESTTMP/shallow/.hg/strip-backup/109c3a557a73-3f43405e-backup.hg (glob) |
| 117 |
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) |
| 118 |
$ clearcache |
| 119 |
|
| 120 |
$ hg pull |
| 121 |
pulling from ssh://user@dummy/master |
| 122 |
searching for changes |
| 123 |
adding changesets |
| 124 |
adding manifests |
| 125 |
adding file changes |
| 126 |
updating bookmark foo |
| 127 |
added 1 changesets with 0 changes to 0 files |
| 128 |
new changesets 109c3a557a73 |
| 129 |
(run 'hg update' to get a working copy) |
| 130 |
prefetching file contents |
| 131 |
2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) |
| 132 |
|
| 133 |
# Make some local commits that produce the same file versions as are on the |
| 134 |
# server. To simulate a situation where we have local commits that were somehow |
| 135 |
# pushed, and we will soon pull. |
| 136 |
|
| 137 |
$ hg prefetch -r 'all()' |
| 138 |
2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) |
| 139 |
$ hg strip -q -r 0 |
| 140 |
$ echo x > x |
| 141 |
$ echo z > z |
| 142 |
$ hg commit -qAm x |
| 143 |
$ echo x2 > x |
| 144 |
$ echo y > y |
| 145 |
$ hg commit -qAm y |
| 146 |
|
| 147 |
# prefetch server versions, even if local versions are available |
| 148 |
|
| 149 |
$ clearcache |
| 150 |
$ hg strip -q tip |
| 151 |
$ hg pull |
| 152 |
pulling from ssh://user@dummy/master |
| 153 |
searching for changes |
| 154 |
adding changesets |
| 155 |
adding manifests |
| 156 |
adding file changes |
| 157 |
updating bookmark foo |
| 158 |
added 1 changesets with 0 changes to 0 files |
| 159 |
new changesets 109c3a557a73 |
| 160 |
1 local changesets published (?) |
| 161 |
(run 'hg update' to get a working copy) |
| 162 |
prefetching file contents |
| 163 |
2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) |
| 164 |
|
| 165 |
$ cd .. |
| 166 |
|
| 167 |
# Prefetch unknown files during checkout |
| 168 |
|
| 169 |
$ hgcloneshallow ssh://user@dummy/master shallow2 |
| 170 |
streaming all changes |
| 171 |
3 files to transfer, 528 bytes of data (no-zstd !) |
| 172 |
stream-cloned 3 files / 528 bytes in * seconds * (glob) (no-zstd !) |
| 173 |
3 files to transfer, 533 bytes of data (zstd no-rust !) |
| 174 |
stream-cloned 3 files / 533 bytes in * seconds (* */sec) (glob) (zstd no-rust !) |
| 175 |
5 files to transfer, 659 bytes of data (zstd rust !) |
| 176 |
stream-cloned 5 files / 659 bytes in * seconds (*/sec) (glob) (zstd rust !) |
| 177 |
searching for changes |
| 178 |
no changes found |
| 179 |
updating to branch default |
| 180 |
3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 181 |
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over * (glob) |
| 182 |
$ cd shallow2 |
| 183 |
$ hg up -q null |
| 184 |
$ echo x > x |
| 185 |
$ echo y > y |
| 186 |
$ echo z > z |
| 187 |
$ clearcache |
| 188 |
$ hg up tip |
| 189 |
x: untracked file differs |
| 190 |
3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over * (glob) |
| 191 |
abort: untracked files in working directory differ from files in requested revision |
| 192 |
[20] |
| 193 |
$ hg revert --all |
| 194 |
|
| 195 |
# Test batch fetching of lookup files during hg status |
| 196 |
$ hg up --clean tip |
| 197 |
3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 198 |
$ hg debugrebuilddirstate |
| 199 |
$ clearcache |
| 200 |
$ hg status |
| 201 |
3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over * (glob) |
| 202 |
|
| 203 |
# Prefetch during addrename detection |
| 204 |
$ hg up -q --clean tip |
| 205 |
$ hg revert --all |
| 206 |
$ mv x x2 |
| 207 |
$ mv y y2 |
| 208 |
$ mv z z2 |
| 209 |
$ echo a > a |
| 210 |
$ hg add a |
| 211 |
$ rm a |
| 212 |
$ clearcache |
| 213 |
$ hg addremove -s 50 > /dev/null |
| 214 |
3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over * (glob) |
| 215 |
$ hg revert --all |
| 216 |
forgetting x2 |
| 217 |
forgetting y2 |
| 218 |
forgetting z2 |
| 219 |
undeleting x |
| 220 |
undeleting y |
| 221 |
undeleting z |
| 222 |
|
| 223 |
|
| 224 |
# Revert across double renames. Note: the scary "abort", error is because |
| 225 |
# https://bz.mercurial-scm.org/5419 . |
| 226 |
|
| 227 |
$ cd ../master |
| 228 |
$ hg mv z z2 |
| 229 |
$ hg commit -m 'move z -> z2' |
| 230 |
$ cd ../shallow2 |
| 231 |
$ hg pull -q |
| 232 |
$ clearcache |
| 233 |
$ hg mv y y2 |
| 234 |
y2: not overwriting - file exists |
| 235 |
('hg rename --after' to record the rename) |
| 236 |
[1] |
| 237 |
$ hg mv x x2 |
| 238 |
x2: not overwriting - file exists |
| 239 |
('hg rename --after' to record the rename) |
| 240 |
[1] |
| 241 |
$ hg mv z2 z3 |
| 242 |
z2: not copying - file is not managed |
| 243 |
abort: no files to copy |
| 244 |
(maybe you meant to use --after --at-rev=.) |
| 245 |
[10] |
| 246 |
$ find $CACHEDIR -type f | sort |
| 247 |
.. The following output line about files fetches is globed because it is |
| 248 |
.. flaky, the core the test is checked when checking the cache dir, so |
| 249 |
.. hopefully this flakyness is not hiding any actual bug. |
| 250 |
$ hg revert -a -r 1 || true |
| 251 |
? files fetched over 1 fetches - (? misses, 0.00% hit ratio) over * (glob) |
| 252 |
abort: z2@109c3a557a73: not found in manifest (?) |
| 253 |
$ find $CACHEDIR -type f | sort |
| 254 |
$TESTTMP/hgcache/master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/ef95c5376f34698742fe34f315fd82136f8f68c0 |
| 255 |
$TESTTMP/hgcache/master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a |
| 256 |
$TESTTMP/hgcache/master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca |
| 257 |
$TESTTMP/hgcache/repos |
| 258 |
|
| 259 |
# warning when we have excess remotefilelog fetching |
| 260 |
|
| 261 |
$ cat > repeated_fetch.py << EOF |
| 262 |
> import binascii |
| 263 |
> from mercurial import extensions, registrar |
| 264 |
> cmdtable = {} |
| 265 |
> command = registrar.command(cmdtable) |
| 266 |
> @command(b'repeated-fetch', [], b'', inferrepo=True) |
| 267 |
> def repeated_fetch(ui, repo, *args, **opts): |
| 268 |
> for i in range(20): |
| 269 |
> try: |
| 270 |
> hexid = (b'%02x' % (i + 1)) * 20 |
| 271 |
> repo.fileservice.prefetch([(b'somefile.txt', hexid)]) |
| 272 |
> except Exception: |
| 273 |
> pass |
| 274 |
> EOF |
| 275 |
|
| 276 |
We should only output to the user once. We're ignoring most of the output |
| 277 |
because we're not actually fetching anything real here, all the hashes are |
| 278 |
bogus, so it's just going to be errors and a final summary of all the misses. |
| 279 |
$ hg --config extensions.repeated_fetch=repeated_fetch.py \ |
| 280 |
> --config remotefilelog.fetchwarning="fetch warning!" \ |
| 281 |
> --config extensions.blackbox= \ |
| 282 |
> repeated-fetch 2>&1 | grep 'fetch warning' |
| 283 |
fetch warning! |
| 284 |
|
| 285 |
We should output to blackbox three times, with a stack trace on each (though |
| 286 |
that isn't tested here). |
| 287 |
$ grep 'excess remotefilelog fetching' .hg/blackbox.log |
| 288 |
.* excess remotefilelog fetching: (re) |
| 289 |
.* excess remotefilelog fetching: (re) |
| 290 |
.* excess remotefilelog fetching: (re) |