changeset 6580:8eda7bc543cd

lib: move special Mercurial HTTP listkey exception out of _check_locking_state Prepare for use with SSH.
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 07 Apr 2017 04:21:38 +0200
parents 72db2cd3e99e
children 2d0de5aa95d1
files kallithea/lib/base.py kallithea/lib/middleware/simplegit.py kallithea/lib/middleware/simplehg.py
diffstat 3 files changed, 10 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/base.py	Fri Apr 07 04:21:32 2017 +0200
+++ b/kallithea/lib/base.py	Fri Apr 07 04:21:38 2017 +0200
@@ -324,7 +324,7 @@
     def _get_ip_addr(self, environ):
         return _get_ip_addr(environ)
 
-    def _check_locking_state(self, environ, action, repo, user_id):
+    def _check_locking_state(self, action, repo, user_id):
         """
         Checks locking on this repository, if locking is enabled, and if lock
         is present. Returns a tuple of make_lock, locked, locked_by. make_lock
@@ -337,13 +337,8 @@
         repo = Repository.get_by_repo_name(repo)
         user = User.get(user_id)
 
-        # this is kind of hacky, but due to how mercurial handles client-server
-        # server see all operation on changeset; bookmarks, phases and
-        # obsolescence marker in different transaction, we don't want to check
-        # locking on those
-        obsolete_call = environ['QUERY_STRING'] in ['cmd=listkeys',]
         locked_by = repo.locked
-        if repo and repo.enable_locking and not obsolete_call:
+        if repo and repo.enable_locking:
             if action == 'push':
                 # Check if repo already is locked !, if it is compare users
                 user_id, _date = locked_by
--- a/kallithea/lib/middleware/simplegit.py	Fri Apr 07 04:21:32 2017 +0200
+++ b/kallithea/lib/middleware/simplegit.py	Fri Apr 07 04:21:38 2017 +0200
@@ -126,10 +126,7 @@
             log.debug('Checking locking on repository')
             (make_lock,
              locked,
-             locked_by) = self._check_locking_state(
-                            environ=environ, action=action,
-                            repo=repo_name, user_id=user.user_id
-                       )
+             locked_by) = self._check_locking_state(action, repo_name, user.user_id)
             # store the make_lock for later evaluation in hooks
             extras.update({'make_lock': make_lock,
                            'locked_by': locked_by})
--- a/kallithea/lib/middleware/simplehg.py	Fri Apr 07 04:21:32 2017 +0200
+++ b/kallithea/lib/middleware/simplehg.py	Fri Apr 07 04:21:38 2017 +0200
@@ -126,15 +126,17 @@
         repo_path = os.path.join(safe_str(self.basepath), str_repo_name)
         log.debug('Repository path is %s', repo_path)
 
+        # A Mercurial HTTP server will see listkeys operations (bookmarks,
+        # phases and obsolescence marker) in a different request - we don't
+        # want to check locking on those
+        if environ['QUERY_STRING'] == 'cmd=listkeys':
+            pass
         # CHECK LOCKING only if it's not ANONYMOUS USER
-        if not user.is_default_user:
+        elif not user.is_default_user:
             log.debug('Checking locking on repository')
             (make_lock,
              locked,
-             locked_by) = self._check_locking_state(
-                            environ=environ, action=action,
-                            repo=repo_name, user_id=user.user_id
-                       )
+             locked_by) = self._check_locking_state(action, repo_name, user.user_id)
             # store the make_lock for later evaluation in hooks
             extras.update({'make_lock': make_lock,
                            'locked_by': locked_by})