Show More
@@ -33,6 +33,8 b' import collections' | |||||
33 | import warnings |
|
33 | import warnings | |
34 |
|
34 | |||
35 | from zope.cachedescriptors.property import Lazy as LazyProperty |
|
35 | from zope.cachedescriptors.property import Lazy as LazyProperty | |
|
36 | from zope.cachedescriptors.property import CachedProperty | |||
|
37 | ||||
36 | from pyramid import compat |
|
38 | from pyramid import compat | |
37 |
|
39 | |||
38 | from rhodecode.translation import lazy_ugettext |
|
40 | from rhodecode.translation import lazy_ugettext | |
@@ -261,6 +263,7 b' class BaseRepository(object):' | |||||
261 | EMPTY_COMMIT_ID = '0' * 40 |
|
263 | EMPTY_COMMIT_ID = '0' * 40 | |
262 |
|
264 | |||
263 | path = None |
|
265 | path = None | |
|
266 | _commit_ids_ver = 0 | |||
264 |
|
267 | |||
265 | def __init__(self, repo_path, config=None, create=False, **kwargs): |
|
268 | def __init__(self, repo_path, config=None, create=False, **kwargs): | |
266 | """ |
|
269 | """ | |
@@ -404,6 +407,15 b' class BaseRepository(object):' | |||||
404 | # COMMITS |
|
407 | # COMMITS | |
405 | # ========================================================================== |
|
408 | # ========================================================================== | |
406 |
|
409 | |||
|
410 | @CachedProperty('_commit_ids_ver') | |||
|
411 | def commit_ids(self): | |||
|
412 | raise NotImplementedError | |||
|
413 | ||||
|
414 | def append_commit_id(self, commit_id): | |||
|
415 | if commit_id not in self.commit_ids: | |||
|
416 | self._rebuild_cache(self.commit_ids + [commit_id]) | |||
|
417 | self._commit_ids_ver = time.time() | |||
|
418 | ||||
407 | def get_commit(self, commit_id=None, commit_idx=None, pre_load=None, translate_tag=None): |
|
419 | def get_commit(self, commit_id=None, commit_idx=None, pre_load=None, translate_tag=None): | |
408 | """ |
|
420 | """ | |
409 | Returns instance of `BaseCommit` class. If `commit_id` and `commit_idx` |
|
421 | Returns instance of `BaseCommit` class. If `commit_id` and `commit_idx` | |
@@ -1509,9 +1521,7 b' class BaseInMemoryCommit(object):' | |||||
1509 | "Cannot remove node at %s from " |
|
1521 | "Cannot remove node at %s from " | |
1510 | "following parents: %s" % (not_removed, parents)) |
|
1522 | "following parents: %s" % (not_removed, parents)) | |
1511 |
|
1523 | |||
1512 | def commit( |
|
1524 | def commit(self, message, author, parents=None, branch=None, date=None, **kwargs): | |
1513 | self, message, author, parents=None, branch=None, date=None, |
|
|||
1514 | **kwargs): |
|
|||
1515 | """ |
|
1525 | """ | |
1516 | Performs in-memory commit (doesn't check workdir in any way) and |
|
1526 | Performs in-memory commit (doesn't check workdir in any way) and | |
1517 | returns newly created :class:`BaseCommit`. Updates repository's |
|
1527 | returns newly created :class:`BaseCommit`. Updates repository's |
@@ -29,8 +29,7 b' from rhodecode.lib.vcs.backends import b' | |||||
29 |
|
29 | |||
30 | class GitInMemoryCommit(base.BaseInMemoryCommit): |
|
30 | class GitInMemoryCommit(base.BaseInMemoryCommit): | |
31 |
|
31 | |||
32 | def commit(self, message, author, parents=None, branch=None, date=None, |
|
32 | def commit(self, message, author, parents=None, branch=None, date=None, **kwargs): | |
33 | **kwargs): |
|
|||
34 | """ |
|
33 | """ | |
35 | Performs in-memory commit (doesn't check workdir in any way) and |
|
34 | Performs in-memory commit (doesn't check workdir in any way) and | |
36 | returns newly created `GitCommit`. Updates repository's |
|
35 | returns newly created `GitCommit`. Updates repository's | |
@@ -94,13 +93,12 b' class GitInMemoryCommit(base.BaseInMemor' | |||||
94 | commit_data, branch, commit_tree, updated, removed) |
|
93 | commit_data, branch, commit_tree, updated, removed) | |
95 |
|
94 | |||
96 | # Update vcs repository object |
|
95 | # Update vcs repository object | |
97 |
|
|
96 | self.repository.append_commit_id(commit_id) | |
98 | self.repository.commit_ids.append(commit_id) |
|
|||
99 | self.repository._rebuild_cache(self.repository.commit_ids) |
|
|||
100 |
|
97 | |||
101 | # invalidate parsed refs after commit |
|
98 | # invalidate parsed refs after commit | |
102 | self.repository._refs = self.repository._get_refs() |
|
99 | self.repository._refs = self.repository._get_refs() | |
103 | self.repository.branches = self.repository._get_branches() |
|
100 | self.repository.branches = self.repository._get_branches() | |
104 | tip = self.repository.get_commit() |
|
101 | tip = self.repository.get_commit(commit_id) | |
|
102 | ||||
105 | self.reset() |
|
103 | self.reset() | |
106 | return tip |
|
104 | return tip |
@@ -25,8 +25,10 b' GIT repository module' | |||||
25 | import logging |
|
25 | import logging | |
26 | import os |
|
26 | import os | |
27 | import re |
|
27 | import re | |
|
28 | import time | |||
28 |
|
29 | |||
29 | from zope.cachedescriptors.property import Lazy as LazyProperty |
|
30 | from zope.cachedescriptors.property import Lazy as LazyProperty | |
|
31 | from zope.cachedescriptors.property import CachedProperty | |||
30 |
|
32 | |||
31 | from rhodecode.lib.compat import OrderedDict |
|
33 | from rhodecode.lib.compat import OrderedDict | |
32 | from rhodecode.lib.datelib import ( |
|
34 | from rhodecode.lib.datelib import ( | |
@@ -69,6 +71,9 b' class GitRepository(BaseRepository):' | |||||
69 | # caches |
|
71 | # caches | |
70 | self._commit_ids = {} |
|
72 | self._commit_ids = {} | |
71 |
|
73 | |||
|
74 | # dependent that trigger re-computation of commit_ids | |||
|
75 | self._commit_ids_ver = 0 | |||
|
76 | ||||
72 | @LazyProperty |
|
77 | @LazyProperty | |
73 | def _remote(self): |
|
78 | def _remote(self): | |
74 | return connection.Git(self.path, self.config, with_wire=self.with_wire) |
|
79 | return connection.Git(self.path, self.config, with_wire=self.with_wire) | |
@@ -81,7 +86,7 b' class GitRepository(BaseRepository):' | |||||
81 | def head(self): |
|
86 | def head(self): | |
82 | return self._remote.head() |
|
87 | return self._remote.head() | |
83 |
|
88 | |||
84 | @LazyProperty |
|
89 | @CachedProperty('_commit_ids_ver') | |
85 | def commit_ids(self): |
|
90 | def commit_ids(self): | |
86 | """ |
|
91 | """ | |
87 | Returns list of commit ids, in ascending order. Being lazy |
|
92 | Returns list of commit ids, in ascending order. Being lazy | |
@@ -608,8 +613,9 b' class GitRepository(BaseRepository):' | |||||
608 | commit = commit.parents[0] |
|
613 | commit = commit.parents[0] | |
609 | self._remote.set_refs('refs/heads/%s' % branch_name, commit.raw_id) |
|
614 | self._remote.set_refs('refs/heads/%s' % branch_name, commit.raw_id) | |
610 |
|
615 | |||
611 | self.commit_ids = self._get_all_commit_ids() |
|
616 | self._commit_ids_ver = time.time() | |
612 | self._rebuild_cache(self.commit_ids) |
|
617 | # we updated _commit_ids_ver so accessing self.commit_ids will re-compute it | |
|
618 | return len(self.commit_ids) | |||
613 |
|
619 | |||
614 | def get_common_ancestor(self, commit_id1, commit_id2, repo2): |
|
620 | def get_common_ancestor(self, commit_id1, commit_id2, repo2): | |
615 | if commit_id1 == commit_id2: |
|
621 | if commit_id1 == commit_id2: |
@@ -30,8 +30,7 b' from rhodecode.lib.vcs.exceptions import' | |||||
30 |
|
30 | |||
31 | class MercurialInMemoryCommit(BaseInMemoryCommit): |
|
31 | class MercurialInMemoryCommit(BaseInMemoryCommit): | |
32 |
|
32 | |||
33 | def commit(self, message, author, parents=None, branch=None, date=None, |
|
33 | def commit(self, message, author, parents=None, branch=None, date=None, **kwargs): | |
34 | **kwargs): |
|
|||
35 | """ |
|
34 | """ | |
36 | Performs in-memory commit (doesn't check workdir in any way) and |
|
35 | Performs in-memory commit (doesn't check workdir in any way) and | |
37 | returns newly created `MercurialCommit`. Updates repository's |
|
36 | returns newly created `MercurialCommit`. Updates repository's | |
@@ -88,11 +87,9 b' class MercurialInMemoryCommit(BaseInMemo' | |||||
88 | commit_time=date, commit_timezone=tz, user=author, |
|
87 | commit_time=date, commit_timezone=tz, user=author, | |
89 | files=self.get_paths(), extra=kwargs, removed=removed, |
|
88 | files=self.get_paths(), extra=kwargs, removed=removed, | |
90 | updated=updated) |
|
89 | updated=updated) | |
91 |
|
|
90 | self.repository.append_commit_id(commit_id) | |
92 | self.repository.commit_ids.append(commit_id) |
|
|||
93 | self.repository._rebuild_cache(self.repository.commit_ids) |
|
|||
94 |
|
91 | |||
95 | self.repository.branches = self.repository._get_branches() |
|
92 | self.repository.branches = self.repository._get_branches() | |
96 | tip = self.repository.get_commit() |
|
93 | tip = self.repository.get_commit(commit_id) | |
97 | self.reset() |
|
94 | self.reset() | |
98 | return tip |
|
95 | return tip |
@@ -24,9 +24,11 b' HG repository module' | |||||
24 | import os |
|
24 | import os | |
25 | import logging |
|
25 | import logging | |
26 | import binascii |
|
26 | import binascii | |
|
27 | import time | |||
27 | import urllib |
|
28 | import urllib | |
28 |
|
29 | |||
29 | from zope.cachedescriptors.property import Lazy as LazyProperty |
|
30 | from zope.cachedescriptors.property import Lazy as LazyProperty | |
|
31 | from zope.cachedescriptors.property import CachedProperty | |||
30 |
|
32 | |||
31 | from rhodecode.lib.compat import OrderedDict |
|
33 | from rhodecode.lib.compat import OrderedDict | |
32 | from rhodecode.lib.datelib import ( |
|
34 | from rhodecode.lib.datelib import ( | |
@@ -85,11 +87,14 b' class MercurialRepository(BaseRepository' | |||||
85 | # caches |
|
87 | # caches | |
86 | self._commit_ids = {} |
|
88 | self._commit_ids = {} | |
87 |
|
89 | |||
|
90 | # dependent that trigger re-computation of commit_ids | |||
|
91 | self._commit_ids_ver = 0 | |||
|
92 | ||||
88 | @LazyProperty |
|
93 | @LazyProperty | |
89 | def _remote(self): |
|
94 | def _remote(self): | |
90 | return connection.Hg(self.path, self.config, with_wire=self.with_wire) |
|
95 | return connection.Hg(self.path, self.config, with_wire=self.with_wire) | |
91 |
|
96 | |||
92 | @LazyProperty |
|
97 | @CachedProperty('_commit_ids_ver') | |
93 | def commit_ids(self): |
|
98 | def commit_ids(self): | |
94 | """ |
|
99 | """ | |
95 | Returns list of commit ids, in ascending order. Being lazy |
|
100 | Returns list of commit ids, in ascending order. Being lazy | |
@@ -157,8 +162,7 b' class MercurialRepository(BaseRepository' | |||||
157 |
|
162 | |||
158 | return OrderedDict(sorted(_tags, key=get_name, reverse=True)) |
|
163 | return OrderedDict(sorted(_tags, key=get_name, reverse=True)) | |
159 |
|
164 | |||
160 | def tag(self, name, user, commit_id=None, message=None, date=None, |
|
165 | def tag(self, name, user, commit_id=None, message=None, date=None, **kwargs): | |
161 | **kwargs): |
|
|||
162 | """ |
|
166 | """ | |
163 | Creates and returns a tag for the given ``commit_id``. |
|
167 | Creates and returns a tag for the given ``commit_id``. | |
164 |
|
168 | |||
@@ -172,6 +176,7 b' class MercurialRepository(BaseRepository' | |||||
172 | """ |
|
176 | """ | |
173 | if name in self.tags: |
|
177 | if name in self.tags: | |
174 | raise TagAlreadyExistError("Tag %s already exists" % name) |
|
178 | raise TagAlreadyExistError("Tag %s already exists" % name) | |
|
179 | ||||
175 | commit = self.get_commit(commit_id=commit_id) |
|
180 | commit = self.get_commit(commit_id=commit_id) | |
176 | local = kwargs.setdefault('local', False) |
|
181 | local = kwargs.setdefault('local', False) | |
177 |
|
182 | |||
@@ -180,8 +185,7 b' class MercurialRepository(BaseRepository' | |||||
180 |
|
185 | |||
181 | date, tz = date_to_timestamp_plus_offset(date) |
|
186 | date, tz = date_to_timestamp_plus_offset(date) | |
182 |
|
187 | |||
183 | self._remote.tag( |
|
188 | self._remote.tag(name, commit.raw_id, message, local, user, date, tz) | |
184 | name, commit.raw_id, message, local, user, date, tz) |
|
|||
185 | self._remote.invalidate_vcs_cache() |
|
189 | self._remote.invalidate_vcs_cache() | |
186 |
|
190 | |||
187 | # Reinitialize tags |
|
191 | # Reinitialize tags | |
@@ -203,6 +207,7 b' class MercurialRepository(BaseRepository' | |||||
203 | """ |
|
207 | """ | |
204 | if name not in self.tags: |
|
208 | if name not in self.tags: | |
205 | raise TagDoesNotExistError("Tag %s does not exist" % name) |
|
209 | raise TagDoesNotExistError("Tag %s does not exist" % name) | |
|
210 | ||||
206 | if message is None: |
|
211 | if message is None: | |
207 | message = "Removed tag %s" % name |
|
212 | message = "Removed tag %s" % name | |
208 | local = False |
|
213 | local = False | |
@@ -271,8 +276,9 b' class MercurialRepository(BaseRepository' | |||||
271 | self._remote.strip(commit_id, update=False, backup="none") |
|
276 | self._remote.strip(commit_id, update=False, backup="none") | |
272 |
|
277 | |||
273 | self._remote.invalidate_vcs_cache() |
|
278 | self._remote.invalidate_vcs_cache() | |
274 | self.commit_ids = self._get_all_commit_ids() |
|
279 | self._commit_ids_ver = time.time() | |
275 | self._rebuild_cache(self.commit_ids) |
|
280 | # we updated _commit_ids_ver so accessing self.commit_ids will re-compute it | |
|
281 | return len(self.commit_ids) | |||
276 |
|
282 | |||
277 | def verify(self): |
|
283 | def verify(self): | |
278 | verify = self._remote.verify() |
|
284 | verify = self._remote.verify() | |
@@ -450,7 +456,8 b' class MercurialRepository(BaseRepository' | |||||
450 | try: |
|
456 | try: | |
451 | raw_id, idx = self._remote.lookup(commit_id, both=True) |
|
457 | raw_id, idx = self._remote.lookup(commit_id, both=True) | |
452 | except CommitDoesNotExistError: |
|
458 | except CommitDoesNotExistError: | |
453 |
msg = "Commit |
|
459 | msg = "Commit {} does not exist for {}".format( | |
|
460 | *map(safe_str, [commit_id, self.name])) | |||
454 | raise CommitDoesNotExistError(msg) |
|
461 | raise CommitDoesNotExistError(msg) | |
455 |
|
462 | |||
456 | return MercurialCommit(self, raw_id, idx, pre_load=pre_load) |
|
463 | return MercurialCommit(self, raw_id, idx, pre_load=pre_load) |
@@ -30,8 +30,7 b' from rhodecode.lib.vcs.backends import b' | |||||
30 |
|
30 | |||
31 | class SubversionInMemoryCommit(base.BaseInMemoryCommit): |
|
31 | class SubversionInMemoryCommit(base.BaseInMemoryCommit): | |
32 |
|
32 | |||
33 | def commit(self, message, author, parents=None, branch=None, date=None, |
|
33 | def commit(self, message, author, parents=None, branch=None, date=None, **kwargs): | |
34 | **kwargs): |
|
|||
35 | if branch not in (None, self.repository.DEFAULT_BRANCH_NAME): |
|
34 | if branch not in (None, self.repository.DEFAULT_BRANCH_NAME): | |
36 | raise NotImplementedError("Branches are not yet supported") |
|
35 | raise NotImplementedError("Branches are not yet supported") | |
37 |
|
36 | |||
@@ -74,8 +73,7 b' class SubversionInMemoryCommit(base.Base' | |||||
74 | # we should not add the commit_id, if it is already evaluated, it |
|
73 | # we should not add the commit_id, if it is already evaluated, it | |
75 | # will not be evaluated again. |
|
74 | # will not be evaluated again. | |
76 | commit_id = str(svn_rev) |
|
75 | commit_id = str(svn_rev) | |
77 |
|
|
76 | self.repository.append_commit_id(commit_id) | |
78 | self.repository.commit_ids.append(commit_id) |
|
|||
79 | tip = self.repository.get_commit() |
|
77 | tip = self.repository.get_commit() | |
80 | self.reset() |
|
78 | self.reset() | |
81 | return tip |
|
79 | return tip |
@@ -27,6 +27,7 b' import os' | |||||
27 | import urllib |
|
27 | import urllib | |
28 |
|
28 | |||
29 | from zope.cachedescriptors.property import Lazy as LazyProperty |
|
29 | from zope.cachedescriptors.property import Lazy as LazyProperty | |
|
30 | from zope.cachedescriptors.property import CachedProperty | |||
30 |
|
31 | |||
31 | from rhodecode.lib.compat import OrderedDict |
|
32 | from rhodecode.lib.compat import OrderedDict | |
32 | from rhodecode.lib.datelib import date_astimestamp |
|
33 | from rhodecode.lib.datelib import date_astimestamp | |
@@ -75,6 +76,9 b' class SubversionRepository(base.BaseRepo' | |||||
75 |
|
76 | |||
76 | self._init_repo(create, src_url) |
|
77 | self._init_repo(create, src_url) | |
77 |
|
78 | |||
|
79 | # dependent that trigger re-computation of commit_ids | |||
|
80 | self._commit_ids_ver = 0 | |||
|
81 | ||||
78 | @LazyProperty |
|
82 | @LazyProperty | |
79 | def _remote(self): |
|
83 | def _remote(self): | |
80 | return connection.Svn(self.path, self.config) |
|
84 | return connection.Svn(self.path, self.config) | |
@@ -93,11 +97,14 b' class SubversionRepository(base.BaseRepo' | |||||
93 | else: |
|
97 | else: | |
94 | self._check_path() |
|
98 | self._check_path() | |
95 |
|
99 | |||
96 | @LazyProperty |
|
100 | @CachedProperty('_commit_ids_ver') | |
97 | def commit_ids(self): |
|
101 | def commit_ids(self): | |
98 | head = self._remote.lookup(None) |
|
102 | head = self._remote.lookup(None) | |
99 | return [str(r) for r in xrange(1, head + 1)] |
|
103 | return [str(r) for r in xrange(1, head + 1)] | |
100 |
|
104 | |||
|
105 | def _rebuild_cache(self, commit_ids): | |||
|
106 | pass | |||
|
107 | ||||
101 | def run_svn_command(self, cmd, **opts): |
|
108 | def run_svn_command(self, cmd, **opts): | |
102 | """ |
|
109 | """ | |
103 | Runs given ``cmd`` as svn command and returns tuple |
|
110 | Runs given ``cmd`` as svn command and returns tuple |
@@ -97,7 +97,7 b' class TestArchives(BackendTestMixin):' | |||||
97 | metafile = out.read('.archival.txt') |
|
97 | metafile = out.read('.archival.txt') | |
98 |
|
98 | |||
99 | raw_id = self.tip.raw_id |
|
99 | raw_id = self.tip.raw_id | |
100 |
assert ' |
|
100 | assert 'commit_id:%s' % raw_id in metafile | |
101 |
|
101 | |||
102 | for x in range(5): |
|
102 | for x in range(5): | |
103 | node_path = '%d/file_%d.txt' % (x, x) |
|
103 | node_path = '%d/file_%d.txt' % (x, x) |
@@ -70,10 +70,13 b' class TestMercurialRemoteRepoInvalidatio' | |||||
70 | tags[name] = raw_id |
|
70 | tags[name] = raw_id | |
71 |
|
71 | |||
72 | repo = backend_hg.repo.scm_instance() |
|
72 | repo = backend_hg.repo.scm_instance() | |
|
73 | ||||
73 | with patch.object(repo, '_remote') as remote: |
|
74 | with patch.object(repo, '_remote') as remote: | |
|
75 | repo.tags = tags | |||
74 | remote.lookup.return_value = ('commit-id', 'commit-idx') |
|
76 | remote.lookup.return_value = ('commit-id', 'commit-idx') | |
75 | remote.tags.return_value = tags |
|
77 | remote.tags.return_value = tags | |
76 | remote._get_tags.return_value = tags |
|
78 | remote._get_tags.return_value = tags | |
|
79 | remote.is_empty.return_value = False | |||
77 | remote.tag.side_effect = add_tag |
|
80 | remote.tag.side_effect = add_tag | |
78 |
|
81 | |||
79 | # Invoke method. |
|
82 | # Invoke method. |
@@ -79,9 +79,17 b' class TestInMemoryCommit(BackendTestMixi' | |||||
79 | self.commit() |
|
79 | self.commit() | |
80 | self.assert_succesful_commit(nodes) |
|
80 | self.assert_succesful_commit(nodes) | |
81 |
|
81 | |||
82 |
@pytest.mark. |
|
82 | @pytest.mark.backends("hg") | |
83 | 'svn', reason="Svn does not support commits on branches.") |
|
83 | def test_add_on_branch_hg(self, nodes): | |
84 | def test_add_on_branch(self, nodes): |
|
84 | for node in nodes: | |
|
85 | self.imc.add(node) | |||
|
86 | self.commit(branch=u'stable') | |||
|
87 | self.assert_succesful_commit(nodes) | |||
|
88 | ||||
|
89 | @pytest.mark.backends("git") | |||
|
90 | def test_add_on_branch_git(self, nodes): | |||
|
91 | self.repo._checkout('stable', create=True) | |||
|
92 | ||||
85 | for node in nodes: |
|
93 | for node in nodes: | |
86 | self.imc.add(node) |
|
94 | self.imc.add(node) | |
87 | self.commit(branch=u'stable') |
|
95 | self.commit(branch=u'stable') |
General Comments 0
You need to be logged in to leave comments.
Login now