From 0dd0cd28b72fa712e614d06757a4ac3ae956967f Mon Sep 17 00:00:00 2001 From: Slavek Kabrda Date: Sep 26 2018 10:54:33 +0000 Subject: Switch from GIT_SORT_TIME to GIT_SORT_NONE to preserver 'git log'-like commit ordering Fixes #3726 --- diff --git a/pagure/internal/__init__.py b/pagure/internal/__init__.py index 28f5c7c..d1942e3 100644 --- a/pagure/internal/__init__.py +++ b/pagure/internal/__init__.py @@ -456,7 +456,7 @@ def get_branches_of_commit(): repo_commit = repo_obj[branch.get_object().hex] for commit in repo_obj.walk( - repo_commit.oid.hex, pygit2.GIT_SORT_TIME + repo_commit.oid.hex, pygit2.GIT_SORT_NONE ): if commit.oid.hex == merge_commit: break diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 70ebb60..8b0601b 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -1751,12 +1751,12 @@ def get_diff_info(repo_obj, orig_repo, branch_from, branch_to, prid=None): if branch: orig_commit = orig_repo[branch.get_object().hex] main_walker = orig_repo.walk( - orig_commit.oid.hex, pygit2.GIT_SORT_TIME + orig_commit.oid.hex, pygit2.GIT_SORT_NONE ) repo_commit = repo_obj[commitid] branch_walker = repo_obj.walk( - repo_commit.oid.hex, pygit2.GIT_SORT_TIME + repo_commit.oid.hex, pygit2.GIT_SORT_NONE ) main_commits = set() @@ -1818,7 +1818,7 @@ def get_diff_info(repo_obj, orig_repo, branch_from, branch_to, prid=None): branch = repo_obj.lookup_branch(branch_from) repo_commit = branch.get_object() - for commit in repo_obj.walk(repo_commit.oid.hex, pygit2.GIT_SORT_TIME): + for commit in repo_obj.walk(repo_commit.oid.hex, pygit2.GIT_SORT_NONE): diff_commits.append(commit) _log.debug("Diff commits: %s", diff_commits) diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index 2ad2193..b8214de 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -914,7 +914,7 @@ def commits_author_stats(self, session, repopath): number_of_commits = 0 authors_email = set() for commit in repo_obj.walk( - repo_obj.head.get_object().oid.hex, pygit2.GIT_SORT_TIME + repo_obj.head.get_object().oid.hex, pygit2.GIT_SORT_NONE ): # For each commit record how many times each combination of name and # e-mail appears in the git history. @@ -971,7 +971,7 @@ def commits_history_stats(self, session, repopath): dates = collections.defaultdict(int) for commit in repo_obj.walk( - repo_obj.head.get_object().oid.hex, pygit2.GIT_SORT_TIME + repo_obj.head.get_object().oid.hex, pygit2.GIT_SORT_NONE ): delta = ( datetime.datetime.utcnow() - arrow.get(commit.commit_time).naive diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 356eb55..5945902 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -265,7 +265,7 @@ def request_pull(repo, requestid, username=None, namespace=None): if request.status != "Open": commitid = request.commit_stop try: - for commit in repo_obj.walk(commitid, pygit2.GIT_SORT_TIME): + for commit in repo_obj.walk(commitid, pygit2.GIT_SORT_NONE): diff_commits.append(commit) if commit.oid.hex == request.commit_start: break @@ -417,7 +417,7 @@ def request_pull_to_diff_or_patch( if request.status != "Open": commitid = request.commit_stop try: - for commit in repo_obj.walk(commitid, pygit2.GIT_SORT_TIME): + for commit in repo_obj.walk(commitid, pygit2.GIT_SORT_NONE): diff_commits.append(commit) if commit.oid.hex == request.commit_start: break diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 68e19db..e2635e4 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -126,7 +126,7 @@ def view_repo(repo, username=None, namespace=None): if not repo_obj.is_empty: try: for commit in repo_obj.walk( - repo_obj.head.target, pygit2.GIT_SORT_TIME + repo_obj.head.target, pygit2.GIT_SORT_NONE ): last_commits.append(commit) cnt += 1 @@ -208,7 +208,7 @@ def view_repo_branch(repo, branchname, username=None, namespace=None): head = None cnt = 0 last_commits = [] - for commit in repo_obj.walk(branch.get_object().hex, pygit2.GIT_SORT_TIME): + for commit in repo_obj.walk(branch.get_object().hex, pygit2.GIT_SORT_NONE): last_commits.append(commit) cnt += 1 if cnt == 3: @@ -240,13 +240,13 @@ def view_repo_branch(repo, branchname, username=None, namespace=None): commit.oid.hex for commit in orig_repo.walk( compare_branch.get_object().hex, - pygit2.GIT_SORT_TIME) + pygit2.GIT_SORT_NONE) ] repo_commit = repo_obj[branch.get_object().hex] for commit in repo_obj.walk( - repo_commit.oid.hex, pygit2.GIT_SORT_TIME): + repo_commit.oid.hex, pygit2.GIT_SORT_NONE): if commit.oid.hex in commit_list: break diff_commits.append(commit.oid.hex) @@ -352,7 +352,7 @@ def view_commits(repo, branchname=None, username=None, namespace=None): n_commits = 0 last_commits = [] if commit: - for commit in repo_obj.walk(commit.hex, pygit2.GIT_SORT_TIME): + for commit in repo_obj.walk(commit.hex, pygit2.GIT_SORT_NONE): # Filters the commits for a user if author_obj: @@ -455,13 +455,13 @@ def compare_commits(repo, commit1, commit2, username=None, namespace=None): # Get commits list diff_commits = [] - order = pygit2.GIT_SORT_TIME + order = pygit2.GIT_SORT_NONE first_commit = commit1 last_commit = commit2 commits = [ commit.oid.hex[: len(first_commit)] - for commit in repo_obj.walk(last_commit, pygit2.GIT_SORT_TIME) + for commit in repo_obj.walk(last_commit, pygit2.GIT_SORT_NONE) ] if first_commit not in commits: diff --git a/tests/test_pagure_lib_task_services.py b/tests/test_pagure_lib_task_services.py index ca546ce..ca9072d 100644 --- a/tests/test_pagure_lib_task_services.py +++ b/tests/test_pagure_lib_task_services.py @@ -644,7 +644,7 @@ class PagureLibTaskServicesLoadJsonTickettests(tests.Modeltests): commits = [ commit for commit in self.repo_obj.walk( - self.repo_obj.head.target, pygit2.GIT_SORT_TIME) + self.repo_obj.head.target, pygit2.GIT_SORT_NONE) ] # 2 commits: creation - new comment self.assertEqual(len(commits), 2) @@ -662,7 +662,7 @@ class PagureLibTaskServicesLoadJsonTickettests(tests.Modeltests): commits = [ commit.oid.hex for commit in self.repo_obj.walk( - self.repo_obj.head.target, pygit2.GIT_SORT_TIME) + self.repo_obj.head.target, pygit2.GIT_SORT_NONE) ] output = pagure.lib.tasks_services.load_json_commits_to_db(