Re: [PATCH] Makefile: always provide a fallback when hardlinks fail
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:13
Andreas Färber [off-list ref] writes:
quoted hunk
From: Andreas Faerber <redacted> Date: Mon, 25 Aug 2008 17:33:03 +0200 Subject: [PATCH] Makefile: always provide a fallback when hardlinks fail We make hardlinks from "git" to "git-<cmd>" built-ins and have been careful to avoid cross-device links when linking "git-<cmd>" to gitexecdir. However, we were not prepared to deal with a build directory that is incapable of making hard links within itself. This patch corrects it. Instead of temporarily linking "git" to gitexecdir, directly link "git- add", falling back to "cp". Try hardlinking that as "git-<cmd>", falling back to symlinks or "cp" on error. While at it, avoid 100+ error messages from hardlink failures when we are going to fall back to symlinks or "cp" by redirecting the standard error to /dev/null. Signed-off-by: Andreas Färber <redacted> --- Makefile | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)diff --git a/Makefile b/Makefile index 7a6cbb6..fb4863c 100644 --- a/Makefile +++ b/Makefile@@ -1110,7 +1110,10 @@ help.o: help.c common-cmds.h GIT-CFLAGS '-DGIT_INFO_PATH="$(infodir_SQ)"' $< $(BUILT_INS): git$X - $(QUIET_BUILT_IN)$(RM) $@ && ln git$X $@ + $(QUIET_BUILT_IN)$(RM) $@ && \ + ln git$X $@ 2>/dev/null || \ + ln -s git$X $@ 2>/dev/null || \ + cp git$X $@
Ok.
quoted hunk
common-cmds.h: ./generate-cmdlist.sh command-list.txt@@ -1371,16 +1374,13 @@ ifneq (,$X) endif bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \ execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \ - if test "z$$bindir" != "z$$execdir"; \ - then \ - ln -f "$$bindir/git$X" "$$execdir/git$X" || \ - cp "$$bindir/git$X" "$$execdir/git$X"; \ - fi && \ - { $(foreach p,$(BUILT_INS), $(RM) "$$execdir/$p" && ln"$$execdir/git $X" "$$execdir/$p" ;) } && \ - if test "z$$bindir" != "z$$execdir"; \ - then \ - $(RM) "$$execdir/git$X"; \ - fi && \
(mental note while reviewing the change) Outside context before this part we have installed "git$X" to $$bindir, and removed leftover "git-foo" without .exe on the platform where X=.exe.
+ { $(RM) "$$execdir/git-add$X" && \
+ ln git-add$X "$$execdir/git-add$X" 2>/dev/null || \
+ cp git-add$X "$$execdir/git-add$X"; } && \(mental note while reviewing the change) First, we install git-add$X to $$execdir, either hardlink or copy.
+ { $(foreach p,$(patsubst git-add,,$(BUILT_INS)), $(RM)
"$$execdir/
$p" && \
+ ln "$$execdir/git-add$X" "$$execdir/$p" 2>/dev/null || \
+ ln -s "$$execdir/git-add$X" "$$execdir/$p" 2>/dev/null || \
+ cp "$$execdir/git-add$X" "$$execdir/$p" || exit;) } && \
Nits.
* Line-wrapped;
* $(patsubst) is probably $(filter-out);
(mental note while reviewing the change) Then we install the rest by
linking, symlinking or copying git-add$X.
We might want to do the "symlinking" to $$bindir/git$X instead, but other
than that (and above two minor nits), this looks pretty good.
Thanks, will try and apply.