--- a/mercurial/hg.py Sat Jul 21 16:02:09 2007 -0500
+++ b/mercurial/hg.py Sat Jul 21 16:02:10 2007 -0500
@@ -130,103 +130,99 @@
if self.dir_:
self.rmtree(self.dir_, True)
- dir_cleanup = None
- if islocal(dest):
- dir_cleanup = DirCleanup(dest)
+ src_lock = dest_lock = dir_cleanup = None
+ try:
+ if islocal(dest):
+ dir_cleanup = DirCleanup(dest)
- abspath = origsource
- copy = False
- if src_repo.local() and islocal(dest):
- abspath = os.path.abspath(origsource)
- copy = not pull and not rev
+ abspath = origsource
+ copy = False
+ if src_repo.local() and islocal(dest):
+ abspath = os.path.abspath(origsource)
+ copy = not pull and not rev
- src_lock, dest_lock = None, None
- if copy:
- try:
- # we use a lock here because if we race with commit, we
- # can end up with extra data in the cloned revlogs that's
- # not pointed to by changesets, thus causing verify to
- # fail
- src_lock = src_repo.lock()
- except lock.LockException:
- copy = False
+ if copy:
+ try:
+ # we use a lock here because if we race with commit, we
+ # can end up with extra data in the cloned revlogs that's
+ # not pointed to by changesets, thus causing verify to
+ # fail
+ src_lock = src_repo.lock()
+ except lock.LockException:
+ copy = False
- if copy:
- def force_copy(src, dst):
- try:
- util.copyfiles(src, dst)
- except OSError, inst:
- if inst.errno != errno.ENOENT:
- raise
+ if copy:
+ def force_copy(src, dst):
+ try:
+ util.copyfiles(src, dst)
+ except OSError, inst:
+ if inst.errno != errno.ENOENT:
+ raise
- src_store = os.path.realpath(src_repo.spath)
- if not os.path.exists(dest):
- os.mkdir(dest)
- dest_path = os.path.realpath(os.path.join(dest, ".hg"))
- os.mkdir(dest_path)
- if src_repo.spath != src_repo.path:
- dest_store = os.path.join(dest_path, "store")
- os.mkdir(dest_store)
- else:
- dest_store = dest_path
- # copy the requires file
- force_copy(src_repo.join("requires"),
- os.path.join(dest_path, "requires"))
- # we lock here to avoid premature writing to the target
- dest_lock = lock.lock(os.path.join(dest_store, "lock"))
+ src_store = os.path.realpath(src_repo.spath)
+ if not os.path.exists(dest):
+ os.mkdir(dest)
+ dest_path = os.path.realpath(os.path.join(dest, ".hg"))
+ os.mkdir(dest_path)
+ if src_repo.spath != src_repo.path:
+ dest_store = os.path.join(dest_path, "store")
+ os.mkdir(dest_store)
+ else:
+ dest_store = dest_path
+ # copy the requires file
+ force_copy(src_repo.join("requires"),
+ os.path.join(dest_path, "requires"))
+ # we lock here to avoid premature writing to the target
+ dest_lock = lock.lock(os.path.join(dest_store, "lock"))
- files = ("data",
- "00manifest.d", "00manifest.i",
- "00changelog.d", "00changelog.i")
- for f in files:
- src = os.path.join(src_store, f)
- dst = os.path.join(dest_store, f)
- force_copy(src, dst)
+ files = ("data",
+ "00manifest.d", "00manifest.i",
+ "00changelog.d", "00changelog.i")
+ for f in files:
+ src = os.path.join(src_store, f)
+ dst = os.path.join(dest_store, f)
+ force_copy(src, dst)
+
+ # we need to re-init the repo after manually copying the data
+ # into it
+ dest_repo = repository(ui, dest)
+
+ else:
+ dest_repo = repository(ui, dest, create=True)
- # we need to re-init the repo after manually copying the data
- # into it
- dest_repo = repository(ui, dest)
-
- else:
- dest_repo = repository(ui, dest, create=True)
+ revs = None
+ if rev:
+ if 'lookup' not in src_repo.capabilities:
+ raise util.Abort(_("src repository does not support revision "
+ "lookup and so doesn't support clone by "
+ "revision"))
+ revs = [src_repo.lookup(r) for r in rev]
- revs = None
- if rev:
- if 'lookup' not in src_repo.capabilities:
- raise util.Abort(_("src repository does not support revision "
- "lookup and so doesn't support clone by "
- "revision"))
- revs = [src_repo.lookup(r) for r in rev]
+ if dest_repo.local():
+ dest_repo.clone(src_repo, heads=revs, stream=stream)
+ elif src_repo.local():
+ src_repo.push(dest_repo, revs=revs)
+ else:
+ raise util.Abort(_("clone from remote to remote not supported"))
if dest_repo.local():
- dest_repo.clone(src_repo, heads=revs, stream=stream)
- elif src_repo.local():
- src_repo.push(dest_repo, revs=revs)
- else:
- raise util.Abort(_("clone from remote to remote not supported"))
-
- if src_lock:
- src_lock.release()
+ fp = dest_repo.opener("hgrc", "w", text=True)
+ fp.write("[paths]\n")
+ fp.write("default = %s\n" % abspath)
+ fp.close()
- if dest_repo.local():
- fp = dest_repo.opener("hgrc", "w", text=True)
- fp.write("[paths]\n")
- fp.write("default = %s\n" % abspath)
- fp.close()
-
- if dest_lock:
- dest_lock.release()
+ if update:
+ try:
+ checkout = dest_repo.lookup("default")
+ except:
+ checkout = dest_repo.changelog.tip()
+ _update(dest_repo, checkout)
+ if dir_cleanup:
+ dir_cleanup.close()
- if update:
- try:
- checkout = dest_repo.lookup("default")
- except:
- checkout = dest_repo.changelog.tip()
- _update(dest_repo, checkout)
- if dir_cleanup:
- dir_cleanup.close()
-
- return src_repo, dest_repo
+ return src_repo, dest_repo
+ finally:
+ del src_lock, dest_lock, dir_cleanup
def _showstats(repo, stats):
stats = ((stats[0], _("updated")),