mercurial/templatefilters.py
changeset 8158 1bef3656d9fe
parent 8014 6a77ba181bc6
child 8225 46293a0c7e9f
--- a/mercurial/templatefilters.py	Fri Apr 24 18:47:15 2009 +0200
+++ b/mercurial/templatefilters.py	Fri Apr 24 18:37:44 2009 +0200
@@ -157,9 +157,18 @@
     else:
         raise TypeError('cannot encode type %s' % obj.__class__.__name__)
 
+def stripdir(text):
+    '''Treat the text as path and strip a directory level, if possible.'''
+    dir = os.path.dirname(text)
+    if dir == "":
+        return os.path.basename(text)
+    else:
+        return dir
+
 filters = {
     "addbreaks": nl2br,
     "basename": os.path.basename,
+    "stripdir": stripdir,
     "age": age,
     "date": lambda x: util.datestr(x),
     "domain": domain,