Edgewall Software

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

File trac-0.10.3-changeset.revision_in_querystring.patch, 3.4 KB (added by Peter Dimov <peter.dimov@…>, 2 years ago)
  • 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        TODO: Adopt new format? The URLs will be consistent with log and browser. 
     103        """) 
    96104 
     105        # INavigationContributor methods 
     106 
    97107    def get_active_navigation_item(self, req): 
    98108        return 'browser' 
    99109 
     
    108118    # IRequestHandler methods 
    109119 
    110120    _request_re = re.compile(r"/changeset(?:/([^/]+))?(/.*)?$") 
     121    _request_re2 = re.compile(r"/changeset(/.*)$") 
    111122 
    112123    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 
     124        new, new_path = None, None 
     125        if not self.revision_in_querystring: 
     126            match = re.match(self._request_re, req.path_info) 
     127            if match: 
     128                new, new_path = match.groups() 
     129        else: 
     130            match = re.match(self._request_re2, req.path_info) 
     131            if match: 
     132                new_path, = match.groups() 
     133        if new: 
     134            req.args['new'] = new 
     135        if new_path: 
     136            req.args['new_path'] = new_path 
     137        return match != None 
    121138 
    122139    def process_request(self, req): 
    123140        """The appropriate mode of operation is inferred from the request 
     
    706723                                                         fullmatch) 
    707724        if intertrac: 
    708725            return intertrac 
    709         sep = chgset.find('/') 
    710         if sep > 0: 
     726        sep = chgset.find('@') or chgset.find('/') 
     727        if sep > 0 and chgset[sep] == '/': 
    711728            rev, path = chgset[:sep], chgset[sep:] 
     729        elif sep > 0 and chgset[sep] == '@': 
     730            rev, path = chgset[sep + 1:], chgset[:sep] 
    712731        else: 
    713732            rev, path = chgset, None 
     733        if self.revision_in_querystring: 
     734            href_changeset = formatter.href.changeset(path, new=rev) 
     735        else: 
     736            href_changeset = formatter.href.changeset(rev, path) 
    714737        try: 
    715738            changeset = self.env.get_repository().get_changeset(rev) 
    716739            return html.A(label, class_="changeset", 
    717740                          title=shorten_line(changeset.message), 
    718                           href=formatter.href.changeset(rev, path)) 
     741                          href=href_changeset) 
    719742        except NoSuchChangeset: 
    720743            return html.A(label, class_="missing changeset", 
    721                           href=formatter.href.changeset(rev, path), 
     744                          href=href_changeset, 
    722745                          rel="nofollow") 
    723746 
    724747    def _format_diff_link(self, formatter, ns, params, label):