def getResourceInst(self, path, environ): """Return HgResource object for path. See DAVProvider.getResourceInst() """ self._count_getResourceInst += 1 # HG expects the resource paths without leading '/' localHgPath = path.strip("/") rev = None cmd, rest = util.popPath(path) if cmd == "": return VirtualCollection(path, environ, "root", ["edit", "released", "archive"]) elif cmd == "edit": localHgPath = rest.strip("/") rev = None elif cmd == "released": localHgPath = rest.strip("/") rev = "tip" elif cmd == "archive": if rest == "/": # Browse /archive: return a list of revision folders: loglist = self._getLog(limit=10) members = [ str(l["local_id"]) for l in loglist ] return VirtualCollection(path, environ, "Revisions", members) revid, rest = util.popPath(rest) try: int(revid) except: # Tried to access /archive/anyname return None # Access /archive/19 rev = revid localHgPath = rest.strip("/") else: return None # read mercurial repo into request cache cache = self._getRepoInfo(environ, rev) if localHgPath in cache["filedict"]: # It is a version controlled file return HgResource(path, False, environ, rev, localHgPath) if localHgPath in cache["dirinfos"] or localHgPath == "": # It is an existing folder return HgResource(path, True, environ, rev, localHgPath) return None
def handleMove(self, destPath): """Handle a MOVE request natively. """ destType, destHgPath = util.popPath(destPath) destHgPath = destHgPath.strip("/") ui = self.provider.ui repo = self.provider.repo util.write("handleCopy %s -> %s" % (self.localHgPath, destHgPath)) if self.rev is None and destType == "edit": # MOVE /edit/a/b to /edit/c/d: turn into 'hg rename -f a/b c/d' commands.rename(ui, repo, self.localHgPath, destHgPath, force=True) elif self.rev is None and destType == "released": # MOVE /edit/a/b to /released/c/d # This is interpreted as 'hg commit a/b' (ignoring the dest. path) self._commit("WsgiDAV commit (MOVE %s -> %s)" % (self.path, destPath)) else: raise DAVError(HTTP_FORBIDDEN) # Return True: request was handled return True
def handleCopy(self, destPath, depthInfinity): """Handle a COPY request natively. """ destType, destHgPath = util.popPath(destPath) destHgPath = destHgPath.strip("/") ui = self.provider.ui repo = self.provider.repo _logger.info("handleCopy %s -> %s" % (self.localHgPath, destHgPath)) if self.rev is None and destType == "edit": # COPY /edit/a/b to /edit/c/d: turn into 'hg copy -f a/b c/d' commands.copy(ui, repo, self.localHgPath, destHgPath, force=True) elif self.rev is None and destType == "released": # COPY /edit/a/b to /released/c/d # This is interpreted as 'hg commit a/b' (ignoring the dest. path) self._commit("WsgiDAV commit (COPY %s -> %s)" % (self.path, destPath)) else: raise DAVError(HTTP_FORBIDDEN) # Return True: request was handled return True
def testBasics(self): """Test basic tool functions.""" assert joinUri("/a/b", "c") == "/a/b/c" assert joinUri("/a/b/", "c") == "/a/b/c" assert joinUri("/a/b", "c", "d") == "/a/b/c/d" assert joinUri("a/b", "c", "d") == "a/b/c/d" assert joinUri("/", "c") == "/c" assert joinUri("", "c") == "/c" assert not isChildUri("/a/b", "/a/") assert not isChildUri("/a/b", "/a/b") assert not isChildUri("/a/b", "/a/b/") assert not isChildUri("/a/b", "/a/bc") assert not isChildUri("/a/b", "/a/bc/") assert isChildUri("/a/b", "/a/b/c") assert isChildUri("/a/b", "/a/b/c") assert not isEqualOrChildUri("/a/b", "/a/") assert isEqualOrChildUri("/a/b", "/a/b") assert isEqualOrChildUri("/a/b", "/a/b/") assert not isEqualOrChildUri("/a/b", "/a/bc") assert not isEqualOrChildUri("/a/b", "/a/bc/") assert isEqualOrChildUri("/a/b", "/a/b/c") assert isEqualOrChildUri("/a/b", "/a/b/c") assert lstripstr("/dav/a/b", "/dav") == "/a/b" assert lstripstr("/dav/a/b", "/DAV") == "/dav/a/b" assert lstripstr("/dav/a/b", "/DAV", True) == "/a/b" assert popPath("/a/b/c") == ("a", "/b/c") assert popPath("/a/b/") == ("a", "/b/") assert popPath("/a/") == ("a", "/") assert popPath("/a") == ("a", "/") assert popPath("/") == ("", "") assert popPath("") == ("", "") self.assertEqual(shiftPath("", "/a/b/c"), ("a", "/a", "/b/c")) self.assertEqual(shiftPath("/a", "/b/c"), ("b", "/a/b", "/c")) self.assertEqual(shiftPath("/a/b", "/c"), ("c", "/a/b/c", "")) self.assertEqual(shiftPath("/a/b/c", "/"), ("", "/a/b/c", "")) self.assertEqual(shiftPath("/a/b/c", ""), ("", "/a/b/c", ""))