Mercurial > kallithea
annotate 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 |
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 |
2762
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
12 from rhodecode.lib.vcs.backends.base import BaseChangeset, EmptyChangeset |
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 |
2693
66c778b8cb54
Extended commit search schema with date of commit
Marcin Kuzminski <marcin@python-works.com>
parents:
2543
diff
changeset
|
63 def _timestamp(self): |
66c778b8cb54
Extended commit search schema with date of commit
Marcin Kuzminski <marcin@python-works.com>
parents:
2543
diff
changeset
|
64 return getattr(self._commit, self._date_property) |
66c778b8cb54
Extended commit search schema with date of commit
Marcin Kuzminski <marcin@python-works.com>
parents:
2543
diff
changeset
|
65 |
66c778b8cb54
Extended commit search schema with date of commit
Marcin Kuzminski <marcin@python-works.com>
parents:
2543
diff
changeset
|
66 @LazyProperty |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 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
|
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 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
|
70 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 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
|
72 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 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
|
75 |
9784a54a0f5b
display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
2116
diff
changeset
|
76 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
|
77 |
2198
9784a54a0f5b
display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
2116
diff
changeset
|
78 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
|
79 if ref: |
9784a54a0f5b
display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
2116
diff
changeset
|
80 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
|
81 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 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
|
83 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 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
|
85 needed. |
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 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
|
88 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
|
89 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
|
90 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 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
|
92 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 # 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
|
94 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
|
95 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
|
96 # set root tree |
2536
aaa41736ae51
Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents:
2499
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 curdir = '' |
2116
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
104 |
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
105 # 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
|
106 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
|
107 if curdir: |
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
108 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
|
109 else: |
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
110 name = item |
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
111 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
|
112 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
|
113 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 # 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
|
125 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
|
126 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
|
127 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
|
128 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 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
|
130 |
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
131 # 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
|
132 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
|
133 if curdir: |
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
134 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
|
135 else: |
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
136 name = item |
048811568c19
temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2089
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 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
|
141 "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
|
142 % (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
|
143 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
|
144 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 |
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 _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
|
153 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
|
154 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 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
|
157 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 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
|
159 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 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
|
161 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
|
162 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 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
|
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 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
|
166 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
|
167 '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
|
168 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 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
|
170 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
177 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
|
178 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
|
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 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
|
181 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 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
|
183 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 '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
|
188 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 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
|
190 try: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 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
|
199 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 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
|
201 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
|
202 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
203 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
|
204 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
205 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
|
206 |
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 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 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
|
215 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
216 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
|
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 # 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
|
219 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
|
220 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
|
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 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
|
223 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
224 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
|
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 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
|
227 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
|
228 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
|
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 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
|
231 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
232 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
|
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 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
|
235 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
|
236 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
|
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 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
|
239 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
240 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
|
241 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
242 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
|
243 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
|
244 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
245 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
|
246 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
247 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
|
248 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
|
249 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
250 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
|
251 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
|
252 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
|
253 """ |
2276
8caaa9955f5e
better regex for history
Marcin Kuzminski <marcin@python-works.com>
parents:
2274
diff
changeset
|
254 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
|
255 self.id, path |
2047 | 256 ) |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
257 so, se = self.repository.run_git_command(cmd) |
2276
8caaa9955f5e
better regex for history
Marcin Kuzminski <marcin@python-works.com>
parents:
2274
diff
changeset
|
258 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
|
259 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
|
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 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
|
262 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
263 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
|
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 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
|
266 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
|
267 commits. |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
268 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
269 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
|
270 # -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
|
271 # --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
|
272 # -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
|
273 so, se = self.repository.run_git_command(cmd) |
2448
c9b08fdcb788
fixed git annotate
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
274 |
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 = [] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
276 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
|
277 ln_no = i + 1 |
2448
c9b08fdcb788
fixed git annotate
Marcin Kuzminski <marcin@python-works.com>
parents:
2384
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 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
|
283 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
|
284 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
285 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
|
286 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
287 :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
|
288 :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
|
289 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
|
290 :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
|
291 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
|
292 (``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
|
293 :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
|
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 :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
|
296 :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
|
297 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
298 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 '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
|
303 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
311 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
|
312 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
|
313 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
322 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
|
323 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
|
324 ' 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
|
325 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
|
326 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
|
327 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 # 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
|
334 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
|
335 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 " %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
|
340 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
|
341 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
|
342 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
|
343 dirnodes = [] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
344 filenodes = [] |
2232
49dc09e9f076
Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
345 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
|
346 for name, stat, id in tree.iteritems(): |
2232
49dc09e9f076
Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
347 if objects.S_ISGITLINK(stat): |
49dc09e9f076
Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
348 dirnodes.append(SubModuleNode(name, url=None, changeset=id, |
49dc09e9f076
Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
349 alias=als)) |
49dc09e9f076
Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
350 continue |
49dc09e9f076
Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
351 |
2007
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 = 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
|
353 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
|
354 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
|
355 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 else: |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
364 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
|
365 "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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
373 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
|
374 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
|
375 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
|
376 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
|
377 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
|
378 try: |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 "directories for a given path: %s" % path) |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
383 |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
384 _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
|
385 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
|
386 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
|
387 alias=self.repository.alias) |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
388 else: |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
389 obj = self.repository._repo.get_object(id_) |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
390 |
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
|
391 if isinstance(obj, objects.Tree): |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
392 if path == '': |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
393 node = RootNode(changeset=self) |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
394 else: |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
395 node = DirNode(path, changeset=self) |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
396 node._tree = obj |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
397 elif isinstance(obj, objects.Blob): |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
398 node = FileNode(path, changeset=self) |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
399 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
|
400 else: |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
401 raise NodeDoesNotExistError("There is no file nor directory " |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
402 "at the given path %r at revision %r" |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2232
diff
changeset
|
403 % (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
|
404 # 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
|
405 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
|
406 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
|
407 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
408 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
409 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
|
410 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
411 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
|
412 """ |
2762
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
413 a, m, d = self._changes_cache |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
414 return list(a.union(m).union(d)) |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
415 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
416 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
417 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
|
418 output = [] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
419 for parent in self.parents: |
2761
e64c64e2b8aa
re implemented affected_files function for git using dulwich
Marcin Kuzminski <marcin@python-works.com>
parents:
2693
diff
changeset
|
420 cmd = 'diff --name-status %s %s --encoding=utf8' % (parent.raw_id, |
e64c64e2b8aa
re implemented affected_files function for git using dulwich
Marcin Kuzminski <marcin@python-works.com>
parents:
2693
diff
changeset
|
421 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
|
422 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
|
423 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
|
424 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
|
425 |
2762
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
426 @LazyProperty |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
427 def _changes_cache(self): |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
428 added = set() |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
429 modified = set() |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
430 deleted = set() |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
431 _r = self.repository._repo |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
432 |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
433 parents = self.parents |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
434 if not self.parents: |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
435 parents = [EmptyChangeset()] |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
436 for parent in parents: |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
437 if isinstance(parent, EmptyChangeset): |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
438 oid = None |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
439 else: |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
440 oid = _r[parent.raw_id].tree |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
441 changes = _r.object_store.tree_changes(oid, _r[self.raw_id].tree) |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
442 for (oldpath, newpath), (_, _), (_, _) in changes: |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
443 if newpath and oldpath: |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
444 modified.add(newpath) |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
445 elif newpath and not oldpath: |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
446 added.add(newpath) |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
447 elif not newpath and oldpath: |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
448 deleted.add(oldpath) |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
449 return added, modified, deleted |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
450 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
451 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
|
452 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
453 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
|
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 :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
|
456 """ |
2762
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
457 a, m, d = self._changes_cache |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
458 return sorted({ |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
459 'added': list(a), |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
460 'modified': list(m), |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
461 'deleted': list(d)}[status] |
ba4fb9c441c6
new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents:
2761
diff
changeset
|
462 ) |
2007
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 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
465 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
|
466 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
467 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
|
468 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
469 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
|
470 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
|
471 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
|
472 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
473 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
474 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
|
475 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
476 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
|
477 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
478 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
|
479 return [] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
480 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
|
481 |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
482 @LazyProperty |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
483 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
|
484 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
485 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
|
486 """ |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
487 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
|
488 return [] |
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
489 return [RemovedFileNode(path) for path in self._get_paths_for_status('deleted')] |