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