From 7395da4cf721f1f28e215edc60b7997fe6fc1144 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 1 Oct 2018 09:30:47 -0400 Subject: [PATCH] Add basic pagination to git log Seeking backwards is kind of expensive so we'll figure it out later --- gitsrht/blueprints/repo.py | 22 ++++++++++++++-------- gitsrht/templates/log.html | 11 ++++++++++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index ccfa081..0949bc0 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -4,7 +4,7 @@ import pygments import subprocess from datetime import datetime, timedelta from jinja2 import Markup -from flask import Blueprint, render_template, abort, send_file +from flask import Blueprint, render_template, abort, send_file, request from flask_login import current_user from gitsrht.access import get_repo, has_access, UserAccess from gitsrht.editorconfig import EditorConfig @@ -90,6 +90,7 @@ def summary(owner, repo): default_branch=default_branch) def resolve_ref(git_repo, ref): + commit = None if ref is None: branch = git_repo.default_branch() ref = branch.name[len("refs/heads/"):] @@ -260,18 +261,23 @@ def log(owner, repo, ref, path): ref, commit = resolve_ref(git_repo, ref) refs = {} - for ref in git_repo.references: - ref = _AnnotatedRef(git_repo, git_repo.references[ref]) - if not ref.type: + for _ref in git_repo.references: + _ref = _AnnotatedRef(git_repo, git_repo.references[_ref]) + if not _ref.type: continue - if ref.target.hex not in refs: - refs[ref.target.hex] = [] - refs[ref.target.hex].append(ref) + if _ref.target.hex not in refs: + refs[_ref.target.hex] = [] + refs[_ref.target.hex].append(_ref) + from_id = request.args.get("from") + if from_id: + commit = git_repo.get(from_id) + + commits_per_page = 20 commits = list() for commit in git_repo.walk(commit.id, pygit2.GIT_SORT_TIME): commits.append(commit) - if len(commits) >= 20: + if len(commits) >= commits_per_page + 1: break return render_template("log.html", view="log", diff --git a/gitsrht/templates/log.html b/gitsrht/templates/log.html index b1b4c00..16db9bb 100644 --- a/gitsrht/templates/log.html +++ b/gitsrht/templates/log.html @@ -5,10 +5,19 @@
- {% for c in commits %} + {% for c in commits[:-1] %} {{ utils.commit_event(c, commit_time, None, True, refs) }} {% endfor %}
+ Next {{icon("caret-right")}}
{% endblock %} -- 2.38.4