##// END OF EJS Templates
templatekw: add new-style template expansion to {manifest}...
templatekw: add new-style template expansion to {manifest} The goal is to allow us to easily access to nested data. The dot operator will be introduced later so we can write '{p1.files}' instead of '{revset("p1()") % "{files}"}' for example. In the example above, 'p1' needs to carry a mapping dict along with its string representation. If it were a list or a dict, it could be wrapped semi-transparently with the _hybrid class, but for non-list/dict types, it would be difficult to proxy all necessary functions to underlying value type because several core operations may conflict with the ones of the underlying value: - hash(value) should be different from hash(wrapped(value)), which means dict[wrapped(value)] would be invalid - 'value == wrapped(value)' would be false, breaks 'ifcontains' - len(wrapped(value)) may be either len(value) or len(iter(wrapped(value))) So the wrapper has no proxy functions and its scope designed to be minimal. It's unwrapped at eval*() functions so we don't have to care for a wrapped object unless it's really needed: # most template functions just call evalfuncarg() unwrapped_value = evalfuncarg(context, mapping, args[n]) # if wrapped value is needed, use evalrawexp() maybe_wrapped_value = evalrawexp(context, mapping, args[n]) Another idea was to wrap every template variable with a tagging class, but which seemed uneasy without a static type checker. This patch updates {manifest} to a mappable as an example.

File last commit:

r32203:d74b0cff default
r34331:89aec183 default
Show More
scmwindows.py
61 lines | 1.9 KiB | text/x-python | PythonLexer
from __future__ import absolute_import
import os
from . import (
encoding,
pycompat,
util,
win32,
)
try:
import _winreg as winreg
winreg.CloseKey
except ImportError:
import winreg
# MS-DOS 'more' is the only pager available by default on Windows.
fallbackpager = 'more'
def systemrcpath():
'''return default os-specific hgrc search path'''
rcpath = []
filename = util.executablepath()
# Use mercurial.ini found in directory with hg.exe
progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
rcpath.append(progrc)
# Use hgrc.d found in directory with hg.exe
progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
if os.path.isdir(progrcd):
for f, kind in util.listdir(progrcd):
if f.endswith('.rc'):
rcpath.append(os.path.join(progrcd, f))
# else look for a system rcpath in the registry
value = util.lookupreg('SOFTWARE\\Mercurial', None,
winreg.HKEY_LOCAL_MACHINE)
if not isinstance(value, str) or not value:
return rcpath
value = util.localpath(value)
for p in value.split(pycompat.ospathsep):
if p.lower().endswith('mercurial.ini'):
rcpath.append(p)
elif os.path.isdir(p):
for f, kind in util.listdir(p):
if f.endswith('.rc'):
rcpath.append(os.path.join(p, f))
return rcpath
def userrcpath():
'''return os-specific hgrc search path to the user dir'''
home = os.path.expanduser('~')
path = [os.path.join(home, 'mercurial.ini'),
os.path.join(home, '.hgrc')]
userprofile = encoding.environ.get('USERPROFILE')
if userprofile and userprofile != home:
path.append(os.path.join(userprofile, 'mercurial.ini'))
path.append(os.path.join(userprofile, '.hgrc'))
return path
def termsize(ui):
return win32.termsize()