Author: NicolasPierron
Date: Sat Aug 20 14:29:57 2011
New Revision: 28709
URL: https://svn.nixos.org/websvn/nix/?rev=28709&sc=1
Log:
Replace fetchgit default builder by a wrapper around nix-prefect-git.
Modified:
nixpkgs/trunk/pkgs/build-support/fetchgit/builder.sh
nixpkgs/trunk/pkgs/build-support/fetchgit/default.nix
nixpkgs/trunk/pkgs/build-support/fetchgit/nix-prefetch-git
Modified: nixpkgs/trunk/pkgs/build-support/fetchgit/builder.sh
==============================================================================
--- nixpkgs/trunk/pkgs/build-support/fetchgit/builder.sh Sat Aug 20
07:55:53 2011 (r28708)
+++ nixpkgs/trunk/pkgs/build-support/fetchgit/builder.sh Sat Aug 20
14:29:57 2011 (r28709)
@@ -6,31 +6,6 @@
header "exporting $url (rev $rev) into $out"
-git init $out
-cd $out
-git remote add origin "$url"
-git fetch --progress origin
-git remote set-head origin -a || (
- test -n "$rev" && echo "that's ok, we want $rev" || exit 1)
-
-if test -n "$rev"; then
- echo "Trying to checkout: $rev"
- parsed_rev=$(
- git rev-parse --verify "$rev" 2>/dev/null ||
- git rev-parse --verify origin/"$rev" 2>/dev/null
- )
- git reset --hard $parsed_rev
- git checkout -b __nixos_build__
-else
- git checkout -b __nixos_build__ origin/HEAD
-fi
-
-if test -f .gitmodules; then
- git submodule update --init
-fi
-
-if test -z "$leaveDotGit"; then
- find $out -name .git\* | xargs rm -rf
-fi
+$fetcher --builder --url "$url" --out "$out" --rev "$rev"
${leaveDotGit:+--leave-dotGit}
stopNest
Modified: nixpkgs/trunk/pkgs/build-support/fetchgit/default.nix
==============================================================================
--- nixpkgs/trunk/pkgs/build-support/fetchgit/default.nix Sat Aug 20
07:55:53 2011 (r28708)
+++ nixpkgs/trunk/pkgs/build-support/fetchgit/default.nix Sat Aug 20
14:29:57 2011 (r28709)
@@ -26,6 +26,7 @@
stdenv.mkDerivation {
name = "git-export";
builder = ./builder.sh;
+ fetcher = ./nix-prefetch-git;
buildInputs = [git];
outputHashAlgo = if sha256 == "" then "md5" else "sha256";
Modified: nixpkgs/trunk/pkgs/build-support/fetchgit/nix-prefetch-git
==============================================================================
--- nixpkgs/trunk/pkgs/build-support/fetchgit/nix-prefetch-git Sat Aug 20
07:55:53 2011 (r28708)
+++ nixpkgs/trunk/pkgs/build-support/fetchgit/nix-prefetch-git Sat Aug 20
14:29:57 2011 (r28709)
@@ -3,26 +3,64 @@
url=$1
rev=$2
expHash=$3
-
hashType=$NIX_HASH_ALGO
-if test -z "$hashType"; then
- hashType=sha256
+deepClone=$NIX_PREFETCH_GIT_DEEP_CLONE
+leaveDotGit=$NIX_PREFETCH_GIT_LEAVE_DOT_GIT
+builder=
+
+if test -n "$deepClone"; then
+ deepClone=true
+else
+ deepClone=false
+fi
+
+if test "$leaveDotGit" != 1; then
+ leaveDotGit=
+else
+ leaveDotGit=true
fi
+
+argi=0
+argfun=""
+for arg; do
+ if test -z "$argfun"; then
+ case $arg in
+ --out) argfun=set_out;;
+ --url) argfun=set_url;;
+ --rev) argfun=set_rev;;
+ --hash) argfun=set_hashType;;
+ --deepClone) deepClone=true;;
+ --no-deepClone) deepClone=false;;
+ --leave-dotGit) leaveDotGit=true;;
+ --keep-dotGit) leaveDotGit=;;
+ --builder) builder=true;;
+ *)
+ argi=$(($argi + 1))
+ case $argi in
+ 1) url=$arg;;
+ 2) rev=$arg;;
+ 3) expHash=$arg;;
+ *) exit 1;;
+ esac
+ ;;
+ esac
+ else
+ case $argfun in
+ set_*)
+ var=$(echo $argfun | sed 's,^set_,,')
+ eval $var=$arg
+ ;;
+ esac
+ argfun=""
+ fi
+done
+
if test -z "$url"; then
echo "syntax: nix-prefetch-git URL [REVISION [EXPECTED-HASH]]" >&2
exit 1
fi
-# If the hash was given, a file with that hash may already be in the
-# store.
-if test -n "$expHash"; then
- finalPath=$(nix-store --print-fixed-path --recursive "$hashType"
"$expHash" git-export)
- if ! nix-store --check-validity "$finalPath" 2> /dev/null; then
- finalPath=
- fi
- hash=$expHash
-fi
init_remote(){
local url=$1;
@@ -51,8 +89,8 @@
hash=$(hash_from_ref $ref);
fi;
- git fetch origin || return 1
- git checkout $hash || return 1
+ git fetch ${builder:+--progress} origin || return 1
+ git checkout -b fetchgit $hash || return 1
}
# Fetch only a branch/tag and checkout it.
@@ -60,7 +98,7 @@
local hash="$1";
local ref="$2";
- if test -n "$NIX_PREFETCH_GIT_DEEP_CLONE"; then
+ if "$deepClone"; then
# The caller explicitly asked for a deep clone. Deep clones
# allow "git describe" and similar tools to work. See
# http://thread.gmane.org/gmane.linux.distributions.nixos/3569
@@ -74,8 +112,8 @@
if test -n "$ref"; then
# --depth option is ignored on http repository.
- git fetch --depth 1 origin +"$ref" || return 1
- git checkout FETCH_HEAD || return 1
+ git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
+ git checkout -b fetchgit FETCH_HEAD || return 1
else
return 1;
fi;
@@ -120,7 +158,7 @@
# Checkout linked sources.
init_submodules;
- if [ -f .topdeps ]; then
+ if [ -z "$builder" -a -f .topdeps ]; then
if tg help 2>&1 > /dev/null
then
echo "populating TopGit branches..."
@@ -134,56 +172,83 @@
cd $top;
}
-# If we don't know the hash or a path with that hash doesn't exist,
-# download the file and add it to the store.
-if test -z "$finalPath"; then
-
- tmpPath=/tmp/git-checkout-tmp-$$
- tmpFile=$tmpPath/git-export
- mkdir $tmpPath $tmpFile
-
- trap "rm -rf $tmpPath" EXIT
+clone_user_rev() {
+ local dir="$1"
+ local url="$2"
+ local rev="$3"
# Perform the checkout.
case "$rev" in
HEAD|refs/*)
- clone "$tmpFile" "$url" "" "$rev" 1>&2;;
+ clone "$dir" "$url" "" "$rev" 1>&2;;
[0-9a-f]*)
if test -z "$(echo $rev | tr -d 0123456789abcdef)"; then
- clone "$tmpFile" "$url" "$rev" "" 1>&2;
+ clone "$dir" "$url" "$rev" "" 1>&2;
else
echo 1>&2 "Bad commit hash or bad reference.";
exit 1;
fi;;
"")
- clone "$tmpFile" "$url" "" "HEAD" 1>&2;;
+ clone "$dir" "$url" "" "HEAD" 1>&2;;
esac
# Allow doing additional processing before .git removal
eval "$NIX_PREFETCH_GIT_CHECKOUT_HOOK"
- if test "$NIX_PREFETCH_GIT_LEAVE_DOT_GIT" != 1
- then
+ if test -z "$leaveDotGit"; then
echo "removing \`.git'..." >&2
- rm -rf $tmpFile/.git
+ find $out -name .git\* | xargs rm -rf
fi
+}
- # Compute the hash.
- hash=$(nix-hash --type $hashType $hashFormat $tmpFile)
- if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
-
- # Add the downloaded file to the Nix store.
- finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)
-
- if test -n "$expHash" -a "$expHash" != "$hash"; then
- echo "hash mismatch for URL \`$url'"
- exit 1
- fi
-fi
-
-if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi
-
-echo $hash
-
-if test -n "$PRINT_PATH"; then
- echo $finalPath
-fi
+if test -n "$builder"; then
+ mkdir $out
+ clone_user_rev "$out" "$url" "$rev"
+else
+ if test -z "$hashType"; then
+ hashType=sha256
+ fi
+
+ # If the hash was given, a file with that hash may already be in the
+ # store.
+ if -n "$expHash"; then
+ finalPath=$(nix-store --print-fixed-path --recursive "$hashType"
"$expHash" git-export)
+ if ! nix-store --check-validity "$finalPath" 2> /dev/null; then
+ finalPath=
+ fi
+ hash=$expHash
+ fi
+
+ # If we don't know the hash or a path with that hash doesn't exist,
+ # download the file and add it to the store.
+ if test -z "$finalPath"; then
+
+ tmpPath=/tmp/git-checkout-tmp-$$
+ tmpFile=$tmpPath/git-export
+ mkdir $tmpPath $tmpFile
+
+ trap "rm -rf $tmpPath" EXIT
+
+ # Perform the checkout.
+ clone_user_rev "$tmpFile" "$url" "$rev"
+
+ # Compute the hash.
+ hash=$(nix-hash --type $hashType $hashFormat $tmpFile)
+ if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
+
+ # Add the downloaded file to the Nix store.
+ finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)
+
+ if test -n "$expHash" -a "$expHash" != "$hash"; then
+ echo "hash mismatch for URL \`$url'"
+ exit 1
+ fi
+ fi
+
+ if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi
+
+ echo $hash
+
+ if test -n "$PRINT_PATH"; then
+ echo $finalPath
+ fi
+fi
\ No newline at end of file
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits