Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mercurial-devel
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mercurial
mercurial-devel
Commits
a1798368
Commit
a1798368
authored
12 years ago
by
durin42
Browse files
Options
Downloads
Patches
Plain Diff
help: introduce topicmatch for finding topics matching a keyword
parent
9eca39a9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mercurial/help.py
+50
-2
50 additions, 2 deletions
mercurial/help.py
with
50 additions
and
2 deletions
mercurial/help.py
+
50
−
2
View file @
a1798368
...
...
@@ -6,5 +6,5 @@
# GNU General Public License version 2 or any later version.
from
i18n
import
gettext
,
_
import
sys
,
os
import
itertools
,
sys
,
os
import
extensions
,
revset
,
fileset
,
templatekw
,
templatefilters
,
filemerge
...
...
@@ -10,5 +10,5 @@
import
extensions
,
revset
,
fileset
,
templatekw
,
templatefilters
,
filemerge
import
util
import
encoding
,
util
def
listexts
(
header
,
exts
,
indent
=
1
):
'''
return a text listing of the given extensions
'''
...
...
@@ -27,6 +27,54 @@
doc
+=
listexts
(
_
(
'
disabled extensions:
'
),
extensions
.
disabled
())
return
doc
def
topicmatch
(
kw
):
"""
Return help topics matching kw.
Returns {
'
section
'
: [(name, summary), ...], ...} where section is
one of topics, commands, extensions, or extensioncommands.
"""
kw
=
encoding
.
lower
(
kw
)
def
lowercontains
(
container
):
return
kw
in
encoding
.
lower
(
_
(
container
))
results
=
{
'
topics
'
:
[],
'
commands
'
:
[],
'
extensions
'
:
[],
'
extensioncommands
'
:
[],
}
for
names
,
header
,
doc
in
helptable
:
if
(
sum
(
map
(
lowercontains
,
names
))
or
lowercontains
(
header
)
or
lowercontains
(
doc
())):
results
[
'
topics
'
].
append
((
names
[
0
],
header
))
import
commands
# avoid cycle
for
cmd
,
entry
in
commands
.
table
.
iteritems
():
if
cmd
.
startswith
(
'
debug
'
):
continue
if
len
(
entry
)
==
3
:
summary
=
entry
[
2
]
else
:
summary
=
''
docs
=
getattr
(
entry
[
0
],
'
__doc__
'
,
None
)
or
''
if
kw
in
cmd
or
lowercontains
(
summary
)
or
lowercontains
(
docs
):
doclines
=
_
(
docs
).
splitlines
()
if
doclines
:
summary
=
doclines
[
0
]
cmdname
=
cmd
.
split
(
'
|
'
)[
0
].
lstrip
(
'
^
'
)
results
[
'
commands
'
].
append
((
cmdname
,
summary
))
for
name
,
docs
in
itertools
.
chain
(
extensions
.
enabled
().
iteritems
(),
extensions
.
disabled
().
iteritems
()):
# extensions.load ignores the UI argument
mod
=
extensions
.
load
(
None
,
name
,
''
)
if
lowercontains
(
name
)
or
lowercontains
(
docs
):
results
[
'
extensions
'
].
append
((
name
,
_
(
docs
).
splitlines
()[
0
]))
for
cmd
,
entry
in
getattr
(
mod
,
'
cmdtable
'
,
{}).
iteritems
():
if
kw
in
cmd
or
lowercontains
(
entry
[
2
]):
cmdname
=
cmd
.
split
(
'
|
'
)[
0
].
lstrip
(
'
^
'
)
results
[
'
extensioncommands
'
].
append
(
(
cmdname
,
_
(
getattr
(
cmd
,
'
__doc__
'
,
''
))))
return
results
def
loaddoc
(
topic
):
"""
Return a delayed loader for help/topic.txt.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment