commits: allow tag commit translation to be skipped for faster commit fetching in big chunks.

This commit is contained in:
Marcin Kuzminski 2019-02-11 19:58:34 +01:00
parent 75d3dfb98c
commit 1b48364bb6
9 changed files with 30 additions and 22 deletions

View file

@ -381,7 +381,7 @@ def get_repo_changesets(request, apiuser, repoid, start_rev, limit,
try:
commits = vcs_repo.get_commits(
start_id=start_rev, pre_load=pre_load)
start_id=start_rev, pre_load=pre_load, translate_tags=False)
except TypeError as e:
raise JSONRPCError(safe_str(e))
except Exception:

View file

@ -203,7 +203,6 @@ class RepoChangelogView(RepoAppView):
pre_load = self._get_preload_attrs()
partial_xhr = self.request.environ.get('HTTP_X_PARTIAL_XHR')
try:
if f_path:
log.debug('generating changelog for path %s', f_path)
@ -231,7 +230,7 @@ class RepoChangelogView(RepoAppView):
else:
collection = self.rhodecode_vcs_repo.get_commits(
branch_name=branch_name, show_hidden=show_hidden,
pre_load=pre_load)
pre_load=pre_load, translate_tags=False)
self._load_changelog_data(
c, collection, p, chunk_size, c.branch_name,
@ -320,7 +319,8 @@ class RepoChangelogView(RepoAppView):
collection = list(reversed(collection))
else:
collection = self.rhodecode_vcs_repo.get_commits(
branch_name=branch_name, show_hidden=show_hidden, pre_load=pre_load)
branch_name=branch_name, show_hidden=show_hidden, pre_load=pre_load,
translate_tags=False)
p = safe_int(self.request.GET.get('page', 1), 1)
try:

View file

@ -97,7 +97,7 @@ class RepoCommitsView(RepoAppView):
if len(commit_range) == 2:
commits = self.rhodecode_vcs_repo.get_commits(
start_id=commit_range[0], end_id=commit_range[1],
pre_load=pre_load)
pre_load=pre_load, translate_tags=False)
commits = list(commits)
else:
commits = [self.rhodecode_vcs_repo.get_commit(

View file

@ -141,7 +141,8 @@ class RepoSummaryView(RepoAppView):
pre_load = ['author', 'branch', 'date', 'message']
try:
collection = self.rhodecode_vcs_repo.get_commits(pre_load=pre_load)
collection = self.rhodecode_vcs_repo.get_commits(
pre_load=pre_load, translate_tags=False)
except EmptyRepositoryError:
collection = self.rhodecode_vcs_repo

View file

@ -401,7 +401,7 @@ class BaseRepository(object):
# COMMITS
# ==========================================================================
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None):
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None, translate_tag=None):
"""
Returns instance of `BaseCommit` class. If `commit_id` and `commit_idx`
are both None, most recent commit is returned.
@ -418,7 +418,7 @@ class BaseRepository(object):
def get_commits(
self, start_id=None, end_id=None, start_date=None, end_date=None,
branch_name=None, show_hidden=False, pre_load=None):
branch_name=None, show_hidden=False, pre_load=None, translate_tags=None):
"""
Returns iterator of `BaseCommit` objects from start to end
not inclusive. This should behave just like a list, ie. end is not
@ -431,6 +431,7 @@ class BaseRepository(object):
:param branch_name:
:param show_hidden:
:param pre_load:
:param translate_tags:
"""
raise NotImplementedError
@ -1646,12 +1647,13 @@ class EmptyRepository(BaseRepository):
class CollectionGenerator(object):
def __init__(self, repo, commit_ids, collection_size=None, pre_load=None):
def __init__(self, repo, commit_ids, collection_size=None, pre_load=None, translate_tag=None):
self.repo = repo
self.commit_ids = commit_ids
# TODO: (oliver) this isn't currently hooked up
self.collection_size = None
self.pre_load = pre_load
self.translate_tag = translate_tag
def __len__(self):
if self.collection_size is not None:
@ -1667,8 +1669,9 @@ class CollectionGenerator(object):
"""
Allows backends to override the way commits are generated.
"""
return self.repo.get_commit(commit_id=commit_id,
pre_load=self.pre_load)
return self.repo.get_commit(
commit_id=commit_id, pre_load=self.pre_load,
translate_tag=self.translate_tag)
def __getslice__(self, i, j):
"""
@ -1676,7 +1679,8 @@ class CollectionGenerator(object):
"""
commit_ids = self.commit_ids[i:j]
return self.__class__(
self.repo, commit_ids, pre_load=self.pre_load)
self.repo, commit_ids, pre_load=self.pre_load,
translate_tag=self.translate_tag)
def __repr__(self):
return '<CollectionGenerator[len:%s]>' % (self.__len__())

View file

@ -269,7 +269,8 @@ class GitCommit(base.BaseCommit):
def _make_commits(self, commit_ids, pre_load=None):
return [
self.repository.get_commit(commit_id=commit_id, pre_load=pre_load)
self.repository.get_commit(commit_id=commit_id, pre_load=pre_load,
translate_tag=False)
for commit_id in commit_ids]
def get_file_mode(self, path):

View file

@ -426,7 +426,7 @@ class GitRepository(BaseRepository):
except Exception:
return
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None):
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None, translate_tag=True):
"""
Returns `GitCommit` object representing commit from git repository
at the given `commit_id` or head (most recent commit) if None given.
@ -438,8 +438,9 @@ class GitRepository(BaseRepository):
commit_id = commit_idx
commit_id = self._get_commit_id(commit_id)
try:
# Need to call remote to translate id for tagging scenario
commit_id = self._remote.get_object(commit_id)["commit_id"]
if translate_tag:
# Need to call remote to translate id for tagging scenario
commit_id = self._remote.get_object(commit_id)["commit_id"]
idx = self._commit_ids[commit_id]
except KeyError:
raise RepositoryError("Cannot get object with id %s" % commit_id)
@ -448,7 +449,7 @@ class GitRepository(BaseRepository):
def get_commits(
self, start_id=None, end_id=None, start_date=None, end_date=None,
branch_name=None, show_hidden=False, pre_load=None):
branch_name=None, show_hidden=False, pre_load=None, translate_tags=True):
"""
Returns generator of `GitCommit` objects from start to end (both
are inclusive), in ascending date order.
@ -528,7 +529,8 @@ class GitRepository(BaseRepository):
if start_pos or end_pos:
commit_ids = commit_ids[start_pos: end_pos]
return CollectionGenerator(self, commit_ids, pre_load=pre_load)
return CollectionGenerator(self, commit_ids, pre_load=pre_load,
translate_tag=translate_tags)
def get_diff(
self, commit1, commit2, path='', ignore_whitespace=False,

View file

@ -414,7 +414,7 @@ class MercurialRepository(BaseRepository):
"""
return os.path.join(self.path, '.hg', '.hgrc')
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None):
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None, translate_tag=None):
"""
Returns ``MercurialCommit`` object representing repository's
commit at the given `commit_id` or `commit_idx`.
@ -456,7 +456,7 @@ class MercurialRepository(BaseRepository):
def get_commits(
self, start_id=None, end_id=None, start_date=None, end_date=None,
branch_name=None, show_hidden=False, pre_load=None):
branch_name=None, show_hidden=False, pre_load=None, translate_tags=None):
"""
Returns generator of ``MercurialCommit`` objects from start to end
(both are inclusive)

View file

@ -250,7 +250,7 @@ class SubversionRepository(base.BaseRepository):
"""
return os.path.join(self.path, 'hooks')
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None):
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None, translate_tag=None):
if self.is_empty():
raise EmptyRepositoryError("There are no commits yet")
if commit_id is not None:
@ -268,7 +268,7 @@ class SubversionRepository(base.BaseRepository):
def get_commits(
self, start_id=None, end_id=None, start_date=None, end_date=None,
branch_name=None, show_hidden=False, pre_load=None):
branch_name=None, show_hidden=False, pre_load=None, translate_tags=None):
if self.is_empty():
raise EmptyRepositoryError("There are no commit_ids yet")
self._validate_branch_name(branch_name)