Show More
@@ -140,7 +140,7 b' def detect_mode(line, default):' | |||||
140 |
|
140 | |||
141 | def generate_api_key(username, salt=None): |
|
141 | def generate_api_key(username, salt=None): | |
142 | """ |
|
142 | """ | |
143 | Generates unique API key for given username,if salt is not given |
|
143 | Generates unique API key for given username, if salt is not given | |
144 | it'll be generated from some random string |
|
144 | it'll be generated from some random string | |
145 |
|
145 | |||
146 | :param username: username as string |
|
146 | :param username: username as string | |
@@ -342,3 +342,23 b' def credentials_filter(uri):' | |||||
342 |
|
342 | |||
343 | return ''.join(uri) |
|
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 | from vcs.utils.annotate import annotate_highlight |
|
38 | from vcs.utils.annotate import annotate_highlight | |
39 | from rhodecode.lib.utils import repo_name_slug |
|
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 | def _reset(name, value=None, id=NotGiven, type="reset", **attrs): |
|
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 | return literal(annotate_highlight(filenode, url_func(repo_name), **kwargs)) |
|
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 | def is_following_repo(repo_name, user_id): |
|
278 | def is_following_repo(repo_name, user_id): | |
294 | from rhodecode.model.scm import ScmModel |
|
279 | from rhodecode.model.scm import ScmModel | |
295 | return ScmModel().is_following_repo(repo_name, user_id) |
|
280 | return ScmModel().is_following_repo(repo_name, user_id) |
@@ -313,14 +313,15 b' class EmptyChangeset(BaseChangeset):' | |||||
313 | an EmptyChangeset |
|
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 | self._empty_cs = cs |
|
317 | self._empty_cs = cs | |
318 | self.revision = -1 |
|
318 | self.revision = -1 | |
319 | self.message = '' |
|
319 | self.message = '' | |
320 | self.author = '' |
|
320 | self.author = '' | |
321 | self.date = '' |
|
321 | self.date = '' | |
322 | self.repository = repo |
|
322 | self.repository = repo | |
323 |
|
323 | self.requested_revision = requested_revision | ||
|
324 | ||||
324 | @LazyProperty |
|
325 | @LazyProperty | |
325 | def raw_id(self): |
|
326 | def raw_id(self): | |
326 | """Returns raw string identifying this changeset, useful for web |
|
327 | """Returns raw string identifying this changeset, useful for web |
@@ -43,7 +43,7 b' from vcs.utils.lazy import LazyProperty' | |||||
43 | from vcs.nodes import FileNode |
|
43 | from vcs.nodes import FileNode | |
44 |
|
44 | |||
45 | from rhodecode.lib.exceptions import UsersGroupsAssignedException |
|
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 | from rhodecode.model.meta import Base, Session |
|
47 | from rhodecode.model.meta import Base, Session | |
48 | from rhodecode.model.caching_query import FromCache |
|
48 | from rhodecode.model.caching_query import FromCache | |
49 |
|
49 | |||
@@ -125,13 +125,13 b' class BaseModel(object):' | |||||
125 | @classmethod |
|
125 | @classmethod | |
126 | def get(cls, id_): |
|
126 | def get(cls, id_): | |
127 | return Session.query(cls).get(id_) |
|
127 | return Session.query(cls).get(id_) | |
128 |
|
128 | |||
129 | @classmethod |
|
129 | @classmethod | |
130 | def delete(cls, id_): |
|
130 | def delete(cls, id_): | |
131 | obj = Session.query(cls).get(id_) |
|
131 | obj = Session.query(cls).get(id_) | |
132 | Session.delete(obj) |
|
132 | Session.delete(obj) | |
133 | Session.commit() |
|
133 | Session.commit() | |
134 |
|
134 | |||
135 |
|
135 | |||
136 | class RhodeCodeSettings(Base, BaseModel): |
|
136 | class RhodeCodeSettings(Base, BaseModel): | |
137 | __tablename__ = 'rhodecode_settings' |
|
137 | __tablename__ = 'rhodecode_settings' | |
@@ -538,8 +538,7 b' class Repository(Base, BaseModel):' | |||||
538 |
|
538 | |||
539 |
|
539 | |||
540 | ret = Session.query(RhodeCodeUi)\ |
|
540 | ret = Session.query(RhodeCodeUi)\ | |
541 | .options(FromCache("sql_cache_short", |
|
541 | .options(FromCache("sql_cache_short", "repository_repo_ui")).all() | |
542 | "repository_repo_ui")).all() |
|
|||
543 |
|
542 | |||
544 | hg_ui = ret |
|
543 | hg_ui = ret | |
545 | for ui_ in hg_ui: |
|
544 | for ui_ in hg_ui: | |
@@ -551,6 +550,25 b' class Repository(Base, BaseModel):' | |||||
551 | return baseui |
|
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 | # SCM CACHE INSTANCE |
|
572 | # SCM CACHE INSTANCE | |
555 | #========================================================================== |
|
573 | #========================================================================== | |
556 |
|
574 | |||
@@ -580,7 +598,7 b' class Repository(Base, BaseModel):' | |||||
580 | Session.add(inv) |
|
598 | Session.add(inv) | |
581 | Session.commit() |
|
599 | Session.commit() | |
582 |
|
600 | |||
583 |
@ |
|
601 | @LazyProperty | |
584 | def scm_instance(self): |
|
602 | def scm_instance(self): | |
585 | return self.__get_instance() |
|
603 | return self.__get_instance() | |
586 |
|
604 |
General Comments 0
You need to be logged in to leave comments.
Login now