mbed-tools icon indicating copy to clipboard operation
mbed-tools copied to clipboard

Allow to fetch the latest mbed-os without the entire Git history

Open tdjastrzebski opened this issue 3 years ago • 2 comments

By default, mbed-tools new . fetches the entire Git history - that's extra 420MB ! Please allow to limit the fetch to the latest version only git clone https://github.com/ARMmbed/mbed-os --branch latest --single-branch --depth 1

tdjastrzebski avatar Aug 28 '21 08:08 tdjastrzebski

We do a shallow clone of mbed-os by default, since version 7.3.0. I ran the command to make a new example with verbose logging enabled, so you can see what options it runs with.

$ mbed-tools -vvv new .
Creating a new Mbed program at path '/private/tmp/bob'.
Downloading mbed-os and adding it to the project.
DEBUG: Searching for mbed-os.lib file at path /private/tmp/bob
DEBUG: Searching for mbed-os.lib file at path /private/tmp
DEBUG: Searching for mbed-os.lib file at path /private
DEBUG: No mbed-os.lib file found.
INFO: Creating Mbed program at path '/private/tmp/bob'
INFO: Creating git repository for the Mbed program '/private/tmp/bob'
INFO: Resolving library reference https://github.com/ARMmbed/mbed-os.
INFO: Checking out revision master for library https://github.com/ARMmbed/mbed-os.
DEBUG: Popen(['git', 'version'], cwd=/private/tmp/bob, universal_newlines=False, shell=None, istream=None)
DEBUG: Popen(['git', 'clone', '-v', '--depth=1', '--branch=master', '--progress', 'https://github.com/ARMmbed/mbed-os', '/private/tmp/bob/mbed-os'], cwd=/private/tmp/bob, universal_newlines=True, shell=None, istream=None)
$

It looks like we do: git clone -v --depth=1 --branch=master --progress https://github.com/ARMmbed/mbed-os

I then ran a git log to see what history was available. Only a single commit was shown, and "grafted" was also displayed.

$ git -C mbed-os log
commit c14396a5b619b185d344ad6dfc25f04cb330f1fc (grafted, HEAD -> master, origin/master, origin/HEAD)
Author: Martin Kojtal <[email protected]>
Date:   Fri Sep 3 15:03:31 2021 +0100

    Merge pull request #15045 from LDong-Arm/malloc_newlib_nano
    
    Workaround for a bug in malloc() from newlib-nano 4.1.0 (in GCC 10.3)

I see your suggested command uses latest instead of master, which would be for the latest released version. You can do the clone yourself however you'd like using git commands, though. To prevent mbed-tools new from cloning Mbed OS on its own, pass in the --create-only option, like mbed-tools new --create-only ..

$ mbed-tools new --create-only .
Creating a new Mbed program at path '/private/tmp/bob'
$ git clone https://github.com/ARMmbed/mbed-os --branch latest --single-branch --depth 1
Cloning into 'mbed-os'...
remote: Enumerating objects: 19956, done.
remote: Counting objects: 100% (19956/19956), done.
remote: Compressing objects: 100% (14335/14335), done.
Receiving objects: 100% (19956/19956), 62.42 MiB | 8.78 MiB/s, done.
remote: Total 19956 (delta 8992), reused 10380 (delta 4812), pack-reused 0
Resolving deltas: 100% (8992/8992), done.
Updating files: 100% (18430/18430), done.
$ git -C mbed-os log
commit 3377f083b3a6bd7a1b45ed2cea5cf083b9007527 (grafted, HEAD -> latest, tag: mbed-os-6.14.0-rc1, tag: mbed-os-6.14.0, origin/latest)
Author: mbedmain <[email protected]>
Date:   Wed Aug 18 12:44:48 2021 +0100

    Update Mbed version block
$ du -sh mbed-os
809M	mbed-os

Only the one commit of mbed-os was fetched, from the branch you've requested. This looks to save about 413 MB on disk (809M for single commit, instead of 1.2G for the entire history).

Patater avatar Sep 06 '21 12:09 Patater

mbed-tools do a shallow copy now, but this has also caveats:

  • a change to #master in mbed-os.lib does not update after a mbed-tools deploy
  • creating a PR from a shallow repo creates a funny merge of +30000 commits

maybe mbed deploy can give a hint for this or can check the deploy command it a shallow copy is used? To unshallow, this can be used (and maybe printed as hint in deploy):

git fetch --unshallow
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

JojoS62 avatar Oct 22 '21 10:10 JojoS62