Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 634:da5378d39269
Add a repo method to report repo device
This is used to establish whether repos are on the same device for
hard linking. Remote repos all return -1.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 06 Jul 2005 22:14:10 -0800 |
parents | 8b8f710bb658 |
children | 85e2209d401c |
comparison
equal
deleted
inserted
replaced
633:f597539c7abd | 634:da5378d39269 |
---|---|
360 fp = sys.stdout | 360 fp = sys.stdout |
361 fp.write(r.read(n)) | 361 fp.write(r.read(n)) |
362 | 362 |
363 def clone(ui, source, dest = None, **opts): | 363 def clone(ui, source, dest = None, **opts): |
364 """make a copy of an existing repository""" | 364 """make a copy of an existing repository""" |
365 source = ui.expandpath(source) | |
366 | |
367 if dest is None: | 365 if dest is None: |
368 dest = os.path.basename(os.path.normpath(source)) | 366 dest = os.path.basename(os.path.normpath(source)) |
369 | 367 |
370 if os.path.exists(dest): | 368 if os.path.exists(dest): |
371 ui.warn("abort: destination '%s' already exists\n" % dest) | 369 ui.warn("abort: destination '%s' already exists\n" % dest) |
382 def __del__(self): | 380 def __del__(self): |
383 if self.dir: | 381 if self.dir: |
384 self.rmtree(self.dir, True) | 382 self.rmtree(self.dir, True) |
385 | 383 |
386 d = dircleanup(dest) | 384 d = dircleanup(dest) |
387 | |
388 link = 0 | 385 link = 0 |
389 abspath = source | 386 abspath = source |
390 if not (source.startswith("http://") or | 387 source = ui.expandpath(source) |
391 source.startswith("hg://") or | 388 other = hg.repository(ui, source) |
392 source.startswith("ssh://") or | 389 |
393 source.startswith("old-http://")): | 390 if other.dev() != -1 and os.stat(dest).st_dev == other.dev(): |
394 abspath = os.path.abspath(source) | 391 ui.status("cloning by hardlink\n") |
395 d1 = os.stat(dest).st_dev | |
396 d2 = os.stat(source).st_dev | |
397 if d1 == d2: link = 1 | |
398 | |
399 if link: | |
400 ui.note("copying by hardlink\n") | |
401 util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest)) | 392 util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest)) |
402 try: | 393 try: |
403 os.remove(os.path.join(dest, ".hg", "dirstate")) | 394 os.remove(os.path.join(dest, ".hg", "dirstate")) |
404 except: pass | 395 except: pass |
405 | 396 |
406 repo = hg.repository(ui, dest) | 397 repo = hg.repository(ui, dest) |
407 | 398 |
408 else: | 399 else: |
409 repo = hg.repository(ui, dest, create=1) | 400 repo = hg.repository(ui, dest, create=1) |
410 other = hg.repository(ui, source) | |
411 repo.pull(other) | 401 repo.pull(other) |
412 | 402 |
413 f = repo.opener("hgrc", "w") | 403 f = repo.opener("hgrc", "w") |
414 f.write("[paths]\n") | 404 f.write("[paths]\n") |
415 f.write("default = %s\n" % abspath) | 405 f.write("default = %s\n" % abspath) |