From c408778a222e7a69d8a9bf7f10a4cfe6a3dd07a3 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 20 2015 12:00:40 +0000 Subject: Simplify the view_issue_raw_file endpoint This endpoint will always be called with a filename as argument so there is no need to handle the situation where no filename is specified. --- diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 51bda42..40b3ef0 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -627,24 +627,14 @@ def view_issue_raw_file(repo, filename=None, username=None): mimetype = None encoding = None - if filename: - content = __get_file_in_tree( - repo_obj, commit.tree, filename.split('/')) - if not content or isinstance(content, pygit2.Tree): - 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() - parent = repo_obj.revparse_single('%s^' % commit.oid) - diff = repo_obj.diff(parent, commit) - else: - # First commit in the repo - diff = commit.tree.diff_to_tree(swap=True) - data = diff.patch + content = __get_file_in_tree( + repo_obj, commit.tree, filename.split('/')) + if not content or isinstance(content, pygit2.Tree): + flask.abort(404, 'File not found') + + mimetype, encoding = mimetypes.guess_type(filename) + data = repo_obj[content.oid].data if not mimetype and data[:2] == '#!': mimetype = 'text/plain'