blob: pass branch name to view explicitly

Passing the branch name into the view indirectly via
Repo.new_in_branch() increases cognitive burden, thus outweighing
whatever minor convenience (if any) is gained by doing so. The code is
easier to reason about when the branch name is passed to the view
directly.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
This commit is contained in:
Eric Sunshine 2015-01-14 02:46:33 -05:00 committed by Alberto Bertogli
parent e6099cf272
commit 37e731fc2e
2 changed files with 7 additions and 8 deletions

@ -231,8 +231,6 @@ def commit(repo, cid):
@bottle.view('blob')
@with_utils
def blob(repo, bname, fname, dirname = ''):
r = repo.new_in_branch(bname)
if dirname and not dirname.endswith('/'):
dirname = dirname + '/'
@ -240,11 +238,12 @@ def blob(repo, bname, fname, dirname = ''):
fname = git.smstr.from_url(fname)
path = dirname.raw + fname.raw
content = r.blob(path)
content = repo.blob(path, bname)
if content is None:
bottle.abort(404, "File %r not found in branch %s" % (path, bname))
return dict(repo = r, dirname = dirname, fname = fname, blob = content)
return dict(repo = repo, branch = bname, dirname = dirname, fname = fname,
blob = content)
@bottle.route('/r/<repo:repo>/b/<bname:path>/t/')
@bottle.route('/r/<repo:repo>/b/<bname:path>/t/<dirname:path>/')

@ -8,10 +8,10 @@
% else:
% reltree = '../' * (len(dirname.split('/')) - 1)
% end
% relroot = reltree + '../' * (len(repo.branch.split('/')) - 1)
% relroot = reltree + '../' * (len(branch.split('/')) - 1)
<title>git &raquo; {{repo.name}} &raquo;
{{repo.branch}} &raquo; {{dirname.unicode}}/{{fname.unicode}}</title>
{{branch}} &raquo; {{dirname.unicode}}/{{fname.unicode}}</title>
<link rel="stylesheet" type="text/css"
href="{{relroot}}../../../../../static/git-arr.css"/>
<link rel="stylesheet" type="text/css"
@ -22,12 +22,12 @@
<body class="tree">
<h1><a href="{{relroot}}../../../../../">git</a> &raquo;
<a href="{{relroot}}../../../">{{repo.name}}</a> &raquo;
<a href="{{reltree}}../">{{repo.branch}}</a> &raquo;
<a href="{{reltree}}../">{{branch}}</a> &raquo;
<a href="{{reltree}}">tree</a>
</h1>
<h3>
<a href="{{reltree}}">[{{repo.branch}}]</a> /
<a href="{{reltree}}">[{{branch}}]</a> /
% base = smstr(reltree)
% for c in dirname.split('/'):
% if not c.raw: