diff --git a/klaus.py b/klaus.py index b4c9e3541b6a77bf2d001f05d55e31f285c27c96..943341d307fc3d48e1dc5374ee5503304d6c0580 100644 --- a/klaus.py +++ b/klaus.py @@ -84,7 +84,7 @@ def timesince(when, now=time.time): for n, unit in result[:2]) app.jinja_env.filters['timesince'] = timesince -app.jinja_env.filters['shorten_id'] = lambda id: id[:7] +app.jinja_env.filters['shorten_id'] = lambda id: id[:7] if len(id) in {20, 40} else id app.jinja_env.filters['shorten_message'] = lambda msg: msg.split('\n')[0] app.jinja_env.filters['pygmentize'] = pygmentize @@ -129,7 +129,7 @@ class BaseRepoView(BaseView): self['commit'], isbranch = self.get_commit(repo, commit_id) self['branch'] = commit_id if isbranch else 'master' self['path'] = path - if path is not None: + if path: self['subpaths'] = subpaths(path) super(BaseRepoView, self).__init__(env) @@ -163,16 +163,13 @@ class BaseRepoView(BaseView): @route('/:repo:/tree/:commit_id:/(?P<path>.*)', 'view_tree') class TreeView(BaseRepoView): def view(self): - self['files'] = ((name, self.get_tree_or_blob_url(entry)) - for name, entry in self.listdir()) + self['files'] = self.listdir() def listdir(self): - return self['repo'].listdir(self['commit'], self['path']) - - def get_tree_or_blob_url(self, tree_entry): - view = 'view_tree' if tree_entry.mode & stat.S_IFDIR else 'view_blob' - return self.build_url(view, path=tree_entry.path) - + for name, entry in self['repo'].listdir(self['commit'], self['path']): + isdir = entry.mode & stat.S_IFDIR + view = 'view_tree' if isdir else 'view_blob' + yield name, isdir, self.build_url(view, path=entry.path) @route('/:repo:/history/:commit_id:/(?P<path>.*)') class History(BaseRepoView): diff --git a/repo.py b/repo.py index bb56f8655a4145bdfc06f9e2c1c6d899f81c936b..54e956233c8e15ea4f316de6d14c4900443d4fba 100644 --- a/repo.py +++ b/repo.py @@ -34,7 +34,7 @@ class RepoWrapper(dulwich.repo.Repo): if path: commits = (c1 for c1, c2 in pairwise(commits) if self._path_changed_between(path, c1, c2)) - return list(islice(commits, skip, max_commits)) + return list(islice(commits, skip, skip+max_commits)) def _history(self, commit): if commit is None: diff --git a/static/klaus.css b/static/klaus.css new file mode 100644 index 0000000000000000000000000000000000000000..b110e92a93f352443bb3698b230f7d928f813018 --- /dev/null +++ b/static/klaus.css @@ -0,0 +1,36 @@ +body { margin: 0; padding: 0; font-size: 11pt; } +pre { font-size: 10pt; } +a, a:visited { color: blue; text-decoration: none; } +a:hover { text-decoration: underline; } +ul { list-style-type: none; padding-left: 0; } + +.clearfloat { clear: both; } + +header { background-color: #ddd; padding: 10px; } +header a + a:before { content: " ยป "; } + +#content { padding: 10px 20px; } + +#treeview .tree, .history { float: left; } +#treeview .tree { width: 30%; } +#treeview .history { width: 70%; } + +.history .commit { + background-color: #f5f5f5; + padding: 8px 10px; + margin-bottom: 2px; + display: block; + border: 1px solid #e0e0e0; +} +.history .commit > span { display: block; } + +.history .commit { color: black; } +.history .commit:hover { text-decoration: none; } +.history .commit:hover .line1 { text-decoration: underline; color: #555; } +.history .commit:hover .line1 span { color: black; } +.history .commit .line1 { font-family: monospace; font-size: 10pt; } + +.history .commit .line2 { margin-top: 3px; margin-left: 1px; } +.history .commit .line2 > span:first-child { float: left; } +.history .commit .line2 > span:nth-child(2) { float: right; } +.history .commit .line2 { color: #737373; font-size: 12px; } diff --git a/templates/history.inc.html b/templates/history.inc.html index 8199ea6f158f6e49a7dc4bcd4f9a9001088e25ce..08c25869c589c9862a9d480d7ac053bea2ce177b 100644 --- a/templates/history.inc.html +++ b/templates/history.inc.html @@ -1,17 +1,24 @@ {% macro history(repo, branch, path, max_length, skip=0) %} <div class=history> + <h2>History of + <a href="{{ build_url('view_tree', repo=repo.name, commit_id=branch, path='') }}"> + {{ repo.name }}/{{ branch }}</a> + </h2> {% set history = repo.history(branch, path, max_length+1, skip) %} <ul> {% for commit in history %} {% if not loop.last or history|length < max_length %} <li> - <span class=id> - <a href="{{ build_url('view_commit', repo=repo.name, commit_id=commit.id) }}"> - {{ commit.id|shorten_id }} - </a> - </span> - <span class=message>{{ commit.message.decode('utf-8')|shorten_message }}</span> - <span class=datetime>{{ commit.commit_time|timesince }} ago</span> + <a class=commit href="{{ build_url('view_commit', repo=repo.name, commit_id=commit.id) }}"> + <span class=line1> + <span>{{ commit.message.decode('utf-8')|shorten_message }}</span> + </span> + <span class=line2> + <span>{{ commit.commit_time|timesince }} ago</span> + <span>{{ commit.author.decode('utf-8') }}</span> + </span> + <span class=clearfloat></span> + </a> </li> {% endif %} {% endfor %} diff --git a/templates/skeleton.html b/templates/skeleton.html index a080a8ded9f63d6c1371b11154c1354b08765f36..e01029a002d48bbdc935b4c6b84febcca3628103 100644 --- a/templates/skeleton.html +++ b/templates/skeleton.html @@ -1,6 +1,7 @@ <!doctype html> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <link rel=stylesheet href=/static/pygments.css> +<link rel=stylesheet href=/static/klaus.css> <header> <a href=/>{{ environ.HTTP_HOST }}</a> diff --git a/templates/view_commit.html b/templates/view_commit.html index 5887a349e6649d643b7e007936b48c6aef73f60b..3efff49614ef181d84d48df941c67754bc4e094e 100644 --- a/templates/view_commit.html +++ b/templates/view_commit.html @@ -11,8 +11,8 @@ <div class=commit> <div class=meta> <span class=id>{{ commit.id|shorten_id }}</span> - <span class=message>{{ commit.message.decode('utf-8') }}</span> <span class=datetime>{{ commit.commit_time|timesince }} ago</span> + <span class=message>{{ commit.message.decode('utf-8') }}</span> </div> <div class=changes> {{ repo.commit_diff(commit)|pygmentize('udiff') }} diff --git a/templates/view_tree.html b/templates/view_tree.html index 0953c83f0cbce03b1b01e1ac476dd73b8d2c84e5..92de37cfe11d2eba80d544f1e8fdce50296ecde6 100644 --- a/templates/view_tree.html +++ b/templates/view_tree.html @@ -1,6 +1,18 @@ {% extends 'base.html' %} {% block content %} +<div id=treeview> + +<div class=tree> + <h2>Tree @ + <a href="{{ build_url('view_commit', repo=repo.name, commit_id=commit_id) }}">{{ commit_id|shorten_id }}</a></h2> +<ul> +{% for name, isdir, url in files %} + <li><a href="{{ url }}" {% if isdir %}class=dir{% endif %}>{{ name }}</a></li> +{% endfor %} +</ul> +</div> + {% from 'history.inc.html' import history %} {% call(have_more_commits) history(repo, branch, path, max_length=10) %} {% if have_more_commits %} @@ -9,10 +21,6 @@ {% endif %} {% endcall %} -<ul class=tree> -{% for name, url in files %} - <li><a href="{{ url }}">{{ name }}</a></li> -{% endfor %} -</ul> + </div> {% endblock %}