Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tdjastrzebski opened this issue Aug 28, 2021 · 2 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@tdjastrzebski
Copy link

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 tdjastrzebski added the enhancement New feature or request label Aug 28, 2021
@Patater
Copy link
Contributor

Patater commented Sep 6, 2021

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 Patater self-assigned this Sep 6, 2021
@JojoS62
Copy link

JojoS62 commented Oct 22, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants