Show More
@@ -342,3 +342,23 b' def credentials_filter(uri):' | |||
|
342 | 342 | |
|
343 | 343 | return ''.join(uri) |
|
344 | 344 | |
|
345 | def get_changeset_safe(repo, rev): | |
|
346 | """ | |
|
347 | Safe version of get_changeset if this changeset doesn't exists for a | |
|
348 | repo it returns a Dummy one instead | |
|
349 | ||
|
350 | :param repo: | |
|
351 | :param rev: | |
|
352 | """ | |
|
353 | from vcs.backends.base import BaseRepository | |
|
354 | from vcs.exceptions import RepositoryError | |
|
355 | if not isinstance(repo, BaseRepository): | |
|
356 | raise Exception('You must pass an Repository ' | |
|
357 | 'object as first argument got %s', type(repo)) | |
|
358 | ||
|
359 | try: | |
|
360 | cs = repo.get_changeset(rev) | |
|
361 | except RepositoryError: | |
|
362 | from rhodecode.lib.utils import EmptyChangeset | |
|
363 | cs = EmptyChangeset(requested_revision=rev) | |
|
364 | return cs No newline at end of file |
@@ -37,7 +37,7 b' from webhelpers.html.tags import _set_in' | |||
|
37 | 37 | |
|
38 | 38 | from vcs.utils.annotate import annotate_highlight |
|
39 | 39 | from rhodecode.lib.utils import repo_name_slug |
|
40 | from rhodecode.lib import str2bool, safe_unicode, safe_str | |
|
40 | from rhodecode.lib import str2bool, safe_unicode, safe_str,get_changeset_safe | |
|
41 | 41 | |
|
42 | 42 | def _reset(name, value=None, id=NotGiven, type="reset", **attrs): |
|
43 | 43 | """ |
@@ -275,21 +275,6 b' def pygmentize_annotation(repo_name, fil' | |||
|
275 | 275 | |
|
276 | 276 | return literal(annotate_highlight(filenode, url_func(repo_name), **kwargs)) |
|
277 | 277 | |
|
278 | def get_changeset_safe(repo, rev): | |
|
279 | from vcs.backends.base import BaseRepository | |
|
280 | from vcs.exceptions import RepositoryError | |
|
281 | if not isinstance(repo, BaseRepository): | |
|
282 | raise Exception('You must pass an Repository ' | |
|
283 | 'object as first argument got %s', type(repo)) | |
|
284 | ||
|
285 | try: | |
|
286 | cs = repo.get_changeset(rev) | |
|
287 | except RepositoryError: | |
|
288 | from rhodecode.lib.utils import EmptyChangeset | |
|
289 | cs = EmptyChangeset() | |
|
290 | return cs | |
|
291 | ||
|
292 | ||
|
293 | 278 | def is_following_repo(repo_name, user_id): |
|
294 | 279 | from rhodecode.model.scm import ScmModel |
|
295 | 280 | return ScmModel().is_following_repo(repo_name, user_id) |
@@ -313,13 +313,14 b' class EmptyChangeset(BaseChangeset):' | |||
|
313 | 313 | an EmptyChangeset |
|
314 | 314 | """ |
|
315 | 315 | |
|
316 | def __init__(self, cs='0' * 40, repo=None): | |
|
316 | def __init__(self, cs='0' * 40, repo=None,requested_revision=None): | |
|
317 | 317 | self._empty_cs = cs |
|
318 | 318 | self.revision = -1 |
|
319 | 319 | self.message = '' |
|
320 | 320 | self.author = '' |
|
321 | 321 | self.date = '' |
|
322 | 322 | self.repository = repo |
|
323 | self.requested_revision = requested_revision | |
|
323 | 324 | |
|
324 | 325 | @LazyProperty |
|
325 | 326 | def raw_id(self): |
@@ -43,7 +43,7 b' from vcs.utils.lazy import LazyProperty' | |||
|
43 | 43 | from vcs.nodes import FileNode |
|
44 | 44 | |
|
45 | 45 | from rhodecode.lib.exceptions import UsersGroupsAssignedException |
|
46 | from rhodecode.lib import str2bool, json, safe_str | |
|
46 | from rhodecode.lib import str2bool, json, safe_str, get_changeset_safe | |
|
47 | 47 | from rhodecode.model.meta import Base, Session |
|
48 | 48 | from rhodecode.model.caching_query import FromCache |
|
49 | 49 | |
@@ -538,8 +538,7 b' class Repository(Base, BaseModel):' | |||
|
538 | 538 | |
|
539 | 539 | |
|
540 | 540 | ret = Session.query(RhodeCodeUi)\ |
|
541 | .options(FromCache("sql_cache_short", | |
|
542 | "repository_repo_ui")).all() | |
|
541 | .options(FromCache("sql_cache_short", "repository_repo_ui")).all() | |
|
543 | 542 | |
|
544 | 543 | hg_ui = ret |
|
545 | 544 | for ui_ in hg_ui: |
@@ -551,6 +550,25 b' class Repository(Base, BaseModel):' | |||
|
551 | 550 | return baseui |
|
552 | 551 | |
|
553 | 552 | #========================================================================== |
|
553 | # SCM PROPERTIES | |
|
554 | #========================================================================== | |
|
555 | ||
|
556 | def get_changeset(self, rev): | |
|
557 | return get_changeset_safe(self.scm_instance, rev) | |
|
558 | ||
|
559 | @property | |
|
560 | def tip(self): | |
|
561 | return self.get_changeset('tip') | |
|
562 | ||
|
563 | @property | |
|
564 | def author(self): | |
|
565 | return self.tip.author | |
|
566 | ||
|
567 | @property | |
|
568 | def last_change(self): | |
|
569 | return self.scm_instance.last_change | |
|
570 | ||
|
571 | #========================================================================== | |
|
554 | 572 | # SCM CACHE INSTANCE |
|
555 | 573 | #========================================================================== |
|
556 | 574 | |
@@ -580,7 +598,7 b' class Repository(Base, BaseModel):' | |||
|
580 | 598 | Session.add(inv) |
|
581 | 599 | Session.commit() |
|
582 | 600 | |
|
583 |
@ |
|
|
601 | @LazyProperty | |
|
584 | 602 | def scm_instance(self): |
|
585 | 603 | return self.__get_instance() |
|
586 | 604 |
General Comments 0
You need to be logged in to leave comments.
Login now