##// 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 20 NodeAlreadyAddedError, NodeAlreadyChangedError, NodeAlreadyExistsError, \
21 21 NodeAlreadyRemovedError, NodeDoesNotExistError, NodeNotChangedError, \
22 22 RepositoryError
23 import datetime
23 24
24 25
25 26 class BaseRepository(object):
@@ -980,12 +981,12 b' class EmptyChangeset(BaseChangeset):'
980 981 """
981 982
982 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 985 self._empty_cs = cs
985 986 self.revision = revision
986 987 self.message = message
987 988 self.author = author
988 self.date = date
989 self.date = date or datetime.datetime.fromtimestamp(0)
989 990 self.repository = repo
990 991 self.requested_revision = requested_revision
991 992 self.alias = alias
@@ -17,6 +17,7 b' from rhodecode.lib.vcs.nodes import File'
17 17 from rhodecode.lib.vcs.utils import safe_unicode
18 18 from rhodecode.lib.vcs.utils import date_fromtimestamp
19 19 from rhodecode.lib.vcs.utils.lazy import LazyProperty
20 from rhodecode.lib.utils2 import safe_int
20 21
21 22
22 23 class GitChangeset(BaseChangeset):
@@ -275,10 +276,9 b' class GitChangeset(BaseChangeset):'
275 276 """
276 277 Returns last commit of the file at the given ``path``.
277 278 """
278 node = self.get_node(path)
279 return node.history[0]
279 return self.get_file_history(path, limit=1)[0]
280 280
281 def get_file_history(self, path):
281 def get_file_history(self, path, limit=None):
282 282 """
283 283 Returns history of file as reversed list of ``Changeset`` objects for
284 284 which file at given ``path`` has been modified.
@@ -287,11 +287,16 b' class GitChangeset(BaseChangeset):'
287 287 which is generally not good. Should be replaced with algorithm
288 288 iterating commits.
289 289 """
290
290 291 self._get_filectx(path)
291
292 cmd = 'log --pretty="format: %%H" -s -p %s -- "%s"' % (
293 self.id, path
294 )
292 if limit:
293 cmd = 'log -n %s --pretty="format: %%H" -s -p %s -- "%s"' % (
294 safe_int(limit, 0), self.id, path
295 )
296 else:
297 cmd = 'log --pretty="format: %%H" -s -p %s -- "%s"' % (
298 self.id, path
299 )
295 300 so, se = self.repository.run_git_command(cmd)
296 301 ids = re.findall(r'[0-9a-fA-F]{40}', so)
297 302 return [self.repository.get_changeset(id) for id in ids]
@@ -219,19 +219,23 b' class MercurialChangeset(BaseChangeset):'
219 219 """
220 220 Returns last commit of the file at the given ``path``.
221 221 """
222 node = self.get_node(path)
223 return node.history[0]
222 return self.get_file_history(path, limit=1)[0]
224 223
225 def get_file_history(self, path):
224 def get_file_history(self, path, limit=None):
226 225 """
227 226 Returns history of file as reversed list of ``Changeset`` objects for
228 227 which file at given ``path`` has been modified.
229 228 """
230 229 fctx = self._get_filectx(path)
231 nodes = [fctx.filectx(x).node() for x in fctx.filelog()]
232 changesets = [self.repository.get_changeset(hex(node))
233 for node in reversed(nodes)]
234 return changesets
230 hist = []
231 cnt = 0
232 for cs in reversed([x for x in fctx.filelog()]):
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 240 def get_file_annotate(self, path):
237 241 """
@@ -89,8 +89,8 b''
89 89 <td>
90 90 %if node.is_file():
91 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>
93 </div>
92 <pre>${'r%s:%s' % (node.last_changeset.revision,node.last_changeset.short_id)}</pre>
93 </div>
94 94 %endif
95 95 </td>
96 96 <td>
General Comments 0
You need to be logged in to leave comments. Login now