M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +3 -9
@@ 10,7 10,7 @@ from flask import Blueprint, render_template, abort, current_app, send_file, req
from flask import Response, url_for, session, redirect
from gitsrht.editorconfig import EditorConfig
from gitsrht.git import Repository as GitRepository, commit_time, annotate_tree
-from gitsrht.git import diffstat, get_log
+from gitsrht.git import diffstat, get_log, diff_for_commit
from gitsrht.rss import generate_feed
from gitsrht.types import Artifact
from io import BytesIO
@@ 399,7 399,7 @@ def log(owner, repo, ref, path):
except ValueError:
abort(404)
- commits = get_log(git_repo, commit)
+ commits = get_log(git_repo, commit, path)
return render_template("log.html", view="log",
owner=owner, repo=repo, ref=ref, path=path,
@@ 434,13 434,7 @@ def commit(owner, repo, ref):
commit, ref, _ = lookup_ref(git_repo, ref, None)
if not isinstance(commit, pygit2.Commit):
abort(404)
- try:
- parent = git_repo.revparse_single(ref + "^")
- diff = git_repo.diff(parent, ref)
- except KeyError:
- parent = None
- diff = commit.tree.diff_to_tree(swap=True)
- diff.find_similar(pygit2.GIT_DIFF_FIND_RENAMES)
+ parent, diff = diff_for_commit(git_repo, commit)
refs = collect_refs(git_repo)
return render_template("commit.html", view="log",
owner=owner, repo=repo, ref=ref, refs=refs,
M gitsrht/git.py => gitsrht/git.py +24 -2
@@ 25,10 25,32 @@ def commit_time(commit):
def _get_ref(repo, ref):
return repo._get(ref)
-def get_log(git_repo, commit, commits_per_page=20, until=None):
+def diff_for_commit(git_repo, commit):
+ try:
+ parent = git_repo.revparse_single(commit.id.hex + "^")
+ diff = git_repo.diff(parent, commit)
+ except KeyError:
+ parent = None
+ diff = commit.tree.diff_to_tree(swap=True)
+ diff.find_similar(pygit2.GIT_DIFF_FIND_RENAMES)
+ return parent, diff
+
+def get_log(git_repo, commit, path="", commits_per_page=20, until=None):
commits = list()
for commit in git_repo.walk(commit.id, pygit2.GIT_SORT_TOPOLOGICAL):
- commits.append(commit)
+ if path:
+ _, diff = diff_for_commit(git_repo, commit)
+ for patch in diff:
+ exact = False
+ if patch.delta.new_file.path == path:
+ path = patch.delta.old_file.path
+ exact = True
+ if exact or patch.delta.new_file.path.startswith(path + "/"):
+ commits.append(commit)
+ break
+ else:
+ commits.append(commit)
+
if until is not None and commit == until:
break
elif len(commits) >= commits_per_page + 1:
M gitsrht/templates/blob.html => gitsrht/templates/blob.html +6 -0
@@ 31,6 31,12 @@ pre, body {
</span>
</span>
<span class="text-muted" style="margin-left: 1rem">
+ <a href="{{url_for("repo.log", owner=repo.owner.canonical_name,
+ repo=repo.name, ref=ref, path=path_join(*path))}}"
+ >Log
+ </a>
+ </span>
+ <span class="text-muted" style="margin-left: 1rem">
<a href="{{url_for("repo.raw_blob", owner=repo.owner.canonical_name,
repo=repo.name, ref=ref, path=path_join(*path))}}"
>View raw</a>
M gitsrht/templates/tree.html => gitsrht/templates/tree.html +6 -0
@@ 9,6 9,12 @@
<span style="padding-left: 1rem">
{{ utils.breadcrumb(ref, repo, path, path_join) }}
</span>
+ <span class="text-muted" style="margin-left: 1rem">
+ <a href="{{url_for("repo.log", owner=repo.owner.canonical_name,
+ repo=repo.name, ref=ref, path=path_join(*path))}}"
+ >Log
+ </a>
+ </span>
<div class="pull-right">
<a
href="{{url_for("repo.commit",