Skip to content

Commit

Permalink
Save more data in sw/MIRROR using --filter=tree:0
Browse files Browse the repository at this point in the history
If git supports it, prefer the `--filter=tree:0` option to
`--filter=blob:none`, but fall back to the latter if the former is not
supported.

If using a Docker container, use neither (as before), since we don't know
whether the git in the container can read the repo we produce outside the
container.
  • Loading branch information
TimoWilken committed Feb 29, 2024
1 parent 85b8064 commit 4dd46ae
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
13 changes: 6 additions & 7 deletions alibuild_helpers/git.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try:
from shlex import quote # Python 3.3+
except ImportError:
from pipes import quote # Python 2.7
from shlex import quote
from alibuild_helpers.cmd import getstatusoutput
from alibuild_helpers.log import debug
from alibuild_helpers.scm import SCM, SCMError
Expand All @@ -12,11 +9,13 @@

def clone_speedup_options():
"""Return a list of options supported by the system git which speed up cloning."""
_, out = getstatusoutput("LANG=C git clone --filter=blob:none")
if "unknown option" not in out and "invalid filter-spec" not in out:
return ["--filter=blob:none"]
for filter_option in ("--filter=tree:0", "--filter=blob:none"):
_, out = getstatusoutput("LANG=C git clone " + filter_option)
if "unknown option" not in out and "invalid filter-spec" not in out:
return [filter_option]
return []


class Git(SCM):
name = "Git"
def checkedOutCommitName(self, directory):
Expand Down
1 change: 0 additions & 1 deletion alibuild_helpers/workarea.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ordereddict import OrderedDict

from alibuild_helpers.log import dieOnError, debug, info, error
from alibuild_helpers.git import clone_speedup_options

FETCH_LOG_NAME = "fetch-log.txt"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def dummy_exists(x):
# A few errors we should handle, together with the expected result
@patch("alibuild_helpers.build.clone_speedup_options",
new=MagicMock(return_value=["--filter=blob:none"]))
@patch("alibuild_helpers.workarea.clone_speedup_options",
@patch("alibuild_helpers.git.clone_speedup_options",
new=MagicMock(return_value=["--filter=blob:none"]))
@patch("alibuild_helpers.build.BASH", new="/bin/bash")
class BuildTestCase(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workarea.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@patch("alibuild_helpers.workarea.debug", new=MagicMock())
@patch("alibuild_helpers.workarea.info", new=MagicMock())
@patch("alibuild_helpers.workarea.clone_speedup_options",
@patch("alibuild_helpers.git.clone_speedup_options",
new=MagicMock(return_value=["--filter=blob:none"]))
class WorkareaTestCase(unittest.TestCase):

Expand Down

0 comments on commit 4dd46ae

Please sign in to comment.