Boost logo

Boost :

Subject: Re: [boost] [git-help] Clone / fetch specific submodule SHA?
From: Daniel James (daniel_at_[hidden])
Date: 2013-12-24 17:37:59


On 24 December 2013 21:28, Rene Rivera <grafikrobot_at_[hidden]> wrote:
> On Tue, Dec 24, 2013 at 3:12 PM, Beman Dawes <bdawes_at_[hidden]> wrote:
>
>> On Tue, Dec 24, 2013 at 3:16 PM, Rene Rivera <grafikrobot_at_[hidden]>
>> wrote:
>>
>> > Does anyone know of a way to do a submodule update and clone that only
>> > fetches a specific SHA? In particular the SHA referenced in the
>> > superproject?
>> >
>>
>> Isn't that what git submodule update does if you give it a path to the
>> submodule? Assuming the super-project is on branch master, of course. So
>> for Boost.Timer, do:
>>
>> cd modular-boost # if needed
>> git checkout master # if needed
>> git submodule update libs/timer
>>
>> Or did I misunderstand your question?
>>
>
> Yes, and no.. submodule update "checks out" the SHA of the commit in the
> reference of the superproject. It doesn't fetch or clone anything. What I'm
> asking is if there's a way to, give that I have the superproject (shallow
> clone, or partial history) to first fetch/clone the SHA of referenced in
> the superproject *only* and then update to that fetched SHA *only*.

With recent versions of git:

git submodule update --depth 1

It's still slow though, and pretty pointless if you have a local
mirror. For older versions I think you're going to need a bit of shell
scripting. 'git submodule foreach' sets a variable with the hash, you
can then do something like the commands at
http://stackoverflow.com/a/3489576/2434 to clone it.

But 'git submodule' is pretty slow anyway, it's a shell script which
has to check lots of configuration options. Tt can be faster to
implement things yourself that doesn't bother with configuration. For
example you can read the submodules directly from the .gitmodules
file, and get their details using git ls-tree:

git config -f .gitmodules -l \
    | grep '^submodule\.\w*\.path' \
    | cut -d = -f2 \
    | xargs git ls-tree HEAD

If you just want to make a copy of a repo, and don't care about git,
it can be quicker using git archive:

git archive master | tar -x -C location

Could put those two together to make a pretty fast shell script. Or
are you doing this in python? I can try to write something if you
want.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk