diff --git a/templates/repository/log.html b/templates/repository/log.html index d65c579..c0372e1 100644 --- a/templates/repository/log.html +++ b/templates/repository/log.html @@ -74,6 +74,17 @@ +
+ + {% if offset > 0 %} + {% set prev_offset = offset - log_pagination %} + « Prev + {% endif %} + + {% if commits|length == log_pagination %} + {% set next_offset = offset + log_pagination %} + Next » + {% endif %} {% endblock %} diff --git a/web.py b/web.py index de85fc3..e36d895 100644 --- a/web.py +++ b/web.py @@ -40,6 +40,9 @@ GITOLITE_HTTP_HOME = '/home/git' # or when the domain needs to be displayed on some pages. INSTANCE_DOMAIN = 'domain.local' +# How many commits to show in the log page +LOG_PAGINATION = 100 + @@ -461,17 +464,29 @@ def log(repository, revision): # At this point git_object should be a valid pygit2.GIT_OBJ_COMMIT - # Read 50 commits + # Read commits + try: commits_offset = int(request.query.get('offset', 0)) + except: commits_offset = 0 + commits = [] + commit_ith = 0 for commit in repo.walk(git_object.id): - commits.append(commit) - if len(commits) >= 50: + # Skip the first one (offset) + if commit_ith < commits_offset: + commit_ith += 1 + continue + + # Stop if we have reached pagination size + if len(commits) >= LOG_PAGINATION: break + + commits.append(commit) return template( 'repository/log.html', heads=heads, head_ref=HEAD, tags=tags, commits=commits, + log_pagination=LOG_PAGINATION, offset=commits_offset, repository=repository, revision=revision) @bottle.post('/.git/log', name='log_change')