view tests/test-hgwebdir-paths.py @ 45725:99b8b73eb622

revset: add diff(pattern) predicate for "grep --diff" I find this is useful in GUI log viewer since the tool only needs to support "log -rREV" command. This is basic implementation. Windowed search is not implemented since it wouldn't work pretty well with the smartset API. And filename matcher is not supported because the syntax isn't determined. My idea is to add handling of diff(pattern, file(..)) and diff(pattern, follow(..)), which will then be evolved to a full revset+matcher combinator support: x & diff(pattern, y & z) ===== y & z builds (revs(y) & revs(z), matcher(y) & matcher(z)) pair, and narrows the search space of diff() ==================== diff() returns matched (revs, matcher) pair ======================== revs and matcher will be combined respectively by &-operator, and the matcher will optionally be used to filter "hg log -p" output The predicate name "diff()" wouldn't be great, but grep() is already used. Another options I can think of are "grepdiff()" and "containsdiff()". Naming suggestions are welcome.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 08 Sep 2020 18:16:24 +0900
parents 2372284d9457
children 6000f5b25c9b
line wrap: on
line source

from __future__ import absolute_import

import os
from mercurial import (
    hg,
    ui as uimod,
)
from mercurial.hgweb import hgwebdir_mod

hgwebdir = hgwebdir_mod.hgwebdir

os.mkdir(b'webdir')
os.chdir(b'webdir')

webdir = os.path.realpath(b'.')

u = uimod.ui.load()
hg.repository(u, b'a', create=1)
hg.repository(u, b'b', create=1)
os.chdir(b'b')
hg.repository(u, b'd', create=1)
os.chdir(b'..')
hg.repository(u, b'c', create=1)
os.chdir(b'..')

paths = {
    b't/a/': b'%s/a' % webdir,
    b'b': b'%s/b' % webdir,
    b'coll': b'%s/*' % webdir,
    b'rcoll': b'%s/**' % webdir,
}

config = os.path.join(webdir, b'hgwebdir.conf')
configfile = open(config, 'wb')
configfile.write(b'[paths]\n')
for k, v in paths.items():
    configfile.write(b'%s = %s\n' % (k, v))
configfile.close()

confwd = hgwebdir(config)
dictwd = hgwebdir(paths)

assert len(confwd.repos) == len(dictwd.repos), 'different numbers'
assert len(confwd.repos) == 9, 'expected 9 repos, found %d' % len(confwd.repos)

found = dict(confwd.repos)
for key, path in dictwd.repos:
    assert key in found, 'repository %s was not found' % key
    assert found[key] == path, 'different paths for repo %s' % key