Build: Auto add Git LFS fallback remote in "make update"

For the official GitHub mirror and other repositories that do not include LFS
files, this adds an `lfs-fallback` remote. It will be used automatically if a
file can't be found on the regular remote.

Ref #137215

Co-authored-by: Sergey Sharybin <sergey@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/137615
This commit is contained in:
Brecht Van Lommel
2025-05-05 15:33:53 +02:00
committed by Sergey Sharybin
parent f844ed7869
commit dfccf9510d
2 changed files with 43 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ def parse_arguments() -> argparse.Namespace:
parser.add_argument("--no-libraries", action="store_true")
parser.add_argument("--no-blender", action="store_true")
parser.add_argument("--no-submodules", action="store_true")
parser.add_argument("--no-lfs-fallback", action="store_true")
parser.add_argument("--git-command", default="git")
parser.add_argument("--use-linux-libraries", action="store_true")
parser.add_argument("--architecture", type=str,
@@ -573,6 +574,31 @@ def submodules_lib_update(args: argparse.Namespace, branch: "str | None") -> str
return msg
def lfs_fallback_setup(args: argparse.Namespace) -> None:
"""
Set up an additional projects.blender.org remote, for LFS fetching fallback
in case the fork does not include LFS files.
"""
remotes = make_utils.git_get_remotes(args.git_command)
add_fallback_remote = True
fallback_remote = "lfs-fallback"
for remote in remotes:
url = make_utils.git_get_remote_url(args.git_command, remote)
if "projects.blender.org" not in url:
make_utils.git_set_config(args.git_command, f"lfs.{remote}.searchall", "true")
else:
add_fallback_remote = False
if add_fallback_remote and not make_utils.git_remote_exist(args.git_command, fallback_remote):
print_stage("Adding Git LFS fallback remote")
print("Used to fetch files from projects.blender.org if missing.")
url = "https://projects.blender.org/blender/blender.git"
push_url = "no_push"
make_utils.git_add_remote(args.git_command, fallback_remote, url, push_url)
def main() -> int:
args = parse_arguments()
@@ -594,6 +620,9 @@ def main() -> int:
if args.prune_destructive:
prune_stale_files(args)
if not args.no_lfs_fallback:
lfs_fallback_setup(args)
if not args.no_blender:
blender_skip_msg = git_update_skip(args)
if not blender_skip_msg:

View File

@@ -150,6 +150,20 @@ def git_is_remote_repository(git_command: str, repo: str) -> bool:
return exit_code == 0
def git_get_remotes(git_command: str) -> Sequence[str]:
"""Get a list of git remotes"""
# Additional check if the remote exists, for safety in case the output of this command
# changes in the future.
remotes = check_output([git_command, "remote"]).split()
return [remote for remote in remotes if git_remote_exist(git_command, remote)]
def git_add_remote(git_command: str, name: str, url: str, push_url: str) -> None:
"""Add a git remote"""
call((git_command, "remote", "add", name, url), silent=True)
call((git_command, "remote", "set-url", "--push", name, push_url), silent=True)
def git_branch(git_command: str) -> str:
"""Get current branch name."""