Skip to content

Commit 9b07ad9

Browse files
avardscho
authored andcommitted
Makefile: optionally symlink libexec/git-core binaries to bin/git
Add a INSTALL_SYMLINKS option which if enabled, changes the default hardlink installation method to one where the relevant binaries in libexec/git-core are symlinked back to ../../bin, instead of being hardlinked. This new option also overrides the behavior of the existing NO_*_HARDLINKS variables which in some cases would produce symlinks within to libexec/, e.g. "git-add" symlinked to "git" which would be copy of the "git" found in bin/, now "git-add" in libexec/ is always going to be symlinked to the "git" found in the bin/ directory. This option is being added because: 1) I think it makes what we're doing a lot more obvious. E.g. I'd never noticed that the libexec binaries were really just hardlinks since e.g. ls(1) won't show that in any obvious way. You need to start stat(1)-ing things and look at the inodes to see what's going on. 2) Some tools have very crappy support for hardlinks, e.g. the Git shipped with GitLab is much bigger than it should be because they're using a chef module that doesn't know about hardlinks, see chef/omnibus#827 I've also ran into other related issues that I think are explained by this, e.g. compiling git with debugging and rpm refusing to install a ~200MB git package with 2GB left on the FS, I think that was because it doesn't consider hardlinks, just the sum of the byte size of everything in the package. As for the implementation, the "../../bin" noted above will vary given some given some values of "../.." and "bin" depending on the depth of the gitexecdir relative to the destdir, and the "bindir" target, e.g. setting "bindir=/tmp/git/binaries gitexecdir=foo/bar/baz" will do the right thing and produce this result: $ file /tmp/git/foo/bar/baz/git-add /tmp/git/foo/bar/baz/git-add: symbolic link to ../../../binaries/git Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f7e556e commit 9b07ad9

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

Makefile

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ all::
335335
# when hardlinking a file to another name and unlinking the original file right
336336
# away (some NTFS drivers seem to zero the contents in that scenario).
337337
#
338+
# Define INSTALL_SYMLINKS if you prefer to have everything that can be
339+
# symlinked between bin/ and libexec/ to use relative symlinks between
340+
# the two. This option overrides NO_CROSS_DIRECTORY_HARDLINKS and
341+
# NO_INSTALL_HARDLINKS which will also use symlinking by indirection
342+
# within the same directory in some cases, INSTALL_SYMLINKS will
343+
# always symlink to the final target directly.
344+
#
338345
# Define NO_CROSS_DIRECTORY_HARDLINKS if you plan to distribute the installed
339346
# programs as a tar, where bin/ and libexec/ might be on different file systems.
340347
#
@@ -2608,35 +2615,44 @@ endif
26082615

26092616
bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
26102617
execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
2618+
destdir_from_execdir_SQ=$$(echo '$(gitexecdir_relative_SQ)' | sed -e 's|[^/][^/]*|..|g') && \
26112619
{ test "$$bindir/" = "$$execdir/" || \
26122620
for p in git$X $(filter $(install_bindir_programs),$(ALL_PROGRAMS)); do \
26132621
$(RM) "$$execdir/$$p" && \
2614-
test -z "$(NO_INSTALL_HARDLINKS)$(NO_CROSS_DIRECTORY_HARDLINKS)" && \
2615-
ln "$$bindir/$$p" "$$execdir/$$p" 2>/dev/null || \
2616-
cp "$$bindir/$$p" "$$execdir/$$p" || exit; \
2622+
test -n "$(INSTALL_SYMLINKS)" && \
2623+
ln -s "$$destdir_from_execdir_SQ/$(bindir_relative_SQ)/$$p" "$$execdir/$$p" || \
2624+
{ test -z "$(NO_INSTALL_HARDLINKS)$(NO_CROSS_DIRECTORY_HARDLINKS)" && \
2625+
ln "$$bindir/$$p" "$$execdir/$$p" 2>/dev/null || \
2626+
cp "$$bindir/$$p" "$$execdir/$$p" || exit; } \
26172627
done; \
26182628
} && \
26192629
for p in $(filter $(install_bindir_programs),$(BUILT_INS)); do \
26202630
$(RM) "$$bindir/$$p" && \
2621-
test -z "$(NO_INSTALL_HARDLINKS)" && \
2622-
ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
2623-
ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
2624-
cp "$$bindir/git$X" "$$bindir/$$p" || exit; \
2631+
test -n "$(INSTALL_SYMLINKS)" && \
2632+
ln -s "git$X" "$$bindir/$$p" || \
2633+
{ test -z "$(NO_INSTALL_HARDLINKS)" && \
2634+
ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
2635+
ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
2636+
cp "$$bindir/git$X" "$$bindir/$$p" || exit; } \
26252637
done && \
26262638
for p in $(BUILT_INS); do \
26272639
$(RM) "$$execdir/$$p" && \
2628-
test -z "$(NO_INSTALL_HARDLINKS)" && \
2629-
ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \
2630-
ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
2631-
cp "$$execdir/git$X" "$$execdir/$$p" || exit; \
2640+
test -n "$(INSTALL_SYMLINKS)" && \
2641+
ln -s "$$destdir_from_execdir_SQ/$(bindir_relative_SQ)/git$X" "$$execdir/$$p" || \
2642+
{ test -z "$(NO_INSTALL_HARDLINKS)" && \
2643+
ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \
2644+
ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
2645+
cp "$$execdir/git$X" "$$execdir/$$p" || exit; } \
26322646
done && \
26332647
remote_curl_aliases="$(REMOTE_CURL_ALIASES)" && \
26342648
for p in $$remote_curl_aliases; do \
26352649
$(RM) "$$execdir/$$p" && \
2636-
test -z "$(NO_INSTALL_HARDLINKS)" && \
2637-
ln "$$execdir/git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
2638-
ln -s "git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
2639-
cp "$$execdir/git-remote-http$X" "$$execdir/$$p" || exit; \
2650+
test -n "$(INSTALL_SYMLINKS)" && \
2651+
ln -s "git-remote-http$X" "$$execdir/$$p" || \
2652+
{ test -z "$(NO_INSTALL_HARDLINKS)" && \
2653+
ln "$$execdir/git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
2654+
ln -s "git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
2655+
cp "$$execdir/git-remote-http$X" "$$execdir/$$p" || exit; } \
26402656
done && \
26412657
./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X"
26422658

0 commit comments

Comments
 (0)