Add a repo method to report repo device
authorMatt Mackall <mpm@selenic.com>
Wed, 06 Jul 2005 22:14:10 -0800
changeset 634 da5378d39269
parent 633 f597539c7abd
child 635 85e2209d401c
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.
mercurial/commands.py
mercurial/hg.py
--- a/mercurial/commands.py	Wed Jul 06 22:11:54 2005 -0800
+++ b/mercurial/commands.py	Wed Jul 06 22:14:10 2005 -0800
@@ -362,8 +362,6 @@
 
 def clone(ui, source, dest = None, **opts):
     """make a copy of an existing repository"""
-    source = ui.expandpath(source)
-
     if dest is None:
         dest = os.path.basename(os.path.normpath(source))
 
@@ -384,20 +382,13 @@
                 self.rmtree(self.dir, True)
 
     d = dircleanup(dest)
-
     link = 0
     abspath = source
-    if not (source.startswith("http://") or
-            source.startswith("hg://") or
-            source.startswith("ssh://") or
-            source.startswith("old-http://")):
-        abspath = os.path.abspath(source)
-        d1 = os.stat(dest).st_dev
-        d2 = os.stat(source).st_dev
-        if d1 == d2: link = 1
+    source = ui.expandpath(source)
+    other = hg.repository(ui, source)
 
-    if link:
-        ui.note("copying by hardlink\n")
+    if other.dev() != -1 and os.stat(dest).st_dev == other.dev():
+        ui.status("cloning by hardlink\n")
         util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest))
         try:
             os.remove(os.path.join(dest, ".hg", "dirstate"))
@@ -407,7 +398,6 @@
 
     else:
         repo = hg.repository(ui, dest, create=1)
-        other = hg.repository(ui, source)
         repo.pull(other)
 
     f = repo.opener("hgrc", "w")
--- a/mercurial/hg.py	Wed Jul 06 22:11:54 2005 -0800
+++ b/mercurial/hg.py	Wed Jul 06 22:14:10 2005 -0800
@@ -498,6 +498,10 @@
         except KeyError:
             return self.changelog.lookup(key)
 
+    def dev(self):
+        if self.remote: return -1
+        return os.stat(self.path).st_dev
+
     def join(self, f):
         return os.path.join(self.path, f)
 
@@ -1547,6 +1551,9 @@
         opener = urllib2.build_opener(proxy_handler, authinfo)
         urllib2.install_opener(opener)
 
+    def dev(self):
+        return -1
+
     def do_cmd(self, cmd, **args):
         self.ui.debug("sending %s command\n" % cmd)
         q = {"cmd": cmd}
@@ -1624,6 +1631,9 @@
         self.pipeo.close()
         self.pipei.close()
 
+    def dev(self):
+        return -1
+
     def do_cmd(self, cmd, **args):
         self.ui.debug("sending %s command\n" % cmd)
         self.pipeo.write("%s\n" % cmd)