Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH git-r3 02/10] Replace 'git fetch' checkout with more efficient pseudo-shared fetch.
Date: Wed, 26 Feb 2014 12:00:15
Message-Id: 1393415954-19313-2-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCHES git-r3] Clean up and different clone type support by "Michał Górny"
1 'git fetch' uses git transport to compress and transfer all the commits
2 even though they're on a local machine -- both very slow and space
3 consuming.
4
5 Setting 'alternates' before fetching solves the issue partially since
6 the commits no longer need to be transferred. The checkout is still slow
7 since git needs to recheck all of them.
8
9 Instead, just set 'alternates' and copy the refs manually. This is
10 pretty much what 'git clone --shared' does. And we can't use 'git clone'
11 because it refuses non-empty destinations.
12
13 This also makes it possible to use the same checkout method for shallow
14 clones with <git-1.9 (git-1.9 finally allows clones and fetches using
15 shallow repos).
16 ---
17 eclass/git-r3.eclass | 15 ++++++++-------
18 1 file changed, 8 insertions(+), 7 deletions(-)
19
20 diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
21 index c00b3a0..892ed07 100644
22 --- a/eclass/git-r3.eclass
23 +++ b/eclass/git-r3.eclass
24 @@ -458,13 +458,14 @@ git-r3_checkout() {
25 # non-empty directories.
26
27 git init --quiet || die
28 - set -- git fetch --update-head-ok "${orig_repo}" \
29 - "refs/heads/*:refs/heads/*" \
30 - "refs/tags/*:refs/tags/*" \
31 - "refs/notes/*:refs/notes/*"
32 -
33 - echo "${@}" >&2
34 - "${@}" || die "git fetch into checkout dir failed"
35 + # setup 'alternates' to avoid copying objects
36 + echo "${orig_repo}/objects" > "${GIT_DIR}"/objects/info/alternates || die
37 + # now copy the refs
38 + # [htn]* safely catches heads, tags, notes without complaining
39 + # on non-existing ones, and omits internal 'git-r3' ref
40 + cp -R "${orig_repo}"/refs/[htn]* "${GIT_DIR}"/refs/ || die
41 +
42 + # (no need to copy HEAD, we will set it via checkout)
43
44 set -- git checkout --quiet
45 if [[ ${remote_ref} ]]; then
46 --
47 1.8.3.2