comparison mercurial/commands.py @ 525:337163e4d4b9

[PATCH] Perform clone in place -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [PATCH] Perform clone in place From: Bryan O'Sullivan <bos@serpentine.com> This is a rewrite of one of my earlier clone cleanup patches. This patch only does one thing - make clone operate in place. It depends on safe-clone.patch. Don't have clone use os.chdir. Instead, do everything in place. manifest hash: cf7cf24f8fa1120b609b0beee4281bc236e484c0 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCwxxJywK+sNU5EO8RAjnlAJ44B1jhFvuYF3uNDH6qWDKaqgURuwCdFeFo Y9tjLx6TLCBWT146h21YEGA= =E1n/ -----END PGP SIGNATURE-----
author mpm@selenic.com
date Wed, 29 Jun 2005 14:10:17 -0800
parents 003df62ae39f
children 55af04e26bad
comparison
equal deleted inserted replaced
524:230676d0df6f 525:337163e4d4b9
267 267
268 def clone(ui, source, dest = None, **opts): 268 def clone(ui, source, dest = None, **opts):
269 """make a copy of an existing repository""" 269 """make a copy of an existing repository"""
270 source = ui.expandpath(source) 270 source = ui.expandpath(source)
271 271
272 success = created = False 272 success = False
273 273
274 if dest is None: 274 if dest is None:
275 dest = os.path.basename(source) 275 dest = os.path.basename(source)
276 if dest == source: 276 if dest == source:
277 ui.warn('abort: source and destination are the same\n') 277 ui.warn('abort: source and destination are the same\n')
278 sys.exit(1) 278 sys.exit(1)
279 279
280 os.mkdir(dest) 280 os.mkdir(dest)
281 281
282 try: 282 try:
283 dest = os.path.realpath(dest)
284
285 link = 0 283 link = 0
286 if not source.startswith("http://"): 284 if not source.startswith("http://"):
287 source = os.path.realpath(source)
288 d1 = os.stat(dest).st_dev 285 d1 = os.stat(dest).st_dev
289 d2 = os.stat(source).st_dev 286 d2 = os.stat(source).st_dev
290 if d1 == d2: link = 1 287 if d1 == d2: link = 1
291 288
292 os.chdir(dest)
293
294 if link: 289 if link:
295 ui.debug("copying by hardlink\n") 290 ui.debug("copying by hardlink\n")
296 util.system("cp -al %s/.hg .hg" % source) 291 util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest))
297 try: 292 try:
298 os.remove(".hg/dirstate") 293 os.remove(os.path.join(dest, ".hg", "dirstate"))
299 except: pass 294 except: pass
300 295
301 repo = hg.repository(ui, ".") 296 repo = hg.repository(ui, dest)
302 297
303 else: 298 else:
304 repo = hg.repository(ui, ".", create=1) 299 repo = hg.repository(ui, dest, create=1)
305 other = hg.repository(ui, source) 300 other = hg.repository(ui, source)
306 fetch = repo.findincoming(other) 301 fetch = repo.findincoming(other)
307 if fetch: 302 if fetch:
308 cg = other.changegroup(fetch) 303 cg = other.changegroup(fetch)
309 repo.addchangegroup(cg) 304 repo.addchangegroup(cg)
316 update(ui, repo) 311 update(ui, repo)
317 312
318 success = True 313 success = True
319 314
320 finally: 315 finally:
321 if created and not success: 316 if not success:
322 import shutil 317 import shutil
323 shutil.rmtree(dest, True) 318 shutil.rmtree(dest, True)
324 319
325 def commit(ui, repo, *files, **opts): 320 def commit(ui, repo, *files, **opts):
326 """commit the specified files or all outstanding changes""" 321 """commit the specified files or all outstanding changes"""