Teach rsync transport about alternates.
For local operations and downloading and uploading via git aware protocols, use of $GIT_OBJECT_DIRECTORY/info/alternates is recommended on the server side for big projects that are derived from another one (like Linux kernel). However, dumb protocols and rsync transport needs to resolve this on the client end, which we did not bother doing until this week. I noticed we use "rsync -z" but most of our payload is already compressed, which was not quite right. This commit also fixes it. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 17, 2005 at 11:56 UTC
4447badcd22a889d656192803eff1003602839c5
3 files changed
+68
-5
git-clone.sh
+26
-2
@@ -144,8 +144,32 @@ yes,yes)
144
*)
145
case "$repo" in
146
rsync://*)
147
- rsync $quiet -avz --ignore-existing "$repo/objects/" "$D/.git/objects/" &&
148
- rsync $quiet -avz --ignore-existing "$repo/refs/" "$D/.git/refs/"
147
+ rsync $quiet -av --ignore-existing \
148
+ --exclude info "$repo/objects/" "$D/.git/objects/" &&
149
+ rsync $quiet -av --ignore-existing \
150
+ --exclude info "$repo/refs/" "$D/.git/refs/" || exit
151
+
152
+ # Look at objects/info/alternates for rsync -- http will
153
+ # support it natively and git native ones will do it on the
154
+ # remote end. Not having that file is not a crime.
155
+ rsync -q "$repo/objects/info/alternates" "$D/.git/TMP_ALT" ||
156
+ rm -f "$D/.git/TMP_ALT"
157
+ if test -f "$D/.git/TMP_ALT"
158
+ then
159
+ ( cd $D &&
160
+ . git-parse-remote &&
161
+ resolve_alternates "$repo" <"./.git/TMP_ALT" ) |
162
+ while read alt
163
+ do
164
+ case "$alt" in 'bad alternate: '*) die "$alt";; esac
165
+ case "$quiet" in
166
+ '') echo >&2 "Getting alternate: $alt" ;;
167
+ esac
168
+ rsync $quiet -av --ignore-existing \
169
+ --exclude info "$alt" "$D/.git/objects" || exit
170
+ done
171
+ rm -f "$D/.git/TMP_ALT"
172
+ fi
173
;;
174
http://*)
175
clone_dumb_http "$repo" "$D"
git-fetch.sh
+21
-3
@@ -183,12 +183,30 @@ do
183
;;
184
rsync://*)
185
TMP_HEAD="$GIT_DIR/TMP_HEAD"
186
- rsync -L "$remote/$remote_name" "$TMP_HEAD" || exit 1
186
+ rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
187
head=$(git-rev-parse TMP_HEAD)
188
rm -f "$TMP_HEAD"
189
test "$rsync_slurped_objects" || {
190
- rsync -avz --ignore-existing "$remote/objects/" \
191
- "$GIT_OBJECT_DIRECTORY/" || exit
190
+ rsync -av --ignore-existing --exclude info \
191
+ "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit
192
+
193
+ # Look at objects/info/alternates for rsync -- http will
194
+ # support it natively and git native ones will do it on the remote
195
+ # end. Not having that file is not a crime.
196
+ rsync -q "$remote/objects/info/alternates" "$GIT_DIR/TMP_ALT" ||
197
+ rm -f "$GIT_DIR/TMP_ALT"
198
+ if test -f "$GIT_DIR/TMP_ALT"
199
+ then
200
+ resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |
201
+ while read alt
202
+ do
203
+ case "$alt" in 'bad alternate: '*) die "$alt";; esac
204
+ echo >&2 "Getting alternate: $alt"
205
+ rsync -av --ignore-existing --exclude info \
206
+ "$alt" "$GIT_OBJECT_DIRECTORY/" || exit
207
+ done
208
+ rm -f "$GIT_DIR/TMP_ALT"
209
+ fi
210
rsync_slurped_objects=t
211
}
212
;;
git-parse-remote.sh
+21
@@ -153,3 +153,24 @@ get_remote_refs_for_fetch () {
153
;;
154
esac
155
}
156
+
157
+resolve_alternates () {
158
+ # original URL (xxx.git)
159
+ top_=`expr "$1" : '\([^:]*:/*[^/]*\)/'`
160
+ while read path
161
+ do
162
+ case "$path" in
163
+ \#* | '')
164
+ continue ;;
165
+ /*)
166
+ echo "$top_$path/" ;;
167
+ ../*)
168
+ # relative -- ugly but seems to work.
169
+ echo "$1/objects/$path/" ;;
170
+ *)
171
+ # exit code may not be caught by the reader.
172
+ echo "bad alternate: $path"
173
+ exit 1 ;;
174
+ esac
175
+ done
176
+}