[PATCH] add clone command
authormpm@selenic.com
Sun, 26 Jun 2005 15:20:46 -0800
changeset 485 c5705ab9cebd
parent 484 934279f3ca53
child 486 098d1f039c18
child 490 df9b77f67998
[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-----
doc/hg.1.txt
mercurial/commands.py
tests/test-bad-pull
tests/test-help.out
tests/test-pull
tests/test-simple-update
tests/test-simple-update.out
tests/test-tags.out
tests/test-up-local-change
tests/test-up-local-change.out
--- a/doc/hg.1.txt	Sun Jun 26 15:12:51 2005 -0800
+++ b/doc/hg.1.txt	Sun Jun 26 15:20:46 2005 -0800
@@ -73,6 +73,24 @@
 cat <file> [revision]::
     Output the given revision or tip of the specified file to stdout.
 
+clone [-U] <source> [dest]::
+    Create a new copy of an existing repository.
+
+    If the specified source is on the same filesystem, the repository
+    will be copied via hardlinks. This is the fastest and most
+    space-efficient mode of operation.
+
+    If the destination directory is not specified, it defaults to the
+    current directory.
+
+    If the destination is specified, but does not exist, it is created.
+
+    The source is added to .hg/hgrc in the new copy as the default for
+    future pulls.
+
+    options:
+    -U, --no-update   do not update the new working directory
+
 commit [-A -t -l <file> -t <text> -u <user> -d <datecode>] [files...]::
     Commit all changed files in the working dir to the repository.  This uses
     the EDITOR environment variable to bring up an editor to add a commit
@@ -134,6 +152,9 @@
 init [-u] [source]::
     Initialize a repository in the current directory.
 
+    NOTE: The following use is deprecated, and will be removed soon;
+    use the "hg clone" command instead.
+
     If a source is specified, pull that source into the repository.
     This source is added to .hg/hgrc as the default for future pulls
     in this repository.
--- 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():
--- a/tests/test-bad-pull	Sun Jun 26 15:12:51 2005 -0800
+++ b/tests/test-bad-pull	Sun Jun 26 15:20:46 2005 -0800
@@ -1,8 +1,7 @@
 #!/bin/bash
 
-mkdir copy
+hg clone http://localhost:20059/ copy
 cd copy
-hg init http://localhost:20059/
 hg verify
 hg co
 cat foo
@@ -23,9 +22,8 @@
 
 python dumb.py 2>/dev/null &
 
-mkdir copy2
+hg clone http://localhost:20059/foo copy2
 cd copy2
-hg init http://localhost:20059/foo
 hg verify
 hg co
 cat foo
--- a/tests/test-help.out	Sun Jun 26 15:12:51 2005 -0800
+++ b/tests/test-help.out	Sun Jun 26 15:20:46 2005 -0800
@@ -5,6 +5,7 @@
  addremove   add all new files, delete all missing files
  annotate    show changeset information per file line
  cat         output the latest or given revision of a file
+ clone       make a copy of an existing repository
  commit      commit the specified files or all outstanding changes
  copy        mark a file as copied or renamed for the next commit
  diff        diff working directory (or selected files)
@@ -15,7 +16,7 @@
  history     show the changelog history
  identify    print information about the working copy
  import      import an ordered set of patches
- init        create a new repository or copy an existing one
+ init        create a new repository or (deprecated, use clone) copy an existing one
  log         show the revision history of a single file
  manifest    output the latest or given revision of the project manifest
  parents     show the parents of the current working dir
@@ -56,6 +57,7 @@
  addremove   add all new files, delete all missing files
  annotate    show changeset information per file line
  cat         output the latest or given revision of a file
+ clone       make a copy of an existing repository
  commit      commit the specified files or all outstanding changes
  copy        mark a file as copied or renamed for the next commit
  diff        diff working directory (or selected files)
@@ -66,7 +68,7 @@
  history     show the changelog history
  identify    print information about the working copy
  import      import an ordered set of patches
- init        create a new repository or copy an existing one
+ init        create a new repository or (deprecated, use clone) copy an existing one
  log         show the revision history of a single file
  manifest    output the latest or given revision of the project manifest
  parents     show the parents of the current working dir
--- a/tests/test-pull	Sun Jun 26 15:12:51 2005 -0800
+++ b/tests/test-pull	Sun Jun 26 15:20:46 2005 -0800
@@ -10,9 +10,8 @@
 hg serve -p 20059 2>/dev/null &
 cd ..
 
-mkdir copy
+hg clone http://localhost:20059/ copy
 cd copy
-hg init http://localhost:20059/
 hg verify
 hg co
 cat foo
--- a/tests/test-simple-update	Sun Jun 26 15:12:51 2005 -0800
+++ b/tests/test-simple-update	Sun Jun 26 15:20:46 2005 -0800
@@ -9,11 +9,9 @@
 hg addremove
 hg commit -t "1"
 hg verify
-cd ..
 
-mkdir branch
-cd branch
-hg init ../test
+hg clone . ../branch
+cd ../branch
 hg co
 echo bar>>foo
 hg commit -t "2"
@@ -23,4 +21,4 @@
 hg verify
 hg co
 cat foo
-hg manifest
\ No newline at end of file
+hg manifest
--- a/tests/test-simple-update.out	Sun Jun 26 15:12:51 2005 -0800
+++ b/tests/test-simple-update.out	Sun Jun 26 15:20:46 2005 -0800
@@ -10,10 +10,8 @@
 crosschecking files in changesets and manifests
 checking files
 1 files, 1 changesets, 1 total revisions
-+ cd ..
-+ mkdir branch
-+ cd branch
-+ hg init ../test
++ hg clone . ../branch
++ cd ../branch
 + hg co
 + echo bar
 + hg commit -t 2
--- a/tests/test-tags.out	Sun Jun 26 15:12:51 2005 -0800
+++ b/tests/test-tags.out	Sun Jun 26 15:20:46 2005 -0800
@@ -43,5 +43,5 @@
 + hg id
 c8edf04160c7+b9154636be93+ tip
 + hg status
+C .hgtags
 C a
-C .hgtags
--- a/tests/test-up-local-change	Sun Jun 26 15:12:51 2005 -0800
+++ b/tests/test-up-local-change	Sun Jun 26 15:20:46 2005 -0800
@@ -10,10 +10,8 @@
 hg addremove
 hg commit -t "1" -u test -d "0 0"
 
-cd ..
-mkdir r2
-cd r2
-hg init ../r1
+hg clone . ../r2
+cd ../r2
 hg up
 echo abc > a
 hg diff > ../d
--- a/tests/test-up-local-change.out	Sun Jun 26 15:12:51 2005 -0800
+++ b/tests/test-up-local-change.out	Sun Jun 26 15:20:46 2005 -0800
@@ -4,10 +4,8 @@
 + echo a
 + hg addremove
 + hg commit -t 1 -u test -d '0 0'
-+ cd ..
-+ mkdir r2
-+ cd r2
-+ hg init ../r1
++ hg clone . ../r2
++ cd ../r2
 + hg up
 + echo abc
 + hg diff