# HG changeset patch # User Søren Løvborg # Date 1483395392 -3600 # Node ID 701f0a3f9616ebf7ba97a86d354433e6501187d3 # Parent 5b40eb88a46dd1190c9462ac6aec10876dabf97e vcs: remove confusing and unnecessary local variable This removes the "username" local variable, substituting the equivalent "user.username". The function also has another, unrelated use of the same local variable name; this OTHER "username" variable is untouched. The relevant code is duplicated between Hg and Git... and thus also this change. diff -r 5b40eb88a46d -r 701f0a3f9616 kallithea/lib/middleware/simplegit.py --- a/kallithea/lib/middleware/simplegit.py Wed Jan 04 23:05:11 2017 +0100 +++ b/kallithea/lib/middleware/simplegit.py Mon Jan 02 23:16:32 2017 +0100 @@ -96,7 +96,7 @@ # CHECK PERMISSIONS #====================================================================== anonymous_user = User.get_default_user(cache=True) - username = anonymous_user.username + user = anonymous_user if anonymous_user.active: # ONLY check permissions if the user is activated anonymous_perm = self._check_permission(action, anonymous_user, @@ -145,7 +145,6 @@ user = User.get_by_username_or_email(username) if user is None or not user.active: return HTTPForbidden()(environ, start_response) - username = user.username except Exception: log.error(traceback.format_exc()) return HTTPInternalServerError()(environ, start_response) @@ -161,7 +160,7 @@ server_url = get_server_url(environ) extras = { 'ip': ip_addr, - 'username': username, + 'username': user.username, 'action': action, 'repository': repo_name, 'scm': 'git', @@ -178,7 +177,7 @@ log.debug('Repository path is %s', repo_path) # CHECK LOCKING only if it's not ANONYMOUS USER - if username != User.DEFAULT_USER: + if user.username != User.DEFAULT_USER: log.debug('Checking locking on repository') (make_lock, locked, @@ -198,7 +197,7 @@ try: self._handle_githooks(repo_name, action, baseui, environ) log.info('%s action on Git repo "%s" by "%s" from %s', - action, str_repo_name, safe_str(username), ip_addr) + action, str_repo_name, safe_str(user.username), ip_addr) app = self.__make_app(repo_name, repo_path, extras) result = app(environ, start_response) if action == 'push': diff -r 5b40eb88a46d -r 701f0a3f9616 kallithea/lib/middleware/simplehg.py --- a/kallithea/lib/middleware/simplehg.py Wed Jan 04 23:05:11 2017 +0100 +++ b/kallithea/lib/middleware/simplehg.py Mon Jan 02 23:16:32 2017 +0100 @@ -104,7 +104,7 @@ # CHECK PERMISSIONS #====================================================================== anonymous_user = User.get_default_user(cache=True) - username = anonymous_user.username + user = anonymous_user if anonymous_user.active: # ONLY check permissions if the user is activated anonymous_perm = self._check_permission(action, anonymous_user, @@ -153,7 +153,6 @@ user = User.get_by_username_or_email(username) if user is None or not user.active: return HTTPForbidden()(environ, start_response) - username = user.username except Exception: log.error(traceback.format_exc()) return HTTPInternalServerError()(environ, start_response) @@ -169,7 +168,7 @@ server_url = get_server_url(environ) extras = { 'ip': ip_addr, - 'username': username, + 'username': user.username, 'action': action, 'repository': repo_name, 'scm': 'hg', @@ -185,7 +184,7 @@ log.debug('Repository path is %s', repo_path) # CHECK LOCKING only if it's not ANONYMOUS USER - if username != User.DEFAULT_USER: + if user.username != User.DEFAULT_USER: log.debug('Checking locking on repository') (make_lock, locked, @@ -204,7 +203,7 @@ try: log.info('%s action on Mercurial repo "%s" by "%s" from %s', - action, str_repo_name, safe_str(username), ip_addr) + action, str_repo_name, safe_str(user.username), ip_addr) app = self.__make_app(repo_path, baseui, extras) result = app(environ, start_response) if action == 'push':