Edgewall Software

Ticket #8536: 8536-hide-repos-r8441.patch

File 8536-hide-repos-r8441.patch, 9.0 KB (added by rblank, 3 years ago)

Improved patch fixing aliases and .hidden values.

  • trac/env.py

    diff --git a/trac/env.py b/trac/env.py
    a b  
    253253                    return False 
    254254                return enabled 
    255255 
    256         # versioncontrol components are automatically enabled if the 
    257         # repository_dir key is present in the [trac] section 
    258         # FIXME: this probably shouldn't be hardcoded like this 
    259         if component_name.startswith('trac.versioncontrol.'): 
    260             return 'repository_dir' in self.config['trac'] 
    261  
    262256        # By default, all components in the trac package are enabled 
    263257        return component_name.startswith('trac.') 
    264258 
  • trac/versioncontrol/admin.py

    diff --git a/trac/versioncontrol/admin.py b/trac/versioncontrol/admin.py
    a b  
    1414import sys 
    1515 
    1616from trac.admin import IAdminCommandProvider, IAdminPanelProvider, get_dir_list 
     17from trac.config import _TRUE_VALUES 
    1718from trac.core import * 
    1819from trac.util.text import breakable_path, normalize_whitespace, print_table, \ 
    1920                           printerr, printout 
     
    190191                    changes = {} 
    191192                    for field in db_provider.repository_attrs: 
    192193                        value = normalize_whitespace(req.args.get(field)) 
    193                         if value is not None and value != info.get(field): 
     194                        if (value is not None or field == 'hidden') \ 
     195                                and value != info.get(field): 
    194196                            changes[field] = value 
    195197                    if changes: 
    196198                        db_provider.modify_repository(reponame, changes) 
     
    300302            info['prettydir'] = breakable_path(info['dir']) or '' 
    301303        if info.get('alias') == '': 
    302304            info['alias'] = '(default)' 
     305        info['hidden'] = info.get('hidden') in _TRUE_VALUES 
    303306        info['editable'] = editable 
    304307        if not info.get('alias'): 
    305308            try: 
  • trac/versioncontrol/api.py

    diff --git a/trac/versioncontrol/api.py b/trac/versioncontrol/api.py
    a b  
    9696 
    9797    implements(IRepositoryProvider, IAdminCommandProvider) 
    9898 
    99     repository_attrs = ('alias', 'dir', 'type', 'url') 
     99    repository_attrs = ('alias', 'dir', 'hidden', 'type', 'url') 
    100100     
    101101    # IRepositoryProvider methods 
    102102 
     
    262262 
    263263    repository_dir = Option('trac', 'repository_dir', '', 
    264264        """Path to the default repository. This can also be a relative path 
    265         (''since 0.11''). If this entry is specified (even when left empty), 
    266         this will auto-enable the trac.versioncontrol.* components.  
    267         This means that if you want to use Trac without the source browser, 
    268         simply remove that entry from the [trac] section.""") 
     265        (''since 0.11''). 
     266         
     267        This option is deprecated, and repositories should be defined in the 
     268        `[repositories]` section, or using the "Repositories" admin panel. 
     269        (''since 0.12'')""") 
    269270 
    270271    repository_sync_per_request = ListOption('trac', 
    271272        'repository_sync_per_request', '(default)', 
     
    369370        for option in repositories: 
    370371            if option.endswith('.dir'): 
    371372                reponames[option[:-4]] = {} 
    372         # second pass to gather the <name>.<detail> entries or <alias> ones 
     373        # second pass to gather aliases 
     374        for option in repositories: 
     375            if '.' not in option: 
     376                alias = repositories.get(option) 
     377                if reponames.get(alias) == {}: 
     378                    reponames[option] = {'alias': alias} 
     379        # third pass to gather the <name>.<detail> entries 
    373380        for option in repositories: 
    374381            if '.' in option: 
    375                 dotindex = option.rindex('.') 
    376                 name, detail = option[:dotindex], option[dotindex+1:] 
     382                name, detail = option.rsplit('.', 1) 
    377383                if name in reponames: 
    378384                    reponames[name][detail] = repositories.get(option) 
    379                 elif detail == 'alias': 
    380                     alias = repositories.get(option) 
    381                     if alias in reponames: 
    382                         reponames[option] = {'alias': alias} 
    383385        # eventually add pre-0.12 default repository 
    384386        if '' not in reponames and self.repository_dir: 
    385387            reponames[''] = {'dir': self.repository_dir} 
  • trac/versioncontrol/templates/admin_repositories.html

    diff --git a/trac/versioncontrol/templates/admin_repositories.html b/trac/versioncontrol/templates/admin_repositories.html
    a b  
    6262              </div> 
    6363            </py:otherwise> 
    6464          </py:choose> 
     65          <div class="field"> 
     66            <label><input type="checkbox" name="hidden" value="1" checked="${info.hidden or None}"/> 
     67              Hide from repository index 
     68            </label> 
     69          </div> 
    6570          <div class="buttons"> 
    6671            <input type="submit" name="cancel" value="${_('Cancel')}"/> 
    6772            <input py:if="info.editable" type="submit" name="save" value="${_('Save')}"/> 
  • trac/versioncontrol/templates/browser.html

    diff --git a/trac/versioncontrol/templates/browser.html b/trac/versioncontrol/templates/browser.html
    a b  
    4747  <body> 
    4848    <div id="content" class="browser"> 
    4949 
    50       <py:if test="repo"> 
    51         <h1>Repository Index</h1> 
    52         <py:with vars="repoindex = 'repoindex'"> 
    53           <xi:include href="repository_index.html" /> 
    54         </py:with> 
    55       </py:if> 
    56  
    5750      <py:if test="dir or file"> 
    5851        <py:choose> 
    59           <py:when test="repo"> 
    60             <hr /> 
    61             <h1>Default Repository</h1> 
    62             <p class="hint">The entries in that repository are reachable directly,  
    63             without a repository prefix. <br /> 
    64             However, a repository name will always take precedence over a similarly  
    65             named entry in the default repository. <br /> 
    66             If this is a problem, add a separate explicit entry for that repository.</p> 
    67           </py:when> 
     52          <h1 py:when="repo">Default Repository</h1> 
    6853          <h1 py:otherwise=""><xi:include href="path_links.html" /></h1> 
    6954        </py:choose> 
    7055   
     
    153138        </tr> 
    154139      </table> 
    155140 
     141      <py:if test="repo and repo.repositories"> 
     142        <hr py:if="dir"/> 
     143        <h1>Repository Index</h1> 
     144        <py:with vars="repoindex = 'repoindex'"> 
     145          <xi:include href="repository_index.html" /> 
     146        </py:with> 
     147      </py:if> 
     148 
    156149      <div py:if="file and file.preview" id="preview" class="searchable"> 
    157150        ${preview_file(file.preview)} 
    158151      </div> 
  • trac/versioncontrol/templates/repository_index.html

    diff --git a/trac/versioncontrol/templates/repository_index.html b/trac/versioncontrol/templates/repository_index.html
    a b  
    99        <tr class="${idx % 2 and 'even' or 'odd'}"> 
    1010          <td class="name"> 
    1111            <em py:strip="not err"> 
    12               <a class="dir" title="View Root Directory" 
    13                 href="${href.browser(reponame, order=(order != 'name' and order or None), desc=desc)}" py:choose="reponame"><b py:when="''">(default)</b><py:otherwise>$reponame</py:otherwise></a> 
     12              <b py:strip="repoinfo.alias != ''"> 
     13                <a class="dir" title="View Root Directory" 
     14                  href="${href.browser(reponame, order=(order != 'name' and order or None), desc=desc)}">$reponame</a> 
     15              </b> 
    1416            </em> 
    1517          </td> 
    1618          <td class="size" /> 
  • trac/versioncontrol/web_ui/browser.py

    diff --git a/trac/versioncontrol/web_ui/browser.py b/trac/versioncontrol/web_ui/browser.py
    a b  
    2323 
    2424from genshi.builder import tag 
    2525 
    26 from trac.config import ListOption, BoolOption, Option 
     26from trac.config import ListOption, BoolOption, Option, _TRUE_VALUES 
    2727from trac.core import * 
    2828from trac.mimeview.api import Mimeview, is_binary, get_mimetype, \ 
    2929                              IHTMLPreviewAnnotator, Context 
     
    338338        # Repository index 
    339339        all_repositories = None 
    340340        if not reponame and path == '/': 
    341             all_repositories = rm.get_all_repositories().items() 
    342             if all_repositories: 
    343                 repos = rm.get_repository('', req.authname) 
     341            all_repositories = rm.get_all_repositories() 
     342            if all_repositories and repos \ 
     343                    and all_repositories[''].get('hidden') in _TRUE_VALUES: 
     344                repos = None 
    344345 
    345346        if not repos and reponame: 
    346347            raise ResourceNotFound(_("No repository '%(repo)s' found", 
     
    450451 
    451452        rm = RepositoryManager(self.env) 
    452453        repositories = [] 
    453         for reponame, repoinfo in all_repositories: 
     454        for reponame, repoinfo in all_repositories.items(): 
     455            if not reponame or repoinfo.get('hidden') in _TRUE_VALUES: 
     456                continue 
    454457            try: 
    455458                repos = rm.get_repository(reponame, context.perm.username) 
    456459                if repos: