Patchwork [3,of,3,V2] hardlink: check directory's st_dev when copying files

mail settings
Submitter Jun Wu
Date March 29, 2017, 7:42 p.m.
Message ID <e9e48ce378c982f4ecba.1490816538@x1c>
Download mbox | patch
Permalink /patch/19826/
State Accepted
Headers show


Jun Wu - March 29, 2017, 7:42 p.m.
# HG changeset patch
# User Jun Wu <>
# Date 1490816223 25200
#      Wed Mar 29 12:37:03 2017 -0700
# Node ID e9e48ce378c982f4ecbace5dd61ba85d1fc12ad6
# Parent  b4e6f395c7940676c56b6f5308e203aa861d8bbe
# Available At
#              hg pull -r e9e48ce378c9
hardlink: check directory's st_dev when copying files

Previously, when copying a file, copyfiles will compare src's st_dev with
dirname(dst)'s st_dev, to decide whether to enable hardlink or not.

That could have issues on Linux's overlayfs, where stating directories could
result in different st_dev from st_dev of stating files, even if both the
directories and the files exist in the overlay's upperdir.

This patch fixes it by checking dirname(src) instead. It's more consistent
because we are checking directories for both src and dest.

That fixes test-hardlinks.t running on common Docker setups.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -1145,5 +1145,5 @@  def copyfiles(src, dst, hardlink=None, p
         if hardlink is None:
-            hardlink = (os.stat(src).st_dev ==
+            hardlink = (os.stat(os.path.dirname(src)).st_dev ==
         topic = gettopic()