Commits

Marcin Kuzminski committed 66f03a8

Fixes issue #201
Fixed bug when repository was deleted on filesystem, and not from rhodecode

  • Participants
  • Parent commits fced987
  • Branches beta

Comments (0)

Files changed (7)

rhodecode/controllers/summary.py

     def index(self, repo_name):
 
         e = request.environ
-        c.dbrepo = dbrepo = Repository.by_repo_name(repo_name)
+        c.dbrepo = dbrepo = c.rhodecode_db_repo
 
         c.following = self.scm_model.is_following_repo(repo_name,
                                                 self.rhodecode_user.user_id)

rhodecode/lib/__init__.py

     return _str in ('t', 'true', 'y', 'yes', 'on', '1')
 
 
-def convert_line_endings(temp, mode):
+def convert_line_endings(line, mode):
+    """
+    Converts a given line  "line end" accordingly to given mode
+    
+    Available modes are::
+        0 - Unix
+        1 - Mac
+        2 - DOS
+    
+    :param line: given line to convert
+    :param mode: mode to convert to
+    :rtype: str
+    :return: converted line according to mode
+    """
     from string import replace
-    #modes:  0 - Unix, 1 - Mac, 2 - DOS
+
     if mode == 0:
-            temp = replace(temp, '\r\n', '\n')
-            temp = replace(temp, '\r', '\n')
+            line = replace(line, '\r\n', '\n')
+            line = replace(line, '\r', '\n')
     elif mode == 1:
-            temp = replace(temp, '\r\n', '\r')
-            temp = replace(temp, '\n', '\r')
+            line = replace(line, '\r\n', '\r')
+            line = replace(line, '\n', '\r')
     elif mode == 2:
             import re
-            temp = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", temp)
-    return temp
+            line = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", line)
+    return line
 
 
 def detect_mode(line, default):
     return _(u'just now')
 
 
-def credentials_hidder(uri):
+def uri_filter(uri):
     """
     Removes user:password from given url string
     
     :param uri:
     :rtype: unicode
-    :returns: filtered list of strings    
+    :returns: filtered list of strings  
     """
     if not uri:
         return ''
         host, port = uri[:cred_pos], uri[cred_pos + 1:]
 
     return filter(None, [proto, host, port])
+
+
+def credentials_filter(uri):
+    """
+    Returns a url with removed credentials
+    
+    :param uri:
+    """
+
+    uri = uri_filter(uri)
+    #check if we have port
+    if len(uri) > 2 and uri[2]:
+        uri[2] = ':' + uri[2]
+
+    return ''.join(uri)
+

rhodecode/lib/base.py

 
 Provides the BaseController class for subclassing.
 """
-from pylons import config, tmpl_context as c, request, session
+import logging
+
+from pylons import config, tmpl_context as c, request, session, url
 from pylons.controllers import WSGIController
+from pylons.controllers.util import redirect
 from pylons.templating import render_mako as render
 
 from rhodecode import __version__
 from rhodecode import BACKENDS
 from rhodecode.model.db import Repository
 
+log = logging.getLogger(__name__)
 
 class BaseController(WSGIController):
 
         super(BaseRepoController, self).__before__()
         if c.repo_name:
 
-            c.rhodecode_repo = Repository.by_repo_name(c.repo_name).scm_instance
+            c.rhodecode_db_repo = Repository.by_repo_name(c.repo_name)
+            c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
 
-            if c.rhodecode_repo is not None:
-                c.repository_followers = \
-                    self.scm_model.get_followers(c.repo_name)
-                c.repository_forks = self.scm_model.get_forks(c.repo_name)
-            else:
-                c.repository_followers = 0
-                c.repository_forks = 0
+            if c.rhodecode_repo is None:
+                log.error('%s this repository is present in database but it '
+                          'cannot be created as an scm instance', c.repo_name)
 
+                redirect(url('home'))
+
+            c.repository_followers = \
+                self.scm_model.get_followers(c.repo_name)
+            c.repository_forks = self.scm_model.get_forks(c.repo_name)
+

rhodecode/lib/helpers.py

 # SCM FILTERS available via h.
 #==============================================================================
 from vcs.utils import author_name, author_email
-from rhodecode.lib import credentials_hidder, age as _age
+from rhodecode.lib import credentials_filter, age as _age
 
 age = lambda  x:_age(x)
 capitalize = lambda x: x.capitalize()
 email_or_none = lambda x: email(x) if email(x) != x else None
 person = lambda x: author_name(x)
 short_id = lambda x: x[:12]
-hide_credentials = lambda x: ''.join(credentials_hidder(x))
+hide_credentials = lambda x: ''.join(credentials_filter(x))
 
 def bool2icon(value):
     """Returns True/False values represented as small html image of true/false

rhodecode/model/scm.py

                 continue
 
 
-
+            if not scmr:
+                log.error('%s this repository is present in database but it '
+                          'cannot be created as an scm instance',
+                          dbr.repo_name)
+                continue
 
 
             last_change = scmr.last_change

rhodecode/tests/test_models.py

+import unittest
+from rhodecode.tests import *
 #########################################################
 ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG    ###
 #########################################################
-#sqlalchemy.db1.url = sqlite:///%(here)s/test.db
-sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode_tests
+sqlalchemy.db1.url = sqlite:///%(here)s/test.db
+#sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode_tests
 #sqlalchemy.db1.echo = False
 #sqlalchemy.db1.pool_recycle = 3600
 sqlalchemy.convert_unicode = true
 qualname = routes.middleware
 # "level = DEBUG" logs the route matched and routing variables.
 
+[logger_beaker]
+level = DEBUG
+handlers = 
+qualname = beaker.container
+propagate = 1
+
+[logger_templates]
+level = INFO
+handlers = 
+qualname = pylons.templating
+propagate = 1
+
 [logger_rhodecode]
 level = ERROR
 handlers = console