[PATCH 2 of 3] Add ability to directly clone from all-history bundles

John Mulligan phlogistonjohn at asynchrono.us
Sat Mar 15 11:34:52 CDT 2008


# HG changeset patch
# User John Mulligan <phlogistonjohn at asynchrono.us>
# Date 1205597068 14400
# Node ID c34ecd6ab6df54b86d1ed4bcb1c83fc3270d6a37
# Parent  ee80fcb9d96fd9aa9cb2c1e7a0031da4eaccf267
Add ability to directly clone from all-history bundles
bundlerepos can be used as clone src, even if CWD is not a repo

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -12,8 +12,8 @@
 
 from node import hex, nullid, short
 from i18n import _
-import changegroup, util, os, struct, bz2, tempfile, mdiff
-import localrepo, changelog, manifest, filelog, revlog
+import changegroup, util, os, struct, bz2, tempfile, shutil, mdiff
+import repo, localrepo, changelog, manifest, filelog, revlog
 
 class bundlerevlog(revlog.revlog):
     def __init__(self, opener, indexfile, bundlefile,
@@ -153,7 +153,13 @@
 
 class bundlerepository(localrepo.localrepository):
     def __init__(self, ui, path, bundlename):
-        localrepo.localrepository.__init__(self, ui, path)
+        self._tempparent = None
+        try:
+            localrepo.localrepository.__init__(self, ui, path)
+        except repo.RepoError:
+            self._tempparent = tempfile.mkdtemp()
+            tmprepo = localrepo.instance(ui,self._tempparent,1)
+            localrepo.localrepository.__init__(self, ui, self._tempparent)
 
         if path:
             self._url = 'bundle:' + path + '+' + bundlename
@@ -258,6 +264,8 @@
         tempfile = getattr(self, 'tempfile', None)
         if tempfile is not None:
             os.unlink(tempfile)
+        if self._tempparent:
+            shutil.rmtree(self._tempparent, True)
 
 def instance(ui, path, create):
     if create:


More information about the Mercurial-devel mailing list