##// END OF EJS Templates
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
marcink -
r3496:58905069 beta
parent child Browse files
Show More
@@ -20,6 +20,7 b' from rhodecode.lib.vcs.exceptions import'
20 NodeAlreadyAddedError, NodeAlreadyChangedError, NodeAlreadyExistsError, \
20 NodeAlreadyAddedError, NodeAlreadyChangedError, NodeAlreadyExistsError, \
21 NodeAlreadyRemovedError, NodeDoesNotExistError, NodeNotChangedError, \
21 NodeAlreadyRemovedError, NodeDoesNotExistError, NodeNotChangedError, \
22 RepositoryError
22 RepositoryError
23 import datetime
23
24
24
25
25 class BaseRepository(object):
26 class BaseRepository(object):
@@ -980,12 +981,12 b' class EmptyChangeset(BaseChangeset):'
980 """
981 """
981
982
982 def __init__(self, cs='0' * 40, repo=None, requested_revision=None,
983 def __init__(self, cs='0' * 40, repo=None, requested_revision=None,
983 alias=None, revision=-1, message='', author='', date=''):
984 alias=None, revision=-1, message='', author='', date=None):
984 self._empty_cs = cs
985 self._empty_cs = cs
985 self.revision = revision
986 self.revision = revision
986 self.message = message
987 self.message = message
987 self.author = author
988 self.author = author
988 self.date = date
989 self.date = date or datetime.datetime.fromtimestamp(0)
989 self.repository = repo
990 self.repository = repo
990 self.requested_revision = requested_revision
991 self.requested_revision = requested_revision
991 self.alias = alias
992 self.alias = alias
@@ -17,6 +17,7 b' from rhodecode.lib.vcs.nodes import File'
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):
@@ -275,10 +276,9 b' class GitChangeset(BaseChangeset):'
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):
281 def get_file_history(self, path, limit=None):
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.
@@ -287,11 +287,16 b' class GitChangeset(BaseChangeset):'
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]
@@ -219,19 +219,23 b' class MercurialChangeset(BaseChangeset):'
219 """
219 """
220 Returns last commit of the file at the given ``path``.
220 Returns last commit of the file at the given ``path``.
221 """
221 """
222 node = self.get_node(path)
222 return self.get_file_history(path, limit=1)[0]
223 return node.history[0]
224
223
225 def get_file_history(self, path):
224 def get_file_history(self, path, limit=None):
226 """
225 """
227 Returns history of file as reversed list of ``Changeset`` objects for
226 Returns history of file as reversed list of ``Changeset`` objects for
228 which file at given ``path`` has been modified.
227 which file at given ``path`` has been modified.
229 """
228 """
230 fctx = self._get_filectx(path)
229 fctx = self._get_filectx(path)
231 nodes = [fctx.filectx(x).node() for x in fctx.filelog()]
230 hist = []
232 changesets = [self.repository.get_changeset(hex(node))
231 cnt = 0
233 for node in reversed(nodes)]
232 for cs in reversed([x for x in fctx.filelog()]):
234 return changesets
233 cnt += 1
234 hist.append(hex(fctx.filectx(cs).node()))
235 if limit and cnt == limit:
236 break
237
238 return [self.repository.get_changeset(node) for node in hist]
235
239
236 def get_file_annotate(self, path):
240 def get_file_annotate(self, path):
237 """
241 """
@@ -89,8 +89,8 b''
89 <td>
89 <td>
90 %if node.is_file():
90 %if node.is_file():
91 <div class="tooltip" title="${h.tooltip(node.last_changeset.message)}">
91 <div class="tooltip" title="${h.tooltip(node.last_changeset.message)}">
92 <pre>${'r%s:%s' % (node.last_changeset.revision,node.last_changeset.short_id)}</pre>
92 <pre>${'r%s:%s' % (node.last_changeset.revision,node.last_changeset.short_id)}</pre>
93 </div>
93 </div>
94 %endif
94 %endif
95 </td>
95 </td>
96 <td>
96 <td>
General Comments 0
You need to be logged in to leave comments. Login now