From f93bacc5c5088cbdfa34635ee5427074e99e82d4 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Fri, 20 Sep 2024 20:12:48 -0700 Subject: [PATCH] [upstream_utils] Remove unused clone_repo() function (#7091) --- upstream_utils/upstream_utils.py | 55 +------------------------------- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/upstream_utils/upstream_utils.py b/upstream_utils/upstream_utils.py index f750139f5e..72ad63eb51 100644 --- a/upstream_utils/upstream_utils.py +++ b/upstream_utils/upstream_utils.py @@ -7,59 +7,6 @@ import sys import tempfile -def clone_repo(url, treeish, shallow=True): - """Clones a Git repo at the given URL into a temp folder, checks out the - given tree-ish (either branch or tag), then returns the repo root. - - Keyword argument: - url -- The URL of the Git repo - treeish -- The tree-ish to check out (branch or tag) - shallow -- Whether to do a shallow clone - - Returns: - root -- root directory of the cloned Git repository - """ - cwd = os.getcwd() - if url.startswith("file://"): - os.chdir(os.path.dirname(url[7:])) - else: - os.chdir(tempfile.gettempdir()) - - repo = os.path.basename(url) - dest = os.path.join(os.getcwd(), repo) - if dest.endswith(".git"): - dest = dest[:-4] - - # Clone Git repository into current directory or update it - if not os.path.exists(dest): - cmd = ["git", "clone"] - if shallow: - cmd += ["--branch", treeish, "--depth", "1"] - subprocess.run(cmd + [url, dest]) - os.chdir(dest) - else: - os.chdir(dest) - subprocess.run(["git", "fetch", "origin", treeish]) - - # Get list of heads - # Example output of "git ls-remote --heads": - # From https://gitlab.com/libeigen/eigen.git - # 77c66e368c7e355f8be299659f57b0ffcaedb505 refs/heads/3.4 - # 3e006bfd31e4389e8c5718c30409cddb65a73b04 refs/heads/master - ls_out = subprocess.check_output(["git", "ls-remote", "--heads"]).decode().rstrip() - heads = [x.split()[1] for x in ls_out.split("\n")[1:]] - - if f"refs/heads/{treeish}" in heads: - # Checking out the remote branch avoids needing to handle syncing a - # preexisting local one - subprocess.run(["git", "checkout", f"origin/{treeish}"]) - else: - subprocess.run(["git", "checkout", treeish]) - - os.chdir(cwd) - return dest - - def get_repo_root(): """Returns the Git repository root as an absolute path. @@ -558,7 +505,7 @@ class Lib: ) parser_rebase.add_argument("new_tag", help="The tag to rebase onto") - parser_format_patch = subparsers.add_parser( + subparsers.add_parser( "format-patch", help="Generates patch files for the upstream repository and moves them into the upstream_utils patch directory", )