Source

distribute / setuptools / package_index.py

The branch 'default' does not exist.
Diff from to

setuptools/package_index.py

         os.system("svn checkout -q %s %s" % (url, filename))
         return filename
 
+    def _vcs_split_rev_from_url(self, url, pop_prefix=False):
+        scheme, netloc, path, query, frag = urlparse.urlsplit(url)
+
+        scheme = scheme.split('+', 1)[-1]
+
+        # Some fragment identification fails
+        path = path.split('#',1)[0]
+
+        rev = None
+        if '@' in path:
+            path, rev = path.rsplit('@', 1)
+
+        # Also, discard fragment
+        url = urlparse.urlunsplit((scheme, netloc, path, query, ''))
+
+        return url, rev
+
     def _download_git(self, url, filename):
-        if url.startswith('git+'):
-            url = url[4:]
-        url = url.split('#',1)[0]   # remove any fragment for svn's sake
-        filename = filename.split('#',1)[0]   # remove any fragment to get a decent name.
+        filename = filename.split('#',1)[0]
+        url, rev = self._vcs_split_rev_from_url(url, pop_prefix=True)
+
         self.info("Doing git clone from %s to %s", url, filename)
-        os.system("git clone -q %s %s" % (url, filename))
+        os.system("git clone --quiet %s %s" % (url, filename))
+
+        if rev is not None:
+            self.info("Checking out %s", rev)
+            os.system("(cd %s && git checkout --quiet %s)" % (
+                filename,
+                rev,
+            ))
+
         return filename
 
     def _download_hg(self, url, filename):
-        if url.startswith('hg+'):
-            url = url[3:]
-        url = url.split('#',1)[0]   # remove any fragment for svn's sake
-        filename = filename.split('#',1)[0]   # remove any fragment to get a decent name.
+        filename = filename.split('#',1)[0]
+        url, rev = self._vcs_split_rev_from_url(url, pop_prefix=True)
+
         self.info("Doing hg clone from %s to %s", url, filename)
         os.system("hg clone --quiet %s %s" % (url, filename))
+
+        if rev is not None:
+            self.info("Updating to %s", rev)
+            os.system("(cd %s && hg up -C -r %s >&-)" % (
+                filename,
+                rev,
+            ))
+
         return filename
 
     def debug(self, msg, *args):