Patchwork [4,of,4,"] discovery-helper: use reflink copy if available

mail settings
Submitter Pierre-Yves David
Date March 10, 2019, 7:19 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/39202/
State Accepted
Headers show


Pierre-Yves David - March 10, 2019, 7:19 p.m.
# HG changeset patch
# User Pierre-Yves David <>
# Date 1552240916 -3600
#      Sun Mar 10 19:01:56 2019 +0100
# Node ID 4de0f37ebaaeb674f6f2deb78ab6f278836deb0c
# Parent  849b8fd6ec5613e1f667d7ccd1d4d00d77050251
# EXP-Topic perf-utils
# Available At
#              hg pull -r 4de0f37ebaae
discovery-helper: use reflink copy if available

A reflink copy will copy the files "as usual" but keep using the same data block
underneath. This is only supported by "copy on write" file system like btrfs or

This will achieve similar performance that the existing hardlink clone that
Mercurial performs with the same initial space saving. However, it will behave
better on revlogs start being touch by strip. Instead of duplicating all data in
the touched revlogs, only the block actually affected by the strip will be
duplicated. This save a lot of space when building many variants of large

The --reflink=always flag make sure the `cp` call fails if reflink copies are
not supported. Falling back to local clone.


diff --git a/contrib/perf-utils/ b/contrib/perf-utils/
--- a/contrib/perf-utils/
+++ b/contrib/perf-utils/
@@ -91,7 +91,9 @@  buildone() {
         exit 1
     echo '# cloning'
-    hg clone --noupdate "${repo}" "${dest}"
+    if ! cp --recursive --reflink=always ${repo} ${dest}; then
+        hg clone --noupdate "${repo}" "${dest}"
+    fi
     echo '# stripping' '"'${revset}'"'
     hg -R "${dest}" --config extensions.strip= strip --rev "$revset" --no-backup