tests/test-context.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 31 Dec 2014 17:55:43 +0900
changeset 23709 33e5431684c0
parent 23700 a4958cdb2202
child 23711 1e6fb8db666e
permissions -rw-r--r--
context: make unknown/ignored/clean of cached status empty for equivalence Before this patch, "workingctx.status" caches the result of "dirstate.status" directly into "self._status". But "dirstate.status" is invoked with False "list*" arguments in normal "self._status" accessing route, and this makes "unknown"/"ignored"/"clean" of status empty. This may cause unexpected result of code paths internally accessing to them (accessors for external usage are already removed by previous patch). This patch makes "unknown"/"ignored"/"clean" of cached status empty for equivalence. Making them empty is executed only when at least one of "unknown", "ignored" or "clean" has files, for efficiency.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4110
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     1
import os
14379
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
     2
from mercurial import hg, ui, context, encoding
4110
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     3
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     4
u = ui.ui()
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     5
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     6
repo = hg.repository(u, 'test1', create=1)
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     7
os.chdir('test1')
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     8
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     9
# create 'foo' with fixed time stamp
23060
4eaea93b3e5b tests: open file in binary mode to use POSIX end-of-line style anywhere
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21837
diff changeset
    10
f = open('foo', 'wb')
4110
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    11
f.write('foo\n')
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    12
f.close()
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    13
os.utime('foo', (1000, 1000))
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    14
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    15
# add+commit 'foo'
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9031
diff changeset
    16
repo[None].add(['foo'])
4110
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    17
repo.commit(text='commit1', date="0 0")
20af6a2f0b0e Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    18
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6740
diff changeset
    19
print "workingfilectx.date =", repo[None]['foo'].date()
14379
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    20
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    21
# test memctx with non-ASCII commit message
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    22
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    23
def filectxfn(repo, memctx, path):
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 14379
diff changeset
    24
    return context.memfilectx(repo, "foo", "")
14379
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    25
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    26
ctx = context.memctx(repo, ['tip', None],
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    27
                     encoding.tolocal("Gr\xc3\xbcezi!"),
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    28
                     ["foo"], filectxfn)
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    29
ctx.commit()
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    30
for enc in "ASCII", "Latin-1", "UTF-8":
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    31
    encoding.encoding = enc
bd23d5f28bbb changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents: 11303
diff changeset
    32
    print "%-8s: %s" % (enc, repo["tip"].description())
21836
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    33
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    34
# test performing a status
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    35
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    36
def getfilectx(repo, memctx, f):
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    37
    fctx = memctx.parents()[0][f]
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    38
    data, flags = fctx.data(), fctx.flags()
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    39
    if f == 'foo':
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    40
        data += 'bar\n'
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    41
    return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags)
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    42
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    43
ctxa = repo.changectx(0)
21837
61b333b982ea test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 21836
diff changeset
    44
ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"],
61b333b982ea test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 21836
diff changeset
    45
                      getfilectx, ctxa.user(), ctxa.date())
21836
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    46
232038a05fdb test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents: 21689
diff changeset
    47
print ctxb.status(ctxa)
21837
61b333b982ea test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 21836
diff changeset
    48
61b333b982ea test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 21836
diff changeset
    49
# test performing a diff on a memctx
61b333b982ea test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 21836
diff changeset
    50
61b333b982ea test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 21836
diff changeset
    51
for d in ctxb.diff(ctxa, git=True):
61b333b982ea test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents: 21836
diff changeset
    52
    print d
23700
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    53
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    54
# test safeness and correctness of "cxt.status()"
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    55
print '= checking context.status():'
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    56
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    57
# ancestor "wcctx ~ 2"
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    58
actx2 = repo['.']
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    59
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    60
repo.wwrite('bar-m', 'bar-m\n', '')
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    61
repo.wwrite('bar-r', 'bar-r\n', '')
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    62
repo[None].add(['bar-m', 'bar-r'])
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    63
repo.commit(text='add bar-m, bar-r', date="0 0")
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    64
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    65
# ancestor "wcctx ~ 1"
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    66
actx1 = repo['.']
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    67
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    68
repo.wwrite('bar-m', 'bar-m bar-m\n', '')
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    69
repo.wwrite('bar-a', 'bar-a\n', '')
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    70
repo[None].add(['bar-a'])
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    71
repo[None].forget(['bar-r'])
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    72
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    73
# status at this point:
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    74
#   M bar-m
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    75
#   A bar-a
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    76
#   R bar-r
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    77
#   C foo
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    78
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    79
from mercurial import scmutil
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    80
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    81
print '== checking workingctx.status:'
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    82
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    83
wctx = repo[None]
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    84
print 'wctx._status=%s' % (str(wctx._status))
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    85
23709
33e5431684c0 context: make unknown/ignored/clean of cached status empty for equivalence
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23700
diff changeset
    86
print '=== with "pattern match":'
23700
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    87
print actx1.status(other=wctx,
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    88
                   match=scmutil.matchfiles(repo, ['bar-m', 'foo']))
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    89
print 'wctx._status=%s' % (str(wctx._status))
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    90
print actx2.status(other=wctx,
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    91
                   match=scmutil.matchfiles(repo, ['bar-m', 'foo']))
a4958cdb2202 context: cache self._status correctly at workingctx.status
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23060
diff changeset
    92
print 'wctx._status=%s' % (str(wctx._status))
23709
33e5431684c0 context: make unknown/ignored/clean of cached status empty for equivalence
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23700
diff changeset
    93
33e5431684c0 context: make unknown/ignored/clean of cached status empty for equivalence
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23700
diff changeset
    94
print '=== with "always match" and "listclean=True":'
33e5431684c0 context: make unknown/ignored/clean of cached status empty for equivalence
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23700
diff changeset
    95
print actx1.status(other=wctx, listclean=True)
33e5431684c0 context: make unknown/ignored/clean of cached status empty for equivalence
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23700
diff changeset
    96
print 'wctx._status=%s' % (str(wctx._status))
33e5431684c0 context: make unknown/ignored/clean of cached status empty for equivalence
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23700
diff changeset
    97
print actx2.status(other=wctx, listclean=True)
33e5431684c0 context: make unknown/ignored/clean of cached status empty for equivalence
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23700
diff changeset
    98
print 'wctx._status=%s' % (str(wctx._status))