Skip to content

Commit 7507e12

Browse files
authored
Merge pull request #264 from GEOS-ESM/feature/mathomp4/add-partial-clones
Add support for partial clones
2 parents bf85281 + dc705f0 commit 7507e12

File tree

7 files changed

+92
-10
lines changed

7 files changed

+92
-10
lines changed

.github/workflows/mepo.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, macos-latest]
11-
python-version: ['3.9', '3.10', '3.11', 'pypy-3.9']
11+
python-version: ['3.9', '3.10', '3.11', '3.12', 'pypy-3.9', 'pypy-3.10']
1212

1313
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616

1717
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v4
18+
uses: actions/setup-python@v5
1919
with:
2020
python-version: ${{ matrix.python-version }}
2121
cache: 'pip'

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Removed
1717

18+
## [1.52.0] - 2024-01-10
19+
20+
### Added
21+
22+
- Added new `--partial` option to `mepo clone` with two settings: `blobless` and `treeless`. If you set, `--partial=blobless` then
23+
the clone will not download blobs by using `--filter=blob:none`. If you set `--partial=treeless` then the clone will not download
24+
trees by using `--filter=tree:0`. The `blobless` option is useful for large repos that have a lot of binary files that you don't
25+
need. The `treeless` option is even more aggressive and *SHOULD NOT* be used unless you know what you are doing.
26+
- Add a new section for `.mepoconfig` to allow users to set `--partial` as a default for `mepo clone`.
27+
1828
## [1.51.1] - 2023-08-25
1929

2030
### Fixed

etc/mepoconfig-example

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# .mepoconfig is a config file a la gitconfig with sections and options.
44
#
5-
# Currently, .mepoconfig files recognize two sections: [init] and [alias]
5+
# Currently, .mepoconfig files recognize three sections: [init], [alias], and [clone].
66
#
77
# =======================================================================
88
#
@@ -24,6 +24,10 @@
2424
#
2525
# mepo clone --style postfix
2626
#
27+
# You set these options by running:
28+
#
29+
# mepo config set init.style <value>
30+
#
2731
# =======================================================================
2832
#
2933
# [alias] Section
@@ -40,3 +44,40 @@
4044
# you can only alias mepo primary commands and not "subcommands" or
4145
# "options". So you can have an alias for "commit" and for "branch",
4246
# but you can't do an option for "commit -m" or "branch create".
47+
#
48+
# You can set an alias by running:
49+
#
50+
# mepo config set alias.<alias> <command>
51+
#
52+
# =======================================================================
53+
#
54+
# [clone] Section
55+
#
56+
# The clone section currently recognizes one option, partial.
57+
# This has two allowed values: blobless and treeless
58+
#
59+
# So if you have:
60+
#
61+
# [clone]
62+
# partial = blobless
63+
#
64+
# This is equivalent to doing:
65+
#
66+
# mepo clone --partial=blobless
67+
#
68+
# which corresponds to the git clone option --filter=blob:none
69+
#
70+
# and similarly for treeless:
71+
#
72+
# [clone]
73+
# partial = treeless
74+
#
75+
# is equivalent to doing:
76+
#
77+
# mepo clone --partial=treeless
78+
#
79+
# which corresponds to the git clone option --filter=tree:0
80+
#
81+
# You set these options by running:
82+
#
83+
# mepo config set clone.partial <value>

mepo.d/cmdline/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ def __clone(self):
104104
'--allrepos',
105105
action = 'store_true',
106106
help = 'Must be passed with -b/--branch. When set, it not only checkouts out the branch/tag for the fixture, but for all the subrepositories as well.')
107+
clone.add_argument(
108+
'--partial',
109+
metavar = 'partial-type',
110+
nargs = '?',
111+
default = None,
112+
choices = ['blobless','treeless'],
113+
help = 'Style of partial clone, default: None, allowed options: %(choices)s. Note that blobless means cloning with --filter=blob:none and treeless means cloning with --filter=tree:0. NOTE: We do *not* recommend using "treeless" as it is very aggressive and will cause problems with many git commands.')
107114

108115
def __list(self):
109116
listcomps = self.subparsers.add_parser(

mepo.d/command/clone/clone.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from state.state import MepoState, StateDoesNotExistError
22
from repository.git import GitRepository
33
from command.init import init as mepo_init
4-
from utilities import shellcmd, colors
4+
from utilities import shellcmd, colors, mepoconfig
55
from urllib.parse import urlparse
66

77
import os
@@ -18,6 +18,19 @@ def run(args):
1818
if args.allrepos and not args.branch:
1919
raise RuntimeError("The allrepos option must be used with a branch/tag.")
2020

21+
# We can get the blobless and treeless options from the config or the args
22+
if args.partial:
23+
partial = args.partial
24+
elif mepoconfig.has_option('clone','partial'):
25+
allowed = ['blobless','treeless']
26+
partial = mepoconfig.get('clone','partial')
27+
if partial not in allowed:
28+
raise Exception(f'Detected partial clone type [{partial}] from .mepoconfig is not an allowed partial clone type: {allowed}')
29+
else:
30+
print(f'Found partial clone type [{partial}] in .mepoconfig')
31+
else:
32+
partial = None
33+
2134
# If you pass in a config, with clone, it could be outside the repo.
2235
# So use the full path
2336
passed_in_config = False
@@ -34,15 +47,15 @@ def run(args):
3447
last_url_node = p.path.rsplit('/')[-1]
3548
url_suffix = pathlib.Path(last_url_node).suffix
3649
if args.directory:
37-
local_clone(args.repo_url,args.branch,args.directory)
50+
local_clone(args.repo_url,args.branch,args.directory,partial)
3851
os.chdir(args.directory)
3952
else:
4053
if url_suffix == '.git':
4154
git_url_directory = pathlib.Path(last_url_node).stem
4255
else:
4356
git_url_directory = last_url_node
4457

45-
local_clone(args.repo_url,args.branch,git_url_directory)
58+
local_clone(args.repo_url,args.branch,git_url_directory,partial)
4659
os.chdir(git_url_directory)
4760

4861
# Copy the new file into the repo only if we pass it in
@@ -71,7 +84,7 @@ def run(args):
7184
recurse = comp.recurse_submodules
7285
# We need the type to handle hashes in components.yaml
7386
type = comp.version.type
74-
git.clone(version,recurse,type,comp.name)
87+
git.clone(version,recurse,type,comp.name,partial)
7588
if comp.sparse:
7689
git.sparsify(comp.sparse)
7790
print_clone_info(comp, max_namelen)
@@ -89,8 +102,12 @@ def print_clone_info(comp, name_width):
89102
ver_name_type = '({}) {}'.format(comp.version.type, comp.version.name)
90103
print('{:<{width}} | {:<s}'.format(comp.name, ver_name_type, width = name_width))
91104

92-
def local_clone(url,branch=None,directory=None):
105+
def local_clone(url,branch=None,directory=None,partial=None):
93106
cmd1 = 'git clone '
107+
if partial == 'blobless':
108+
cmd1 += '--filter=blob:none '
109+
elif partial == 'treeless':
110+
cmd1 += '--filter=tree:0 '
94111
if branch:
95112
cmd1 += '--branch {} '.format(branch)
96113
cmd1 += '--quiet {}'.format(url)

mepo.d/repository/git.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ def get_full_local_path(self):
3939
def get_remote_url(self):
4040
return self.__remote
4141

42-
def clone(self, version, recurse, type, comp_name):
42+
def clone(self, version, recurse, type, comp_name, partial=None):
4343
cmd1 = 'git clone '
44+
45+
if partial == 'blobless':
46+
cmd1 += '--filter=blob:none '
47+
elif partial == 'treeless':
48+
cmd1 += '--filter=tree:0 '
49+
4450
if recurse:
4551
cmd1 += '--recurse-submodules '
4652

mepo.d/utest/test_mepo_commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def setUpClass(cls):
5353
args.repo_url = None
5454
args.branch = None
5555
args.directory = None
56+
args.partial = 'blobless'
5657
mepo_clone.run(args)
5758
# In order to better test compare, we need to do *something*
5859
args.comp_name = ['env','cmake','fvdycore']

0 commit comments

Comments
 (0)