From 5500b24324de0f34e0c1c331abea60ad07b8b9d5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 05 2016 21:38:14 +0000 Subject: Fix rendering raw file when the sha1 provided is one of a blob In the regular UI, you can view the content of a file at any sha1 provided be it one of a commit (the expected/default being the sha1 of a commit). For binary files, the UI would then point you to the raw endpoint. But if you were trying to see a binary file in a blob, the raw endpoint would just error out since it was considering the commit object to be a commit not a blob and thus ``commit.tree`` would fail. With this change, pagure will happily return you whatever is in this blob instead of failing. --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index afd5b5b..71b946a 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -630,8 +630,11 @@ def view_raw_file( mimetype = None encoding = None if filename: - content = __get_file_in_tree( - repo_obj, commit.tree, filename.split('/'), bail_on_tree=True) + if isinstance(commit, pygit2.Blob): + content = commit + else: + content = __get_file_in_tree( + repo_obj, commit.tree, filename.split('/'), bail_on_tree=True) if not content or isinstance(content, pygit2.Tree): flask.abort(404, 'File not found')