[PATCH] templatefilters: add new dirname filter

Martin Geisler mg at lazybytes.net
Fri Apr 24 08:34:17 CDT 2009


Aleix Conchillo Flaque <aleix at member.fsf.org> writes:

> # HG changeset patch
> # User Aleix Conchillo Flaque <aleix at member.fsf.org>
> # Date 1240561285 -7200
> # Node ID 58e9ce722255c65d24a039487b40f1d1ffd61149
> # Parent  441dc7becd4305f3884aab2fcf6f8e51cb547aac
> templatefilters: add new dirname filter
>
> diff -r 441dc7becd43 -r 58e9ce722255 mercurial/templatefilters.py
> --- a/mercurial/templatefilters.py	Fri Apr 24 00:06:01 2009 -0700
> +++ b/mercurial/templatefilters.py	Fri Apr 24 10:21:25 2009 +0200
> @@ -157,9 +157,19 @@
>      else:
>          raise TypeError('cannot encode type %s' % obj.__class__.__name__)
>  
> +def dirname(text):
> +    '''Treat the text as path, and return dirname. If no base path is found,
> +       return basename. Useful for recursive repos.'''
> +    dir = os.path.dirname(text)
> +    if dir == "":
> +        return os.path.basename(text)
> +    else:
> +        return dir

I think it is a bit misleading to call the filter 'dirname' when it
mixes both dirname and basename. Could you add both a dirname and a
basename filter and combine them?

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090424/ac036291/attachment.pgp 


More information about the Mercurial-devel mailing list