views: fix broken URLs involving hierarchical branch names

Git branch names can be hierarchical (for example, "wip/parser/fix"),
however, git-arr does not take this into account when formulating URLs
on branch, tree, and blobs pages. These URLs are dysfunctional because
it is assumed incorrectly that a single "../" is sufficient to climb
over the branch name when computing relative paths to resources higher
in the hierarchy. This problem manifests as failure to load static
resources (stylesheet, etc.), broken links to commits on branch pages,
and malfunctioning breadcrumb trails.

Fix this problem by computing the the proper number of "../" based upon
the branch name, rather than assuming that a single "../" will work
unconditionally. (This is analogous to the treatment already given to
hierarchical pathnames in tree and blob views.)

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
This commit is contained in:
Eric Sunshine 2014-12-31 04:50:08 -05:00 committed by Alberto Bertogli
parent 7f2f67629f
commit 93b161c23e
3 changed files with 21 additions and 16 deletions

@ -4,10 +4,11 @@
<head>
% if not dirname.raw:
% relroot = './'
% reltree = './'
% else:
% relroot = '../' * (len(dirname.split('/')) - 1)
% reltree = '../' * (len(dirname.split('/')) - 1)
% end
% relroot = reltree + '../' * (len(repo.branch.split('/')) - 1)
<title>git &raquo; {{repo.name}} &raquo;
{{repo.branch}} &raquo; {{dirname.unicode}}/{{fname.unicode}}</title>
@ -21,13 +22,13 @@
<body class="tree">
<h1><a href="{{relroot}}../../../../../">git</a> &raquo;
<a href="{{relroot}}../../../">{{repo.name}}</a> &raquo;
<a href="{{relroot}}../">{{repo.branch}}</a> &raquo;
<a href="{{relroot}}">tree</a>
<a href="{{reltree}}../">{{repo.branch}}</a> &raquo;
<a href="{{reltree}}">tree</a>
</h1>
<h3>
<a href="{{relroot}}">[{{repo.branch}}]</a> /
% base = smstr(relroot)
<a href="{{reltree}}">[{{repo.branch}}]</a> /
% base = smstr(reltree)
% for c in dirname.split('/'):
% if not c.raw:
% continue

@ -2,14 +2,17 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
% relroot = '../' * (len(repo.branch.split('/')) - 1)
<title>git &raquo; {{repo.name}} &raquo; {{repo.branch}}</title>
<link rel="stylesheet" type="text/css" href="../../../../static/git-arr.css"/>
<link rel="stylesheet" type="text/css" href="{{relroot}}../../../../static/git-arr.css"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<body class="branch">
<h1><a href="../../../../">git</a> &raquo;
<a href="../../">{{repo.name}}</a> &raquo;
<h1><a href="{{relroot}}../../../../">git</a> &raquo;
<a href="{{relroot}}../../">{{repo.name}}</a> &raquo;
<a href="./">{{repo.branch}}</a>
</h1>
@ -35,7 +38,7 @@
% include paginate more = more, offset = offset
% kwargs = dict(repo=repo, commits=commits,
% shorten=shorten, repo_root="../..")
% shorten=shorten, repo_root=relroot + "../..")
% include commit-list **kwargs
<p/>

@ -4,10 +4,11 @@
<head>
% if not dirname.raw:
% relroot = './'
% reltree = './'
% else:
% relroot = '../' * (len(dirname.split('/')) - 1)
% reltree = '../' * (len(dirname.split('/')) - 1)
% end
% relroot = reltree + '../' * (len(repo.branch.split('/')) - 1)
<title>git &raquo; {{repo.name}} &raquo;
{{repo.branch}} &raquo; {{dirname.unicode}}</title>
@ -19,13 +20,13 @@
<body class="tree">
<h1><a href="{{relroot}}../../../../../">git</a> &raquo;
<a href="{{relroot}}../../../">{{repo.name}}</a> &raquo;
<a href="{{relroot}}../">{{repo.branch}}</a> &raquo;
<a href="{{relroot}}">tree</a>
<a href="{{reltree}}../">{{repo.branch}}</a> &raquo;
<a href="{{reltree}}">tree</a>
</h1>
<h3>
<a href="{{relroot}}">[{{repo.branch}}]</a> /
% base = smstr(relroot)
<a href="{{reltree}}">[{{repo.branch}}]</a> /
% base = smstr(reltree)
% for c in dirname.split('/'):
% if not c.raw:
% continue