Changeset - c9f97be1927e
[Not reviewed]
default
0 1 0
Andrew Shadura - 9 years ago 2016-07-12 21:47:14
andrew@shadura.me
pygrack: refactor _get_fixedpath

This function strips the repository name and any slashes from the
URL path, leaving the protocol command, like info/refs or
git-{receive,upload}-pack.

Using .split() and .strip() for this purpose isn't entirely reliable
and is entirely unreadable, so it's better to write it out, even if
it's a bit verbose.

Also, error out in the unlikely case the path doesn't start with
a slash and the repository name; that shouldn't happen normally.
1 file changed with 2 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/middleware/pygrack.py
Show inline comments
 
@@ -77,25 +77,26 @@ class GitRepository(object):
 
        self.content_path = content_path
 
        self.valid_accepts = ['application/x-%s-result' %
 
                              c for c in self.commands]
 
        self.repo_name = repo_name
 
        self.extras = extras
 

	
 
    def _get_fixedpath(self, path):
 
        """
 
        Small fix for repo_path
 

	
 
        :param path:
 
        """
 
        return path.split(self.repo_name, 1)[-1].strip('/')
 
        assert path.startswith('/' + self.repo_name + '/')
 
        return path[len(self.repo_name) + 2:].strip('/')
 

	
 
    def inforefs(self, request, environ):
 
        """
 
        WSGI Response producer for HTTP GET Git Smart
 
        HTTP /info/refs request.
 
        """
 

	
 
        git_command = request.GET.get('service')
 
        if git_command not in self.commands:
 
            log.debug('command %s not allowed', git_command)
 
            return exc.HTTPMethodNotAllowed()
 

	
0 comments (0 inline, 0 general)