# HG changeset patch # User Mads Kiilerich # Date 1491531698 -7200 # Node ID 8eda7bc543cd1aed3ebb05305a74e862807481bb # Parent 72db2cd3e99e8404fedb7180fb165c799643fe37 lib: move special Mercurial HTTP listkey exception out of _check_locking_state Prepare for use with SSH. diff -r 72db2cd3e99e -r 8eda7bc543cd kallithea/lib/base.py --- 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 diff -r 72db2cd3e99e -r 8eda7bc543cd kallithea/lib/middleware/simplegit.py --- 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}) diff -r 72db2cd3e99e -r 8eda7bc543cd kallithea/lib/middleware/simplehg.py --- 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})