# HG changeset patch # User Matt Mackall # Date 1120716850 28800 # Node ID da5378d392697d59e07a969fbc37f43afcaa8c1b # Parent f597539c7abdaff27563b8a894da97ca602ba7e6 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -362,8 +362,6 @@ def cat(ui, repo, file, rev = [], **opts 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 @@ def clone(ui, source, dest = None, **opt 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 @@ def clone(ui, source, dest = None, **opt else: repo = hg.repository(ui, dest, create=1) - other = hg.repository(ui, source) repo.pull(other) f = repo.opener("hgrc", "w") diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -498,6 +498,10 @@ class localrepository: 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 @@ class httprepository: 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 @@ class sshrepository: 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)