+url = require('url')
+
 # Captures the tree and repo path from a request path
 treePathRegexp = /^([^\/]+)\/(.+)$/
 

  @path = null

  constructor: (config, nodeReq) ->
    # Find the repo we're requesting
    for httpRoot, repo of config.repos
      # Don't do this in the regexp because escaping is annoying
      if nodeReq.url.indexOf(httpRoot) == 0
        @repo = repo
        @httpRoot = httpRoot
        break

      return

    # Parse the remaining URL components
    decodedPath = decodeURIComponent(fullPath[(@httpRoot.length)..])
    treeAndPath = treePathRegexp.exec(decodedPath)

    [unused, @tree, @path] = treeAndPath if treeAndPath

