From d3efd77b6d6107b29d9cb359baf93c844030c9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 22 Jan 2022 21:36:13 +0100 Subject: [PATCH] Unsplit blame chunks from consecutive final commits These are split, like in porcelain mode in CLI, when consecutive final commit lines are non-consecutive in the originals (I think?) Closes: https://todo.sr.ht/~sircmpwn/git.sr.ht/357 --- gitsrht/blueprints/repo.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index bc0d0a0..d509e1f 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -334,6 +334,31 @@ def lookup_user(): cache = {} return lambda email: _lookup_user(email, cache) +# We only care about these fields in in blame.html, so we discard +# boundary, final_start_line_number, orig_commit_id, orig_committer, +# orig_path, and orig_start_line_number here +class FakeBlameHunk: + def __init__(self, hunk): + self.final_commit_id = hunk.final_commit_id + self.final_committer = hunk.final_committer + self.lines_in_hunk = hunk.lines_in_hunk + +# Blame hunks of the same final commit are split if they're not consecutive +# lines in the original commit (cf. https://todo.sr.ht/~sircmpwn/git.sr.ht/357) +def weld_hunks(blame): + last = None + for nxt in map(FakeBlameHunk, blame): + if last is None: + last = nxt + continue + if last.final_commit_id == nxt.final_commit_id: + last.lines_in_hunk += nxt.lines_in_hunk + else: + yield last + last = nxt + if last is not None: + yield last + @repo.route("///blame/", defaults={"path": ""}) @repo.route("///blame//") def blame(owner, repo, ref, path): @@ -361,7 +386,7 @@ def blame(owner, repo, ref, path): return render_template("blame.html", view="blame", owner=owner, repo=repo, ref=ref, path=path, entry=entry, blob=blob, data=data, - blame=blame, commit=orig_commit, highlight_file=_highlight_file, + blame=list(weld_hunks(blame)), commit=orig_commit, highlight_file=_highlight_file, editorconfig=EditorConfig(git_repo, orig_commit.tree, path), lookup_user=lookup_user(), pygit2=pygit2) -- 2.38.4