Changeset - 701f0a3f9616
[Not reviewed]
default
0 2 0
Søren Løvborg - 9 years ago 2017-01-02 23:16:32
sorenl@unity3d.com
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.
2 files changed with 8 insertions and 10 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/middleware/simplegit.py
Show inline comments
 
@@ -93,13 +93,13 @@ class SimpleGit(BaseVCSController):
 
        action = self.__get_action(environ)
 

	
 
        #======================================================================
 
        # 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,
 
                                                    repo_name, ip_addr)
 
        else:
 
            anonymous_perm = False
 
@@ -142,13 +142,12 @@ class SimpleGit(BaseVCSController):
 
            # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME
 
            #==============================================================
 
            try:
 
                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)
 

	
 
            #check permissions for this repository
 
            perm = self._check_permission(action, user, repo_name, ip_addr)
 
@@ -158,13 +157,13 @@ class SimpleGit(BaseVCSController):
 
        # extras are injected into UI object and later available
 
        # in hooks executed by kallithea
 
        from kallithea import CONFIG
 
        server_url = get_server_url(environ)
 
        extras = {
 
            'ip': ip_addr,
 
            'username': username,
 
            'username': user.username,
 
            'action': action,
 
            'repository': repo_name,
 
            'scm': 'git',
 
            'config': CONFIG['__file__'],
 
            'server_url': server_url,
 
            'make_lock': None,
 
@@ -175,13 +174,13 @@ class SimpleGit(BaseVCSController):
 
        # GIT REQUEST HANDLING
 
        #===================================================================
 
        repo_path = os.path.join(safe_str(self.basepath),str_repo_name)
 
        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,
 
             locked_by) = self._check_locking_state(
 
                            environ=environ, action=action,
 
                            repo=repo_name, user_id=user.user_id
 
@@ -195,13 +194,13 @@ class SimpleGit(BaseVCSController):
 
        baseui = make_ui('db')
 
        self.__inject_extras(repo_path, baseui, extras)
 

	
 
        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':
 
                result = WSGIResultCloseCallback(result,
 
                    lambda: self._invalidate_cache(repo_name))
 
            return result
kallithea/lib/middleware/simplehg.py
Show inline comments
 
@@ -101,13 +101,13 @@ class SimpleHg(BaseVCSController):
 
            return e(environ, start_response)
 

	
 
        #======================================================================
 
        # 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,
 
                                                    repo_name, ip_addr)
 
        else:
 
            anonymous_perm = False
 
@@ -150,13 +150,12 @@ class SimpleHg(BaseVCSController):
 
            # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME
 
            #==============================================================
 
            try:
 
                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)
 

	
 
            #check permissions for this repository
 
            perm = self._check_permission(action, user, repo_name, ip_addr)
 
@@ -166,13 +165,13 @@ class SimpleHg(BaseVCSController):
 
        # extras are injected into mercurial UI object and later available
 
        # in hg hooks executed by kallithea
 
        from kallithea import CONFIG
 
        server_url = get_server_url(environ)
 
        extras = {
 
            'ip': ip_addr,
 
            'username': username,
 
            'username': user.username,
 
            'action': action,
 
            'repository': repo_name,
 
            'scm': 'hg',
 
            'config': CONFIG['__file__'],
 
            'server_url': server_url,
 
            'make_lock': None,
 
@@ -182,13 +181,13 @@ class SimpleHg(BaseVCSController):
 
        # MERCURIAL REQUEST HANDLING
 
        #======================================================================
 
        repo_path = os.path.join(safe_str(self.basepath), str_repo_name)
 
        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,
 
             locked_by) = self._check_locking_state(
 
                            environ=environ, action=action,
 
                            repo=repo_name, user_id=user.user_id
 
@@ -201,13 +200,13 @@ class SimpleHg(BaseVCSController):
 
        log.debug('HOOKS extras is %s', extras)
 
        baseui = make_ui('db')
 
        self.__inject_extras(repo_path, baseui, extras)
 

	
 
        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':
 
                result = WSGIResultCloseCallback(result,
 
                    lambda: self._invalidate_cache(repo_name))
 
            return result
0 comments (0 inline, 0 general)