Skip to content

Share objects when possible during git checkout from localmirrors - #251

Merged
James Bruten (james-bruten-mo) merged 5 commits into
MetOffice:mainfrom
jfrost-mo:add_local_mirror_error_help
Sep 4, 2026
Merged

Share objects when possible during git checkout from localmirrors#251
James Bruten (james-bruten-mo) merged 5 commits into
MetOffice:mainfrom
jfrost-mo:add_local_mirror_error_help

Conversation

@jfrost-mo

@jfrost-mo James Frost (jfrost-mo) commented Sep 4, 2026

Copy link
Copy Markdown
Member

PR Summary

Sci/Tech Reviewer:
Code Reviewer: James Bruten (@james-bruten-mo)

This directly clones the refs that are desired. Where the localmirrors exist on the same system as the new clone the objects are merely referenced instead of being copied, making it much faster, especially on high latency filesystems. A small test on my VDI gives a 3x speedup:

Command Mean [s] Min [s] Max [s] Relative
git clone --branch vn14.2 localmirrors:MetOffice/um.git 2.524 ± 0.802 1.988 4.641 3.16 ± 1.00
git clone --shared --branch vn14.2 localmirrors:MetOffice/um.git 0.799 ± 0.014 0.770 0.821 1.00

The --shared flag won't do anything for remote repositories that can't directly share objects and will be silently ignored.

I have also included an extra error message when cloning from mirrors fails. People not having their mirrors setup is a common support question; hopefully this will encourage people to actively seek out our written guidance on this. I have however left it fairly generic as the process will be different at different sites.

Code Quality Checklist

  • I have performed a self-review of my own code
  • My code follows the project's style guidelines
  • Comments have been included that aid understanding and enhance the readability of the code
  • My changes generate no new warnings
  • All automated checks in the CI pipeline have completed successfully

Testing

  • This change has been tested appropriately (please describe)

I have run an existing workflow (u-dn674) with this change and observed no change in behaviour. Clones not from the localmirror are unchanged.

Security Considerations

  • I have reviewed my changes for potential security issues

The only potential security relevant change is the sharing of objects, as that makes it possible for the owner of the local mirror to change objects after the repository has been cloned. This won't affect the checkout out code, but could affect repositories that switch between branches. Git can detect this tampering through its hashes, however I do not believe that is verified on a regular checkout.

This is unlikely to be a major issue as the owner of a mirror can already change the content of the repository before it is checked out. Additionally write access to the mirror's underlying files is a sensitive permission that should be restricted; at least at the Met Office this is restricted to only a few trusted individuals.

  • Sensitive data is properly handled (if applicable)
  • Authentication and authorisation are properly implemented (if applicable)

AI Assistance and Attribution

  • Some of the content of this change has been produced with the assistance of Generative AI tool name (e.g., Met Office Github Copilot Enterprise, Github Copilot Personal, ChatGPT GPT-4, etc) and I have followed the Simulation Systems AI policy (including attribution labels)

Sci/Tech Review

  • I understand this area of code and the changes being added
  • The proposed changes correspond to the pull request description
  • Documentation is sufficient (do documentation papers need updating)
  • Sufficient testing has been completed

(Please alert the code reviewer via a tag when you have approved the SR)

Code Review

  • All dependencies have been resolved
  • Related Issues have been properly linked and addressed
  • Code quality standards have been met
  • Tests are adequate and have passed
  • Security considerations have been addressed
  • Performance impact is acceptable

This avoids the need to separately check this in other code.
This directly clones the refs that are desired. Where the localmirrors
exist on the same system as the new clone the objects are merely
referenced instead of being copied, making it much faster, especially on
high latency filesystems. A small test on my VDI gives a 3x speedup:

| Command                                                            | Mean [s]      |Min [s]|Max [s]| Relative    |
|:-------------------------------------------------------------------|--------------:|------:|------:|------------:|
| `git clone --branch vn14.2 localmirrors:MetOffice/um.git`          | 2.524 ± 0.802 | 1.988 | 4.641 | 3.16 ± 1.00 |
| `git clone --shared --branch vn14.2 localmirrors:MetOffice/um.git` | 0.799 ± 0.014 | 0.770 | 0.821 | 1.00        |

The `--shared` flag won't do anything for remote repositories that can't
directly share objects and will be silently ignored.
People not having their mirrors setup is a common support question;
hopefully this will encourage people to actively seek out our written
guidance on this. I have however left it fairly generic as the process
will be different at different sites.
@github-actions github-actions Bot added the cla-required The CLA has not yet been signed by the author of this PR - added by GA label Sep 4, 2026
@github-actions github-actions Bot added cla-signed The CLA has been signed as part of this PR - added by GA and removed cla-required The CLA has not yet been signed by the author of this PR - added by GA labels Sep 4, 2026
@jfrost-mo James Frost (jfrost-mo) changed the title Add local mirror error help During git checkout from localmirrors share objects when possible Sep 4, 2026
@jfrost-mo
James Frost (jfrost-mo) marked this pull request as ready for review September 4, 2026 13:16

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks James, if my understanding of --shared is correct then this seems a sensible addition. Just one comment from me about the use of --branch

Comment thread github_scripts/get_git_sources.py Outdated
# Clone if the repo doesn't exist. If the mirror is local we don't copy
# the objects to make it much faster.
try:
run_command(f"git clone --shared --branch {fetch} {mirror_loc} {loc}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be able to checkout hashes as well as tags/branches, so I don't think we can do this in one step with --branch?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. There is the --revision option to clone which would do what we want here, except that it is relatively new, only being adding in git 2.49 in early 2025. Therefore we don't have it on the HPCs.

Given that I'll switch this to using an explicit checkout command.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d4ca08f. I decided to avoid adding extra complexity by accepting some performance lost from checking out the files twice, rather than having a second code path just hashes. I've also left a comment suggesting this code is upgraded when we can assume at least git 2.49.

@yaswant Yaswant Pradhan (yaswant) Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the script is already handling branch, tag, hash and we can achieve the shared optimisation without the updated git version.

For example:

REPO="um"
REF="vn14.2" # or 23785d7b7fc65364d4160e211f3593d5ec45a08c or stable
git clone --shared --no-checkout localmirrors:MetOffice/${REPO}.git  # only initialise the clone
git -C $REPO fetch origin $REF
git -C $REPO checkout $REF

You can also avoid the detached HEAD warning, by giving a local branch name, e.g.,

...
git -C $REPO fetch origin $REF:test
git -C $REPO checkout test

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the extra fetch?

git clone --shared --no-checkout localmirrors:MetOffice/um.git && git -C ./um checkout main

seems to work just fine.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and No. I suggested this as a safety net, in case the localmirror indexing has not completed during the sync cycle. Anyway, in such case the checkout should fail too.

The `--branch` option to git clone only takes branchs or tags.
@jfrost-mo James Frost (jfrost-mo) changed the title During git checkout from localmirrors share objects when possible Share objects when possible during git checkout from localmirrors Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks James. Looks good to me. I've also checked that the merging functionality hasn't been affected, and all looks good.

@james-bruten-mo
James Bruten (james-bruten-mo) merged commit 9cb84d6 into MetOffice:main Sep 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The CLA has been signed as part of this PR - added by GA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants