2016-04-03 16:34:55 +03:00
|
|
|
from __future__ import absolute_import, print_function
|
2007-02-23 19:31:00 +03:00
|
|
|
import os
|
2016-04-03 06:20:17 +03:00
|
|
|
from mercurial import (
|
|
|
|
context,
|
|
|
|
encoding,
|
2016-04-03 16:34:55 +03:00
|
|
|
hg,
|
2016-04-03 13:52:13 +03:00
|
|
|
ui as uimod,
|
2016-04-03 06:20:17 +03:00
|
|
|
)
|
2007-02-23 19:31:00 +03:00
|
|
|
|
2016-04-03 13:52:13 +03:00
|
|
|
u = uimod.ui()
|
2007-02-23 19:31:00 +03:00
|
|
|
|
|
|
|
repo = hg.repository(u, 'test1', create=1)
|
|
|
|
os.chdir('test1')
|
|
|
|
|
|
|
|
# create 'foo' with fixed time stamp
|
2014-10-20 17:08:08 +04:00
|
|
|
f = open('foo', 'wb')
|
2007-02-23 19:31:00 +03:00
|
|
|
f.write('foo\n')
|
|
|
|
f.close()
|
|
|
|
os.utime('foo', (1000, 1000))
|
|
|
|
|
|
|
|
# add+commit 'foo'
|
2010-06-07 22:03:32 +04:00
|
|
|
repo[None].add(['foo'])
|
2007-02-23 19:31:00 +03:00
|
|
|
repo.commit(text='commit1', date="0 0")
|
|
|
|
|
2015-11-10 01:15:36 +03:00
|
|
|
if os.name == 'nt':
|
|
|
|
d = repo[None]['foo'].date()
|
2016-04-03 16:34:55 +03:00
|
|
|
print("workingfilectx.date = (%d, %d)" % (d[0], d[1]))
|
2015-11-10 01:15:36 +03:00
|
|
|
else:
|
2016-04-03 16:34:55 +03:00
|
|
|
print("workingfilectx.date =", repo[None]['foo'].date())
|
2011-05-19 20:09:25 +04:00
|
|
|
|
|
|
|
# test memctx with non-ASCII commit message
|
|
|
|
|
|
|
|
def filectxfn(repo, memctx, path):
|
2013-08-16 01:49:27 +04:00
|
|
|
return context.memfilectx(repo, "foo", "")
|
2011-05-19 20:09:25 +04:00
|
|
|
|
|
|
|
ctx = context.memctx(repo, ['tip', None],
|
|
|
|
encoding.tolocal("Gr\xc3\xbcezi!"),
|
|
|
|
["foo"], filectxfn)
|
|
|
|
ctx.commit()
|
|
|
|
for enc in "ASCII", "Latin-1", "UTF-8":
|
|
|
|
encoding.encoding = enc
|
2016-04-03 16:34:55 +03:00
|
|
|
print("%-8s: %s" % (enc, repo["tip"].description()))
|
2014-06-14 02:56:11 +04:00
|
|
|
|
|
|
|
# test performing a status
|
|
|
|
|
|
|
|
def getfilectx(repo, memctx, f):
|
|
|
|
fctx = memctx.parents()[0][f]
|
|
|
|
data, flags = fctx.data(), fctx.flags()
|
|
|
|
if f == 'foo':
|
|
|
|
data += 'bar\n'
|
|
|
|
return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags)
|
|
|
|
|
|
|
|
ctxa = repo.changectx(0)
|
2014-06-14 02:59:18 +04:00
|
|
|
ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"],
|
|
|
|
getfilectx, ctxa.user(), ctxa.date())
|
2014-06-14 02:56:11 +04:00
|
|
|
|
2016-04-03 16:34:55 +03:00
|
|
|
print(ctxb.status(ctxa))
|
2014-06-14 02:59:18 +04:00
|
|
|
|
|
|
|
# test performing a diff on a memctx
|
|
|
|
|
|
|
|
for d in ctxb.diff(ctxa, git=True):
|
2016-04-03 16:34:55 +03:00
|
|
|
print(d)
|
context: cache self._status correctly at workingctx.status
Before this patch, "workingctx.status" always replaces "self._status"
by the recent result, even though:
- status isn't calculated against the parent of the working directory, or
- specified "match" isn't "always" one
(status is only visible partially)
If "workingctx" object is shared between some procedures indirectly
referring "ctx._status", this incorrect caching may cause unexpected
result: for example, "ctx._status" is used via "manifest()", "files()"
and so on.
To cache "self._status" correctly at "workingctx.status", this patch
overwrites "self._status" in "workingctx._buildstatus" only when:
- status is calculated against the parent of the working directory, and
- specified "match" is "always" one
This patch can be applied (and effective) only on default branch,
because procedure around "basectx.status" is much different between
stable and default: for example, overwriting "self._status" itself is
executed not in "workingctx._buildstatus" but in
"workingctx._poststatus", on stable branch.
2014-12-31 11:55:43 +03:00
|
|
|
|
2015-01-18 04:38:57 +03:00
|
|
|
# test safeness and correctness of "ctx.status()"
|
2016-04-03 16:34:55 +03:00
|
|
|
print('= checking context.status():')
|
context: cache self._status correctly at workingctx.status
Before this patch, "workingctx.status" always replaces "self._status"
by the recent result, even though:
- status isn't calculated against the parent of the working directory, or
- specified "match" isn't "always" one
(status is only visible partially)
If "workingctx" object is shared between some procedures indirectly
referring "ctx._status", this incorrect caching may cause unexpected
result: for example, "ctx._status" is used via "manifest()", "files()"
and so on.
To cache "self._status" correctly at "workingctx.status", this patch
overwrites "self._status" in "workingctx._buildstatus" only when:
- status is calculated against the parent of the working directory, and
- specified "match" is "always" one
This patch can be applied (and effective) only on default branch,
because procedure around "basectx.status" is much different between
stable and default: for example, overwriting "self._status" itself is
executed not in "workingctx._buildstatus" but in
"workingctx._poststatus", on stable branch.
2014-12-31 11:55:43 +03:00
|
|
|
|
|
|
|
# ancestor "wcctx ~ 2"
|
|
|
|
actx2 = repo['.']
|
|
|
|
|
|
|
|
repo.wwrite('bar-m', 'bar-m\n', '')
|
|
|
|
repo.wwrite('bar-r', 'bar-r\n', '')
|
|
|
|
repo[None].add(['bar-m', 'bar-r'])
|
|
|
|
repo.commit(text='add bar-m, bar-r', date="0 0")
|
|
|
|
|
|
|
|
# ancestor "wcctx ~ 1"
|
|
|
|
actx1 = repo['.']
|
|
|
|
|
|
|
|
repo.wwrite('bar-m', 'bar-m bar-m\n', '')
|
|
|
|
repo.wwrite('bar-a', 'bar-a\n', '')
|
|
|
|
repo[None].add(['bar-a'])
|
|
|
|
repo[None].forget(['bar-r'])
|
|
|
|
|
|
|
|
# status at this point:
|
|
|
|
# M bar-m
|
|
|
|
# A bar-a
|
|
|
|
# R bar-r
|
|
|
|
# C foo
|
|
|
|
|
|
|
|
from mercurial import scmutil
|
|
|
|
|
2016-04-03 16:34:55 +03:00
|
|
|
print('== checking workingctx.status:')
|
context: cache self._status correctly at workingctx.status
Before this patch, "workingctx.status" always replaces "self._status"
by the recent result, even though:
- status isn't calculated against the parent of the working directory, or
- specified "match" isn't "always" one
(status is only visible partially)
If "workingctx" object is shared between some procedures indirectly
referring "ctx._status", this incorrect caching may cause unexpected
result: for example, "ctx._status" is used via "manifest()", "files()"
and so on.
To cache "self._status" correctly at "workingctx.status", this patch
overwrites "self._status" in "workingctx._buildstatus" only when:
- status is calculated against the parent of the working directory, and
- specified "match" is "always" one
This patch can be applied (and effective) only on default branch,
because procedure around "basectx.status" is much different between
stable and default: for example, overwriting "self._status" itself is
executed not in "workingctx._buildstatus" but in
"workingctx._poststatus", on stable branch.
2014-12-31 11:55:43 +03:00
|
|
|
|
|
|
|
wctx = repo[None]
|
2016-04-03 16:34:55 +03:00
|
|
|
print('wctx._status=%s' % (str(wctx._status)))
|
context: cache self._status correctly at workingctx.status
Before this patch, "workingctx.status" always replaces "self._status"
by the recent result, even though:
- status isn't calculated against the parent of the working directory, or
- specified "match" isn't "always" one
(status is only visible partially)
If "workingctx" object is shared between some procedures indirectly
referring "ctx._status", this incorrect caching may cause unexpected
result: for example, "ctx._status" is used via "manifest()", "files()"
and so on.
To cache "self._status" correctly at "workingctx.status", this patch
overwrites "self._status" in "workingctx._buildstatus" only when:
- status is calculated against the parent of the working directory, and
- specified "match" is "always" one
This patch can be applied (and effective) only on default branch,
because procedure around "basectx.status" is much different between
stable and default: for example, overwriting "self._status" itself is
executed not in "workingctx._buildstatus" but in
"workingctx._poststatus", on stable branch.
2014-12-31 11:55:43 +03:00
|
|
|
|
2016-04-03 16:34:55 +03:00
|
|
|
print('=== with "pattern match":')
|
|
|
|
print(actx1.status(other=wctx,
|
|
|
|
match=scmutil.matchfiles(repo, ['bar-m', 'foo'])))
|
|
|
|
print('wctx._status=%s' % (str(wctx._status)))
|
|
|
|
print(actx2.status(other=wctx,
|
|
|
|
match=scmutil.matchfiles(repo, ['bar-m', 'foo'])))
|
|
|
|
print('wctx._status=%s' % (str(wctx._status)))
|
2014-12-31 11:55:43 +03:00
|
|
|
|
2016-04-03 16:34:55 +03:00
|
|
|
print('=== with "always match" and "listclean=True":')
|
|
|
|
print(actx1.status(other=wctx, listclean=True))
|
|
|
|
print('wctx._status=%s' % (str(wctx._status)))
|
|
|
|
print(actx2.status(other=wctx, listclean=True))
|
|
|
|
print('wctx._status=%s' % (str(wctx._status)))
|
2014-12-31 11:55:43 +03:00
|
|
|
|
2016-04-03 16:34:55 +03:00
|
|
|
print("== checking workingcommitctx.status:")
|
2014-12-31 11:55:43 +03:00
|
|
|
|
|
|
|
wcctx = context.workingcommitctx(repo,
|
|
|
|
scmutil.status(['bar-m'],
|
|
|
|
['bar-a'],
|
|
|
|
[],
|
|
|
|
[], [], [], []),
|
|
|
|
text='', date='0 0')
|
2016-04-03 16:34:55 +03:00
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|
|
|
|
|
|
|
|
print('=== with "always match":')
|
|
|
|
print(actx1.status(other=wcctx))
|
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|
|
|
|
print(actx2.status(other=wcctx))
|
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|
|
|
|
|
|
|
|
print('=== with "always match" and "listclean=True":')
|
|
|
|
print(actx1.status(other=wcctx, listclean=True))
|
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|
|
|
|
print(actx2.status(other=wcctx, listclean=True))
|
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|
|
|
|
|
|
|
|
print('=== with "pattern match":')
|
|
|
|
print(actx1.status(other=wcctx,
|
|
|
|
match=scmutil.matchfiles(repo, ['bar-m', 'foo'])))
|
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|
|
|
|
print(actx2.status(other=wcctx,
|
|
|
|
match=scmutil.matchfiles(repo, ['bar-m', 'foo'])))
|
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|
|
|
|
|
|
|
|
print('=== with "pattern match" and "listclean=True":')
|
|
|
|
print(actx1.status(other=wcctx,
|
2014-12-31 11:55:43 +03:00
|
|
|
match=scmutil.matchfiles(repo, ['bar-r', 'foo']),
|
2016-04-03 16:34:55 +03:00
|
|
|
listclean=True))
|
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|
|
|
|
print(actx2.status(other=wcctx,
|
2014-12-31 11:55:43 +03:00
|
|
|
match=scmutil.matchfiles(repo, ['bar-r', 'foo']),
|
2016-04-03 16:34:55 +03:00
|
|
|
listclean=True))
|
|
|
|
print('wcctx._status=%s' % (str(wcctx._status)))
|