Mercurial > kallithea
comparison rhodecode/lib/vcs/backends/git/repository.py @ 3835:42981614c624 beta
vcs: fixed issues with calling get_changesets method doesn't
throws EmptyRepositoryError when called on empty repos
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 10 May 2013 14:35:02 +0200 |
parents | 08d439bfbd8c |
children | f5a1314886ec |
comparison
equal
deleted
inserted
replaced
3834:2ad55d8ba11d | 3835:42981614c624 |
---|---|
78 def head(self): | 78 def head(self): |
79 try: | 79 try: |
80 return self._repo.head() | 80 return self._repo.head() |
81 except KeyError: | 81 except KeyError: |
82 return None | 82 return None |
83 | |
84 @property | |
85 def _empty(self): | |
86 """ | |
87 Checks if repository is empty ie. without any changesets | |
88 """ | |
89 | |
90 try: | |
91 self.revisions[0] | |
92 except (KeyError, IndexError): | |
93 return True | |
94 return False | |
83 | 95 |
84 @LazyProperty | 96 @LazyProperty |
85 def revisions(self): | 97 def revisions(self): |
86 """ | 98 """ |
87 Returns list of revisions' ids, in ascending order. Being lazy | 99 Returns list of revisions' ids, in ascending order. Being lazy |
248 that changset's revision attribute would become integer. | 260 that changset's revision attribute would become integer. |
249 """ | 261 """ |
250 | 262 |
251 is_null = lambda o: len(o) == revision.count('0') | 263 is_null = lambda o: len(o) == revision.count('0') |
252 | 264 |
253 try: | 265 if self._empty: |
254 self.revisions[0] | |
255 except (KeyError, IndexError): | |
256 raise EmptyRepositoryError("There are no changesets yet") | 266 raise EmptyRepositoryError("There are no changesets yet") |
257 | 267 |
258 if revision in (None, '', 'tip', 'HEAD', 'head', -1): | 268 if revision in (None, '', 'tip', 'HEAD', 'head', -1): |
259 return self.revisions[-1] | 269 return self.revisions[-1] |
260 | 270 |
490 | 500 |
491 """ | 501 """ |
492 if branch_name and branch_name not in self.branches: | 502 if branch_name and branch_name not in self.branches: |
493 raise BranchDoesNotExistError("Branch '%s' not found" \ | 503 raise BranchDoesNotExistError("Branch '%s' not found" \ |
494 % branch_name) | 504 % branch_name) |
505 # actually we should check now if it's not an empty repo to not spaw | |
506 # subprocess commands | |
507 if self._empty: | |
508 raise EmptyRepositoryError("There are no changesets yet") | |
509 | |
495 # %H at format means (full) commit hash, initial hashes are retrieved | 510 # %H at format means (full) commit hash, initial hashes are retrieved |
496 # in ascending date order | 511 # in ascending date order |
497 cmd_template = 'log --date-order --reverse --pretty=format:"%H"' | 512 cmd_template = 'log --date-order --reverse --pretty=format:"%H"' |
498 cmd_params = {} | 513 cmd_params = {} |
499 if start_date: | 514 if start_date: |