diff --git a/pagure/internal/__init__.py b/pagure/internal/__init__.py index 5d9c6f4..9d02860 100644 --- a/pagure/internal/__init__.py +++ b/pagure/internal/__init__.py @@ -550,13 +550,13 @@ def get_branches_of_commit(): if compare_branch: merge_commit_obj = repo_obj.merge_base( - compare_branch.get_object().hex, branch.get_object().hex + compare_branch.peel().hex, branch.peel().hex ) if merge_commit_obj: merge_commit = merge_commit_obj.hex - repo_commit = repo_obj[branch.get_object().hex] + repo_commit = repo_obj[branch.peel().hex] for commit in repo_obj.walk( repo_commit.oid.hex, pygit2.GIT_SORT_NONE @@ -634,7 +634,7 @@ def get_branches_head(): if not repo_obj.is_empty and len(repo_obj.listall_branches()) > 1: for branchname in repo_obj.listall_branches(): branch = repo_obj.lookup_branch(branchname) - branches[branchname] = branch.get_object().hex + branches[branchname] = branch.peel().hex # invert the dict heads = collections.defaultdict(list) diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 55f11fb..6dfb438 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -268,7 +268,7 @@ def _update_git(obj, repo): # See if there is a parent to this commit parent = None try: - parent = new_repo.head.get_object().oid + parent = new_repo.head.peel().oid except pygit2.GitError: pass @@ -341,7 +341,7 @@ def _clean_git(repo, obj_repotype, obj_uid): # See if there is a parent to this commit parent = None if not new_repo.is_empty: - parent = new_repo.head.get_object().oid + parent = new_repo.head.peel().oid parents = [] if parent: @@ -838,7 +838,7 @@ def _add_file_to_git(repo, issue, attachmentfolder, user, filename): # See if there is a parent to this commit parent = None try: - parent = new_repo.head.get_object().oid + parent = new_repo.head.peel().oid except pygit2.GitError: pass @@ -978,12 +978,10 @@ class TemporaryClone(object): # This gets checked out by default continue branch = self.repo.branches.remote.get("origin/%s" % localname) - self.repo.branches.local.create(localname, branch.get_object()) + self.repo.branches.local.create(localname, branch.peel()) elif ref.startswith("refs/pull/"): reference = self._origrepo.references.get(ref) - self.repo.references.create( - ref, reference.get_object().oid.hex - ) + self.repo.references.create(ref, reference.peel().oid.hex) return self @@ -1144,7 +1142,7 @@ def _update_file_in_git( # See if there is a parent to this commit branch_ref = get_branch_ref(new_repo, branch) - parent = branch_ref.get_object() + parent = branch_ref.peel() # See if we need to create the branch nbranch_ref = None @@ -1566,8 +1564,8 @@ def merge_pull_request(session, request, username, domerge=True): # Fetch the commits remote.fetch() - # repo_commit = fork_obj[branch.get_object().hex] - repo_commit = new_repo[branch.get_object().hex] + # repo_commit = fork_obj[branch.peel().hex] + repo_commit = new_repo[branch.peel().hex] # Checkout the correct branch if new_repo.is_empty or new_repo.head_is_unborn: @@ -1677,7 +1675,7 @@ def merge_pull_request(session, request, username, domerge=True): if domerge: _log.info(" PR merged using fast-forward") - head = new_repo.lookup_reference("HEAD").get_object() + head = new_repo.lookup_reference("HEAD").peel() if not request.project.settings.get("always_merge", False): if merge is not None: # This is depending on the pygit2 version @@ -1754,7 +1752,7 @@ def merge_pull_request(session, request, username, domerge=True): _log.info(" Merge non-FF PR is disabled for this project") return "MERGE" _log.info(" Writing down merge commit") - head = new_repo.lookup_reference("HEAD").get_object() + head = new_repo.lookup_reference("HEAD").peel() _log.info( " Basing on: %s - %s", head.hex, repo_commit.oid.hex ) @@ -1972,7 +1970,7 @@ def get_diff_info(repo_obj, orig_repo, branch_from, branch_to, prid=None): commitid = None if frombranch: - commitid = frombranch.get_object().hex + commitid = frombranch.peel().hex elif prid is not None: # If there is not branch found but there is a PR open, use the ref # of that PR in the main repo @@ -2000,7 +1998,7 @@ def get_diff_info(repo_obj, orig_repo, branch_from, branch_to, prid=None): "pagure.lib.git.get_diff_info: Pulling into a non-empty repo" ) if branch: - orig_commit = orig_repo[branch.get_object().hex] + orig_commit = orig_repo[branch.peel().hex] main_walker = orig_repo.walk( orig_commit.oid.hex, pygit2.GIT_SORT_NONE ) @@ -2067,7 +2065,7 @@ def get_diff_info(repo_obj, orig_repo, branch_from, branch_to, prid=None): repo_commit = repo_obj[repo_obj.head.target] else: branch = repo_obj.lookup_branch(branch_from) - repo_commit = branch.get_object() + repo_commit = branch.peel() for commit in repo_obj.walk(repo_commit.oid.hex, pygit2.GIT_SORT_NONE): diff_commits.append(commit) @@ -2252,7 +2250,7 @@ def get_git_tags(project, with_commits=False): if tag.startswith("refs/tags/"): ref = repo_obj.lookup_reference(tag) if ref: - com = ref.get_object() + com = ref.peel() if com: tags[tag.split("refs/tags/")[1]] = com.oid.hex else: @@ -2281,9 +2279,7 @@ def get_git_tags_objects(project): theobject = None objecttype = "" if isinstance(theobject, pygit2.Tag): - underlying_obj = theobject.get_object() - if isinstance(underlying_obj, pygit2.Tree): - continue + underlying_obj = theobject.peel(pygit2.Commit) commit_time = underlying_obj.commit_time objecttype = "tag" elif isinstance(theobject, pygit2.Commit): @@ -2396,7 +2392,7 @@ def new_git_branch( raise pagure.exceptions.PagureException( 'The "{0}" branch does not exist'.format(from_branch) ) - parent = get_branch_ref(repo_obj, from_branch).get_object() + parent = get_branch_ref(repo_obj, from_branch).peel() else: if from_commit not in repo_obj: raise pagure.exceptions.PagureException( diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index 211d77d..27ccb3d 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -947,7 +947,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_NONE + repo_obj.head.peel().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. @@ -1008,7 +1008,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_NONE + repo_obj.head.peel().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 2b9231f..e67979f 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -432,7 +432,7 @@ def request_pull_to_diff_or_patch( branch = repo_obj.lookup_branch(request.branch_from) commitid = None if branch: - commitid = branch.get_object().hex + commitid = branch.peel().hex diff_commits = [] if request.status != "Open": diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index dd2bed7..2edeca6 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -1436,7 +1436,7 @@ def view_issue_raw_file(repo, filename=None, username=None, namespace=None): flask.abort(404, "Empty repo cannot have a file") branch = repo_obj.lookup_branch("master") - commit = branch.get_object() + commit = branch.peel() content = __get_file_in_tree( repo_obj, commit.tree, ["files", filename], bail_on_tree=True diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index a1c28e1..3b4736b 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -209,7 +209,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_NONE): + for commit in repo_obj.walk(branch.peel().hex, pygit2.GIT_SORT_NONE): last_commits.append(commit) cnt += 1 if cnt == 3: @@ -240,11 +240,11 @@ def view_repo_branch(repo, branchname, username=None, namespace=None): commit_list = [ commit.oid.hex for commit in orig_repo.walk( - compare_branch.get_object().hex, + compare_branch.peel().hex, pygit2.GIT_SORT_NONE) ] - repo_commit = repo_obj[branch.get_object().hex] + repo_commit = repo_obj[branch.peel().hex] for commit in repo_obj.walk( repo_commit.oid.hex, pygit2.GIT_SORT_NONE): @@ -305,7 +305,7 @@ def view_commits(repo, branchname=None, username=None, namespace=None): branch = None if branchname and branchname in repo_obj.listall_branches(): branch = repo_obj.lookup_branch(branchname) - commit = branch.get_object() + commit = branch.peel() elif branchname: try: commit = repo_obj.get(branchname) @@ -314,16 +314,16 @@ def view_commits(repo, branchname=None, username=None, namespace=None): if "refs/tags/%s" % branchname in list(repo_obj.references): ref = repo_obj.lookup_reference("refs/tags/%s" % branchname) - commit = ref.get_object() + commit = ref.peel() # If we're arriving here from the release page, we may have a Tag # where we expected a commit, in this case, get the actual commit if isinstance(commit, pygit2.Tag): - commit = commit.get_object() + commit = commit.peel() branchname = commit.oid.hex elif not repo_obj.is_empty and not repo_obj.head_is_unborn: branch = repo_obj.lookup_branch(repo_obj.head.shorthand) - commit = branch.get_object() + commit = branch.peel() branchname = branch.branch_name if not repo_obj.is_empty and not repo_obj.head_is_unborn: @@ -515,7 +515,7 @@ def view_file(repo, identifier, filename, username=None, namespace=None): if identifier in repo_obj.listall_branches(): branchname = identifier branch = repo_obj.lookup_branch(identifier) - commit = branch.get_object() + commit = branch.peel() else: try: commit = repo_obj.get(identifier) @@ -528,7 +528,7 @@ def view_file(repo, identifier, filename, username=None, namespace=None): branchname = "master" if isinstance(commit, pygit2.Tag): - commit = commit.get_object() + commit = commit.peel() tree = None if isinstance(commit, pygit2.Tree): @@ -679,7 +679,7 @@ def view_raw_file( if identifier in repo_obj.listall_branches(): branch = repo_obj.lookup_branch(identifier) - commit = branch.get_object() + commit = branch.peel() else: try: commit = repo_obj.get(identifier) @@ -693,7 +693,7 @@ def view_raw_file( flask.abort(404, "Commit %s not found" % (identifier)) if isinstance(commit, pygit2.Tag): - commit = commit.get_object() + commit = commit.peel() if filename: if isinstance(commit, pygit2.Blob): @@ -743,7 +743,7 @@ def view_blame_file(repo, filename, username=None, namespace=None): if branchname in repo_obj.listall_branches(): branch = repo_obj.lookup_branch(branchname) - commit = branch.get_object() + commit = branch.peel() else: try: commit = repo_obj[branchname] @@ -751,7 +751,7 @@ def view_blame_file(repo, filename, username=None, namespace=None): commit = repo_obj[repo_obj.head.target] if isinstance(commit, pygit2.Tag): - commit = commit.get_object() + commit = commit.peel() content = __get_file_in_tree( repo_obj, commit.tree, filename.split("/"), bail_on_tree=True @@ -952,7 +952,7 @@ def view_tree(repo, identifier=None, username=None, namespace=None): if identifier in repo_obj.listall_branches(): branchname = identifier branch = repo_obj.lookup_branch(identifier) - commit = branch.get_object() + commit = branch.peel() else: try: commit = repo_obj.get(identifier) @@ -971,7 +971,7 @@ def view_tree(repo, identifier=None, username=None, namespace=None): # If we're arriving here from the release page, we may have a Tag # where we expected a commit, in this case, get the actual commit if isinstance(commit, pygit2.Tag): - commit = commit.get_object() + commit = commit.peel() branchname = commit.oid.hex if commit and not isinstance(commit, pygit2.Blob): @@ -2450,7 +2450,7 @@ def edit_file(repo, branchname, filename, username=None, namespace=None): branch = None if branchname in repo_obj.listall_branches(): branch = repo_obj.lookup_branch(branchname) - commit = branch.get_object() + commit = branch.peel() else: flask.abort(400, "Invalid branch specified") @@ -3447,7 +3447,7 @@ def generate_project_archive( tag = repo_obj[reference.target] if not isinstance(tag, pygit2.Tag): flask.abort(400, "Invalid reference provided") - commit = tag.get_object() + commit = tag.peel(pygit2.Commit) else: try: commit = repo_obj.get(ref) diff --git a/tests/__init__.py b/tests/__init__.py index c81e383..c21ac3d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -728,7 +728,7 @@ def _clone_and_top_commits(folder, branch, branch_ref=False): commit = None try: if branch_ref_obj: - commit = repo[branch_ref_obj.get_object().hex] + commit = repo[branch_ref_obj.peel().hex] else: commit = repo.revparse_single('HEAD') except KeyError: @@ -894,7 +894,7 @@ def add_commit_git_repo(folder, ncommits=10, filename='sources', commit = None try: if branch_ref_obj: - commit = repo[branch_ref_obj.get_object().hex] + commit = repo[branch_ref_obj.peel().hex] else: commit = repo.revparse_single('HEAD') except (KeyError, AttributeError): @@ -945,7 +945,7 @@ def add_content_to_git( commit = None try: if branch_ref_obj: - commit = repo[branch_ref_obj.get_object().hex] + commit = repo[branch_ref_obj.peel().hex] else: commit = repo.revparse_single('HEAD') except (KeyError, AttributeError): diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index 22ea91f..8502d68 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -126,7 +126,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): # Create two other branches based on master for branch in ['pats-win-49', 'pats-win-51']: - clone_repo.create_branch(branch, clone_repo.head.get_object()) + clone_repo.create_branch(branch, clone_repo.head.peel()) refname = 'refs/heads/{0}:refs/heads/{0}'.format(branch) PagureRepo.push(clone_repo.remotes[0], refname) @@ -2841,7 +2841,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): self.session, 'aaabbbcccddd', 'create_branch') git_path = os.path.join(self.path, 'repos', 'test.git') repo_obj = pygit2.Repository(git_path) - parent = pagure.lib.git.get_branch_ref(repo_obj, 'master').get_object() + parent = pagure.lib.git.get_branch_ref(repo_obj, 'master').peel() repo_obj.create_branch('dev123', parent) headers = {'Authorization': 'token aaabbbcccddd'} args = {'branch': 'test123', 'from_branch': 'dev123'} diff --git a/tests/test_pagure_flask_ui_no_master_branch.py b/tests/test_pagure_flask_ui_no_master_branch.py index 1eeff35..6986425 100644 --- a/tests/test_pagure_flask_ui_no_master_branch.py +++ b/tests/test_pagure_flask_ui_no_master_branch.py @@ -67,7 +67,7 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest): ) feature_branch = clone_repo.lookup_branch('feature') - first_commit = feature_branch.get_object().hex + first_commit = feature_branch.peel().hex # Second commit with open(os.path.join(repopath, '.gitignore'), 'w') as stream: diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index 9bdb959..be77354 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -4815,7 +4815,7 @@ index 0000000..fb7093d # list of binary strings representing parents of the new commit [] ) - repo_obj.create_branch("feature",repo_obj.head.get_object()) + repo_obj.create_branch("feature",repo_obj.head.peel()) data = { 'branches': 'feature', @@ -5386,7 +5386,7 @@ index 0000000..fb7093d path = os.path.join(self.path, 'repos', 'test.git') tests.add_content_git_repo(path) repo = pygit2.Repository(path) - repo.create_branch('foo', repo.head.get_object()) + repo.create_branch('foo', repo.head.peel()) # Check before deletion output = self.app.get('/test') @@ -5409,7 +5409,7 @@ index 0000000..fb7093d path = os.path.join(self.path, 'repos', 'test.git') tests.add_content_git_repo(path) repo = pygit2.Repository(path) - repo.create_branch('feature/foo', repo.head.get_object()) + repo.create_branch('feature/foo', repo.head.peel()) # Check before deletion output = self.app.get('/test') @@ -5440,7 +5440,7 @@ index 0000000..fb7093d path = os.path.join(self.path, 'repos', 'test.git') tests.add_content_git_repo(path) repo = pygit2.Repository(path) - repo.create_branch('foo', repo.head.get_object()) + repo.create_branch('foo', repo.head.peel()) user = tests.FakeUser(username = 'pingou') with tests.user_set(self.app.application, user): @@ -5464,7 +5464,7 @@ index 0000000..fb7093d path = os.path.join(self.path, 'repos', 'test.git') tests.add_content_git_repo(path) repo = pygit2.Repository(path) - repo.create_branch('foo', repo.head.get_object()) + repo.create_branch('foo', repo.head.peel()) user = tests.FakeUser(username = 'pingou') with tests.user_set(self.app.application, user): @@ -5503,7 +5503,7 @@ index 0000000..fb7093d path = os.path.join(self.path, 'repos', 'forks', 'foo', 'test.git') tests.add_content_git_repo(path) repo = pygit2.Repository(path) - repo.create_branch('foo', repo.head.get_object()) + repo.create_branch('foo', repo.head.peel()) user = tests.FakeUser(username = 'foo') with tests.user_set(self.app.application, user): diff --git a/tests/test_pagure_flask_ui_repo_slash_name.py b/tests/test_pagure_flask_ui_repo_slash_name.py index 9c1a3e9..70c57a7 100644 --- a/tests/test_pagure_flask_ui_repo_slash_name.py +++ b/tests/test_pagure_flask_ui_repo_slash_name.py @@ -229,7 +229,7 @@ class PagureFlaskSlashInNametests(tests.SimplePagureTest): gitrepo = os.path.join(self.path, 'repos', 'forks/test.git') repo = pygit2.Repository(gitrepo) master_branch = repo.lookup_branch('master') - first_commit = master_branch.get_object().hex + first_commit = master_branch.peel().hex output = self.app.get('/forks/test/commits') self.assertEqual(output.status_code, 200) diff --git a/tests/test_pagure_flask_ui_slash_branch_name.py b/tests/test_pagure_flask_ui_slash_branch_name.py index 7bb19c5..1f49cd9 100644 --- a/tests/test_pagure_flask_ui_slash_branch_name.py +++ b/tests/test_pagure_flask_ui_slash_branch_name.py @@ -70,7 +70,7 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest): PagureRepo.push(ori_remote, refname) master_branch = clone_repo.lookup_branch('master') - first_commit = master_branch.get_object().hex + first_commit = master_branch.peel().hex # Second commit with open(os.path.join(repopath, '.gitignore'), 'w') as stream: diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index 4915a65..e740c59 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -2627,7 +2627,7 @@ index 0000000..60f7480 # Case 4, get revs between two commits on two different branches newgitrepo = tempfile.mkdtemp(prefix='pagure-') newrepo = pygit2.clone_repository(gitrepo, newgitrepo) - newrepo.create_branch('feature', newrepo.head.get_object()) + newrepo.create_branch('feature', newrepo.head.peel()) with open(os.path.join(newgitrepo, 'sources'), 'w') as stream: stream.write('foo\n bar') @@ -3039,19 +3039,19 @@ index 0000000..60f7480 # make sure that creating works the first time pagure.lib.git.update_pull_ref(fake_pr, fork) - oldhex = fork.references["refs/heads/master"].get_object().hex + oldhex = fork.references["refs/heads/master"].peel().hex self.assertEqual( - orig.references["refs/pull/6/head"].get_object().hex, + orig.references["refs/pull/6/head"].peel().hex, oldhex, ) # make sure that updating works correctly tests.add_content_git_repo(projects[1], append="foobar") - newhex = fork.references["refs/heads/master"].get_object().hex + newhex = fork.references["refs/heads/master"].peel().hex self.assertNotEqual(oldhex, newhex) pagure.lib.git.update_pull_ref(fake_pr, fork) self.assertEqual( - orig.references["refs/pull/6/head"].get_object().hex, + orig.references["refs/pull/6/head"].peel().hex, newhex, ) @@ -3061,11 +3061,11 @@ index 0000000..60f7480 pagure.lib.git.update_pull_ref(fake_pr, fork) self.assertIsNotNone(fork.remotes["pingou_1234567"]) tests.add_content_git_repo(projects[1], append="foobarbaz") - newesthex = fork.references["refs/heads/master"].get_object().hex + newesthex = fork.references["refs/heads/master"].peel().hex self.assertNotEqual(newhex, newesthex) pagure.lib.git.update_pull_ref(fake_pr, fork) self.assertEqual( - orig.references["refs/pull/6/head"].get_object().hex, + orig.references["refs/pull/6/head"].peel().hex, newesthex, ) diff --git a/tests/test_pagure_lib_git_diff_pr.py b/tests/test_pagure_lib_git_diff_pr.py index d9fc3a9..6790eb3 100644 --- a/tests/test_pagure_lib_git_diff_pr.py +++ b/tests/test_pagure_lib_git_diff_pr.py @@ -310,7 +310,7 @@ class PagureFlaskForkPrtests(tests.Modeltests): self.assertTrue(cnt < 60) pr_ref = repo.lookup_reference('refs/pull/1/head') - commit = pr_ref.get_object() + commit = pr_ref.peel() self.assertEqual( commit.oid.hex, diff_commits[0].oid.hex @@ -350,7 +350,7 @@ class PagureFlaskForkPrtests(tests.Modeltests): self.assertTrue(cnt < 60) pr_ref = repo.lookup_reference('refs/pull/1/head') - commit = pr_ref.get_object() + commit = pr_ref.peel() self.assertEqual( commit.oid.hex, diff_commits[0].oid.hex @@ -366,7 +366,7 @@ class PagureFlaskForkPrtests(tests.Modeltests): clone_repo.index.add('sources') clone_repo.index.write() - last_commit = clone_repo.lookup_branch('feature_foo').get_object() + last_commit = clone_repo.lookup_branch('feature_foo').peel() # Commits the files added tree = clone_repo.index.write_tree() @@ -413,7 +413,7 @@ class PagureFlaskForkPrtests(tests.Modeltests): self.assertTrue(cnt < 60) pr_ref = repo.lookup_reference('refs/pull/1/head') - commit2 = pr_ref.get_object() + commit2 = pr_ref.peel() self.assertEqual( commit2.oid.hex, diff_commits[0].oid.hex @@ -457,7 +457,7 @@ class PagureFlaskForkPrtests(tests.Modeltests): self.assertTrue(cnt < 60) pr_ref = repo.lookup_reference('refs/pull/1/head') - commit = pr_ref.get_object() + commit = pr_ref.peel() self.assertEqual( commit.oid.hex, diff_commits[0].oid.hex @@ -489,7 +489,7 @@ class PagureFlaskForkPrtests(tests.Modeltests): self.assertTrue(cnt < 60) pr_ref = repo.lookup_reference('refs/pull/1/head') - commit2 = pr_ref.get_object() + commit2 = pr_ref.peel() self.assertEqual( commit2.oid.hex, diff_commits[0].oid.hex