@matheusbsbs / matheus-bagliano / commits / 03febf99bc
Fork 0

git-fetch: auto-following tags.

I added things to ls-remote so that Cogito can auto-follow tags easily and correctly a while ago, but git-fetch did not use the facility. Recently added git-describe command relies on repository keeping up-to-date set of tags, which made it much more attractive to automatically follow tags, so we do that as well. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 7, 2006 at 00:48 UTC 03febf99bc77001af6709ee1c17d3dc5e71e8990
2 files changed +169 -124
Documentation/fetch-options.txt
+13 -5
@@ -10,15 +10,23 @@
10 fetches is a descendant of `<lbranch>`. This option
11 overrides that check.
12
13 +\--no-tags::
14 + By default, `git-fetch` fetches tags that point at
15 + objects that are downloaded from the remote repository
16 + and stores them locally. This option disables this
17 + automatic tag following.
18 +
19 -t, \--tags::
14 - By default, the git core utilities will not fetch and store
15 - tags under the same name as the remote repository; ask it
16 - to do so using `--tags`. Using this option will bound the
17 - list of objects pulled to the remote tags. Commits in branches
18 - beyond the tags will be ignored.
20 + Most of the tags are fetched automatically as branch
21 + heads are downloaded, but tags that do not point at
22 + objects reachable from the branch heads that are being
23 + tracked will not be fetched by this mechanism. This
24 + flag lets all tags and their associated objects be
25 + downloaded.
26
27 -u, \--update-head-ok::
28 By default `git-fetch` refuses to update the head which
29 corresponds to the current branch. This flag disables the
30 check. Note that fetching into the current branch will not
31 update the index and working directory, so use it with care.
32 +
git-fetch.sh
+156 -119
@@ -11,6 +11,7 @@ LF='
11 '
12 IFS="$LF"
13
14 +no_tags=
15 tags=
16 append=
17 force=
@@ -28,6 +29,9 @@ do
29 -t|--t|--ta|--tag|--tags)
30 tags=t
31 ;;
32 + -n|--n|--no|--no-|--no-t|--no-ta|--no-tag|--no-tags)
33 + no_tags=t
34 + ;;
35 -u|--u|--up|--upd|--upda|--updat|--update|--update-|--update-h|\
36 --update-he|--update-hea|--update-head|--update-head-|\
37 --update-head-o|--update-head-ok)
@@ -212,133 +216,166 @@ then
216 fi
217 fi
218
215 -for ref in $reflist
216 -do
217 - refs="$refs$LF$ref"
219 +fetch_main () {
220 + reflist="$1"
221 + refs=
222
219 - # These are relative path from $GIT_DIR, typically starting at refs/
220 - # but may be HEAD
221 - if expr "$ref" : '\.' >/dev/null
222 - then
223 - not_for_merge=t
224 - ref=$(expr "$ref" : '\.\(.*\)')
225 - else
226 - not_for_merge=
227 - fi
228 - if expr "$ref" : '\+' >/dev/null
229 - then
230 - single_force=t
231 - ref=$(expr "$ref" : '\+\(.*\)')
232 - else
233 - single_force=
234 - fi
235 - remote_name=$(expr "$ref" : '\([^:]*\):')
236 - local_name=$(expr "$ref" : '[^:]*:\(.*\)')
223 + for ref in $reflist
224 + do
225 + refs="$refs$LF$ref"
226
238 - rref="$rref$LF$remote_name"
227 + # These are relative path from $GIT_DIR, typically starting at refs/
228 + # but may be HEAD
229 + if expr "$ref" : '\.' >/dev/null
230 + then
231 + not_for_merge=t
232 + ref=$(expr "$ref" : '\.\(.*\)')
233 + else
234 + not_for_merge=
235 + fi
236 + if expr "$ref" : '\+' >/dev/null
237 + then
238 + single_force=t
239 + ref=$(expr "$ref" : '\+\(.*\)')
240 + else
241 + single_force=
242 + fi
243 + remote_name=$(expr "$ref" : '\([^:]*\):')
244 + local_name=$(expr "$ref" : '[^:]*:\(.*\)')
245
240 - # There are transports that can fetch only one head at a time...
241 - case "$remote" in
242 - http://* | https://*)
243 - if [ -n "$GIT_SSL_NO_VERIFY" ]; then
244 - curl_extra_args="-k"
245 - fi
246 - remote_name_quoted=$(perl -e '
247 - my $u = $ARGV[0];
248 - $u =~ s{([^-a-zA-Z0-9/.])}{sprintf"%%%02x",ord($1)}eg;
249 - print "$u";
250 - ' "$remote_name")
251 - head=$(curl -nsfL $curl_extra_args "$remote/$remote_name_quoted") &&
252 - expr "$head" : "$_x40\$" >/dev/null ||
253 - die "Failed to fetch $remote_name from $remote"
254 - echo >&2 Fetching "$remote_name from $remote" using http
255 - git-http-fetch -v -a "$head" "$remote/" || exit
256 - ;;
257 - rsync://*)
258 - TMP_HEAD="$GIT_DIR/TMP_HEAD"
259 - rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
260 - head=$(git-rev-parse --verify TMP_HEAD)
261 - rm -f "$TMP_HEAD"
262 - test "$rsync_slurped_objects" || {
263 - rsync -av --ignore-existing --exclude info \
264 - "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit
246 + rref="$rref$LF$remote_name"
247
266 - # Look at objects/info/alternates for rsync -- http will
267 - # support it natively and git native ones will do it on the remote
268 - # end. Not having that file is not a crime.
269 - rsync -q "$remote/objects/info/alternates" \
270 - "$GIT_DIR/TMP_ALT" 2>/dev/null ||
271 - rm -f "$GIT_DIR/TMP_ALT"
272 - if test -f "$GIT_DIR/TMP_ALT"
273 - then
274 - resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |
275 - while read alt
276 - do
277 - case "$alt" in 'bad alternate: '*) die "$alt";; esac
278 - echo >&2 "Getting alternate: $alt"
279 - rsync -av --ignore-existing --exclude info \
280 - "$alt" "$GIT_OBJECT_DIRECTORY/" || exit
281 - done
282 - rm -f "$GIT_DIR/TMP_ALT"
283 - fi
284 - rsync_slurped_objects=t
285 - }
286 - ;;
287 - *)
288 - # We will do git native transport with just one call later.
289 - continue ;;
290 - esac
248 + # There are transports that can fetch only one head at a time...
249 + case "$remote" in
250 + http://* | https://*)
251 + if [ -n "$GIT_SSL_NO_VERIFY" ]; then
252 + curl_extra_args="-k"
253 + fi
254 + remote_name_quoted=$(perl -e '
255 + my $u = $ARGV[0];
256 + $u =~ s{([^-a-zA-Z0-9/.])}{sprintf"%%%02x",ord($1)}eg;
257 + print "$u";
258 + ' "$remote_name")
259 + head=$(curl -nsfL $curl_extra_args "$remote/$remote_name_quoted") &&
260 + expr "$head" : "$_x40\$" >/dev/null ||
261 + die "Failed to fetch $remote_name from $remote"
262 + echo >&2 Fetching "$remote_name from $remote" using http
263 + git-http-fetch -v -a "$head" "$remote/" || exit
264 + ;;
265 + rsync://*)
266 + TMP_HEAD="$GIT_DIR/TMP_HEAD"
267 + rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
268 + head=$(git-rev-parse --verify TMP_HEAD)
269 + rm -f "$TMP_HEAD"
270 + test "$rsync_slurped_objects" || {
271 + rsync -av --ignore-existing --exclude info \
272 + "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit
273
292 - append_fetch_head "$head" "$remote" \
293 - "$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
274 + # Look at objects/info/alternates for rsync -- http will
275 + # support it natively and git native ones will do it on
276 + # the remote end. Not having that file is not a crime.
277 + rsync -q "$remote/objects/info/alternates" \
278 + "$GIT_DIR/TMP_ALT" 2>/dev/null ||
279 + rm -f "$GIT_DIR/TMP_ALT"
280 + if test -f "$GIT_DIR/TMP_ALT"
281 + then
282 + resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |
283 + while read alt
284 + do
285 + case "$alt" in 'bad alternate: '*) die "$alt";; esac
286 + echo >&2 "Getting alternate: $alt"
287 + rsync -av --ignore-existing --exclude info \
288 + "$alt" "$GIT_OBJECT_DIRECTORY/" || exit
289 + done
290 + rm -f "$GIT_DIR/TMP_ALT"
291 + fi
292 + rsync_slurped_objects=t
293 + }
294 + ;;
295 + *)
296 + # We will do git native transport with just one call later.
297 + continue ;;
298 + esac
299
295 -done
300 + append_fetch_head "$head" "$remote" \
301 + "$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
302
297 -case "$remote" in
298 -http://* | https://* | rsync://* )
299 - ;; # we are already done.
300 -*)
301 - IFS=" $LF"
302 - (
303 - git-fetch-pack "$remote" $rref || echo failed "$remote"
304 - ) |
305 - while read sha1 remote_name
306 - do
307 - case "$sha1" in
308 - failed)
309 - echo >&2 "Fetch failure: $remote"
310 - exit 1 ;;
311 - esac
312 - found=
313 - single_force=
314 - for ref in $refs
303 + done
304 +
305 + case "$remote" in
306 + http://* | https://* | rsync://* )
307 + ;; # we are already done.
308 + *)
309 + ( : subshell because we muck with IFS
310 + IFS=" $LF"
311 + (
312 + git-fetch-pack "$remote" $rref || echo failed "$remote"
313 + ) |
314 + while read sha1 remote_name
315 + do
316 + case "$sha1" in
317 + failed)
318 + echo >&2 "Fetch failure: $remote"
319 + exit 1 ;;
320 + esac
321 + found=
322 + single_force=
323 + for ref in $refs
324 + do
325 + case "$ref" in
326 + +$remote_name:*)
327 + single_force=t
328 + not_for_merge=
329 + found="$ref"
330 + break ;;
331 + .+$remote_name:*)
332 + single_force=t
333 + not_for_merge=t
334 + found="$ref"
335 + break ;;
336 + .$remote_name:*)
337 + not_for_merge=t
338 + found="$ref"
339 + break ;;
340 + $remote_name:*)
341 + not_for_merge=
342 + found="$ref"
343 + break ;;
344 + esac
345 + done
346 + local_name=$(expr "$found" : '[^:]*:\(.*\)')
347 + append_fetch_head "$sha1" "$remote" \
348 + "$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
349 + done
350 + ) || exit ;;
351 + esac
352 +
353 +}
354 +
355 +fetch_main "$reflist"
356 +
357 +# automated tag following
358 +case "$no_tags$tags" in
359 +'')
360 + taglist=$(IFS=" " &&
361 + git-ls-remote --tags "$remote" |
362 + sed -ne 's|^\([0-9a-f]*\)[ ]\(refs/tags/.*\)^{}$|\1 \2|p' |
363 + while read sha1 name
364 do
316 - case "$ref" in
317 - +$remote_name:*)
318 - single_force=t
319 - not_for_merge=
320 - found="$ref"
321 - break ;;
322 - .+$remote_name:*)
323 - single_force=t
324 - not_for_merge=t
325 - found="$ref"
326 - break ;;
327 - .$remote_name:*)
328 - not_for_merge=t
329 - found="$ref"
330 - break ;;
331 - $remote_name:*)
332 - not_for_merge=
333 - found="$ref"
334 - break ;;
335 - esac
336 - done
337 - local_name=$(expr "$found" : '[^:]*:\(.*\)')
338 - append_fetch_head "$sha1" "$remote" \
339 - "$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
340 - done || exit
341 - ;;
365 + test -f "$GIT_DIR/$name" && continue
366 + git-check-ref-format "$name" || {
367 + echo >&2 "warning: tag ${name} ignored"
368 + continue
369 + }
370 + git-cat-file -t "$sha1" >/dev/null 2>&1 || continue
371 + echo >&2 "Auto-following $name"
372 + echo ".${name}:${name}"
373 + done)
374 + case "$taglist" in
375 + '') ;;
376 + ?*)
377 + fetch_main "$taglist" ;;
378 + esac
379 esac
380
381 # If the original head was empty (i.e. no "master" yet), or