@matheusbsbs / matheus-bagliano / commits / 099c783767
Fork 0

git-clone --reference: work well with pack-ref'ed reference repository

Earlier we only used loose refs to anchor already existing objects. When cloning from a repository that forked relatively long time ago from the reference repository, this made the want/have exchange by fetch-pack to do unnecessary work. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 7, 2007 at 02:10 UTC 099c7837678361985ca9df1240cdaf6a42fc89f9
1 file changed +21 -35
git-clone.sh
+21 -35
@@ -178,46 +178,32 @@ esac && export GIT_DIR && git-init ${template+"$template"} || usage
178
179 if test -n "$reference"
180 then
181 + ref_git=
182 if test -d "$reference"
183 then
184 if test -d "$reference/.git/objects"
185 then
185 - reference="$reference/.git"
186 + ref_git="$reference/.git"
187 + elif test -d "$reference/objects"
188 + then
189 + ref_git="$reference"
190 fi
187 - reference=$(cd "$reference" && pwd)
188 - echo "$reference/objects" >"$GIT_DIR/objects/info/alternates"
189 - (cd "$reference" && tar cf - refs) |
190 - (cd "$GIT_DIR/refs" &&
191 - mkdir reference-tmp &&
192 - cd reference-tmp &&
193 - tar xf - &&
194 - find refs ! -type d -print |
195 - while read ref
196 - do
197 - if test -h "$ref"
198 - then
199 - # Old-style symbolic link ref. Not likely
200 - # to appear under refs/ but we might as well
201 - # deal with them.
202 - :
203 - elif test -f "$ref"
204 - then
205 - point=$(cat "$ref") &&
206 - case "$point" in
207 - 'ref: '*) ;;
208 - *) continue ;;
209 - esac
210 - fi
211 - # The above makes true ref to 'continue' and
212 - # we will come here when we are looking at
213 - # symbolic link ref or a textual symref (or
214 - # garbage, like fifo).
215 - # The true ref pointed at by it is enough to
216 - # ensure that we do not fetch objects reachable
217 - # from it.
218 - rm -f "$ref"
219 - done
220 - )
191 + fi
192 + if test -n "$ref_git"
193 + then
194 + ref_git=$(cd "$ref_git" && pwd)
195 + echo "$ref_git/objects" >"$GIT_DIR/objects/info/alternates"
196 + (
197 + GIT_DIR="$ref_git" git for-each-ref \
198 + --format='%(objectname) %(*objectname)'
199 + ) |
200 + while read a b
201 + do
202 + test -z "$a" ||
203 + git update-ref "refs/reference-tmp/$a" "$a"
204 + test -z "$b" ||
205 + git update-ref "refs/reference-tmp/$b" "$b"
206 + done
207 else
208 die "reference repository '$reference' is not a local directory."
209 fi