changeset 8074:fc78313cba53

convert: Improved svn source detection.
author Augie Fackler <durin42@gmail.com>
date Sat, 04 Apr 2009 20:19:51 -0500
parents e8a28556a0a8
children 2a4a71b15e95
files hgext/convert/subversion.py
diffstat 1 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/subversion.py	Thu Apr 16 15:34:03 2009 +0200
+++ b/hgext/convert/subversion.py	Sat Apr 04 20:19:51 2009 -0500
@@ -134,6 +134,38 @@
             self._stdout.close()
             self._stdout = None
 
+
+# Check to see if the given path is a local Subversion repo. Verify this by
+# looking for several svn-specific files and directories in the given
+# directory.
+def filecheck(path, proto):
+    for x in ('locks', 'hooks', 'format', 'db', ):
+        if not os.path.exists(os.path.join(path, x)):
+            return False
+    return True
+
+# Check to see if a given path is the root of an svn repo over http. We verify
+# this by requesting a version-controlled URL we know can't exist and looking
+# for the svn-specific "not found" XML.
+def httpcheck(path, proto):
+   return ('<m:human-readable errcode="160013">' in
+           urllib.urlopen('%s://%s/!svn/ver/0/.svn' % (proto, path)).read())
+
+protomap = {'http': httpcheck,
+            'https': httpcheck,
+            'file': filecheck,
+            }
+def issvnurl(url):
+    if not '://' in url:
+        return False
+    proto, path = url.split('://', 1)
+    check = protomap.get(proto, lambda p, p2: False)
+    while '/' in path:
+        if check(path, proto):
+            return True
+        path = path.rsplit('/', 1)[0]
+    return False
+
 # SVN conversion code stolen from bzr-svn and tailor
 #
 # Subversion looks like a versioned filesystem, branches structures
@@ -155,7 +187,7 @@
         if not (url.startswith('svn://') or url.startswith('svn+ssh://') or
                 (os.path.exists(url) and
                  os.path.exists(os.path.join(url, '.svn'))) or
-                 (url.startswith('file://'))):
+                issvnurl(url)):
             raise NoRepo("%s does not look like a Subversion repo" % url)
 
         try: