Edgewall Software

Ticket #4612: trac-0.10.3-changeset.revision_in_querystring.3.patch

File trac-0.10.3-changeset.revision_in_querystring.3.patch, 4.5 KB (added by Peter Dimov <peter.dimov@…>, 2 years ago)

This patches also the changeset entries in the timeline to support revision_in_querystring.

  • trac/versioncontrol/web_ui/changeset.py

     
    9292        If this option is disabled, changeset messages will be rendered as 
    9393        pre-formatted text.""") 
    9494 
    95     # INavigationContributor methods 
     95    revision_in_querystring = BoolOption('changeset', 'revision_in_querystring', 
     96                                      'false', 
     97        """Set to true if you want the chagneset URLs to be formatted like 
     98        /changeset/path?new=revision instead of /cangeset/revision/path 
     99        That makes sense when your revision ids can contain '/'. 
     100         
     101        Set to false to keep the previous befavior. 
     102        """) 
    96103 
     104        # INavigationContributor methods 
     105 
    97106    def get_active_navigation_item(self, req): 
    98107        return 'browser' 
    99108 
     
    108117    # IRequestHandler methods 
    109118 
    110119    _request_re = re.compile(r"/changeset(?:/([^/]+))?(/.*)?$") 
     120    _request_re2 = re.compile(r"/changeset/?(.*)$") 
    111121 
    112122    def match_request(self, req): 
    113         match = re.match(self._request_re, req.path_info) 
    114         if match: 
    115             new, new_path = match.groups() 
    116             if new: 
    117                 req.args['new'] = new 
    118             if new_path: 
    119                 req.args['new_path'] = new_path 
    120             return True 
     123        new, new_path = None, None 
     124        if not self.revision_in_querystring: 
     125            match = re.match(self._request_re, req.path_info) 
     126            if match: 
     127                new, new_path = match.groups() 
     128        else: 
     129            match = re.match(self._request_re2, req.path_info) 
     130            if match: 
     131                new_path, = match.groups() 
     132        if new: 
     133            req.args['new'] = new 
     134        if new_path: 
     135            req.args['new_path'] = new_path 
     136        return match != None 
    121137 
    122138    def process_request(self, req): 
    123139        """The appropriate mode of operation is inferred from the request 
     
    645661 
    646662                if format == 'rss': 
    647663                    title = Markup('Changeset [%s]: %s', chgset.rev, shortlog) 
    648                     href = req.abs_href.changeset(chgset.rev) 
     664                    if self.revision_in_querystring: 
     665                        href = req.abs_href.changeset(new=chgset.rev) 
     666                    else: 
     667                        href = req.abs_href.changeset(chgset.rev) 
    649668                    if wiki_format: 
    650669                        message = wiki_to_html(message, self.env, req, db, 
    651670                                               absurls=True) 
     
    654673                else: 
    655674                    title = Markup('Changeset <em>[%s]</em> by %s', chgset.rev, 
    656675                                   chgset.author) 
    657                     href = req.href.changeset(chgset.rev) 
     676                    if self.revision_in_querystring: 
     677                        href = req.abs_href.changeset(new=chgset.rev) 
     678                    else: 
     679                        href = req.abs_href.changeset(chgset.rev) 
    658680 
    659681                    if wiki_format: 
    660682                        if self.timeline_long_messages: 
     
    706728                                                         fullmatch) 
    707729        if intertrac: 
    708730            return intertrac 
    709         sep = chgset.find('/') 
    710         if sep > 0: 
    711             rev, path = chgset[:sep], chgset[sep:] 
     731        sep1 = chgset.find('@') 
     732        sep2 = chgset.find('/') 
     733        if sep1 >= 0: 
     734            rev, path = chgset[sep1 + 1:], chgset[:sep1] 
     735        elif sep2 > 0: 
     736            rev, path = chgset[:sep2], chgset[sep2:] 
    712737        else: 
    713738            rev, path = chgset, None 
     739        if self.revision_in_querystring: 
     740            href_changeset = formatter.href.changeset(path, new=rev) 
     741        else: 
     742            href_changeset = formatter.href.changeset(rev, path) 
    714743        try: 
    715744            changeset = self.env.get_repository().get_changeset(rev) 
    716745            return html.A(label, class_="changeset", 
    717746                          title=shorten_line(changeset.message), 
    718                           href=formatter.href.changeset(rev, path)) 
     747                          href=href_changeset) 
    719748        except NoSuchChangeset: 
    720749            return html.A(label, class_="missing changeset", 
    721                           href=formatter.href.changeset(rev, path), 
     750                          href=href_changeset, 
    722751                          rel="nofollow") 
    723752 
    724753    def _format_diff_link(self, formatter, ns, params, label):