annotate tests/test-context.py @ 22167:d4bc38f6eab7 stable

cmdutil: add a hook for making custom non-follow log file matchers This will be used by largefiles (and basically only by largefiles) in an upcoming patch.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 13 Aug 2014 15:17:03 -0700
parents 61b333b982ea
children 4eaea93b3e5b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
9031
3b76321aa0de compat: use open() instead of file() everywhere
Alejandro Santos <alejolp@alejolp.com>
parents: 6747
diff changeset
10 f = open('foo', 'w')
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