tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 3a2830ce6ce6c3427e6ee535e8c9367eb1945bd0
parent 39a0a968d6e5500090b72e22dd605b4fa5005a3c
Author: Michael Froman <mfroman@mozilla.com>
Date:   Thu, 13 Nov 2025 18:37:45 +0000

Bug 2000029 - make extract-for-git.py work in both git and mercurial. r=dbaker DONTBUILD

Differential Revision: https://phabricator.services.mozilla.com/D272514

Diffstat:
Mdom/media/webrtc/third_party_build/extract-for-git.py | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 72 insertions(+), 6 deletions(-)

diff --git a/dom/media/webrtc/third_party_build/extract-for-git.py b/dom/media/webrtc/third_party_build/extract-for-git.py @@ -7,12 +7,20 @@ import re import subprocess import sys +from run_operations import ( + RepoType, + detect_repo_type, + run_git, +) + # This script extracts commits that touch third party webrtc code so they can # be imported into Git. It filters out commits that are not part of upstream # code and rewrites the paths to match upstream. Finally, the commits are # combined into a mailbox file that can be applied with `git am`. LIBWEBRTC_DIR = "third_party/libwebrtc" +repo_type = detect_repo_type() + def build_commit_list(revset, env): """Build commit list from the specified revset. @@ -21,6 +29,16 @@ def build_commit_list(revset, env): e.g. 8c08a5bb8a99::52bb9bb94661, or any other valid revset (check hg help revset). Only commits that touch libwebrtc are included. """ + if repo_type == RepoType.GIT: + if ".." not in revset and "^" not in revset: + # Single commit shas in git need to be converted to a range + # otherwise git log will return all the commits from the + # given sha back in history. + revset = f"{revset}^..{revset}" + cmd = f"git log --reverse --oneline --format=%h -r {revset} ." + commits = run_git(cmd, LIBWEBRTC_DIR) + return commits + res = subprocess.run( ["hg", "log", "-r", revset, "-M", "--template", "{node}\n", LIBWEBRTC_DIR], capture_output=True, @@ -35,7 +53,19 @@ def build_commit_list(revset, env): return [line.strip() for line in res.stdout.strip().split("\n")] -def extract_author_date(sha1, env): +def extract_git_author_date(sha1, env): + res = subprocess.run( + ["git", "show", "--no-patch", "--format=%aN <%aE>|%ai", sha1], + capture_output=True, + text=True, + env=env, + check=False, + ) + # we don't want a line break at the end of date, rstrip() before split + return res.stdout.rstrip().split("|") + + +def extract_hg_author_date(sha1, env): res = subprocess.run( ["hg", "log", "-r", sha1, "--template", "{author}|{date|isodate}"], capture_output=True, @@ -46,7 +76,18 @@ def extract_author_date(sha1, env): return res.stdout.split("|") -def extract_description(sha1, env): +def extract_git_description(sha1, env): + res = subprocess.run( + ["git", "show", "--no-patch", "--format=%B", sha1], + capture_output=True, + text=True, + env=env, + check=False, + ) + return res.stdout.rstrip() + + +def extract_hg_description(sha1, env): res = subprocess.run( ["hg", "log", "-r", sha1, "--template", "{desc}"], capture_output=True, @@ -57,7 +98,20 @@ def extract_description(sha1, env): return res.stdout -def extract_commit(sha1, env): +def extract_git_commit(sha1, env): + # an empty format string just gives us the raw diffs, cutting out all + # the header info like author, date, etc. + res = subprocess.run( + ["git", "show", "--format=", sha1], + capture_output=True, + text=True, + env=env, + check=False, + ) + return "\n" + res.stdout + + +def extract_hg_commit(sha1, env): res = subprocess.run( ["hg", "log", "-r", sha1, "-pg", "--template", "\n"], capture_output=True, @@ -118,6 +172,11 @@ def write_as_mbox(sha1, author, date, description, commit, ofile): if __name__ == "__main__": + # first, check which repo we're in, git or hg + if repo_type is None or not isinstance(repo_type, RepoType): + print("Unable to detect repo (git or hg)") + sys.exit(1) + commits = [] parser = argparse.ArgumentParser( description="Format commits for upstream libwebrtc" @@ -153,9 +212,16 @@ if __name__ == "__main__": with open("mailbox.patch", "w") as ofile: for sha1 in commits: - author, date = extract_author_date(sha1, env) - description = extract_description(sha1, env) - filtered_commit = filter_nonwebrtc(extract_commit(sha1, env)) + if repo_type == RepoType.GIT: + author, date = extract_git_author_date(sha1, env) + description = extract_git_description(sha1, env) + commit = extract_git_commit(sha1, env) + else: + author, date = extract_hg_author_date(sha1, env) + description = extract_hg_description(sha1, env) + commit = extract_hg_commit(sha1, env) + + filtered_commit = filter_nonwebrtc(commit) if len(filtered_commit) == 0: continue if args.target == "abseil-cpp":