Subject: [PATCH 2/2] Set User-Agent string in shell scripts used for fetching

From: Jakub Narebski <[email-masked]>
Date: Tue, 1 Aug 2006 11:36:54 +0200

This needs checking for shell portability.

Signed-off-by: Jakub Narebski <[email-masked]>
---
Junio C Hamano wrote:

> Jakub Narebski <[email-masked]> writes:
> 
>> By the way, I wonder why git when cloning/fetching via http protocol
>> uses e.g. "git/1.4.2.rc2.ge0bed" as User-Agent: string when fetching objects
>> and packs, and e.g. "curl/7.15.4 (i486-pc-linux-gnu) libcurl/7.15.4
>> OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5" as User-Agent: when fetching refs
>> (heads and tags) and info/refs.
> 
> "Why?", meaning if we deliberately do so for some good reason?
> 
> There isn't.
> 
> git-http-fetch uses its own User-Agent string, but the shell
> script wrappers that use curl executable do not bother setting
> customized User-Agent string; that is why.

So there :-)

 git-clone.sh     |    4 +++-
 git-fetch.sh     |    5 ++++-
 git-ls-remote.sh |    7 +++++--
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index adb752d..a9676d6 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -20,10 +20,12 @@ get_repo_base() {
 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
 	curl_extra_args="-k"
 fi
+curl_user_agent="$(git --version)"
+curl_user_agent="git/${curl_user_agent##git version }"
 
 http_fetch () {
 	# $1 = Remote, $2 = Local
-	curl -nsfL $curl_extra_args "$1" >"$2"
+	curl -nsfL $curl_extra_args $curl_user_agent "$1" >"$2"
 }
 
 clone_dumb_http () {
diff --git a/git-fetch.sh b/git-fetch.sh
index cea6e0b..6635bd5 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -291,6 +291,8 @@ fetch_main () {
 			if [ -n "$GIT_SSL_NO_VERIFY" ]; then
 				curl_extra_args="-k"
 			fi
+			curl_user_agent="$(git --version)"
+			curl_user_agent="git/${curl_user_agent##git version }"
 			max_depth=5
 			depth=0
 			head="ref: $remote_name"
@@ -302,7 +304,8 @@ fetch_main () {
 					$u =~ s{([^-a-zA-Z0-9/.])}{sprintf"%%%02x",ord($1)}eg;
 					print "$u";
 					' "$head")
-				head=$(curl -nsfL $curl_extra_args "$remote/$remote_name_quoted")
+				head=$(curl -nsfL $curl_extra_args $curl_user_agent \
+					"$remote/$remote_name_quoted")
 				depth=$( expr \( $depth + 1 \) )
 			done
 			expr "z$head" : "z$_x40\$" >/dev/null ||
diff --git a/git-ls-remote.sh b/git-ls-remote.sh
index 38122ad..32b93da 100755
--- a/git-ls-remote.sh
+++ b/git-ls-remote.sh
@@ -53,8 +53,11 @@ http://* | https://* )
 	if [ -n "$GIT_SSL_NO_VERIFY" ]; then
 		curl_extra_args="-k"
 	fi
-	curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
-		echo "failed	slurping"
+	curl_user_agent="$(git --version)"
+	curl_user_agent="git/${curl_user_agent##git version }"
+	curl -nsf $curl_extra_args $curl_user_agent --header "Pragma: no-cache" \
+		"$peek_repo/info/refs" ||
+		echo "failed slurping"
 	;;
 
 rsync://* )
-- 
1.4.1.1