comparison rhodecode/lib/vcs/backends/git/changeset.py @ 2762:ba4fb9c441c6 beta

new dulwich based implementation of added/modified/removed functions for GIT changeset. Much faster some test up to 70% speed improvements. Pure awesomeness !
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 30 Aug 2012 01:47:09 +0200
parents e64c64e2b8aa
children 4abfb1afd9f5
comparison
equal deleted inserted replaced
2761:e64c64e2b8aa 2762:ba4fb9c441c6
7 from rhodecode.lib.vcs.exceptions import ChangesetError 7 from rhodecode.lib.vcs.exceptions import ChangesetError
8 from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError 8 from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError
9 from rhodecode.lib.vcs.exceptions import VCSError 9 from rhodecode.lib.vcs.exceptions import VCSError
10 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError 10 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError
11 from rhodecode.lib.vcs.exceptions import ImproperArchiveTypeError 11 from rhodecode.lib.vcs.exceptions import ImproperArchiveTypeError
12 from rhodecode.lib.vcs.backends.base import BaseChangeset 12 from rhodecode.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
13 from rhodecode.lib.vcs.nodes import FileNode, DirNode, NodeKind, RootNode, \ 13 from rhodecode.lib.vcs.nodes import FileNode, DirNode, NodeKind, RootNode, \
14 RemovedFileNode, SubModuleNode 14 RemovedFileNode, SubModuleNode
15 from rhodecode.lib.vcs.utils import safe_unicode 15 from rhodecode.lib.vcs.utils import safe_unicode
16 from rhodecode.lib.vcs.utils import date_fromtimestamp 16 from rhodecode.lib.vcs.utils import date_fromtimestamp
17 from rhodecode.lib.vcs.utils.lazy import LazyProperty 17 from rhodecode.lib.vcs.utils.lazy import LazyProperty
408 @LazyProperty 408 @LazyProperty
409 def affected_files(self): 409 def affected_files(self):
410 """ 410 """
411 Get's a fast accessible file changes for given changeset 411 Get's a fast accessible file changes for given changeset
412 """ 412 """
413 #OLD SOLUTION 413 a, m, d = self._changes_cache
414 #files = set() 414 return list(a.union(m).union(d))
415 #for f in (self.added + self.changed + self.removed):
416 # files.add(f.path)
417 #files = list(files)
418
419 _r = self.repository._repo
420 files = set()
421 for parent in self.parents:
422 changes = _r.object_store.tree_changes(_r[parent.raw_id].tree,
423 _r[self.raw_id].tree)
424 for (oldpath, newpath), (_, _), (_, _) in changes:
425 files.add(newpath or oldpath)
426 return list(files)
427 415
428 @LazyProperty 416 @LazyProperty
429 def _diff_name_status(self): 417 def _diff_name_status(self):
430 output = [] 418 output = []
431 for parent in self.parents: 419 for parent in self.parents:
433 self.raw_id) 421 self.raw_id)
434 so, se = self.repository.run_git_command(cmd) 422 so, se = self.repository.run_git_command(cmd)
435 output.append(so.strip()) 423 output.append(so.strip())
436 return '\n'.join(output) 424 return '\n'.join(output)
437 425
426 @LazyProperty
427 def _changes_cache(self):
428 added = set()
429 modified = set()
430 deleted = set()
431 _r = self.repository._repo
432
433 parents = self.parents
434 if not self.parents:
435 parents = [EmptyChangeset()]
436 for parent in parents:
437 if isinstance(parent, EmptyChangeset):
438 oid = None
439 else:
440 oid = _r[parent.raw_id].tree
441 changes = _r.object_store.tree_changes(oid, _r[self.raw_id].tree)
442 for (oldpath, newpath), (_, _), (_, _) in changes:
443 if newpath and oldpath:
444 modified.add(newpath)
445 elif newpath and not oldpath:
446 added.add(newpath)
447 elif not newpath and oldpath:
448 deleted.add(oldpath)
449 return added, modified, deleted
450
438 def _get_paths_for_status(self, status): 451 def _get_paths_for_status(self, status):
439 """ 452 """
440 Returns sorted list of paths for given ``status``. 453 Returns sorted list of paths for given ``status``.
441 454
442 :param status: one of: *added*, *modified* or *deleted* 455 :param status: one of: *added*, *modified* or *deleted*
443 """ 456 """
444 paths = set() 457 a, m, d = self._changes_cache
445 char = status[0].upper() 458 return sorted({
446 for line in self._diff_name_status.splitlines(): 459 'added': list(a),
447 if not line: 460 'modified': list(m),
448 continue 461 'deleted': list(d)}[status]
449 462 )
450 if line.startswith(char):
451 splitted = line.split(char, 1)
452 if not len(splitted) == 2:
453 raise VCSError("Couldn't parse diff result:\n%s\n\n and "
454 "particularly that line: %s" % (self._diff_name_status,
455 line))
456 _path = splitted[1].strip()
457 paths.add(_path)
458 return sorted(paths)
459 463
460 @LazyProperty 464 @LazyProperty
461 def added(self): 465 def added(self):
462 """ 466 """
463 Returns list of added ``FileNode`` objects. 467 Returns list of added ``FileNode`` objects.