From 3d9979a5a5f3badd52825da291626f29d6bc085e Mon Sep 17 00:00:00 2001 From: Carlos Mogas da Silva Date: Jul 13 2017 10:18:24 +0000 Subject: Simplify diff calculation The old code had 2 diff atributions and I could not see any reason for them. Also, instead of getting the parent via revparse_single, just get it from the attributes. --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 8675109..dcf9fc3 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -51,10 +51,7 @@ def commit_to_patch(repo_obj, commits): patch = "" for cnt, commit in enumerate(commits): if commit.parents: - diff = commit.tree.diff_to_tree() - - parent = repo_obj.revparse_single('%s^' % commit.oid.hex) - diff = repo_obj.diff(parent, commit) + diff = repo_obj.diff(commit.parents[0], commit) else: # First commit in the repo diff = commit.tree.diff_to_tree(swap=True) diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 6252161..79f3de8 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -620,13 +620,8 @@ def view_raw_file( data = repo_obj[content.oid].data else: if commit.parents: - diff = commit.tree.diff_to_tree() - - try: - parent = repo_obj.revparse_single('%s^' % identifier) - diff = repo_obj.diff(parent, commit) - except (KeyError, ValueError): - flask.abort(404, 'Identifier not found') + # We already know that commit and parents exist. We shouldn't fail here + diff = repo_obj.diff(commit.parents[0], commit); else: # First commit in the repo diff = commit.tree.diff_to_tree(swap=True) @@ -750,10 +745,7 @@ def view_commit(repo, commitid, username=None, namespace=None): flask.abort(404, 'Commit not found') if commit.parents: - diff = commit.tree.diff_to_tree() - - parent = repo_obj.revparse_single('%s^' % commitid) - diff = repo_obj.diff(parent, commit) + diff = repo_obj.diff(commit.parents[0], commit) else: # First commit in the repo diff = commit.tree.diff_to_tree(swap=True)