Skip to content
Snippets Groups Projects
Commit bd1f043d1ea3 authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

templater: add relpath() to convert repo path to relative path (issue5394)

File paths in template are repository-absolute paths. This function can be
used to convert them to filesystem paths relative to cwd. This also converts
'/' to '\\' on Windows.
parent ebc03e64548a
No related branches found
No related tags found
No related merge requests found
......@@ -713,6 +713,18 @@
tzoffset = util.makedate()[1]
return (date[0], tzoffset)
@templatefunc('relpath(path)')
def relpath(context, mapping, args):
"""Convert a repository-absolute path into a filesystem path relative to
the current working directory."""
if len(args) != 1:
# i18n: "relpath" is a keyword
raise error.ParseError(_("relpath expects one argument"))
repo = mapping['ctx'].repo()
path = evalstring(context, mapping, args[0])
return repo.pathto(path)
@templatefunc('revset(query[, formatargs...])')
def revset(context, mapping, args):
"""Execute a revision set query. See
......
......@@ -3521,6 +3521,15 @@
0
Test relpath function
$ hg log -r0 -T '{files % "{file|relpath}\n"}'
a
$ cd ..
$ hg log -R r -r0 -T '{files % "{file|relpath}\n"}'
r/a (glob)
$ cd r
Test active bookmark templating
$ hg book foo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment