From 5500b24324de0f34e0c1c331abea60ad07b8b9d5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 05 2016 21:38:14 +0000 Subject: [PATCH 1/2] 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') From 676aa1c5c8127b97ab65c240521fc99236b46efe Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 05 2016 21:38:14 +0000 Subject: [PATCH 2/2] Let's return a 404 error is the identifier provided isn't found The identifier can be one of a commit (default/expected) but also one of a blob, but in either case a 404 error seems to make more sense than a 400 one. --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 71b946a..64819f3 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -622,7 +622,7 @@ def view_raw_file( commit = repo_obj[repo_obj.head.target] if not commit: - flask.abort(400, 'Commit %s not found' % (identifier)) + flask.abort(404, 'Commit %s not found' % (identifier)) if isinstance(commit, pygit2.Tag): commit = commit.get_object()