Commits

Marcin Kuzminski committed faaadfc

fixed condition evaluated for gitrepo that returned null, simplified scm functions

Comments (0)

Files changed (2)

rhodecode/lib/base.py

 
             c.rhodecode_repo, dbrepo = self.scm_model.get(c.repo_name,
                                                           retval='repo')
-            if c.rhodecode_repo:
+
+            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:

rhodecode/model/scm.py

         return f is not None
 
     def get_followers(self, repo_id):
-        if isinstance(repo_id, int):
-            return self.sa.query(UserFollowing)\
-                    .filter(UserFollowing.follows_repo_id == repo_id).count()
-        else:
-            return self.sa.query(UserFollowing)\
-                    .filter(UserFollowing.follows_repository \
-                            == RepoModel().get_by_repo_name(repo_id)).count()
+        if not isinstance(repo_id, int):
+            repo_id = getattr(Repository.by_repo_name(repo_id), 'repo_id')
+
+        return self.sa.query(UserFollowing)\
+                .filter(UserFollowing.follows_repo_id == repo_id).count()
 
     def get_forks(self, repo_id):
-        if isinstance(repo_id, int):
-            return self.sa.query(Repository)\
+        if not isinstance(repo_id, int):
+            repo_id = getattr(Repository.by_repo_name(repo_id), 'repo_id')
+
+        return self.sa.query(Repository)\
                 .filter(Repository.fork_id == repo_id).count()
-        else:
-            return self.sa.query(Repository)\
-                .filter(Repository.fork \
-                        == RepoModel().get_by_repo_name(repo_id)).count()
 
     def pull_changes(self, repo_name, username):
         repo, dbrepo = self.get(repo_name, retval='all')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.