Subject: Re: Efficiency of initial clone from server

From: "Shawn O. Pearce" <[email-masked]>
Date: Mon, 12 Feb 2007 12:04:03 -0500

Jon Smirl <[email-masked]> wrote:
> On 2/12/07, Jon Smirl <[email-masked]> wrote:
> >On 2/12/07, Junio C Hamano <[email-masked]> wrote:
> >> Time to learn to use --reference perhaps?
> >>
> >>         git clone --reference linux-2.6 
> >git://.../linville/wireless-dev.git
> >>
> >> where "linux-2.6" is local repository which is my personal copy
> >> of Linus's repo.
> 
> Does this use hard links so that if I whack my linux-2.6 it won't also
> destroy my wireless-dev repo?

No.  It uses a Git specific 'symlink workalike'.  We record
the path to the reference repository in the plain text file

  .git/objects/info/alternates

This file can list multiple repositories that this repository borrows
objects from.  If you delete any of those, then this repository
will likely lose access to objects it thinks should be here,
thereby totally screwing this repository.

There's also some risk with repacking or pruneing the reference
source (your linux-2.6 repository) as that repository doesn't know
what objects it has which it itself doesn't need, but which are in
use by the other repositories.

The easiest way to prevent this from destroying a repository later
on is to make your shiny new wireless-dev clone standalone by
completely repacking it after creation (*without* -l !) :

  git repack -a -d
  rm .git/objects/info/alternates

Another solution is don't clone from the remote, but instead clone
locally then update the origin and refetch:

  git clone -l -n linux-2.6 wireless-dev
  cd wireless-dev
  git config remote.origin.url git://.../linville/wireless-dev.git
  git fetch

The initial clone will setup hardlinks, but also uses the wrong
origin URL.  Hence we have to change it just before we attempt to
fetch from wireless-dev.

-- 
Shawn.