[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 5/5] scripts/git-checkout.sh: store repositories with Xen, use worktrees



Date: Fri, 16 Oct 2026 19:42:44 -0700

The problem with checking out repositories in subdirectories is they may
get removed by `git clean`.  Whereas storing them with the Xen
repository renders them immune to this.  Then git worktrees can be used
for checking out the specified trees.

Remote the addition of "-remote" to the checkout directory names.  This
is very confusing and a great source for bugs.

Signed-off-by: Elliott Mitchell <ehem+xen@xxxxxxx>
---
WARNING: As of this writing this is known to break qemu-xen building.
I've been trying to figure this out, but so far I'm puzzled.
---
 Makefile                | 10 +++++++---
 scripts/git-checkout.sh | 42 +++++++++++++++++++++++------------------
 tools/Makefile          | 12 ++++--------
 tools/firmware/Makefile | 14 ++++++--------
 4 files changed, 41 insertions(+), 37 deletions(-)

diff --git a/Makefile b/Makefile
index f063ce56819..495e2387db2 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,7 @@ include Config.mk
 mini-os-dir:
        if [ ! -d $(XEN_ROOT)/extras/mini-os ]; then \
                GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh \
+                       mini-os \
                        $(MINIOS_UPSTREAM_URL) \
                        $(MINIOS_UPSTREAM_REVISION) \
                        $(XEN_ROOT)/extras/mini-os ; \
@@ -31,9 +32,12 @@ mini-os-dir:
 mini-os-dir-force-update: mini-os-dir
        set -ex; \
        if [ "$(MINIOS_UPSTREAM_REVISION)" ]; then \
-               cd extras/mini-os-remote; \
-               $(GIT) fetch origin; \
-               $(GIT) reset --hard $(MINIOS_UPSTREAM_REVISION); \
+               rm -rf extras/mini-os; \
+               GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh \
+                       mini-os \
+                       $(MINIOS_UPSTREAM_URL) \
+                       $(MINIOS_UPSTREAM_REVISION) \
+                       $(XEN_ROOT)/extras/mini-os ; \
        fi
 
 export XEN_TARGET_ARCH
diff --git a/scripts/git-checkout.sh b/scripts/git-checkout.sh
index 7dde6702b6c..49c5f4b10fd 100755
--- a/scripts/git-checkout.sh
+++ b/scripts/git-checkout.sh
@@ -3,28 +3,34 @@
 set -e
 
 if test $# -lt 3; then
-       echo "Usage: $0 <repo> <committish> <dir>"
+       echo "Usage: $0 <name> <repo> <committish> <dir>"
        exit 1
 fi
 
 GIT="${GIT:-git}"
 
-REPO="$1"
-COMMITTISH="$2"
-DIR="$3"
-
-if test \! -d "$DIR-remote"; then
-       rm -rf "$DIR-remote" "$DIR-remote.tmp"
-       mkdir -p "$DIR-remote.tmp"; rmdir "$DIR-remote.tmp"
-       "$GIT" clone "$REPO" "$DIR-remote.tmp"
-       if test "$COMMITTISH" ; then
-               cd "$DIR-remote.tmp"
-               "$GIT" fetch origin "$COMMITTISH"
-               "$GIT" branch -D dummy >/dev/null 2>&1 ||:
-               "$GIT" checkout -b dummy FETCH_HEAD
-               cd -
+NAME="$1"
+REPO="$2"
+COMMITTISH="$3"
+DIR="$4"
+
+# Setup a remote for keeping track of the specified repository
+if ! "$GIT" remote | grep -q -e"BUILD/xen/$NAME"
+then   "$GIT" remote add "BUILD/xen/$NAME" "$REPO"
+elif [ "$("$GIT" remote get-url "BUILD/xen/$NAME")" \!= "$REPO" ]
+then   "$GIT" remote set-url "BUILD/xen/$NAME" "$REPO"
+       rm -rf "$DIR"
+fi
+
+if [ -e "$DIR" ]
+then   if [ -d "$DIR" ]
+       then    exit 0
+       else    rm -rf "$DIR"
        fi
-       mv "$DIR-remote.tmp" "$DIR-remote"
 fi
-rm -f "$DIR"
-ln -sf $(basename "$DIR-remote") "$DIR"
+
+# Retrieve the specified commitish
+"$GIT" fetch -n "BUILD/xen/$NAME" "$COMMITTISH"
+
+# Checkout the commitish as a worktree
+"$GIT" worktree add -f --detach "$DIR" FETCH_HEAD
diff --git a/tools/Makefile b/tools/Makefile
index 46847fca998..5739064db98 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -111,9 +111,7 @@ endif
 #
 # Directories for external trees:
 #  ${target}-dir
-#    Used for local builds.  Usually a link to ${target}-dir-remote
-#  ${target}-dir-remote
-#    Where remote repositories are cloned
+#    Used for local builds.
 #  ${target}
 #    Where a copy of the source files are put when building a source 
 #    tarball for release
@@ -134,17 +132,15 @@ qemu-xen-dir-find:
        if test -d $(QEMU_UPSTREAM_LOC) ; then \
                mkdir -p qemu-xen-dir; \
        else \
-               export GIT=$(GIT); \
-               $(XEN_ROOT)/scripts/git-checkout.sh $(QEMU_UPSTREAM_LOC) 
$(QEMU_UPSTREAM_REVISION) $(XEN_ROOT)/tools/qemu-xen-dir ; \
+               GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh qemu-xen 
$(QEMU_UPSTREAM_LOC) $(QEMU_UPSTREAM_REVISION) $(XEN_ROOT)/tools/qemu-xen-dir ; 
\
        fi
 
 .PHONY: qemu-xen-dir-force-update
 qemu-xen-dir-force-update: qemu-xen-dir-find
        set -ex; \
        if [ "$(QEMU_UPSTREAM_REVISION)" ]; then \
-               cd qemu-xen-dir-remote; \
-               $(GIT) fetch origin; \
-               $(GIT) reset --hard $(QEMU_UPSTREAM_REVISION); \
+               rm -rf qemu-xen-dir; \
+               GIT=$(GIT)  $(XEN_ROOT)/scripts/git-checkout.sh qemu-xen 
$(QEMU_UPSTREAM_LOC) $(QEMU_UPSTREAM_REVISION) $(XEN_ROOT)/tools/qemu-xen-dir ; 
\
        fi
 
 ifeq ($(debug),y)
diff --git a/tools/firmware/Makefile b/tools/firmware/Makefile
index a14e7cadd05..0b4d1904e28 100644
--- a/tools/firmware/Makefile
+++ b/tools/firmware/Makefile
@@ -20,11 +20,11 @@ SEABIOSLD ?= $(LD)
 SEABIOS_EXTRAVERSION ?= "-Xen"
 
 ovmf-dir:
-       GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(OVMF_UPSTREAM_URL) 
$(OVMF_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/ovmf-dir
+       GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh ovmf 
$(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) 
$(XEN_ROOT)/tools/firmware/ovmf-dir
        cp ovmf-makefile ovmf-dir/Makefile;
 
 seabios-dir:
-       GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(SEABIOS_UPSTREAM_URL) 
$(SEABIOS_UPSTREAM_REVISION) $(XEN_ROOT)/tools/firmware/seabios-dir
+       GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh seabios 
$(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) 
$(XEN_ROOT)/tools/firmware/seabios-dir
        cp seabios-config seabios-dir/.config;
        $(MAKE) -C seabios-dir olddefconfig CC=$(SEABIOSCC) LD=$(SEABIOSLD)
        rm -f seabios-dir/.version
@@ -95,9 +95,8 @@ subdir-distclean-seabios-dir: .phony
 ovmf-dir-force-update: ovmf-dir
        set -ex; \
        if [ "$(OVMF_UPSTREAM_REVISION)" ]; then \
-               cd ovmf-dir-remote; \
-               $(GIT) fetch origin; \
-               $(GIT) reset --hard $(OVMF_UPSTREAM_REVISION); \
+               rm -rf ovmf-dir-remote; \
+               GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh ovmf 
$(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) 
$(XEN_ROOT)/tools/firmware/ovmf-dir ; \
        fi
 
 subdir-clean-ovmf-dir:
@@ -109,9 +108,8 @@ subdir-clean-ovmf-dir:
 seabios-dir-force-update: seabios-dir
        set -ex; \
        if [ "$(SEABIOS_UPSTREAM_REVISION)" ]; then \
-               cd seabios-dir-remote; \
-               $(GIT) fetch origin; \
-               $(GIT) reset --hard $(SEABIOS_UPSTREAM_REVISION); \
+               rm -rf seabios-dir; \
+               GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh seabios 
$(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) 
$(XEN_ROOT)/tools/firmware/seabios-dir ; \
        fi
 
 subdir-clean-seabios-dir:
-- 
2.47.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.