Mercurial > hg
annotate tests/test-parseindex.t @ 24725:ee751d47cf2c
vfs: add walk
To eliminate "path prefix" (= "the root of vfs") part from "dirpath"
yielded by "os.walk()" correctly, "path prefix" should have "os.sep"
at the end of own string, but it isn't easy to ensure it, because:
- examination by "path.endswith(os.sep)" isn't portable
Some problematic encodings use 0x5c (= "os.sep" on Windows) as the
tail byte of some multi-byte characters.
- "os.path.join(path, '')" isn't portable
With Python 2.7.9, this invocation doesn't add "os.sep" at the end
of UNC path (see issue4557 for detail).
Python 2.7.9 changed also behavior of "os.path.normpath()" (see *) and
"os.path.splitdrive()" for UNC path.
vfs root normpath splitdrive os.sep required
=============== ============== =================== ============
z:\ z:\ z: + \ no
z:\foo z:\foo z: + \foo yes
z:\foo\ z:\foo z: + \foo yes
[before Python 2.7.9]
\\foo\bar \\foo\bar '' + \\foo\bar yes
\\foo\bar\ \\foo\bar (*) '' + \\foo\bar yes
\\foo\bar\baz \\foo\bar\baz '' + \\foo\bar\baz yes
\\foo\bar\baz\ \\foo\bar\baz '' + \\foo\bar\baz yes
[Python 2.7.9]
\\foo\bar \\foo\bar \\foo\bar + '' yes
\\foo\bar\ \\foo\bar\ (*) \\foo\bar + \ no
\\foo\bar\baz \\foo\bar\baz \\foo\bar + \baz yes
\\foo\bar\baz\ \\foo\bar\baz \\foo\bar + \baz yes
If it is ensured that "normpath()"-ed vfs root is passed to
"splitdrive()", adding "os.sep" is required only when "path" part of
"splitdrive()" result isn't "os.sep" itself. This is just what
"pathutil.nameasprefix()" examines.
This patch applies "os.path.normpath()" on "self.join(None)"
explicitly, because it isn't ensured that vfs root is already
normalized: vfs itself is constructed with "realpath=False" (= avoid
normalizing in "vfs.__init__()") in many code paths.
This normalization should be much cheaper than subsequent file I/O for
directory traversal.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 11 Apr 2015 23:00:04 +0900 |
parents | f2719b387380 |
children | 82d6a35cf432 |
rev | line source |
---|---|
12476
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
1 revlog.parseindex must be able to parse the index file even if |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
2 an index entry is split between two 64k blocks. The ideal test |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
3 would be to create an index file with inline data where |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
4 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
5 the size of an index entry) and with an index entry starting right |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
6 before the 64k block boundary, and try to read it. |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
7 We approximate that by reducing the read buffer to 1 byte. |
2290
6563438219e3
add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
8 |
12476
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
9 $ hg init a |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
10 $ cd a |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
11 $ echo abc > foo |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
12 $ hg add foo |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
13 $ hg commit -m 'add foo' |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
14 $ echo >> foo |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
15 $ hg commit -m 'change foo' |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
16 $ hg log -r 0: |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
17 changeset: 0:7c31755bf9b5 |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
18 user: test |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
19 date: Thu Jan 01 00:00:00 1970 +0000 |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
20 summary: add foo |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
21 |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
22 changeset: 1:26333235a41c |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
23 tag: tip |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
24 user: test |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
25 date: Thu Jan 01 00:00:00 1970 +0000 |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
26 summary: change foo |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
27 |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
28 $ cat >> test.py << EOF |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
12476
diff
changeset
|
29 > from mercurial import changelog, scmutil |
12476
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
30 > from mercurial.node import * |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
31 > |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
32 > class singlebyteread(object): |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
33 > def __init__(self, real): |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
34 > self.real = real |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
35 > |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
36 > def read(self, size=-1): |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
37 > if size == 65536: |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
38 > size = 1 |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
39 > return self.real.read(size) |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
40 > |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
41 > def __getattr__(self, key): |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
42 > return getattr(self.real, key) |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
43 > |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
44 > def opener(*args): |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
12476
diff
changeset
|
45 > o = scmutil.opener(*args) |
12476
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
46 > def wrapper(*a): |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
47 > f = o(*a) |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
48 > return singlebyteread(f) |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
49 > return wrapper |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
50 > |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
51 > cl = changelog.changelog(opener('.hg/store')) |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
52 > print len(cl), 'revisions:' |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
53 > for r in cl: |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
54 > print short(cl.node(r)) |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
55 > EOF |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
56 $ python test.py |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
57 2 revisions: |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
58 7c31755bf9b5 |
4cce5194c307
tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents:
12156
diff
changeset
|
59 26333235a41c |
16913
f2719b387380
tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents:
13970
diff
changeset
|
60 |
f2719b387380
tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents:
13970
diff
changeset
|
61 $ cd .. |