Re: Updated handling of the git repositories

Thorsten Behrens <[email protected]> Sun, 29 Aug 2010 19:10:11 +0200
Newsgroups gmane.comp.gnome.ximian.openoffice
Message-ID <[email protected]>
Jan Holesovsky wrote:
> OK - now, after some fixes I am much more confident in this framework,
> and ask everyone to configure with --with-git for the development.
> 
Hi all,

while playing with the new framework a bit more, I found it kinda
inconvenient that the stuff below ooo-build/clone is always a
stand-alone repo. Let me explain: I tend to have several checkouts
of ooo-build on my disk, on the one hand because I play with cross-
cutting feature work (that would require costly recompilation when
reverted), and on the other because I frequently at least need the
last-released version around.

So initially, I configured the new-style ooo-build via ...
--with-git=/local/shared-sources/clone, i.e. cloning from local repo
copies. That's a lot faster, but pulling/pushing ends up in the
local repos, so that sucks, and especially for pulling, can be a
pretty hard-to-diagnose error (wtf?! I've just pulled - why don't I
see the changes just announced by Joe Hacker?!).

Enter stage git-new-workdir - that's a script from the git/contrib,
that creates a new working directory plus index from a local repo,
but shares all the rest - so pulls / pushes e.g. all go to the
original remote repo.

Attached is a patch that unconditionally makes use of
git-new-workdir - I did not push that yet, as I may be yet unaware
of nasty side-effects when using git-new-workdir. Still, I consider
that pretty darn useful.

What do you think?

-- Thorsten
0001-Integrated-git-new-workdir-cloning-to-download-scrip.patch (text/x-patch, 5 KB)
From 703d7a2cfce493190e87514fb5f565e3ab7b8ced Mon Sep 17 00:00:00 2001
From: Thorsten Behrens <[email protected]>
Date: Sun, 29 Aug 2010 18:52:43 +0200
Subject: [PATCH] Integrated git-new-workdir cloning to download script

* bin/git-new-workdir: stolen from git/contrib, git-new-workdir is
  a very nice trick to generate multiple working directories from
  the same repo (on the same disk), sharing refs & commits, but
  keeping working tree and index separate
* configure.in/download.in: tweaked configure and download to use
  lightweight git-new-workdir instead of git clone, whenever the
  repo given at --with-git=<repo> appears to be local
---
 bin/git-new-workdir |   82 +++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.in        |    6 ++++
 download.in         |    4 ++-
 3 files changed, 91 insertions(+), 1 deletions(-)
 create mode 100755 bin/git-new-workdir

diff --git a/bin/git-new-workdir b/bin/git-new-workdir
new file mode 100755
index 0000000..3ad2c0c
--- /dev/null
+++ b/bin/git-new-workdir
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+usage () {
+	echo "usage:" $@
+	exit 127
+}
+
+die () {
+	echo $@
+	exit 128
+}
+
+if test $# -lt 2 || test $# -gt 3
+then
+	usage "$0 <repository> <new_workdir> [<branch>]"
+fi
+
+orig_git=$1
+new_workdir=$2
+branch=$3
+
+# want to make sure that what is pointed to has a .git directory ...
+git_dir=$(cd "$orig_git" 2>/dev/null &&
+  git rev-parse --git-dir 2>/dev/null) ||
+  die "Not a git repository: \"$orig_git\""
+
+case "$git_dir" in
+.git)
+	git_dir="$orig_git/.git"
+	;;
+.)
+	git_dir=$orig_git
+	;;
+esac
+
+# don't link to a configured bare repository
+isbare=$(git --git-dir="$git_dir" config --bool --get core.bare)
+if test ztrue = z$isbare
+then
+	die "\"$git_dir\" has core.bare set to true," \
+		" remove from \"$git_dir/config\" to use $0"
+fi
+
+# don't link to a workdir
+if test -L "$git_dir/config"
+then
+	die "\"$orig_git\" is a working directory only, please specify" \
+		"a complete repository."
+fi
+
+# don't recreate a workdir over an existing repository
+if test -e "$new_workdir"
+then
+	die "destination directory '$new_workdir' already exists."
+fi
+
+# make sure the links use full paths
+git_dir=$(cd "$git_dir"; pwd)
+
+# create the workdir
+mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
+
+# create the links to the original repo.  explicitly exclude index, HEAD and
+# logs/HEAD from the list since they are purely related to the current working
+# directory, and should not be shared.
+for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
+do
+	case $x in
+	*/*)
+		mkdir -p "$(dirname "$new_workdir/.git/$x")"
+		;;
+	esac
+	ln -s "$git_dir/$x" "$new_workdir/.git/$x"
+done
+
+# now setup the workdir
+cd "$new_workdir"
+# copy the HEAD from the original repository as a default branch
+cp "$git_dir/HEAD" .git/HEAD
+# checkout the branch (either the same as HEAD from the original repository, or
+# the one that was asked for)
+git checkout -f $branch
diff --git a/configure.in b/configure.in
index e30ce36..c5e8b9b 100644
--- a/configure.in
+++ b/configure.in
@@ -1574,14 +1574,19 @@ AC_MSG_RESULT([$build_product])
 
 AC_MSG_CHECKING([whether to use git to get the up-stream sources])
 OOO_GIT=
+OOO_GIT_ACTION=
 CLONEDIR="$BASEDIR/clone"
 RAWBUILDDIR="$BASEDIR/rawbuild"
 if test \( -z "$with_git" -a -f "$SRCDIR/$CVSTAG-bootstrap.tar.bz2" \) -o "$with_git" = "no"; then
     AC_MSG_RESULT([no])
 else
     OOO_GIT="git://anongit.freedesktop.org/git/ooo-build"
+    OOO_GIT_ACTION='sub do_git_action ($$) { return "git clone " . shift; }'
     if test "$with_git" != "yes" ; then
         OOO_GIT="$with_git"
+        if test "${with_git:0:1}" = "/" ; then
+            OOO_GIT_ACTION="sub do_git_action (\$\$) { return \"$TOOLSDIR/bin/git-new-workdir \" . shift . \" \" . shift; }"
+        fi
     else
         guess=`git config remote.origin.url | sed 's#/ooo-build$##'`
         if test -n "$guess" ; then
@@ -1600,6 +1605,7 @@ else
     fi
 fi
 AC_SUBST(OOO_GIT)
+AC_SUBST(OOO_GIT_ACTION)
 AC_SUBST(CLONEDIR)
 AC_SUBST(RAWBUILDDIR)
 
diff --git a/download.in b/download.in
index cadcd50..3d1a586 100755
--- a/download.in
+++ b/download.in
@@ -222,6 +222,8 @@ sub source_file
     push @files, { 'file' => "$file", 'save_as' => "$save_as", 'is_cgit' => $is_cgit };
 }
 
+@OOO_GIT_ACTION@
+
 sub source_file_ooo($)
 {
     my ($upstream_what) = @_;
@@ -243,7 +245,7 @@ sub source_file_ooo($)
         $op = "updating" if ( -d "@CLONEDIR@/$what" );
         print "* $op from " . '@OOO_GIT@' . "/$what\n";
 
-        system( "cd @CLONEDIR@ ; if [ -d $what ] ; then cd $what ; git fetch -t origin ; else git clone " . '@OOO_GIT@' . "/$what ; fi" ) && exit 1;
+        system( "cd @CLONEDIR@ ; if [ -d $what ] ; then cd $what ; git fetch -t origin ; git fetch origin ; else " . do_git_action( '@OOO_GIT@' . "/$what", "@CLONEDIR@/$what" ) . " ; fi" ) && exit 1;
         system( "cd @CLONEDIR@/$what ; git status | grep '^# Your branch is'" );
         system( "for file in `cd git-hooks ; echo *`
                  do
-- 
1.7.1
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)

iEYEARECAAYFAkx6lHMACgkQ0atnB9QI2h+iTACgxKo3aoZy+AsKXO92g6vGz706
xAcAn3KRCoZNxMV+T65IZGb5ndQ0kqxA
=iQde
-----END PGP SIGNATURE-----