Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/commands.py Sun Jun 26 15:12:51 2005 -0800 +++ b/mercurial/commands.py Sun Jun 26 15:20:46 2005 -0800 @@ -259,6 +259,50 @@ if rev: n = r.lookup(rev) sys.stdout.write(r.read(n)) +def clone(ui, source, dest = None, **opts): + """make a copy of an existing repository""" + paths = {} + for name, path in ui.configitems("paths"): + paths[name] = path + + if source in paths: source = paths[source] + + if dest is None: + dest = os.getcwd() + elif not os.path.exists(dest): + os.makedirs(dest) + + link = 0 + if not source.startswith("http://"): + source = os.path.realpath(source) + d1 = os.stat(dest).st_dev + d2 = os.stat(source).st_dev + if d1 == d2: link = 1 + + os.chdir(dest) + + if link: + ui.debug("copying by hardlink\n") + os.system("cp -al %s/.hg .hg" % source) + try: + os.remove(".hg/dirstate") + except: pass + + repo = hg.repository(ui, ".") + + else: + repo = hg.repository(ui, ".", create=1) + other = hg.repository(ui, source) + cg = repo.getchangegroup(other) + repo.addchangegroup(cg) + + f = repo.opener("hgrc", "w") + f.write("[paths]\n") + f.write("default = %s\n" % source) + + if not opts['no-update']: + update(ui, repo) + def commit(ui, repo, *files, **opts): """commit the specified files or all outstanding changes""" text = opts['text'] @@ -444,42 +488,12 @@ repo.commit(files, text) def init(ui, source=None, **opts): - """create a new repository or copy an existing one""" + """create a new repository or (deprecated, use clone) copy an existing one""" if source: - paths = {} - for name, path in ui.configitems("paths"): - paths[name] = path - - if source in paths: source = paths[source] - - link = 0 - if not source.startswith("http://"): - d1 = os.stat(os.getcwd()).st_dev - d2 = os.stat(source).st_dev - if d1 == d2: link = 1 - - if link: - ui.debug("copying by hardlink\n") - os.system("cp -al %s/.hg .hg" % source) - try: - os.remove(".hg/dirstate") - except: pass - - repo = hg.repository(ui, ".") - - else: - repo = hg.repository(ui, ".", create=1) - other = hg.repository(ui, source) - cg = repo.getchangegroup(other) - repo.addchangegroup(cg) - - f = repo.opener("hgrc", "w") - f.write("[paths]\n") - f.write("default = %s\n" % source) - - if opts['update']: - update(ui, repo) + ui.warn("this use of init is deprecated: use \"hg clone\" instead\n") + opts['no-update'] = not opts['update'] + clone(ui, source, None, **opts) else: repo = hg.repository(ui, ".", create=1) @@ -707,6 +721,8 @@ ('c', 'changeset', None, 'show changeset')], 'hg annotate [-u] [-c] [-n] [-r id] [files]'), "cat": (cat, [], 'hg cat <file> [rev]'), + "clone": (clone, [('U', 'no-update', None, 'skip update after cloning')], + 'hg clone [options] <source> [dest]'), "commit|ci": (commit, [('t', 'text', "", 'commit text'), ('A', 'addremove', None, 'run add/remove during commit'), @@ -773,7 +789,7 @@ "version": (show_version, [], 'hg version'), } -norepo = "init version help debugindex debugindexdot" +norepo = "clone init version help debugindex debugindexdot" def find(cmd): for e in table.keys():