Commit a64f9e20 authored by henry's avatar henry
Browse files

fixup! BB 41803: Add some developer tools for working on tor-browser.

TB 44367: Use function caching instead of global variables.
parent a0bff3f5
Loading
Loading
Loading
Loading
+14 −30
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ Useful tools for working on tor-browser repository.

import argparse
import atexit
import functools
import json
import os
import re
@@ -95,30 +96,27 @@ def git_lines(args: list[str]) -> Iterator[str]:
        yield line


local_root: str | None = None


@functools.cache
def get_local_root() -> str:
    """
    Get the path for the tor-browser root directory.
    :returns: The local root.
    """
    global local_root
    if local_root is None:
    try:
        # Make sure we have a matching remote in this git repository.
        if get_upstream_details()["is-browser-repo"] == "True":
                local_root = git_get(["rev-parse", "--show-toplevel"])
            return git_get(["rev-parse", "--show-toplevel"])
        else:
                local_root = ""
            return ""
    except TbDevException:
            local_root = ""
    return local_root
        return ""


def determine_upstream_details() -> dict[str, str]:
@functools.cache
def get_upstream_details() -> dict[str, str]:
    """
    :returns: Details about the upstream branch.
    Get details about the upstream repository.
    :returns: The details.
    """
    remote_urls = {
        remote: git_get(["remote", "get-url", remote])
@@ -157,20 +155,6 @@ def determine_upstream_details() -> dict[str, str]:
    return details


cached_upstream_details: None | dict[str, str] = None


def get_upstream_details() -> dict[str, str]:
    """
    Get details about the upstream repository.
    :returns: The details.
    """
    global cached_upstream_details
    if cached_upstream_details is None:
        cached_upstream_details = determine_upstream_details()
    return cached_upstream_details


class Reference:
    """Represents a git reference to a commit."""