##// END OF EJS Templates
synced with latest vcs
marcink -
r3805:a5c234e9 beta
parent child Browse files
Show More
@@ -10,7 +10,7 b''
10 10 :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
11 11 """
12 12
13 VERSION = (0, 4, 0, 'dev')
13 VERSION = (0, 5, 0, 'dev')
14 14
15 15 __version__ = '.'.join((str(each) for each in VERSION[:4]))
16 16
@@ -29,7 +29,7 b' class GitChangeset(BaseChangeset):'
29 29 self.repository = repository
30 30
31 31 try:
32 commit = self.repository._repo.get_object(revision)
32 commit = self.repository._repo[revision]
33 33 if isinstance(commit, objects.Tag):
34 34 revision = commit.object[1]
35 35 commit = self.repository._repo.get_object(commit.object[1])
@@ -39,7 +39,6 b' class GitChangeset(BaseChangeset):'
39 39 self.id = self.raw_id
40 40 self.short_id = self.raw_id[:12]
41 41 self._commit = commit
42
43 42 self._tree_id = commit.tree
44 43 self._committer_property = 'committer'
45 44 self._author_property = 'author'
@@ -47,12 +46,14 b' class GitChangeset(BaseChangeset):'
47 46 self._date_tz_property = 'commit_timezone'
48 47 self.revision = repository.revisions.index(revision)
49 48
50 self.message = safe_unicode(commit.message)
51
52 49 self.nodes = {}
53 50 self._paths = {}
54 51
55 52 @LazyProperty
53 def message(self):
54 return safe_unicode(self._commit.message)
55
56 @LazyProperty
56 57 def committer(self):
57 58 return safe_unicode(getattr(self._commit, self._committer_property))
58 59
@@ -43,6 +43,8 b' from .config import ConfigFile'
43 43 from .inmemory import GitInMemoryChangeset
44 44 from .workdir import GitWorkdir
45 45
46 SHA_PATTERN = re.compile(r'^[[0-9a-fA-F]{12}|[0-9a-fA-F]{40}]$')
47
46 48 log = logging.getLogger(__name__)
47 49
48 50
@@ -60,11 +62,13 b' class GitRepository(BaseRepository):'
60 62 repo = self._get_repo(create, src_url, update_after_clone, bare)
61 63 self.bare = repo.bare
62 64
63 self._config_files = [
64 bare and abspath(self.path, 'config')
65 or abspath(self.path, '.git', 'config'),
66 abspath(get_user_home(), '.gitconfig'),
67 ]
65 @property
66 def _config_files(self):
67 return [
68 self.bare and abspath(self.path, 'config')
69 or abspath(self.path, '.git', 'config'),
70 abspath(get_user_home(), '.gitconfig'),
71 ]
68 72
69 73 @property
70 74 def _repo(self):
@@ -242,17 +246,19 b' class GitRepository(BaseRepository):'
242 246 For git backend we always return integer here. This way we ensure
243 247 that changset's revision attribute would become integer.
244 248 """
245 pattern = re.compile(r'^[[0-9a-fA-F]{12}|[0-9a-fA-F]{40}]$')
246 is_bstr = lambda o: isinstance(o, (str, unicode))
249
247 250 is_null = lambda o: len(o) == revision.count('0')
248 251
249 if len(self.revisions) == 0:
252 try:
253 self.revisions[0]
254 except (KeyError, IndexError):
250 255 raise EmptyRepositoryError("There are no changesets yet")
251 256
252 257 if revision in (None, '', 'tip', 'HEAD', 'head', -1):
253 revision = self.revisions[-1]
258 return self.revisions[-1]
254 259
255 if ((is_bstr(revision) and revision.isdigit() and len(revision) < 12)
260 is_bstr = isinstance(revision, (str, unicode))
261 if ((is_bstr and revision.isdigit() and len(revision) < 12)
256 262 or isinstance(revision, int) or is_null(revision)):
257 263 try:
258 264 revision = self.revisions[int(revision)]
@@ -260,23 +266,23 b' class GitRepository(BaseRepository):'
260 266 raise ChangesetDoesNotExistError("Revision %s does not exist "
261 267 "for this repository" % (revision))
262 268
263 elif is_bstr(revision):
269 elif is_bstr:
264 270 # get by branch/tag name
265 271 _ref_revision = self._parsed_refs.get(revision)
266 _tags_shas = self.tags.values()
267 272 if _ref_revision: # and _ref_revision[1] in ['H', 'RH', 'T']:
268 273 return _ref_revision[0]
269 274
275 _tags_shas = self.tags.values()
270 276 # maybe it's a tag ? we don't have them in self.revisions
271 elif revision in _tags_shas:
277 if revision in _tags_shas:
272 278 return _tags_shas[_tags_shas.index(revision)]
273 279
274 elif not pattern.match(revision) or revision not in self.revisions:
280 elif not SHA_PATTERN.match(revision) or revision not in self.revisions:
275 281 raise ChangesetDoesNotExistError("Revision %s does not exist "
276 282 "for this repository" % (revision))
277 283
278 284 # Ensure we return full id
279 if not pattern.match(str(revision)):
285 if not SHA_PATTERN.match(str(revision)):
280 286 raise ChangesetDoesNotExistError("Given revision %s not recognized"
281 287 % revision)
282 288 return revision
@@ -492,10 +492,12 b' class MercurialRepository(BaseRepository'
492 492 if branch_name:
493 493 filter_.append('branch("%s")' % (branch_name))
494 494
495 if start_date:
495 if start_date and not end_date:
496 496 filter_.append('date(">%s")' % start_date)
497 if end_date:
497 if end_date and not start_date:
498 498 filter_.append('date("<%s")' % end_date)
499 if start_date and end_date:
500 filter_.append('date(">%s") and date("<%s")' % (start_date, end_date))
499 501 if filter_:
500 502 revisions = scmutil.revrange(self._repo, filter_)
501 503 else:
@@ -208,6 +208,14 b' class ChangesetsTestCaseMixin(BackendTes'
208 208 self.assertGreaterEqual(cs.date, start_date)
209 209
210 210 def test_get_changesets_respects_end_date(self):
211 start_date = datetime.datetime(2010, 1, 1)
212 end_date = datetime.datetime(2010, 2, 1)
213 for cs in self.repo.get_changesets(start_date=start_date,
214 end_date=end_date):
215 self.assertGreaterEqual(cs.date, start_date)
216 self.assertLessEqual(cs.date, end_date)
217
218 def test_get_changesets_respects_start_date_and_end_date(self):
211 219 end_date = datetime.datetime(2010, 2, 1)
212 220 for cs in self.repo.get_changesets(end_date=end_date):
213 221 self.assertLessEqual(cs.date, end_date)
@@ -49,8 +49,10 b' class WorkdirTestCaseMixin(BackendTestMi'
49 49 author=u'joe',
50 50 branch='foobar',
51 51 )
52 self.assertEqual(self.repo.workdir.get_branch(), self.default_branch)
52 53
53 54 def test_get_changeset(self):
55 old_head = self.repo.get_changeset()
54 56 self.imc.add(FileNode('docs/index.txt',
55 57 content='Documentation\n'))
56 58 head = self.imc.commit(
@@ -58,8 +60,14 b' class WorkdirTestCaseMixin(BackendTestMi'
58 60 author=u'joe',
59 61 branch='foobar',
60 62 )
63 self.assertEqual(self.repo.workdir.get_branch(), self.default_branch)
64 self.repo.workdir.checkout_branch('foobar')
61 65 self.assertEqual(self.repo.workdir.get_changeset(), head)
62 66
67 # Make sure that old head is still there after update to defualt branch
68 self.repo.workdir.checkout_branch(self.default_branch)
69 self.assertEqual(self.repo.workdir.get_changeset(), old_head)
70
63 71 def test_checkout_branch(self):
64 72 from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError
65 73 # first, 'foobranch' does not exist.
General Comments 0
You need to be logged in to leave comments. Login now