diff --git a/vcsserver/remote/git_remote.py b/vcsserver/remote/git_remote.py --- a/vcsserver/remote/git_remote.py +++ b/vcsserver/remote/git_remote.py @@ -149,6 +149,7 @@ def get_obfuscated_url(url_obj): class GitRemote(RemoteBase): + COMMIT_ID_PAT = re.compile(rb'[0-9a-fA-F]{40}') def __init__(self, factory): self._factory = factory @@ -633,6 +634,14 @@ class GitRemote(RemoteBase): return new_commit_id @reraise_safe_exceptions + def compare_commits(self, wire, commit_id1, commit_id2): + output, __ = self.run_git_command( + wire, ['log', '--reverse', '--pretty=format: %H', '-s', + f'{commit_id1}..{commit_id2}']) + commits = [safe_str(commit_id) for commit_id in self.COMMIT_ID_PAT.findall(output)] + return commits + + @reraise_safe_exceptions def commit(self, wire, commit_data, branch, commit_tree, updated, removed): def mode2pygit(mode): @@ -872,6 +881,14 @@ class GitRemote(RemoteBase): return revs @reraise_safe_exceptions + def get_common_ancestor(self, wire, rev1, rev2): + repo_init = self._factory.repo_libgit2(wire) + with repo_init as repo: + ancestor_id = repo.merge_base(rev1, rev2) + + return str(ancestor_id) + + @reraise_safe_exceptions def get_object(self, wire, sha, maybe_unreachable=False): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire)