Edgewall Software

Ticket #5249: browser.diff

File browser.diff, 1.9 KB (added by dan@…, 21 months ago)

proposed patch for ticket #5249

  • browser.py

     
    5757        glob patterns, i.e. "*" can be used as a wild card) 
    5858        (''since 0.10'')""") 
    5959 
     60    project_root = Option('browser', 'project_root', '', 
     61        """The root of the project in the repository. 
     62                 
     63                This tells trac to treat the specified path as the root of the repository. 
     64                 
     65                Omit the option to use the actual root of the repository as the root of the project.""") 
     66 
    6067    render_unsafe_content = BoolOption('browser', 'render_unsafe_content', 
    6168                                        'false', 
    6269        """Whether attachments should be rendered in the browser, or 
     
    100107            return True 
    101108 
    102109    def process_request(self, req): 
    103         path = req.args.get('path', '/') 
     110        path = self.project_root + req.args.get('path', '/') 
    104111        rev = req.args.get('rev') or None 
    105112 
    106113        # Find node for the requested path/rev 
     
    133140            'anydiff_href': req.href.anydiff(), 
    134141        } 
    135142 
    136         path_links = get_path_links(req.href, path, rev) 
     143        relative_path = path.replace(self.project_root, '', 1) 
     144        path_links = get_path_links(req.href, relative_path, rev) 
    137145        if len(path_links) > 1: 
    138146            add_link(req, 'up', path_links[-2]['href'], 'Parent directory') 
    139147        req.hdf['browser.path'] = path_links 
     
    163171                'size': pretty_size(entry.content_length), 
    164172                'rev': entry.rev, 
    165173                'log_href': req.href.log(entry.path, rev=rev), 
    166                 'browser_href': req.href.browser(entry.path, rev=rev) 
     174                'browser_href': req.href.browser(entry.path, rev=rev).replace(self.project_root+'/', '', 1) 
    167175            }) 
    168176        changes = get_changes(self.env, repos, [i['rev'] for i in info]) 
    169177