# HG changeset patch # User Andrew Shadura # Date 2016-07-12 21:47:14 # Node ID c9f97be1927eef99626d7932d842e9d47d7e39cf # Parent a90f8f33adeb5fc0a54d500c24d0023e5b96bd88 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. diff --git a/kallithea/lib/middleware/pygrack.py b/kallithea/lib/middleware/pygrack.py --- a/kallithea/lib/middleware/pygrack.py +++ b/kallithea/lib/middleware/pygrack.py @@ -86,7 +86,8 @@ class GitRepository(object): :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): """