annotate rhodecode/lib/vcs/backends/git/changeset.py @ 2543:03a770980b55 beta

Synced vcs with upstream
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 04 Jul 2012 11:42:16 +0200
parents 952dd2c95e45
children 66c778b8cb54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import re
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 from itertools import chain
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 from dulwich import objects
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from subprocess import Popen, PIPE
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from rhodecode.lib.vcs.conf import settings
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from rhodecode.lib.vcs.exceptions import RepositoryError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from rhodecode.lib.vcs.exceptions import ChangesetError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 from rhodecode.lib.vcs.exceptions import VCSError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 from rhodecode.lib.vcs.exceptions import ImproperArchiveTypeError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 from rhodecode.lib.vcs.backends.base import BaseChangeset
2232
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
13 from rhodecode.lib.vcs.nodes import FileNode, DirNode, NodeKind, RootNode, \
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
14 RemovedFileNode, SubModuleNode
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 from rhodecode.lib.vcs.utils import safe_unicode
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 from rhodecode.lib.vcs.utils import date_fromtimestamp
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 from rhodecode.lib.vcs.utils.lazy import LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 class GitChangeset(BaseChangeset):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 Represents state of the repository at single revision.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 def __init__(self, repository, revision):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 self._stat_modes = {}
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 self.repository = repository
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
28
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 try:
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
30 commit = self.repository._repo.get_object(revision)
2543
03a770980b55 Synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 2537
diff changeset
31 if isinstance(commit, objects.Tag):
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
32 revision = commit.object[1]
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
33 commit = self.repository._repo.get_object(commit.object[1])
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 except KeyError:
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
35 raise RepositoryError("Cannot get object with id %s" % revision)
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
36 self.raw_id = revision
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
37 self.id = self.raw_id
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
38 self.short_id = self.raw_id[:12]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 self._commit = commit
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
40
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
41 self._tree_id = commit.tree
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
42 self._commiter_property = 'committer'
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
43 self._date_property = 'commit_time'
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
44 self._date_tz_property = 'commit_timezone'
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
45 self.revision = repository.revisions.index(revision)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
2297
4747af4ce203 safe_unicode never fails. No need to catch decode exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 2281
diff changeset
47 self.message = safe_unicode(commit.message)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 #self.branch = None
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 self.tags = []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 self.nodes = {}
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 self._paths = {}
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 def author(self):
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
55 return safe_unicode(getattr(self._commit, self._commiter_property))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 def date(self):
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
59 return date_fromtimestamp(getattr(self._commit, self._date_property),
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
60 getattr(self._commit, self._date_tz_property))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 def status(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 Returns modified, added, removed, deleted files for current changeset
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 return self.changed, self.added, self.removed
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 def branch(self):
2198
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
71
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
72 heads = self.repository._heads(reverse=False)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73
2198
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
74 ref = heads.get(self.raw_id)
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
75 if ref:
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
76 return safe_unicode(ref)
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
77
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 def _fix_path(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 Paths are stored without trailing slash so we need to get rid off it if
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 needed.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 if path.endswith('/'):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 path = path.rstrip('/')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 return path
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 def _get_id_for_path(self, path):
2116
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
88
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 # FIXME: Please, spare a couple of minutes and make those codes cleaner;
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 if not path in self._paths:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 path = path.strip('/')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 # set root tree
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
93 tree = self.repository._repo[self._tree_id]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 if path == '':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 self._paths[''] = tree.id
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 return tree.id
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 splitted = path.split('/')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 dirs, name = splitted[:-1], splitted[-1]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 curdir = ''
2116
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
100
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
101 # initially extract things from root dir
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
102 for item, stat, id in tree.iteritems():
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
103 if curdir:
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
104 name = '/'.join((curdir, item))
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
105 else:
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
106 name = item
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
107 self._paths[name] = id
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
108 self._stat_modes[name] = stat
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
109
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 for dir in dirs:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 if curdir:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 curdir = '/'.join((curdir, dir))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 curdir = dir
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 dir_id = None
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 for item, stat, id in tree.iteritems():
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 if dir == item:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 dir_id = id
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 if dir_id:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120 # Update tree
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 tree = self.repository._repo[dir_id]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 if not isinstance(tree, objects.Tree):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 raise ChangesetError('%s is not a directory' % curdir)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 raise ChangesetError('%s have not been found' % curdir)
2116
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
126
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
127 # cache all items from the given traversed tree
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
128 for item, stat, id in tree.iteritems():
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
129 if curdir:
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
130 name = '/'.join((curdir, item))
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
131 else:
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
132 name = item
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
133 self._paths[name] = id
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
134 self._stat_modes[name] = stat
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 if not path in self._paths:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 raise NodeDoesNotExistError("There is no file nor directory "
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 "at the given path %r at revision %r"
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 % (path, self.short_id))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 return self._paths[path]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141 def _get_kind(self, path):
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
142 obj = self.repository._repo[self._get_id_for_path(path)]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 if isinstance(obj, objects.Blob):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 return NodeKind.FILE
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145 elif isinstance(obj, objects.Tree):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 return NodeKind.DIR
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148 def _get_file_nodes(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 return chain(*(t[2] for t in self.walk()))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 def parents(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 Returns list of parents changesets.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 return [self.repository.get_changeset(parent)
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
157 for parent in self._commit.parents]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 def next(self, branch=None):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
161 if branch and self.branch != branch:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 raise VCSError('Branch option used on changeset not belonging '
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
163 'to that branch')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 def _next(changeset, branch):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 try:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167 next_ = changeset.revision + 1
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 next_rev = changeset.repository.revisions[next_]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 except IndexError:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 raise ChangesetDoesNotExistError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171 cs = changeset.repository.get_changeset(next_rev)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173 if branch and branch != cs.branch:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 return _next(cs, branch)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 return cs
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178 return _next(self, branch)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180 def prev(self, branch=None):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 if branch and self.branch != branch:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 raise VCSError('Branch option used on changeset not belonging '
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 'to that branch')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 def _prev(changeset, branch):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186 try:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187 prev_ = changeset.revision - 1
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 if prev_ < 0:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189 raise IndexError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 prev_rev = changeset.repository.revisions[prev_]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191 except IndexError:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192 raise ChangesetDoesNotExistError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 cs = changeset.repository.get_changeset(prev_rev)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 if branch and branch != cs.branch:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 return _prev(cs, branch)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
199 return cs
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
200
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201 return _prev(self, branch)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202
2384
5563af834d92 Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents: 2297
diff changeset
203 def diff(self, ignore_whitespace=True, context=3):
2499
c919d8c4f6a2 fixed git diff function when initial revision had no parents to compare with
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
204 rev1 = self.parents[0] if self.parents else self.repository.EMPTY_CHANGESET
c919d8c4f6a2 fixed git diff function when initial revision had no parents to compare with
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
205 rev2 = self
c919d8c4f6a2 fixed git diff function when initial revision had no parents to compare with
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
206 return ''.join(self.repository.get_diff(rev1, rev2,
2384
5563af834d92 Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents: 2297
diff changeset
207 ignore_whitespace=ignore_whitespace,
5563af834d92 Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents: 2297
diff changeset
208 context=context))
5563af834d92 Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents: 2297
diff changeset
209
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
210 def get_file_mode(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
212 Returns stat mode of the file at the given ``path``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
213 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214 # ensure path is traversed
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
215 self._get_id_for_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
216 return self._stat_modes[path]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
218 def get_file_content(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220 Returns content of the file at given ``path``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 id = self._get_id_for_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223 blob = self.repository._repo[id]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 return blob.as_pretty_string()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226 def get_file_size(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 Returns size of the file at given ``path``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230 id = self._get_id_for_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 blob = self.repository._repo[id]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232 return blob.raw_length()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
233
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
234 def get_file_changeset(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
235 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236 Returns last commit of the file at the given ``path``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
237 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
238 node = self.get_node(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
239 return node.history[0]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
240
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
241 def get_file_history(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
242 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
243 Returns history of file as reversed list of ``Changeset`` objects for
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
244 which file at given ``path`` has been modified.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
246 TODO: This function now uses os underlying 'git' and 'grep' commands
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
247 which is generally not good. Should be replaced with algorithm
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
248 iterating commits.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
249 """
2276
8caaa9955f5e better regex for history
Marcin Kuzminski <marcin@python-works.com>
parents: 2274
diff changeset
250 cmd = 'log --pretty="format: %%H" -s -p %s -- "%s"' % (
2089
a9f2aa1e15e6 bring back cs id for node history in git as it improves performance. Adding format prevents from crashes of modified gitconfigs
Marcin Kuzminski <marcin@python-works.com>
parents: 2047
diff changeset
251 self.id, path
2047
092080cd96ba Git fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
252 )
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
253 so, se = self.repository.run_git_command(cmd)
2276
8caaa9955f5e better regex for history
Marcin Kuzminski <marcin@python-works.com>
parents: 2274
diff changeset
254 ids = re.findall(r'[0-9a-fA-F]{40}', so)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
255 return [self.repository.get_changeset(id) for id in ids]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
256
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
257 def get_file_annotate(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
258 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
259 Returns a list of three element tuples with lineno,changeset and line
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
260
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
261 TODO: This function now uses os underlying 'git' command which is
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
262 generally not good. Should be replaced with algorithm iterating
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
263 commits.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
264 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
265 cmd = 'blame -l --root -r %s -- "%s"' % (self.id, path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
266 # -l ==> outputs long shas (and we need all 40 characters)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267 # --root ==> doesn't put '^' character for bounderies
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
268 # -r sha ==> blames for the given revision
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
269 so, se = self.repository.run_git_command(cmd)
2448
c9b08fdcb788 fixed git annotate
Marcin Kuzminski <marcin@python-works.com>
parents: 2384
diff changeset
270
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
271 annotate = []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
272 for i, blame_line in enumerate(so.split('\n')[:-1]):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
273 ln_no = i + 1
2448
c9b08fdcb788 fixed git annotate
Marcin Kuzminski <marcin@python-works.com>
parents: 2384
diff changeset
274 id, line = re.split(r' ', blame_line, 1)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
275 annotate.append((ln_no, self.repository.get_changeset(id), line))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
276 return annotate
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
277
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
278 def fill_archive(self, stream=None, kind='tgz', prefix=None,
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
279 subrepos=False):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
280 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 Fills up given stream.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
282
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
283 :param stream: file like object.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
284 :param kind: one of following: ``zip``, ``tgz`` or ``tbz2``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
285 Default: ``tgz``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
286 :param prefix: name of root directory in archive.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287 Default is repository name and changeset's raw_id joined with dash
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
288 (``repo-tip.<KIND>``).
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
289 :param subrepos: include subrepos in this archive.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
290
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
291 :raise ImproperArchiveTypeError: If given kind is wrong.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
292 :raise VcsError: If given stream is None
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
293
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
294 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
295 allowed_kinds = settings.ARCHIVE_SPECS.keys()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
296 if kind not in allowed_kinds:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
297 raise ImproperArchiveTypeError('Archive kind not supported use one'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
298 'of %s', allowed_kinds)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
299
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
300 if prefix is None:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
301 prefix = '%s-%s' % (self.repository.name, self.short_id)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302 elif prefix.startswith('/'):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
303 raise VCSError("Prefix cannot start with leading slash")
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 elif prefix.strip() == '':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
305 raise VCSError("Prefix cannot be empty")
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
306
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
307 if kind == 'zip':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
308 frmt = 'zip'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
309 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
310 frmt = 'tar'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
311 cmd = 'git archive --format=%s --prefix=%s/ %s' % (frmt, prefix,
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
312 self.raw_id)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
313 if kind == 'tgz':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
314 cmd += ' | gzip -9'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
315 elif kind == 'tbz2':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
316 cmd += ' | bzip2 -9'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
317
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
318 if stream is None:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
319 raise VCSError('You need to pass in a valid stream for filling'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
320 ' with archival data')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
321 popen = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True,
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
322 cwd=self.repository.path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
323
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
324 buffer_size = 1024 * 8
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
325 chunk = popen.stdout.read(buffer_size)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
326 while chunk:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
327 stream.write(chunk)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
328 chunk = popen.stdout.read(buffer_size)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
329 # Make sure all descriptors would be read
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
330 popen.communicate()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
331
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
332 def get_nodes(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
333 if self._get_kind(path) != NodeKind.DIR:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
334 raise ChangesetError("Directory does not exist for revision %r at "
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
335 " %r" % (self.revision, path))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
336 path = self._fix_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
337 id = self._get_id_for_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
338 tree = self.repository._repo[id]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
339 dirnodes = []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
340 filenodes = []
2232
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
341 als = self.repository.alias
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
342 for name, stat, id in tree.iteritems():
2232
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
343 if objects.S_ISGITLINK(stat):
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
344 dirnodes.append(SubModuleNode(name, url=None, changeset=id,
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
345 alias=als))
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
346 continue
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
347
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
348 obj = self.repository._repo.get_object(id)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
349 if path != '':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
350 obj_path = '/'.join((path, name))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
351 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
352 obj_path = name
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
353 if obj_path not in self._stat_modes:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
354 self._stat_modes[obj_path] = stat
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
355 if isinstance(obj, objects.Tree):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
356 dirnodes.append(DirNode(obj_path, changeset=self))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
357 elif isinstance(obj, objects.Blob):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
358 filenodes.append(FileNode(obj_path, changeset=self, mode=stat))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
359 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
360 raise ChangesetError("Requested object should be Tree "
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
361 "or Blob, is %r" % type(obj))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
362 nodes = dirnodes + filenodes
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
363 for node in nodes:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
364 if not node.path in self.nodes:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
365 self.nodes[node.path] = node
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
366 nodes.sort()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
367 return nodes
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
368
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
369 def get_node(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
370 if isinstance(path, unicode):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
371 path = path.encode('utf-8')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
372 path = self._fix_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
373 if not path in self.nodes:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
374 try:
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
375 id_ = self._get_id_for_path(path)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
376 except ChangesetError:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
377 raise NodeDoesNotExistError("Cannot find one of parents' "
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
378 "directories for a given path: %s" % path)
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
379
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
380 _GL = lambda m: m and objects.S_ISGITLINK(m)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
381 if _GL(self._stat_modes.get(path)):
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
382 node = SubModuleNode(path, url=None, changeset=id_,
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
383 alias=self.repository.alias)
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
384 else:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
385 obj = self.repository._repo.get_object(id_)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
386
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
387 if isinstance(obj, objects.Tree):
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
388 if path == '':
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
389 node = RootNode(changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
390 else:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
391 node = DirNode(path, changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
392 node._tree = obj
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
393 elif isinstance(obj, objects.Blob):
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
394 node = FileNode(path, changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
395 node._blob = obj
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
396 else:
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
397 raise NodeDoesNotExistError("There is no file nor directory "
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
398 "at the given path %r at revision %r"
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
399 % (path, self.short_id))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
400 # cache node
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
401 self.nodes[path] = node
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
402 return self.nodes[path]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
403
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
404 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
405 def affected_files(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
406 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
407 Get's a fast accessible file changes for given changeset
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
408 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
409
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
410 return self.added + self.changed
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
411
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
412 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
413 def _diff_name_status(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
414 output = []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
415 for parent in self.parents:
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2198
diff changeset
416 cmd = 'diff --name-status %s %s --encoding=utf8' % (parent.raw_id, self.raw_id)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
417 so, se = self.repository.run_git_command(cmd)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
418 output.append(so.strip())
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
419 return '\n'.join(output)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
420
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
421 def _get_paths_for_status(self, status):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
422 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
423 Returns sorted list of paths for given ``status``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
424
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
425 :param status: one of: *added*, *modified* or *deleted*
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
426 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
427 paths = set()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
428 char = status[0].upper()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
429 for line in self._diff_name_status.splitlines():
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
430 if not line:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
431 continue
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2198
diff changeset
432
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
433 if line.startswith(char):
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2198
diff changeset
434 splitted = line.split(char, 1)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
435 if not len(splitted) == 2:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
436 raise VCSError("Couldn't parse diff result:\n%s\n\n and "
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
437 "particularly that line: %s" % (self._diff_name_status,
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
438 line))
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2198
diff changeset
439 _path = splitted[1].strip()
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2198
diff changeset
440 paths.add(_path)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
441 return sorted(paths)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
442
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
443 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
444 def added(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
445 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
446 Returns list of added ``FileNode`` objects.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
447 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
448 if not self.parents:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
449 return list(self._get_file_nodes())
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
450 return [self.get_node(path) for path in self._get_paths_for_status('added')]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
451
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
452 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
453 def changed(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
454 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
455 Returns list of modified ``FileNode`` objects.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
456 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
457 if not self.parents:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
458 return []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
459 return [self.get_node(path) for path in self._get_paths_for_status('modified')]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
460
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
461 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
462 def removed(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
463 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
464 Returns list of removed ``FileNode`` objects.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
465 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
466 if not self.parents:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
467 return []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
468 return [RemovedFileNode(path) for path in self._get_paths_for_status('deleted')]