def listdir(self, path): """\ Modification of the function mercurial.hgweb.webcommands.manifest """ ctx = self.storage._ctx path = webutil.cleanpath(self.storage._repo, path) mf = ctx.manifest() node = ctx.node() substate = ctx.substate def fullviewpath(base, node, file): # XXX this needs to be some kind of resolution method view = 'file' return '%s/%s/%s/%s' % (base, view, node, file) if path in mf: raise PathNotDirError('path is dir: ' + path) files = {} dirs = {} subrepos = [] if path and path[-1] != "/": path += "/" l = len(path) abspath = "/" + path for f, n in mf.iteritems(): if f[:l] != path: continue remain = f[l:] elements = remain.split('/') if len(elements) == 1: files[remain] = f else: h = dirs # need to retain ref to dirs (root) for elem in elements[0:-1]: if elem not in h: h[elem] = {} h = h[elem] if len(h) > 1: break h[None] = None # denotes files present if mf and not files and not dirs: raise PathNotFoundError('path not found: ' + path) subrepos = list_subrepo(substate, abspath) def listdir(): if not path == '': yield self.format(**{ 'permissions': 'drwxr-xr-x', 'contenttype': None, 'node': self.rev, 'date': '', 'size': '', 'path': '%s..' % path, 'desc': '', 'contents': '', # XXX # 'emptydirs': '/'.join(emptydirs), }) for n, v in sorted(subrepos): p = '' url, rev, repotype = v if v[0] is None: # can't really link it anywhere... p = '%s%s' % (path, n) else: # XXX 'file' is specific to PMR2, bitbucket uses # 'src' to access the human friendly view. p = '%s/file/%s' % (url, rev) result = self.format(**{ 'permissions': 'lrwxrwxrwx', 'contenttype': repotype, 'node': self.rev, 'date': '', 'size': '', 'path': p, 'desc': '', 'contents': '', # XXX # 'emptydirs': '/'.join(emptydirs), }) # need to "fix" some values result['basename'] = n # name result['fullpath'] = p # full url yield result for d in sorted(dirs): emptydirs = [] h = dirs[d] while isinstance(h, dict) and len(h) == 1: k, v = h.items()[0] if v: emptydirs.append(k) h = v p = '%s%s' % (path, d) yield self.format(**{ 'permissions': 'drwxr-xr-x', 'contenttype': 'folder', 'node': self.rev, 'date': '', 'size': '', 'path': p, 'desc': '', 'contents': '', # XXX # 'emptydirs': '/'.join(emptydirs), }) for f in sorted(files): full = files[f] fctx = ctx.filectx(full) yield self.format(**{ 'permissions': '-rw-r--r--', 'contenttype': 'file', 'node': self.rev, 'date': filter(fctx.date(), self.datefmtfilter), 'size': str(fctx.size()), 'path': full, 'desc': fctx.description(), # XXX if self.rev changes, this can result in inconsistency 'contents': lambda: self.file(p), }) return listdir()