From d84ac920943e07b4dd78b8ee446f23de6859a1fe Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Wed, 6 Jun 2007 20:41:50 +0000 Subject: Frontported fixes in mirror support from repsys-1.6 - fixed bad URLs being used when checking out from mirrors - "switch" subcommand to ease switching between mirror and real repositories - smarter "ci" --- RepSys/mirror.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) (limited to 'RepSys/mirror.py') diff --git a/RepSys/mirror.py b/RepSys/mirror.py index a24f594..7a0bc4e 100644 --- a/RepSys/mirror.py +++ b/RepSys/mirror.py @@ -4,21 +4,51 @@ import urlparse from RepSys import config from RepSys.svn import SVN +def _normdirurl(url): + """normalize url for relocate_path needs""" + parsed = urlparse.urlparse(url) + path = os.path.normpath(parsed.path) + path += "/" # assuming we always deal with directories + newurl = urlparse.urlunparse((parsed.scheme, parsed.netloc, path, + parsed.params, parsed.query, parsed.fragment)) + return newurl + +def _joinurl(url, relpath): + parsed = urlparse.urlparse(url) + newpath = os.path.join(parsed.path, relpath) + newurl = urlparse.urlunparse((parsed.scheme, parsed.netloc, newpath, + parsed.params, parsed.query, parsed.fragment)) + return newurl + +def same_base(parent, url): + """returns true if parent is parent of url""" + parent = _normdirurl(parent) + url = _normdirurl(url) + #FIXME handle paths with/without username/password + return url.startswith(parent) + def relocate_path(oldparent, newparent, url): - subpath = url[len(oldparent)-1:] - newurl = newparent + "/" + subpath # subpath usually gets / at begining + oldparent = _normdirurl(oldparent) + newparent = _normdirurl(newparent) + url = _normdirurl(url) + subpath = url[len(oldparent):] + newurl = _joinurl(newparent, subpath) # subpath usually gets / at begining return newurl -def enabled(): +def enabled(wcurl=None): mirror = config.get("global", "mirror") default_parent = config.get("global", "default_parent") - return (mirror is not None and - default_parent is not None) + enabled = False + if mirror and default_parent: + enabled = True + if wcurl and (not same_base(mirror, wcurl)): + enabled = False + return enabled def mirror_relocate(oldparent, newparent, url, wcpath): - svn = SVN(noauth=True) + svn = SVN() newurl = relocate_path(oldparent, newparent, url) - svn.switch(newurl, url, path=wcpath, relocate="True") + svn.relocate(url, newurl, wcpath) return newurl def switchto_parent(svn, url, path): @@ -40,3 +70,39 @@ def checkout_url(url): if mirror is not None and default_parent is not None: return relocate_path(default_parent, mirror, url) return url + +def autoswitch(svn, wcpath, wcurl, newbaseurl=None): + """Switches between mirror, default_parent, or newbaseurl""" + nobase = False + mirror = config.get("global", "mirror") + default_parent = config.get("global", "default_parent") + current = default_parent + if default_parent is None: + raise Error, "the option default_parent from repsys.conf is "\ + "required" + indefault = same_base(default_parent, wcurl) + if not newbaseurl: + if not mirror: + raise Error, "an URL is needed when the option mirror "\ + "from repsys.conf is not set" + if indefault: + chosen = mirror + elif same_base(mirror, wcurl): + current = mirror + chosen = default_parent + else: + nobase = True + else: + if mirror and same_base(mirror, wcurl): + current = mirror + elif indefault: + pass # !!!! + else: + nobase = True + chosen = newbaseurl + if nobase: + raise Error, "the URL of this working copy is not based in "\ + "default_parent nor mirror URLs" + assert current != chosen + newurl = mirror_relocate(current, chosen, wcurl, wcpath) + return newurl -- cgit v1.2.1