Klaus Demo ~jonashaag/klaus / cf9934f
Fix viewing tags, rename 'commit_id' to 'rev'(ision) Jonas Haag 9 years ago
8 changed file(s) with 47 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
4646 def setup_routes(self):
4747 for endpoint, rule in [
4848 ('repo_list', '/'),
49 ('blob', '/<repo>/blob/<commit_id>/'),
50 ('blob', '/<repo>/blob/<commit_id>/<path:path>'),
51 ('raw', '/<repo>/raw/<commit_id>/'),
52 ('raw', '/<repo>/raw/<commit_id>/<path:path>'),
53 ('commit', '/<repo>/commit/<commit_id>/'),
49 ('blob', '/<repo>/blob/<rev>/'),
50 ('blob', '/<repo>/blob/<rev>/<path:path>'),
51 ('raw', '/<repo>/raw/<rev>/'),
52 ('raw', '/<repo>/raw/<rev>/<path:path>'),
53 ('commit', '/<repo>/commit/<rev>/'),
5454 ('history', '/<repo>/'),
55 ('history', '/<repo>/tree/<commit_id>/'),
56 ('history', '/<repo>/tree/<commit_id>/<path:path>'),
55 ('history', '/<repo>/tree/<rev>/'),
56 ('history', '/<repo>/tree/<rev>/<path:path>'),
5757 ]:
5858 self.add_url_rule(rule, view_func=getattr(views, endpoint))
5959
2020 return refs[0].commit_time
2121 return None
2222
23 def get_ref_or_commit(self, name_or_sha1):
24 for prefix in ['', 'refs/heads/', 'refs/tags/']:
23 def get_commit(self, rev):
24 for prefix in ['refs/heads/', 'refs/tags/', '']:
25 key = prefix + rev
2526 try:
26 return self[prefix+name_or_sha1]
27 # XXX: Workaround https://github.com/jelmer/dulwich/issues/82
28 if not key.isalnum():
29 key = self.refs[key]
30 obj = self.object_store[key]
31 if isinstance(obj, dulwich.objects.Tag):
32 obj = self[obj.object[1]]
33 return obj
2734 except KeyError:
2835 pass
29
30 raise KeyError(name_or_sha1)
36 raise KeyError(rev)
3137
3238 def get_default_branch(self):
3339 """
3541 """
3642 for candidate in ['master', 'trunk', 'default', 'gh-pages']:
3743 try:
38 self.get_ref_or_commit(candidate)
44 self.get_commit(candidate)
3945 return candidate
4046 except KeyError:
4147 pass
00 {% extends 'skeleton.html' %}
11
22 {% block title %}
3 {{ repo.name }} ({{ commit_id|shorten_sha1 }})
3 {{ repo.name }} ({{ rev|shorten_sha1 }})
44 {% endblock %}
55
66 {% block breadcrumbs %}
77 <span>
88 <a href="{{ url_for('history', repo=repo.name) }}">{{ repo.name }}</a>
99 <span class=slash>/</span>
10 <a href="{{ url_for('history', repo=repo.name, commit_id=commit_id) }}">{{ commit_id|shorten_sha1 }}</a>
10 <a href="{{ url_for('history', repo=repo.name, rev=rev) }}">{{ rev|shorten_sha1 }}</a>
1111 </span>
1212
1313 {% if subpaths %}
1616 {% if loop.last %}
1717 <a href="">{{ name|force_unicode }}</a>
1818 {% else %}
19 <a href="{{ url_for('history', repo=repo.name, commit_id=commit_id, path=subpath) }}">{{ name|force_unicode }}</a>
19 <a href="{{ url_for('history', repo=repo.name, rev=rev, path=subpath) }}">{{ name|force_unicode }}</a>
2020 <span class=slash>/</span>
2121 {% endif %}
2222 {% endfor %}
2626
2727 {% block extra_header %}
2828 <div class=branch-selector>
29 <span>{{ commit_id|shorten_sha1 }}</span>
29 <span>{{ rev|shorten_sha1 }}</span>
3030 <div>
3131 <ul class=branches>
3232 {% for branch in branches %}
33 <li><a href="{{ url_for(view, repo=repo.name, commit_id=branch, path=path) }}">{{ branch }}</a></li>
33 <li><a href="{{ url_for(view, repo=repo.name, rev=branch, path=path) }}">{{ branch }}</a></li>
3434 {% endfor %}
3535 </ul>
3636 {% if tags %}
3737 <ul class=tags>
3838 {% for tag in tags %}
39 <li><a href="{{ url_for(view, repo=repo.name, commit_id=tag, path=path) }}">{{ tag }}</a></li>
39 <li><a href="{{ url_for(view, repo=repo.name, rev=tag, path=path) }}">{{ tag }}</a></li>
4040 {% endfor %}
4141 </ul>
4242 {% endif %}
4444 Commit History
4545 {% endif %}
4646 <span>
47 @<a href="{{ url_for(view, repo=repo.name, commit_id=commit_id) }}">{{ commit_id }}</a>
47 @<a href="{{ url_for(view, repo=repo.name, rev=rev) }}">{{ rev }}</a>
4848 </span>
4949 {% if USE_SMARTHTTP %}
5050 <code>git clone {{ url_for('history', repo=repo.name, _external=True) }}</code>
5656 <ul>
5757 {% for commit in history %}
5858 <li>
59 <a class=commit href="{{ url_for('commit', repo=repo.name, commit_id=commit.id) }}">
59 <a class=commit href="{{ url_for('commit', repo=repo.name, rev=commit.id) }}">
6060 <span class=line1>
6161 <span>{{ commit.message|force_unicode|shorten_message }}</span>
6262 </span>
00 <div class=tree>
1 <h2>Tree @<a href="{{ url_for('commit', repo=repo.name, commit_id=commit_id) }}">{{ commit_id|shorten_sha1 }}</a></h2>
1 <h2>Tree @<a href="{{ url_for('commit', repo=repo.name, rev=rev) }}">{{ rev|shorten_sha1 }}</a></h2>
22 <ul>
33 {% for _, name, fullpath in root_tree.dirs %}
4 <li><a href="{{ url_for('history', repo=repo.name, commit_id=commit_id, path=fullpath) }}" class=dir>{{ name|force_unicode }}</a></li>
4 <li><a href="{{ url_for('history', repo=repo.name, rev=rev, path=fullpath) }}" class=dir>{{ name|force_unicode }}</a></li>
55 {% endfor %}
66 {% for _, name, fullpath in root_tree.files %}
7 <li><a href="{{ url_for('blob', repo=repo.name, commit_id=commit_id, path=fullpath) }}">{{ name|force_unicode }}</a></li>
7 <li><a href="{{ url_for('blob', repo=repo.name, rev=rev, path=fullpath) }}">{{ name|force_unicode }}</a></li>
88 {% endfor %}
99 </ul>
1010 </div>
77
88 {% include 'tree.inc.html' %}
99
10 {% set raw_url = url_for('raw', repo=repo.name, commit_id=commit_id, path=path) %}
10 {% set raw_url = url_for('raw', repo=repo.name, rev=rev, path=path) %}
1111
1212 <div class=blobview>
1313 <h2>
1414 {{ filename|force_unicode }}
1515 <span>
16 @<a href="{{ url_for('commit', repo=repo.name, commit_id=commit_id) }}">{{ commit_id|shorten_sha1 }}</a>
16 @<a href="{{ url_for('commit', repo=repo.name, rev=rev) }}">{{ rev|shorten_sha1 }}</a>
1717 &mdash;
1818 {% if is_markup %}
1919 {% if render_markup %}
2424 &middot;
2525 {% endif %}
2626 <a href="{{ raw_url }}">raw</a>
27 &middot; <a href="{{ url_for('history', repo=repo.name, commit_id=commit_id, path=path) }}">history</a>
27 &middot; <a href="{{ url_for('history', repo=repo.name, rev=rev, path=path) }}">history</a>
2828 </span>
2929 </h2>
3030 {% if is_binary %}
22 {% block extra_header %}{% endblock %} {# no branch selector on commits #}
33
44 {% block title %}
5 Commit {{ commit_id }} - {{ repo.name }}
5 Commit {{ rev }} - {{ repo.name }}
66 {% endblock %}
77
88 {% block content %}
3737 {% if file.new_filename == '/dev/null' %}
3838 <del>{{ file.old_filename|force_unicode }}</del>
3939 {% else %}
40 <a href="{{ url_for('blob', repo=repo.name, commit_id=commit_id, path=file.new_filename) }}">
40 <a href="{{ url_for('blob', repo=repo.name, rev=rev, path=file.new_filename) }}">
4141 {{ file.new_filename|force_unicode }}
4242 </a>
4343 {% endif %}
77 from werkzeug.exceptions import NotFound
88
99 from dulwich.objects import Blob
10 from dulwich.diff_tree import RenameDetector
1110
1211 from klaus import markup
1312 from klaus.utils import parent_directory, subpaths, get_mimetype_and_encoding, \
3029 """
3130 Base for all views with a repo context.
3231
33 The arguments `repo`, `commit_id`, `path` (see `dispatch_request`) define
34 the repository, branch/commit and directory/file context, respectively --
32 The arguments `repo`, `rev`, `path` (see `dispatch_request`) define the
33 repository, branch/commit and directory/file context, respectively --
3534 that is, they specify what (and in what state) is being displayed in all the
3635 derived views.
3736
3837 For example: The 'history' view is the `git log` equivalent, i.e. if `path`
3938 is "/foo/bar", only commits related to "/foo/bar" are displayed, and if
40 `commit_id` is "master", the history of the "master" branch is displayed.
39 `rev` is "master", the history of the "master" branch is displayed.
4140 """
4241 def __init__(self, view_name, template_name=None):
4342 self.view_name = view_name
4443 self.template_name = template_name
4544 self.context = {}
4645
47 def dispatch_request(self, repo, commit_id=None, path=''):
48 self.make_context(repo, commit_id, path.strip('/'))
46 def dispatch_request(self, repo, rev=None, path=''):
47 self.make_context(repo, rev, path.strip('/'))
4948 return self.get_response()
5049
5150 def get_response(self):
5251 return render_template(self.template_name, **self.context)
5352
54 def make_context(self, repo, commit_id, path):
53 def make_context(self, repo, rev, path):
5554 try:
5655 repo = current_app.repo_map[repo]
57 if commit_id is None:
58 commit_id = repo.get_default_branch()
59 commit = repo.get_ref_or_commit(commit_id)
56 if rev is None:
57 rev = repo.get_default_branch()
58 commit = repo.get_commit(rev)
6059 except KeyError:
6160 raise NotFound("Commit not found")
6261
6867 self.context = {
6968 'view': self.view_name,
7069 'repo': repo,
71 'commit_id': commit_id,
70 'rev': rev,
7271 'commit': commit,
73 'branches': repo.get_branch_names(exclude=commit_id),
72 'branches': repo.get_branch_names(exclude=rev),
7473 'tags': repo.get_tag_names(),
7574 'path': path,
7675 'blob_or_tree': blob_or_tree,
144143 skip = 0
145144
146145 history = self.context['repo'].history(
147 self.context['commit_id'],
146 self.context['rev'],
148147 self.context['path'],
149148 history_length + 1,
150149 skip