Remove the roots collection from the common-to-every-page data

dictionary stuffs.  It can be expensive to generate (especially when
authorization is in place) and brings little value considering we have
a roots listing view.  The sole known casualty in this change is the
little drop-down roots listing box, which is often one of the first
customizations (removing this) that folks make to their ViewVC
instances anyway.

* lib/viewvc.py
  (find_root_in_parents, locate_root): New functions.
  (common_template_data): Move the root listing data dictionary stuff ...
  (view_roots): ... to here.  Now uses expand_root_parents().
  (load_config): This, however, no longer uses expand_root_parents.
  (Request.run_viewvc): Use locate_root() to find a requested root
    name rather than expecting cvs_roots and svn_roots to be fully
    populated.

* templates/include/header.ezt
  Lose the root listing drop-down box, and de-table-ize the breadcrumbs.

* templates/docroot/styles.css
  (.vc_navheader): Add some padding.

* docs/template-authoring-guide.html
  Move the 'roots' stuff from the COMMON template data collection to
  the section specific to the root listing view.


git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@1865 8cb11bc2-c004-0410-86c3-e597b4017df7
remotes/tags/1.1.0-beta1
cmpilato 2008-04-17 19:52:30 +00:00
parent 4f45a6b364
commit 5fb74427f2
4 changed files with 115 additions and 121 deletions

View File

@ -228,35 +228,6 @@ td {
<td>String</td>
<td>Name of the current repository (root).</td>
</tr>
<tr class="varlevel1">
<td class="varname">roots</td>
<td>List</td>
<td>Set of configured viewable repositories.</td>
</tr>
<tr class="varlevel2">
<td class="varname">roots.name</td>
<td>String</td>
<td>Name of a configured repository.</td>
</tr>
<tr class="varlevel2">
<td class="varname">roots.path</td>
<td>String</td>
<td>Server-local location of a configured repository. WARNING: Revealing
information to untrusted guests about the details of your server
configuration can have negative security implications. Use this
token at your own risk.</td>
</tr>
<tr class="varlevel2">
<td class="varname">roots.type</td>
<td>String</td>
<td>Version control type of a configured repository. Valid
values: <tt>cvs</tt>, <tt>svn</tt>.</td>
</tr>
<tr class="varlevel2">
<td class="varname">roots.href</td>
<td>String</td>
<td>URL of root directory view for a configured repository.</td>
</tr>
<tr class="varlevel1">
<td class="varname">roots_href</td>
<td>String</td>
@ -2234,6 +2205,35 @@ td {
<td colspan="3">Includes all variables from the
<a href="#variables-common">COMMON</a> variable set</td>
</tr>
<tr class="varlevel1">
<td class="varname">roots</td>
<td>List</td>
<td>Set of configured viewable repositories.</td>
</tr>
<tr class="varlevel2">
<td class="varname">roots.name</td>
<td>String</td>
<td>Name of a configured repository.</td>
</tr>
<tr class="varlevel2">
<td class="varname">roots.path</td>
<td>String</td>
<td>Server-local location of a configured repository. WARNING: Revealing
information to untrusted guests about the details of your server
configuration can have negative security implications. Use this
token at your own risk.</td>
</tr>
<tr class="varlevel2">
<td class="varname">roots.type</td>
<td>String</td>
<td>Version control type of a configured repository. Valid
values: <tt>cvs</tt>, <tt>svn</tt>.</td>
</tr>
<tr class="varlevel2">
<td class="varname">roots.href</td>
<td>String</td>
<td>URL of root directory view for a configured repository.</td>
</tr>
</tbody>
</table>

View File

@ -210,32 +210,36 @@ class Request:
self.path_parts = path_parts
if self.rootname:
roottype, rootpath = locate_root(cfg, self.rootname)
if roottype:
# Setup an Authorizer for this rootname and username
self.auth = setup_authorizer(cfg, self.username, self.rootname)
# Setup an Authorizer for this rootname and username
self.auth = setup_authorizer(cfg, self.username, self.rootname)
# Create the repository object
try:
if cfg.general.cvs_roots.has_key(self.rootname):
cfg.overlay_root_options(self.rootname)
self.rootpath = os.path.normpath(cfg.general.cvs_roots[self.rootname])
self.repos = vclib.ccvs.CVSRepository(self.rootname,
self.rootpath,
self.auth,
cfg.utilities,
cfg.options.use_rcsparse)
# required so that spawned rcs programs correctly expand $CVSHeader$
os.environ['CVSROOT'] = self.rootpath
elif cfg.general.svn_roots.has_key(self.rootname):
cfg.overlay_root_options(self.rootname)
self.rootpath = cfg.general.svn_roots[self.rootname]
self.repos = vclib.svn.SubversionRepository(self.rootname,
self.rootpath,
self.auth,
cfg.utilities)
else:
raise vclib.ReposNotFound()
except vclib.ReposNotFound:
# Create the repository object
try:
if roottype == 'cvs':
cfg.overlay_root_options(self.rootname)
self.rootpath = os.path.normpath(rootpath)
self.repos = vclib.ccvs.CVSRepository(self.rootname,
self.rootpath,
self.auth,
cfg.utilities,
cfg.options.use_rcsparse)
# required so that spawned rcs programs correctly expand
# $CVSHeader$
os.environ['CVSROOT'] = self.rootpath
elif roottype == 'svn':
cfg.overlay_root_options(self.rootname)
self.rootpath = rootpath
self.repos = vclib.svn.SubversionRepository(self.rootname,
self.rootpath,
self.auth,
cfg.utilities)
else:
raise vclib.ReposNotFound()
except vclib.ReposNotFound:
pass
if self.repos is None:
raise debug.ViewVCException(
'The root "%s" is unknown. If you believe the value is '
'correct, then please double-check your configuration.'
@ -1146,22 +1150,6 @@ def common_template_data(request):
request.get_form(view_func=view_directory, where='', pathtype=vclib.DIR,
params={'root': None})
# add in the roots for the selection
roots = []
allroots = list_roots(request)
if len(allroots):
rootnames = allroots.keys()
rootnames.sort(icmp)
for rootname in rootnames:
href = request.get_url(view_func=view_directory,
where='', pathtype=vclib.DIR,
params={'root': rootname}, escape=1)
roots.append(_item(name=request.server.escape(rootname),
type=allroots[rootname][1],
path=allroots[rootname][0],
href=href))
data['roots'] = roots
if request.path_parts:
dir = _path_join(request.path_parts[:-1])
data['up_href'] = request.get_url(view_func=view_directory,
@ -1673,7 +1661,24 @@ def icmp(x, y):
return cmp(string.lower(x), string.lower(y))
def view_roots(request):
# add in the roots for the selection
roots = []
expand_root_parents(request.cfg)
allroots = list_roots(request)
if len(allroots):
rootnames = allroots.keys()
rootnames.sort(icmp)
for rootname in rootnames:
href = request.get_url(view_func=view_directory,
where='', pathtype=vclib.DIR,
params={'root': rootname}, escape=1)
roots.append(_item(name=request.server.escape(rootname),
type=allroots[rootname][1],
path=allroots[rootname][0],
href=href))
data = common_template_data(request)
data['roots'] = roots
generate_page(request, "roots", data)
def view_directory(request):
@ -3926,6 +3931,44 @@ def expand_root_parents(cfg):
elif repo_type == 'svn' and \
os.path.exists(os.path.join(pp, subpath, "format")):
cfg.general.svn_roots[subpath] = os.path.join(pp, subpath)
def find_root_in_parents(cfg, rootname, roottype):
"""Return the rootpath for configured ROOTNAME of ROOTTYPE."""
for pp in cfg.general.root_parents:
pos = string.rfind(pp, ':')
if pos < 0:
continue
repo_type = string.strip(pp[pos+1:])
if repo_type != roottype:
continue
pp = os.path.normpath(string.strip(pp[:pos]))
if not os.path.exists(os.path.join(pp, rootname)):
continue
if roottype == 'cvs':
if os.path.exists(os.path.join(pp, rootname, "CVSROOT", "config")) \
or (os.path.exists(os.path.join(pp, "CVSROOT", "config")) \
and (rootname != 'CVSROOT' or not cfg.options.hide_cvsroot)):
return os.path.join(pp, rootname)
elif repo_type == 'svn':
if os.path.exists(os.path.join(pp, rootname, "format")):
return os.path.join(pp, rootname)
return None
def locate_root(cfg, rootname):
"""Return a 2-type ROOTTYPE, ROOTPATH for configured ROOTNAME."""
if cfg.general.cvs_roots.has_key(rootname):
return 'cvs', cfg.general.cvs_roots[rootname]
path_in_parent = find_root_in_parents(cfg, rootname, 'cvs')
if path_in_parent:
cfg.general.cvs_roots[rootname] = path_in_parent
return 'cvs', path_in_parent
if cfg.general.svn_roots.has_key(rootname):
return 'svn', cfg.general.svn_roots[rootname]
path_in_parent = find_root_in_parents(cfg, rootname, 'svn')
if path_in_parent:
cfg.general.svn_roots[rootname] = path_in_parent
return 'svn', path_in_parent
return None, None
def load_config(pathname=None, server=None):
debug.t_start('load-config')
@ -3943,9 +3986,6 @@ def load_config(pathname=None, server=None):
# load mime types file
if cfg.general.mime_types_file:
mimetypes.init([cfg.general.mime_types_file])
# expand root parents into real cvs_roots and svn_roots.
expand_root_parents(cfg)
debug.t_end('load-config')
return cfg

View File

@ -46,6 +46,7 @@ form { margin: 0; }
/*** Navigation Headers ***/
.vc_navheader {
background-color: #cccccc;
padding: .25em;
}

View File

@ -10,14 +10,8 @@
</head>
<body>
<div class="vc_navheader">
[if-any roots]
<form method="get" action="[change_root_action]">
[end]
<table style="padding:0.1em;">
<tr>
<td>
<strong>[if-any roots_href]<a href="[roots_href]">/</a>[else]/[end]</strong>
[if-any nav_path]<strong>
[if-any roots_href]<a href="[roots_href]">/</a>[else]/[end]
[for nav_path]
[if-any nav_path.href]<a href="[nav_path.href]">[end]
[if-index nav_path first]
@ -27,47 +21,6 @@
[end]
</strong>
[end]
</td>
<td style="text-align:right;">
[if-any roots]
[change_root_hidden_values]
<strong>Repository:</strong>
<select name="root" onchange="submit()">
[define cvs_root_options][end]
[define svn_root_options][end]
<option value="*viewroots*"[is view "roots"] selected="selected"[else][end]>Repository Listing</option>
[for roots]
[define root_option][end]
[is roots.name rootname]
[define root_option]<option selected="selected">[roots.name]</option>[end]
[else]
[define root_option]<option>[roots.name]</option>[end]
[end]
[is roots.type "cvs"]
[define cvs_root_options][cvs_root_options][root_option][end]
[else]
[is roots.type "svn"]
[define svn_root_options][svn_root_options][root_option][end]
[end]
[end]
[end]
[is cvs_root_options ""][else]
<optgroup label="CVS Repositories">[cvs_root_options]</optgroup>
[end]
[is svn_root_options ""][else]
<optgroup label="Subversion Repositories">[svn_root_options]</optgroup>
[end]
</select>
<input type="submit" value="Go" />
[else]
&nbsp;
[end]
</td>
</tr>
</table>
[if-any roots]
</form>
[end]
</div>
<div style="float: right; padding: 5px;"><a href="http://www.viewvc.org/" title="ViewVC Home"><img src="[docroot]/images/logo.png" alt="ViewVC logotype" width="128" height="48" /></a></div>