chiark / gitweb /
git-playtree-setup: Rewrite in shell and call it from Perl
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Jul 2019 00:52:05 +0000 (01:52 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Jul 2019 15:22:07 +0000 (16:22 +0100)
We want this because git-debpush is going to want this functionality
but doesn't want to include (or have a copy of) Dgit.pm.

The installation arrangements are rather ugly.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Debian/Dgit.pm
Makefile
debian/rules
git-playtree-create [new file with mode: 0755]

index 3f1d1b7bee630ddaca0d5dd52522e52f2b8f828b..9d4e78e18c2907ea47433cdd83982cedac5c3750 100644 (file)
@@ -1051,23 +1051,25 @@ sub playtree_setup (;$) {
     $t_local_git_cfg //= $local_git_cfg;
     # for use in the playtree
     # $maindir must be set, eg by calling record_maindir or fresh_playground
-    runcmd qw(git init -q);
-    runcmd qw(git config gc.auto 0);
-    foreach my $copy (qw(user.email user.name user.useConfigOnly
-                         core.sharedRepository
-                         core.compression core.looseCompression
-                         core.bigFileThreshold core.fsyncObjectFiles)) {
-       my $v = $t_local_git_cfg->{$copy};
-       next unless $v;
-       runcmd qw(git config), $copy, $_ foreach @$v;
-    }
     # this is confusing: we have
     #   .                   playtree, not a worktree, has .git/, our cwd
     #   $maindir            might be a worktree so
     #   $maindir_gitdir     contains our main working "dgit", HEAD, etc.
     #   $maindir_gitcommon  the shared stuff, including .objects
-    rmtree('.git/objects');
-    symlink "$maindir_gitcommon/objects",'.git/objects' or confess "$!";
+
+    # we need to invoke git-playtree-create via git because
+    # there may be config options it needs which are only available
+    # to us, sensibly, in @git
+
+    # And, we look for it in @INC too.  This is a bit perverse.
+    # We do this because in the Debian packages we want to have
+    # a copy of this script in each binary package, rather than
+    # making yet another .deb or tangling the dependencies.
+    # @INC is conveniently available.
+    my $newpath = join ':', +(grep { !m/:/ } @INC),
+                 '/usr/share/dgit', $ENV{PATH};
+    runcmd qw(env), "PATH=$newpath", @git, qw(playtree-create .);
+
     ensuredir '.git/info';
     open GA, "> .git/info/attributes" or confess "$!";
     print GA "* $negate_harmful_gitattrs\n" or confess "$!";
index 3a4f9e0e6b44aba9bfa9c2daa8cb22159761dbe0..c8937fc9e76133be0b4a3c7c8d868626b7eb752c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,7 @@ infraexamplesdir=$(prefix)/share/doc/dgit-infrastructure/examples
 txtdocdir=$(prefix)/share/doc/dgit
 absurddir=$(prefix)/share/dgit/absurd
 
-PROGRAMS=dgit dgit-badcommit-fixup
+PROGRAMS=dgit dgit-badcommit-fixup git-playtree-create
 MAN1PAGES=dgit.1
 
 MAN7PAGES=dgit.7                               \
index 9c2afb38b2ce68ae7634f51902230cc2428db50e..4e44118d8b245efb21a643b9de798e45c980489e 100755 (executable)
@@ -43,6 +43,7 @@ override_dh_auto_install: specpkg_install_gdp \
        make install prefix=/usr DESTDIR=debian/dgit
        make -C po install prefix=/usr DESTDIR=../debian/tmp \
                SUPPRESS_PO_UPDATE=1 S=''
+       mv debian/dgit/usr/bin/git-playtree-create debian/dgit/usr/share/dgit
        make -C po4a install DESTDIR=../debian/tmp S=''
 
 override_dh_missing:
@@ -72,6 +73,8 @@ specpkg_install_%:
 #      # Most of the Perl modules in this package live in
 #      # $(specperl).  The exception is Debian::Dgit::Infra, which
 #      # lives in $(globalperl) and adds $(specperl) to @INC.
+#      # We also abuse this for git-playtree-create.  In .debs, this
+#      # goes in the per-.deb @INC dir.  See Dgit.pm::playtree_setup.
        set -ex; \
         base=debian/$(p); \
         mod=Debian/Dgit/$(pm).pm; \
@@ -79,6 +82,7 @@ specpkg_install_%:
         dst=$${base}$(globalperl)/$${mod}; \
         mkdir -p $${dst%/*}; \
         mv -f $$src $$dst; \
+        install -m 755 git-playtree-create $${base}$(specperl); \
         perl -i -p -e 'next unless m/###substituted###/;' \
                -e 'next unless s/^# (?=unshift \@INC,)//;' \
                -e 'die unless s{q\{\S+\}}{q{$(specperl)}};' \
diff --git a/git-playtree-create b/git-playtree-create
new file mode 100755 (executable)
index 0000000..5d890a0
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/bash
+#
+# usage:
+#   rm -rf .git/some/play/thing
+#   git-playtree-setup .git/some/play/thing
+# or:
+#   mkdir .git/some/play/thing
+#   cd .git/some/play/thing
+#   git-playtree-setup .
+
+set -ex
+
+target=$1; shift
+
+case "$#.$target" in
+0.[^-]*) ;;
+*) echo >&2 'bad usage' ; exit 8 ;;
+esac
+
+[ "x$target" = x. ] || mkdir $target
+cd $target
+
+gcd=$(cd .. && git rev-parse --git-common-dir)
+case "$gcd" in
+/*) ;;
+*) gcd="../$gcd" ;;
+esac
+
+git init -q
+git config gc.auto 0
+
+unset_all () { git config --local --unset-all $key || [ $? = 5 ]; }
+
+for key in \
+                         user.email user.name user.useConfigOnly \
+                         core.sharedRepository                   \
+                         core.compression core.looseCompression  \
+                         core.bigFileThreshold core.fsyncObjectFiles \
+; do
+       unset_all
+       (
+               git --git-dir="$gcd" config -z --get-all $key || [ $? = 1 ]
+       ) | xargs -n1 -0r -- \
+               git config --local --add $key
+done
+
+rm -rf .git/objects
+ln -s "$gcd/objects" .git/objects