Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 485:c5705ab9cebd
[PATCH] add clone command
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[PATCH] add clone command
Add clone command. Mark with-source version of "init" as deprecated.
manifest hash: 3c31263474977c3d8303f45f71c44f7b7e10e97e
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCvzhOywK+sNU5EO8RAmh+AJwIlRfX143oxKShgPWF2dbDvCuH3gCbBrAW
isIHptwVRX8pcA0lU638pHo=
=ZoQy
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Sun, 26 Jun 2005 15:20:46 -0800 |
parents | 934279f3ca53 |
children | df9b77f67998 e94cebc60d96 |
comparison
equal
deleted
inserted
replaced
484:934279f3ca53 | 485:c5705ab9cebd |
---|---|
257 r = repo.file(relpath(repo, [file])[0]) | 257 r = repo.file(relpath(repo, [file])[0]) |
258 n = r.tip() | 258 n = r.tip() |
259 if rev: n = r.lookup(rev) | 259 if rev: n = r.lookup(rev) |
260 sys.stdout.write(r.read(n)) | 260 sys.stdout.write(r.read(n)) |
261 | 261 |
262 def clone(ui, source, dest = None, **opts): | |
263 """make a copy of an existing repository""" | |
264 paths = {} | |
265 for name, path in ui.configitems("paths"): | |
266 paths[name] = path | |
267 | |
268 if source in paths: source = paths[source] | |
269 | |
270 if dest is None: | |
271 dest = os.getcwd() | |
272 elif not os.path.exists(dest): | |
273 os.makedirs(dest) | |
274 | |
275 link = 0 | |
276 if not source.startswith("http://"): | |
277 source = os.path.realpath(source) | |
278 d1 = os.stat(dest).st_dev | |
279 d2 = os.stat(source).st_dev | |
280 if d1 == d2: link = 1 | |
281 | |
282 os.chdir(dest) | |
283 | |
284 if link: | |
285 ui.debug("copying by hardlink\n") | |
286 os.system("cp -al %s/.hg .hg" % source) | |
287 try: | |
288 os.remove(".hg/dirstate") | |
289 except: pass | |
290 | |
291 repo = hg.repository(ui, ".") | |
292 | |
293 else: | |
294 repo = hg.repository(ui, ".", create=1) | |
295 other = hg.repository(ui, source) | |
296 cg = repo.getchangegroup(other) | |
297 repo.addchangegroup(cg) | |
298 | |
299 f = repo.opener("hgrc", "w") | |
300 f.write("[paths]\n") | |
301 f.write("default = %s\n" % source) | |
302 | |
303 if not opts['no-update']: | |
304 update(ui, repo) | |
305 | |
262 def commit(ui, repo, *files, **opts): | 306 def commit(ui, repo, *files, **opts): |
263 """commit the specified files or all outstanding changes""" | 307 """commit the specified files or all outstanding changes""" |
264 text = opts['text'] | 308 text = opts['text'] |
265 if not text and opts['logfile']: | 309 if not text and opts['logfile']: |
266 try: text = open(opts['logfile']).read() | 310 try: text = open(opts['logfile']).read() |
442 if len(files) > 0: | 486 if len(files) > 0: |
443 addremove(ui, repo, *files) | 487 addremove(ui, repo, *files) |
444 repo.commit(files, text) | 488 repo.commit(files, text) |
445 | 489 |
446 def init(ui, source=None, **opts): | 490 def init(ui, source=None, **opts): |
447 """create a new repository or copy an existing one""" | 491 """create a new repository or (deprecated, use clone) copy an existing one""" |
448 | 492 |
449 if source: | 493 if source: |
450 paths = {} | 494 ui.warn("this use of init is deprecated: use \"hg clone\" instead\n") |
451 for name, path in ui.configitems("paths"): | 495 opts['no-update'] = not opts['update'] |
452 paths[name] = path | 496 clone(ui, source, None, **opts) |
453 | |
454 if source in paths: source = paths[source] | |
455 | |
456 link = 0 | |
457 if not source.startswith("http://"): | |
458 d1 = os.stat(os.getcwd()).st_dev | |
459 d2 = os.stat(source).st_dev | |
460 if d1 == d2: link = 1 | |
461 | |
462 if link: | |
463 ui.debug("copying by hardlink\n") | |
464 os.system("cp -al %s/.hg .hg" % source) | |
465 try: | |
466 os.remove(".hg/dirstate") | |
467 except: pass | |
468 | |
469 repo = hg.repository(ui, ".") | |
470 | |
471 else: | |
472 repo = hg.repository(ui, ".", create=1) | |
473 other = hg.repository(ui, source) | |
474 cg = repo.getchangegroup(other) | |
475 repo.addchangegroup(cg) | |
476 | |
477 f = repo.opener("hgrc", "w") | |
478 f.write("[paths]\n") | |
479 f.write("default = %s\n" % source) | |
480 | |
481 if opts['update']: | |
482 update(ui, repo) | |
483 else: | 497 else: |
484 repo = hg.repository(ui, ".", create=1) | 498 repo = hg.repository(ui, ".", create=1) |
485 | 499 |
486 def log(ui, repo, f): | 500 def log(ui, repo, f): |
487 """show the revision history of a single file""" | 501 """show the revision history of a single file""" |
705 ('u', 'user', None, 'show user'), | 719 ('u', 'user', None, 'show user'), |
706 ('n', 'number', None, 'show revision number'), | 720 ('n', 'number', None, 'show revision number'), |
707 ('c', 'changeset', None, 'show changeset')], | 721 ('c', 'changeset', None, 'show changeset')], |
708 'hg annotate [-u] [-c] [-n] [-r id] [files]'), | 722 'hg annotate [-u] [-c] [-n] [-r id] [files]'), |
709 "cat": (cat, [], 'hg cat <file> [rev]'), | 723 "cat": (cat, [], 'hg cat <file> [rev]'), |
724 "clone": (clone, [('U', 'no-update', None, 'skip update after cloning')], | |
725 'hg clone [options] <source> [dest]'), | |
710 "commit|ci": (commit, | 726 "commit|ci": (commit, |
711 [('t', 'text', "", 'commit text'), | 727 [('t', 'text', "", 'commit text'), |
712 ('A', 'addremove', None, 'run add/remove during commit'), | 728 ('A', 'addremove', None, 'run add/remove during commit'), |
713 ('l', 'logfile', "", 'commit text file'), | 729 ('l', 'logfile', "", 'commit text file'), |
714 ('d', 'date', "", 'data'), | 730 ('d', 'date', "", 'data'), |
771 'hg update [options] [node]'), | 787 'hg update [options] [node]'), |
772 "verify": (verify, [], 'hg verify'), | 788 "verify": (verify, [], 'hg verify'), |
773 "version": (show_version, [], 'hg version'), | 789 "version": (show_version, [], 'hg version'), |
774 } | 790 } |
775 | 791 |
776 norepo = "init version help debugindex debugindexdot" | 792 norepo = "clone init version help debugindex debugindexdot" |
777 | 793 |
778 def find(cmd): | 794 def find(cmd): |
779 for e in table.keys(): | 795 for e in table.keys(): |
780 if re.match("(%s)$" % e, cmd): | 796 if re.match("(%s)$" % e, cmd): |
781 return table[e] | 797 return table[e] |