# HG changeset patch # User Marcin Kuzminski # Date 2019-02-07 10:31:55 # Node ID 57dba41e80ab2cf3f73d5bfc090098dc7cd92722 # Parent a818b875c6e00b81897b2b77d94e3730ba6c45d7 git: use rev-list for fetching last commit data inc ase of single commit. It's faster that using git log diff --git a/rhodecode/lib/vcs/backends/git/commit.py b/rhodecode/lib/vcs/backends/git/commit.py --- a/rhodecode/lib/vcs/backends/git/commit.py +++ b/rhodecode/lib/vcs/backends/git/commit.py @@ -309,10 +309,14 @@ class GitCommit(base.BaseCommit): self._get_filectx(path) f_path = safe_str(path) - cmd = ['log'] - if limit: - cmd.extend(['-n', str(safe_int(limit, 0))]) - cmd.extend(['--pretty=format: %H', '-s', self.raw_id, '--', f_path]) + # optimize for n==1, rev-list is much faster for that use-case + if limit == 1: + cmd = ['rev-list', '-1', self.raw_id, '--', f_path] + else: + cmd = ['log'] + if limit: + cmd.extend(['-n', str(safe_int(limit, 0))]) + cmd.extend(['--pretty=format: %H', '-s', self.raw_id, '--', f_path]) output, __ = self.repository.run_git_command(cmd) commit_ids = re.findall(r'[0-9a-fA-F]{40}', output)