git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Makefile: always provide a fallback when hardlinks fail

From
Andreas Färber <andreas.faerber@web.de>
Date
Aug 25, 2008, 15:42 UTC
Message-ID
<D4374620-C6D8-4CB3-8A7D-C5449BB8E8D1@web.de>
In-Reply-To
<7vljyv6gyo.fsf@gitster.siamese.dyndns.org>
Am 17.08.2008 um 13:03 schrieb Junio C Hamano:
Show 32 quoted lines
> Andreas Färber <andreas.faerber@web.de> writes:
>
>> BFS does not support hardlinks, so suppress the resulting error
>> messages.
>
> Hmm, this is not specific to BFS.  [...]
>
> Your patch seems to be whitespace damaged.  Here is an alternative.
>
> Note.
>
> We currently install $(bindir)/git to $(gitexecdir)/git, make  
> hardlinks to
> "git-<cmd>" from "git" inside $(gitexecdir), and then finally remove  
> "git"
> in $(gitexecdir).
>
> We could avoid this ugliness by:
>
> (1) install "$(gitexecdir)/git-add" (or any other single built-in) by
>     trying hardlink "$(bindir)/git", and if it fails by copying;
>
> (2) for the rest of built-ins, install "$(gitexecdir)/git-<cmd>" by  
> trying
>     ln "$(gitexecdir)/git-add" "$(gitexecdir)/git-<cmd>", then
>     ln -s "git-add" "$(gitexecdir)/git-<cmd>", then finally
>     cp "$(gitexecdir)/git-add" "$(gitexecdir)/git-<cmd>".
>
> That is not what I did, but it should be the right thing to do.  It is
> already very late in the release cycle, and this whole thing can be  
> done
> after 1.6.0 final; we do not have to hurry.
I've tried to implement what you've outlined above.

On Haiku this now results in symlinks within the build dir for the builtins including git-add, and in symlinks for all builtins but git- add in $prefix/libexec/git-core.

---
From: Andreas Faerber <andreas.faerber@web.de>
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 <andreas.faerber@web.de>
---
  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 $@

  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 && \
+	{ $(RM) "$$execdir/git-add$X" && \
+		ln git-add$X "$$execdir/git-add$X" 2>/dev/null || \
+		cp git-add$X "$$execdir/git-add$X"; } && \
+	{ $(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;) } && \
  	./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X"

  install-doc:
-- 
1.6.0.1.91.gaea6



From aea60501ba1651f7ba51de8381db5355d6df472b Mon Sep 17 00:00:00 2001
From: Andreas Faerber <andreas.faerber@web.de>
Date: Mon, 25 Aug 2008 17:33:03 +0200
Subject: [PATCH] Makefile: always provide a fallback when hardlinks fail
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

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>
---
 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 $@
 
 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 && \
+	{ $(RM) "$$execdir/git-add$X" && \
+		ln git-add$X "$$execdir/git-add$X" 2>/dev/null || \
+		cp git-add$X "$$execdir/git-add$X"; } && \
+	{ $(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;) } && \
 	./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X"
 
 install-doc:
-- 
1.6.0.1.91.gaea6
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “Always provide a fallback when hardlinks fail”
  1. 6/6 Always provide a fallback when hardlinks failAndreas Färber, Aug 17, 2008
  2. Junio C HamanoAug 17, 2008
  3. Andreas FärberAug 17, 2008
  4. Junio C HamanoAug 17, 2008
  5. Makefile: always provide a fallback when hardlinks failAndreas Färber, Aug 25, 2008
  6. Junio C HamanoAug 25, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.