From 0021188890386b4b3a4df5a95b8afa6a0f8a180b Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Oct 20 2014 17:57:34 +0000 Subject: Rework commit page --- diff --git a/progit/__init__.py b/progit/__init__.py index f45e2be..328abe4 100644 --- a/progit/__init__.py +++ b/progit/__init__.py @@ -35,6 +35,9 @@ import progit.doc_utils import progit.login_forms import markdown +from pygments import highlight +from pygments.lexers.text import DiffLexer +from pygments.formatters import HtmlFormatter # Create the application. APP = flask.Flask(__name__) @@ -369,6 +372,30 @@ def markdown_filter(text): return '' +@APP.template_filter('html_diff') +def html_diff(diff): + """Display diff as HTML""" + return highlight( + diff, + DiffLexer(), + HtmlFormatter( + noclasses=True, + style="tango",) + ) + + +@APP.template_filter('patch_to_diff') +def patch_to_diff(patch): + """Render a hunk as a diff""" + content = "" + for hunk in patch.hunks: + content = content + "@@ -%i,%i +%i,%i @@\n" % (hunk.old_start, + hunk.old_lines, hunk.new_start, hunk.new_lines) + for line in hunk.lines: + content = content + ' '.join(line) + return content + + @FAS.postlogin def set_user(return_url): ''' After login method. ''' diff --git a/progit/static/progit.css b/progit/static/progit.css index 1c8568c..0885fe9 100644 --- a/progit/static/progit.css +++ b/progit/static/progit.css @@ -14,6 +14,10 @@ textarea { background: rgba(255, 255, 255, 0.5); } +td, th { + padding: .1em .2em; +} + .message { color: green; } @@ -435,7 +439,8 @@ table.list .open_by { .issue_comment > header, .issue_comment > form > header, -.file_content > header +.file_content > header, +.commit_diff > header { border-radius: 10px 10px 0 0; padding: .5em; @@ -482,17 +487,22 @@ table.list .open_by { padding: .5em; } +.header .buttons, header .buttons { + display: inline-block; + float: right; list-style-type: none; text-align: right; margin: 0; } +.header .buttons li, header .buttons li { display: inline-block; padding-left: .5em; } +.header .button, header .button { display: inline-block; color: white; @@ -509,16 +519,20 @@ header .button { box-shadow: inset 0 1px rgba(255, 255, 255, 0.5), 0 0 2px rgba(0, 0, 0, 0.2); } +.header .button:hover, header .button:hover { background-image: linear-gradient(to bottom, #34609f, #0066cc); } +.header a.button:visited, +.header a.button:hover, header a.button:visited, header a.button:hover { color: white; } -.file_content { +.file_content, +.commit_diff { border: 1px solid rgba(237, 237, 237, 0.4); border-radius: 10px 10px 0 0; } @@ -593,3 +607,42 @@ a.user_settings { #profile_button { display: inline-block; } + +.header > h3, +.commit_diff > header h3 { + display: inline-block; + margin: .4em 0 0; +} + +.commit_message_body { + display: block; + font-weight: normal; + font-size: .9em; +} + +.commit_diff { + margin-top: 2em; +} + +.addrem_bar { + display: inline-block; + width: 100px; + padding: 0!important; + text-align: left; + background-color: #ffdddd; +} + +.addrem_bar > span { + display: block; + background-color: #dbffdb; +} + +ul.changes { + margin: 0; + list-style-type: none; + padding: 0; +} + +.header { + padding: .5em 0; +} diff --git a/progit/templates/commit.html b/progit/templates/commit.html index 9060f2b..a70fe98 100644 --- a/progit/templates/commit.html +++ b/progit/templates/commit.html @@ -1,34 +1,55 @@ {% extends "repo_master.html" %} {% block title %}Commit - {{ repo.name }} - {{ commitid }}{% endblock %} -{%block tag %}home{% endblock %} +{%block tag %}commit{% endblock %} {% block repo %} +{% set splitted_message = commit.message.split('\n') %} +

- Commit: {{ commitid }} - (tree) + {{ splitted_message[0] }} + (commit: {{ commitid|short }} + - tree) + {% if splitted_message|length > 1 %} + + {% for message in splitted_message %} + {% if loop.index > 1 %} + {{ message }} + {% endif %} + {% endfor %} + + {% endif %}

+ + +
- + - + - + +
AuthorAuthor {{ commit.author.name }} {{ '<' + commit.author.email + '>' }} - {{ commit.commit_time | format_ts}}
CommitterCommitter {{ commit.committer.name }} {{ '<' + commit.committer.email + '>' }} - {{ commit.commit_time | format_ts }}
ParentParent {% for parent in commit.parents %} + {% for patch in diff %} +
  • + + + {% if patch.additions > 0 %}+{{ patch.additions }}{% endif %} + {% if patch.deletions > 0 %}-{{ patch.deletions }}{% endif %} + + + {{ patch.new_file_path }} +
  • + {% endfor %} + +
    -
    - - {{ commit.message.split('\n')[0] }} - - - {{ commit.message.split('\n')[1] }} - -
    - +{% for patch in diff %}
    -

    Diff:

    - {% autoescape false %} - {{ html_diff }} - {% endautoescape %} +
    +

    {{ patch.new_file_path }}

    +
      +
    • + + {% if patch.additions > 0 %}+{{ patch.additions }}{% endif %} + {% if patch.deletions > 0 %}-{{ patch.deletions }}{% endif %} + +
    • +
    • + View +
    • +
    +
    + + {% if patch.is_binary %} +

    Binary diffs cannot be rendered.

    + {% else %} + {% autoescape false %} + {{ patch|patch_to_diff|html_diff}} + {% endautoescape %} + {% endif %}
    +{% endfor %} + {% endblock %} diff --git a/progit/ui/repo.py b/progit/ui/repo.py index c41f5d7..3fc459a 100644 --- a/progit/ui/repo.py +++ b/progit/ui/repo.py @@ -361,10 +361,12 @@ def view_file(repo, identifier, filename, username=None): ) +@APP.route('//raw/', defaults={'filename': None}) @APP.route('//raw//') +@APP.route('/fork///raw/', defaults={'filename': None}) @APP.route('/fork///raw//') -def view_raw_file(repo, identifier, filename, username=None): - """ Displays the raw content of a file for the specified repo. +def view_raw_file(repo, identifier, filename=None, username=None): + """ Displays the raw content of a file of a commit for the specified repo. """ repo = progit.lib.get_project(SESSION, repo, user=username) @@ -386,12 +388,25 @@ def view_raw_file(repo, identifier, filename, username=None): # If it's not a commit id then it's part of the filename commit = repo_obj[repo_obj.head.target] - content = __get_file_in_tree(repo_obj, commit.tree, filename.split('/')) - if not content: - flask.abort(404, 'File not found') + mimetype = None + encoding = None + if filename: + content = __get_file_in_tree(repo_obj, commit.tree, filename.split('/')) + if not content: + flask.abort(404, 'File not found') + + mimetype, encoding = mimetypes.guess_type(filename) + data = repo_obj[content.oid].data + else: + if commit.parents: + diff = commit.tree.diff_to_tree() - mimetype, encoding = mimetypes.guess_type(filename) - data = repo_obj[content.oid].data + parent = repo_obj.revparse_single('%s^' % identifier) + diff = repo_obj.diff(parent, commit) + else: + # First commit in the repo + diff = commit.tree.diff_to_tree(swap=True) + data = diff.patch if not mimetype and data[:2] == '#!': mimetype = 'text/plain' @@ -441,14 +456,6 @@ def view_commit(repo, commitid, username=None): # First commit in the repo diff = commit.tree.diff_to_tree(swap=True) - html_diff = highlight( - diff.patch, - DiffLexer(), - HtmlFormatter( - noclasses=True, - style="tango",) - ) - return flask.render_template( 'commit.html', select='logs', @@ -457,7 +464,6 @@ def view_commit(repo, commitid, username=None): commitid=commitid, commit=commit, diff=diff, - html_diff=html_diff, )