[PATCH] Add ability to clone from all-history bundles
John Mulligan
phlogistonjohn at asynchrono.us
Sun Mar 9 13:40:15 CDT 2008
Hello dev list, this is my first attempt a a non-trivial patch, so please be
gentle :-)
This patch allows the user to clone from all-history bundles without doing
anything special. The bundles must be local files, there is no support for
remote urls like mentioned in the thread here
[http://www.selenic.com/pipermail/mercurial/2008-February/017330.html].
A bug was also recently created on this same subject too
[http://www.selenic.com/mercurial/bts/issue1024]. This motivated me to attack
this issue again.
# HG changeset patch
# User John Mulligan <phlogistonjohn at asynchrono.us>
# Date 1205087188 14400
# Node ID 1cf834046bdafe39929d57c14f8c677bca14a379
# Parent d2353ed8b153eb38dc804b704aa73b7edd4315bb
Add ability to clone from all-history bundles
- Don't copy a bundle like a normal localrepo on clone
- bundlerepos can be cloned from, 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,
@@ -151,8 +151,14 @@
linkmapper)
class bundlerepository(localrepo.localrepository):
+ _tempparent = None
def __init__(self, ui, path, bundlename):
- localrepo.localrepository.__init__(self, ui, path)
+ try:
+ localrepo.localrepository.__init__(self, ui, path)
+ except repo.RepoError, ee:
+ 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
@@ -254,6 +260,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:
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -148,7 +148,8 @@
abspath = origsource
copy = False
- if src_repo.local() and islocal(dest):
+ bundlesrc = isinstance(src_repo, bundlerepo.bundlerepository)
+ if src_repo.local() and islocal(dest) and not bundlesrc:
abspath = os.path.abspath(util.drop_scheme('file', origsource))
copy = not pull and not rev
-------------------------------------------------------
More information about the Mercurial-devel
mailing list