Skip to content

Commit 3e073dc

Browse files
afaerbergitster
authored andcommitted
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 <andreas.faerber@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5760a6b commit 3e073dc

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Makefile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,10 @@ help.o: help.c common-cmds.h GIT-CFLAGS
10991099
'-DGIT_INFO_PATH="$(infodir_SQ)"' $<
11001100

11011101
$(BUILT_INS): git$X
1102-
$(QUIET_BUILT_IN)$(RM) $@ && ln git$X $@
1102+
$(QUIET_BUILT_IN)$(RM) $@ && \
1103+
ln git$X $@ 2>/dev/null || \
1104+
ln -s git$X $@ 2>/dev/null || \
1105+
cp git$X $@
11031106

11041107
common-cmds.h: ./generate-cmdlist.sh command-list.txt
11051108

@@ -1364,16 +1367,13 @@ ifneq (,$X)
13641367
endif
13651368
bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
13661369
execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
1367-
if test "z$$bindir" != "z$$execdir"; \
1368-
then \
1369-
ln -f "$$bindir/git$X" "$$execdir/git$X" || \
1370-
cp "$$bindir/git$X" "$$execdir/git$X"; \
1371-
fi && \
1372-
{ $(foreach p,$(BUILT_INS), $(RM) "$$execdir/$p" && ln "$$execdir/git$X" "$$execdir/$p" ;) } && \
1373-
if test "z$$bindir" != "z$$execdir"; \
1374-
then \
1375-
$(RM) "$$execdir/git$X"; \
1376-
fi && \
1370+
{ $(RM) "$$execdir/git-add$X" && \
1371+
ln git-add$X "$$execdir/git-add$X" 2>/dev/null || \
1372+
cp git-add$X "$$execdir/git-add$X"; } && \
1373+
{ $(foreach p,$(filter-out git-add,$(BUILT_INS)), $(RM) "$$execdir/$p" && \
1374+
ln "$$execdir/git-add$X" "$$execdir/$p" 2>/dev/null || \
1375+
ln -s "git-add$X" "$$execdir/$p" 2>/dev/null || \
1376+
cp "$$execdir/git-add$X" "$$execdir/$p" || exit;) } && \
13771377
./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X"
13781378

13791379
install-doc:

0 commit comments

Comments
 (0)