##// END OF EJS Templates
hgweb: support constructing URLs from an alternate base URL...
hgweb: support constructing URLs from an alternate base URL The web.baseurl config option allows server operators to define a custom URL for hosted content. The way it works today is that hgwebdir parses this config option into URL components then updates the appropriate WSGI environment variables so the request "lies" about its details. For example, SERVER_NAME is updated to reflect the alternate base URL's hostname. The WSGI environment should not be modified because WSGI applications may want to know the original request details (for debugging, etc). This commit teaches our request parser about the existence of an alternate base URL. If defined, the advertised URL and other self-reflected paths will take the alternate base URL into account. The hgweb WSGI application didn't use web.baseurl. But hgwebdir did. We update hgwebdir to alter the environment parsing accordingly. The old code around environment manipulation has been removed. With this change, parserequestfromenv() has grown to a bit unwieldy. Now that practically everyone is using it, it is obvious that there is some unused features that can be trimmed. So look for this in follow-up commits. Differential Revision: https://phab.mercurial-scm.org/D2822

File last commit:

r36799:ffa3026d default
r36916:219b2335 default
Show More
test-context.py
193 lines | 5.7 KiB | text/x-python | PythonLexer
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 from __future__ import absolute_import, print_function
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110 import os
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 import stat
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518 from mercurial.node import hex
Robert Stanca
py3: use absolute_import in test-context.py
r28735 from mercurial import (
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 context,
encoding,
Robert Stanca
py3: use absolute_import in test-context.py
r28735 hg,
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518 scmutil,
Yuya Nishihara
tests: alias ui as uimod in test-context
r28775 ui as uimod,
Robert Stanca
py3: use absolute_import in test-context.py
r28735 )
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110
Yuya Nishihara
ui: factor out ui.load() to create a ui without loading configs (API)...
r30559 u = uimod.ui.load()
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110
repo = hg.repository(u, 'test1', create=1)
os.chdir('test1')
# create 'foo' with fixed time stamp
FUJIWARA Katsunori
tests: open file in binary mode to use POSIX end-of-line style anywhere...
r23060 f = open('foo', 'wb')
timeless
tests: mark test-context.py write as binary
r29187 f.write(b'foo\n')
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110 f.close()
os.utime('foo', (1000, 1000))
# add+commit 'foo'
Dirkjan Ochtman
move working dir/dirstate methods from localrepo to workingctx
r11303 repo[None].add(['foo'])
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110 repo.commit(text='commit1', date="0 0")
Tristan Seligmann
hg: tolerate long vs. int in test-context.py...
r33797 d = repo[None]['foo'].date()
Matt Harbison
test-context: conditionalize the workingfilectx date printing for Windows...
r27056 if os.name == 'nt':
Tristan Seligmann
hg: tolerate long vs. int in test-context.py...
r33797 d = d[:2]
print("workingfilectx.date = (%d, %d)" % d)
Martin Geisler
changelog: convert user and desc from local encoding early...
r14379
# test memctx with non-ASCII commit message
def filectxfn(repo, memctx, path):
Martin von Zweigbergk
memfilectx: make changectx argument mandatory in constructor (API)...
r35401 return context.memfilectx(repo, memctx, "foo", "")
Martin Geisler
changelog: convert user and desc from local encoding early...
r14379
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
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print("%-8s: %s" % (enc, repo["tip"].description()))
Sean Farley
test-context: add test for memctx status
r21836
# 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'
Martin von Zweigbergk
memfilectx: make changectx argument mandatory in constructor (API)...
r35401 return context.memfilectx(repo, memctx, f, data, 'l' in flags, 'x' in flags)
Sean Farley
test-context: add test for memctx status
r21836
ctxa = repo.changectx(0)
Sean Farley
test-context: add test for performing a diff on a memctx...
r21837 ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"],
getfilectx, ctxa.user(), ctxa.date())
Sean Farley
test-context: add test for memctx status
r21836
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print(ctxb.status(ctxa))
Sean Farley
test-context: add test for performing a diff on a memctx...
r21837
# test performing a diff on a memctx
for d in ctxb.diff(ctxa, git=True):
Denis Laxalde
test: end printed diff "hunks" with an empty string in test-context.py...
r31270 print(d, end='')
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
Mads Kiilerich
spelling: fixes from proofreading of spell checker issues
r24180 # test safeness and correctness of "ctx.status()"
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('= checking context.status():')
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
# 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
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('== checking workingctx.status:')
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
wctx = repo[None]
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wctx._status=%s' % (str(wctx._status)))
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 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)))
FUJIWARA Katsunori
context: make unknown/ignored/clean of cached status empty for equivalence...
r23709
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 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)))
FUJIWARA Katsunori
context: avoid breaking already fixed self._status at ctx.status()...
r23711
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print("== checking workingcommitctx.status:")
FUJIWARA Katsunori
context: avoid breaking already fixed self._status at ctx.status()...
r23711
wcctx = context.workingcommitctx(repo,
scmutil.status(['bar-m'],
['bar-a'],
[],
[], [], [], []),
text='', date='0 0')
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wcctx._status=%s' % (str(wcctx._status)))
FUJIWARA Katsunori
context: avoid breaking already fixed self._status at ctx.status()...
r23711
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 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)))
FUJIWARA Katsunori
context: avoid breaking already fixed self._status at ctx.status()...
r23711
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 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)))
FUJIWARA Katsunori
context: override _dirstatestatus in workingcommitctx for correct matching...
r23712
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 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)))
FUJIWARA Katsunori
context: override _dirstatestatus in workingcommitctx for correct matching...
r23712
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('=== with "pattern match" and "listclean=True":')
print(actx1.status(other=wcctx,
FUJIWARA Katsunori
context: override _dirstatestatus in workingcommitctx for correct matching...
r23712 match=scmutil.matchfiles(repo, ['bar-r', 'foo']),
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 listclean=True))
print('wcctx._status=%s' % (str(wcctx._status)))
print(actx2.status(other=wcctx,
FUJIWARA Katsunori
context: override _dirstatestatus in workingcommitctx for correct matching...
r23712 match=scmutil.matchfiles(repo, ['bar-r', 'foo']),
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 listclean=True))
print('wcctx._status=%s' % (str(wcctx._status)))
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518
os.chdir('..')
# test manifestlog being changed
print('== commit with manifestlog invalidated')
repo = hg.repository(u, 'test2', create=1)
os.chdir('test2')
# make some commits
for i in [b'1', b'2', b'3']:
with open(i, 'wb') as f:
f.write(i)
status = scmutil.status([], [i], [], [], [], [], [])
ctx = context.workingcommitctx(repo, status, text=i, user=b'test@test.com',
date=(0, 0))
ctx.p1().manifest() # side effect: cache manifestctx
n = repo.commitctx(ctx)
print('commit %s: %s' % (i, hex(n)))
# touch 00manifest.i mtime so storecache could expire.
# repo.__dict__['manifestlog'] is deleted by transaction releasefn.
st = repo.svfs.stat('00manifest.i')
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 repo.svfs.utime('00manifest.i',
(st[stat.ST_MTIME] + 1, st[stat.ST_MTIME] + 1))
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518
# read the file just committed
try:
if repo[n][i].data() != i:
print('data mismatch')
except Exception as ex:
print('cannot read data: %r' % ex)
Martin von Zweigbergk
repo: skip invalidation of changelog if it has 'delayed' changes (API)...
r33672
with repo.wlock(), repo.lock(), repo.transaction('test'):
with open(b'4', 'wb') as f:
f.write(b'4')
repo.dirstate.normal('4')
repo.commit('4')
revsbefore = len(repo.changelog)
repo.invalidate(clearfilecache=True)
revsafter = len(repo.changelog)
if revsbefore != revsafter:
print('changeset lost by repo.invalidate()')