git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #80091 from NixOS/npregit-dumpall
477ea06Jan Tojnar
pkgs/build-support/fetchgit/nix-prefetch-git+24−17
@@ -25,7 +25,7 @@ commitDateStrict8601=
25if test -n "$deepClone"; then
25if test -n "$deepClone"; then
26 deepClone=true
26 deepClone=true
27else
27else
28− deepClone=false
28+ deepClone=
29fi
29fi
30
30
31if test "$leaveDotGit" != 1; then
31if test "$leaveDotGit" != 1; then
@@ -53,6 +53,11 @@ Options:
53 exit 1
53 exit 1
54}
54}
55
55
56+# some git commands print to stdout, which would contaminate our JSON output
57+clean_git(){
58+ git "$@" >&2
59+}
60+
56argi=0
61argi=0
57argfun=""
62argfun=""
58for arg; do
63for arg; do
@@ -65,7 +70,7 @@ for arg; do
65 --branch-name) argfun=set_branchName;;
70 --branch-name) argfun=set_branchName;;
66 --deepClone) deepClone=true;;
71 --deepClone) deepClone=true;;
67 --quiet) QUIET=true;;
72 --quiet) QUIET=true;;
68− --no-deepClone) deepClone=false;;
73+ --no-deepClone) deepClone=;;
69 --leave-dotGit) leaveDotGit=true;;
74 --leave-dotGit) leaveDotGit=true;;
70 --fetch-submodules) fetchSubmodules=true;;
75 --fetch-submodules) fetchSubmodules=true;;
71 --builder) builder=true;;
76 --builder) builder=true;;
@@ -98,9 +103,9 @@ fi
98
103
99init_remote(){
104init_remote(){
100 local url=$1
105 local url=$1
101− git init
106+ clean_git init
102− git remote add origin "$url"
107+ clean_git remote add origin "$url"
103− ( [ -n "$http_proxy" ] && git config http.proxy "$http_proxy" ) || true
108+ ( [ -n "$http_proxy" ] && clean_git config http.proxy "$http_proxy" ) || true
104}
109}
105
110
106# Return the reference of an hash if it exists on the remote repository.
111# Return the reference of an hash if it exists on the remote repository.
@@ -141,8 +146,8 @@ checkout_hash(){
141 hash=$(hash_from_ref "$ref")
146 hash=$(hash_from_ref "$ref")
142 fi
147 fi
143
148
144− git fetch -t ${builder:+--progress} origin || return 1
149+ clean_git fetch -t ${builder:+--progress} origin || return 1
145− git checkout -b "$branchName" "$hash" || return 1
150+ clean_git checkout -b "$branchName" "$hash" || return 1
146}
151}
147
152
148# Fetch only a branch/tag and checkout it.
153# Fetch only a branch/tag and checkout it.
@@ -150,7 +155,7 @@ checkout_ref(){
150 local hash="$1"
155 local hash="$1"
151 local ref="$2"
156 local ref="$2"
152
157
153− if "$deepClone"; then
158+ if [[ -n "$deepClone" ]]; then
154 # The caller explicitly asked for a deep clone. Deep clones
159 # The caller explicitly asked for a deep clone. Deep clones
155 # allow "git describe" and similar tools to work. See
160 # allow "git describe" and similar tools to work. See
156 # https://marc.info/?l=nix-dev&m=139641582514772
161 # https://marc.info/?l=nix-dev&m=139641582514772
@@ -164,8 +169,8 @@ checkout_ref(){
164
169
165 if test -n "$ref"; then
170 if test -n "$ref"; then
166 # --depth option is ignored on http repository.
171 # --depth option is ignored on http repository.
167− git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
172+ clean_git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
168− git checkout -b "$branchName" FETCH_HEAD || return 1
173+ clean_git checkout -b "$branchName" FETCH_HEAD || return 1
169 else
174 else
170 return 1
175 return 1
171 fi
176 fi
@@ -174,7 +179,7 @@ checkout_ref(){
174# Update submodules
179# Update submodules
175init_submodules(){
180init_submodules(){
176 # Add urls into .git/config file
181 # Add urls into .git/config file
177− git submodule init
182+ clean_git submodule init
178
183
179 # list submodule directories and their hashes
184 # list submodule directories and their hashes
180 git submodule status |
185 git submodule status |
@@ -248,7 +253,7 @@ make_deterministic_repo(){
248
253
249 # Remove all remote branches.
254 # Remove all remote branches.
250 git branch -r | while read -r branch; do
255 git branch -r | while read -r branch; do
251− git branch -rD "$branch" >&2
256+ clean_git branch -rD "$branch"
252 done
257 done
253
258
254 # Remove tags not reachable from HEAD. If we're exactly on a tag, don't
259 # Remove tags not reachable from HEAD. If we're exactly on a tag, don't
@@ -256,19 +261,19 @@ make_deterministic_repo(){
256 maybe_tag=$(git tag --points-at HEAD)
261 maybe_tag=$(git tag --points-at HEAD)
257 git tag --contains HEAD | while read -r tag; do
262 git tag --contains HEAD | while read -r tag; do
258 if [ "$tag" != "$maybe_tag" ]; then
263 if [ "$tag" != "$maybe_tag" ]; then
259− git tag -d "$tag" >&2
264+ clean_git tag -d "$tag"
260 fi
265 fi
261 done
266 done
262
267
263 # Do a full repack. Must run single-threaded, or else we lose determinism.
268 # Do a full repack. Must run single-threaded, or else we lose determinism.
264− git config pack.threads 1
269+ clean_git config pack.threads 1
265− git repack -A -d -f
270+ clean_git repack -A -d -f
266 rm -f .git/config
271 rm -f .git/config
267
272
268 # Garbage collect unreferenced objects.
273 # Garbage collect unreferenced objects.
269 # Note: --keep-largest-pack prevents non-deterministic ordering of packs
274 # Note: --keep-largest-pack prevents non-deterministic ordering of packs
270 # listed in .git/objects/info/packs by only using a single pack
275 # listed in .git/objects/info/packs by only using a single pack
271− git gc --prune=all --keep-largest-pack
276+ clean_git gc --prune=all --keep-largest-pack
272 )
277 )
273}
278}
274
279
@@ -369,7 +374,9 @@ print_results() {
369 "rev": "$(json_escape "$fullRev")",
374 "rev": "$(json_escape "$fullRev")",
370 "date": "$(json_escape "$commitDateStrict8601")",
375 "date": "$(json_escape "$commitDateStrict8601")",
371 "$(json_escape "$hashType")": "$(json_escape "$hash")",
376 "$(json_escape "$hashType")": "$(json_escape "$hash")",
372− "fetchSubmodules": $([[ -n "$fetchSubmodules" ]] && echo true || echo false)
377+ "fetchSubmodules": $([[ -n "$fetchSubmodules" ]] && echo true || echo false),
378+ "deepClone": $([[ -n "$deepClone" ]] && echo true || echo false),
379+ "leaveDotGit": $([[ -n "$leaveDotGit" ]] && echo true || echo false)
373}
380}
374EOF
381EOF
375 fi
382 fi