Mercurial > kallithea
comparison rhodecode/lib/vcs/backends/git/changeset.py @ 3496:58905069da21 beta
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
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 07 Mar 2013 13:46:24 +0100 |
parents | 0065f7fe60f6 |
children | c04d1d9b6193 |
comparison
equal
deleted
inserted
replaced
3493:64371c42e2f1 | 3496:58905069da21 |
---|---|
15 RemovedFileNode, SubModuleNode, ChangedFileNodesGenerator,\ | 15 RemovedFileNode, SubModuleNode, ChangedFileNodesGenerator,\ |
16 AddedFileNodesGenerator, RemovedFileNodesGenerator | 16 AddedFileNodesGenerator, RemovedFileNodesGenerator |
17 from rhodecode.lib.vcs.utils import safe_unicode | 17 from rhodecode.lib.vcs.utils import safe_unicode |
18 from rhodecode.lib.vcs.utils import date_fromtimestamp | 18 from rhodecode.lib.vcs.utils import date_fromtimestamp |
19 from rhodecode.lib.vcs.utils.lazy import LazyProperty | 19 from rhodecode.lib.vcs.utils.lazy import LazyProperty |
20 from rhodecode.lib.utils2 import safe_int | |
20 | 21 |
21 | 22 |
22 class GitChangeset(BaseChangeset): | 23 class GitChangeset(BaseChangeset): |
23 """ | 24 """ |
24 Represents state of the repository at single revision. | 25 Represents state of the repository at single revision. |
273 | 274 |
274 def get_file_changeset(self, path): | 275 def get_file_changeset(self, path): |
275 """ | 276 """ |
276 Returns last commit of the file at the given ``path``. | 277 Returns last commit of the file at the given ``path``. |
277 """ | 278 """ |
278 node = self.get_node(path) | 279 return self.get_file_history(path, limit=1)[0] |
279 return node.history[0] | 280 |
280 | 281 def get_file_history(self, path, limit=None): |
281 def get_file_history(self, path): | |
282 """ | 282 """ |
283 Returns history of file as reversed list of ``Changeset`` objects for | 283 Returns history of file as reversed list of ``Changeset`` objects for |
284 which file at given ``path`` has been modified. | 284 which file at given ``path`` has been modified. |
285 | 285 |
286 TODO: This function now uses os underlying 'git' and 'grep' commands | 286 TODO: This function now uses os underlying 'git' and 'grep' commands |
287 which is generally not good. Should be replaced with algorithm | 287 which is generally not good. Should be replaced with algorithm |
288 iterating commits. | 288 iterating commits. |
289 """ | 289 """ |
290 | |
290 self._get_filectx(path) | 291 self._get_filectx(path) |
291 | 292 if limit: |
292 cmd = 'log --pretty="format: %%H" -s -p %s -- "%s"' % ( | 293 cmd = 'log -n %s --pretty="format: %%H" -s -p %s -- "%s"' % ( |
293 self.id, path | 294 safe_int(limit, 0), self.id, path |
294 ) | 295 ) |
296 else: | |
297 cmd = 'log --pretty="format: %%H" -s -p %s -- "%s"' % ( | |
298 self.id, path | |
299 ) | |
295 so, se = self.repository.run_git_command(cmd) | 300 so, se = self.repository.run_git_command(cmd) |
296 ids = re.findall(r'[0-9a-fA-F]{40}', so) | 301 ids = re.findall(r'[0-9a-fA-F]{40}', so) |
297 return [self.repository.get_changeset(id) for id in ids] | 302 return [self.repository.get_changeset(id) for id in ids] |
298 | 303 |
299 def get_file_history_2(self, path): | 304 def get_file_history_2(self, path): |