replace hg branch with hg init [source]
authormpm@selenic.com
Wed, 08 Jun 2005 17:08:55 -0800
changeset 290 07c6cb9fd1c5
parent 289 266396e32006
child 291 2c4f2be05587
replace hg branch with hg init [source] -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 replace hg branch with hg init [source] This does the hardlink trick if both repos are on the same filesystem, otherwise it does a pull. manifest hash: 780a3a0aca6e4a535909c6221ee94394701ec1c9 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp5anywK+sNU5EO8RArdDAJ9Tiia0YZmZ6xiTYdKhZJ2UZY8V5wCfeoPy DamQ2Zyz3yTjNqu4ge0CuRQ= =EXv5 -----END PGP SIGNATURE-----
mercurial/commands.py
--- a/mercurial/commands.py	Wed Jun 08 16:28:34 2005 -0800
+++ b/mercurial/commands.py	Wed Jun 08 17:08:55 2005 -0800
@@ -153,11 +153,6 @@
         for p,l in zip(zip(*pieces), lines):
             u.write(" ".join(p) + ": " + l[1])
 
-def branch(ui, path):
-    '''branch from a local repository'''
-    # this should eventually support remote repos
-    os.system("cp -al %s/.hg .hg" % path)
-
 def cat(ui, repo, file, rev = []):
     """output the latest or given revision of a file"""
     r = repo.file(relpath(repo, [file])[0])
@@ -281,10 +276,33 @@
         print "description:"
         print changes[4]
 
-def init(ui):
-    """create a repository"""
-    hg.repository(ui, ".", create=1)
+def init(ui, source=None):
+    """create a new repository or 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)
+        else:
+            repo = hg.repository(ui, ".", create=1)
+            other = hg.repository(ui, source)
+            cg = repo.getchangegroup(other)
+            repo.addchangegroup(cg)
+    else:
+        hg.repository(ui, ".", create=1)
+    
 def log(ui, repo, f):
     """show the revision history of a single file"""
     f = relpath(repo, [f])[0]
@@ -367,7 +385,7 @@
     """pull changes from the specified source"""
     paths = {}
     for name, path in ui.configitems("paths"):
-            paths[name] = path
+        paths[name] = path
 
     if source in paths: source = paths[source]
     
@@ -484,7 +502,6 @@
                       ('n', 'number', None, 'show revision number'),
                       ('c', 'changeset', None, 'show changeset')],
                      'hg annotate [-u] [-c] [-n] [-r id] [files]'),
-    "branch|clone": (branch, [], 'hg branch [path]'),
     "cat|dump": (cat, [], 'hg cat <file> [rev]'),
     "commit|ci": (commit,
                   [('t', 'text', "", 'commit text'),
@@ -501,7 +518,7 @@
     "heads": (heads, [], 'hg heads'),
     "history": (history, [], 'hg history'),
     "help": (help, [], 'hg help [command]'),
-    "init": (init, [], 'hg init'),
+    "init": (init, [], 'hg init [url]'),
     "log": (log, [], 'hg log <file>'),
     "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'),
     "parents": (parents, [], 'hg parents [node]'),