aboutsummaryrefslogtreecommitdiff
path: root/rhodecode/lib/vcs/backends/git/changeset.py
diff options
context:
space:
mode:
authorMarcin Kuzminski <marcin@python-works.com>2013-03-07 13:46:24 +0100
committerMarcin Kuzminski <marcin@python-works.com>2013-03-07 13:46:24 +0100
commit18a8121056c92295bef3ac75c30a468b0a514083 (patch)
tree34ffd8f3f908a7e98fefa1bc90c94f80c5964d77 /rhodecode/lib/vcs/backends/git/changeset.py
parent185701911317ab20646057f559b1ea35115657da (diff)
Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
--HG-- branch : beta
Diffstat (limited to 'rhodecode/lib/vcs/backends/git/changeset.py')
-rw-r--r--rhodecode/lib/vcs/backends/git/changeset.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/rhodecode/lib/vcs/backends/git/changeset.py b/rhodecode/lib/vcs/backends/git/changeset.py
index 56b3a32a..ed78c91b 100644
--- a/rhodecode/lib/vcs/backends/git/changeset.py
+++ b/rhodecode/lib/vcs/backends/git/changeset.py
@@ -17,6 +17,7 @@ from rhodecode.lib.vcs.nodes import FileNode, DirNode, NodeKind, RootNode, \
from rhodecode.lib.vcs.utils import safe_unicode
from rhodecode.lib.vcs.utils import date_fromtimestamp
from rhodecode.lib.vcs.utils.lazy import LazyProperty
+from rhodecode.lib.utils2 import safe_int
class GitChangeset(BaseChangeset):
@@ -275,10 +276,9 @@ class GitChangeset(BaseChangeset):
"""
Returns last commit of the file at the given ``path``.
"""
- node = self.get_node(path)
- return node.history[0]
+ return self.get_file_history(path, limit=1)[0]
- def get_file_history(self, path):
+ def get_file_history(self, path, limit=None):
"""
Returns history of file as reversed list of ``Changeset`` objects for
which file at given ``path`` has been modified.
@@ -287,11 +287,16 @@ class GitChangeset(BaseChangeset):
which is generally not good. Should be replaced with algorithm
iterating commits.
"""
- self._get_filectx(path)
- cmd = 'log --pretty="format: %%H" -s -p %s -- "%s"' % (
- self.id, path
- )
+ self._get_filectx(path)
+ if limit:
+ cmd = 'log -n %s --pretty="format: %%H" -s -p %s -- "%s"' % (
+ safe_int(limit, 0), self.id, path
+ )
+ else:
+ cmd = 'log --pretty="format: %%H" -s -p %s -- "%s"' % (
+ self.id, path
+ )
so, se = self.repository.run_git_command(cmd)
ids = re.findall(r'[0-9a-fA-F]{40}', so)
return [self.repository.get_changeset(id) for id in ids]