Files
BrowserOS/packages/browseros/build/modules/extract/extract_commit.py
Nikhil 24e9cfd8f2 chromium 142 upgrade, new cli (#214)
* refactor 1: new typer based cli and browseros cli module

* refactor 2: fixes to context.py

* refactor 3: common/ and notify

* new sign and package module

* update .gitignore

* refactor 5: dev.py and modules for each

* refactor 6: clean-up old files

* refactor 7: organise modules fruther

* refactor 8: renaming nxtscape to browseros

* refactor 9: dev.py remove cli load

* fix: pyproject.toml

* fix: typer pretty exception disable

* refactor 10: cli/build.py set to primary

* refactor 10: cli/build.py set to primary, move OS detection

* refactor: context split, env and module dataclass

* reactor: clean and git moved ot new module type

* refactor: compile and configure

* reactor: sign and package module update

* refactor: new build.py cli

* 'refactor: remove reducant OS checks

* refactor: rename BuildContext to Context

* refactor: rename BuildModule to CommandModule

* refactor: dev.py to use the new modules

* build.py: improve help output

* remove old patching way

* clean-up: remove old build.py stuff

* refactor: move to proper yaml parsing

* clean-up: remove legacy args gating

* fix: patches issues

* fix: clean-up build.py and ars resolver

* minor: gitignore

* fix: patches.py issue

* support universal build

* fix: ENV variable and YAMLs

* fix: move compile to folder to avoid compflics

* fixes: more env fixes

* fix: build_type override in CLI fix

* fix: universal clean all archs before starting

* fix: universal build type constants

* fix: linter, extract options

* fix: linter

* fix: remove chromium_src as a not a conflicting flag

* fix: support chromium_src from cli in config mode

* fix: notify with better messages

* feat: new apply patch with --reset-to feature

* feat: refactor apply and extract into separate sub modules

* 142 patches working (#211)

* updates to build.py apply/patch

* removed all old patches

* 142 build update

* fix: get updated patches from main to 142

* fix: correct patches dir

* fix: import path

* add pyright

* fix: setup pyright

* fix: new updated patches from 137 rebased on 142

* feat: new extract_patch command

* fix: add mising side_panel build patch

* fix: extension uninstall for browseros

* fix: prefs fix

* fix: ota extension updater patch fix

* fix: llm hub and chat

* feat: unvisersal module also package individual archs

* fix: add browseros-server binaries

* fix: attach color for notify

* fix: attachment for slack

* fix: update chromium version to 142.0.7444.175

* feat: add new icons needed

* fix: disable settings in menu

* fix: uv add build-backend

* minor: chromium version bump

* clean-up: removed old files of extnesion and sidepanel

* fix: product logo generate and assets.car and appicon.icns

* feat: few chromium UI fixes

* fix: update features.yaml

* fix: features.yaml path in context

* refactor: rename to get_patches_dir()

* feat: show browserOS version in about page

* fix: copy browseros_version on the build time and rename other to offset

* bump offset

* fix: update features.yaml

* feat: load env from .env files too

* fix: enable split view

* clean-up: removed old prefs

* fix: minor import issue

* fix: linux flag update
2025-12-03 13:09:23 -08:00

112 lines
3.6 KiB
Python

"""
Extract Commit - Extract patches from a single git commit.
"""
from pathlib import Path
from typing import Optional
from ...common.context import Context
from ...common.module import CommandModule, ValidationError
from ...common.utils import log_info, log_success, log_warning
from .utils import (
GitError,
validate_git_repository,
validate_commit_exists,
get_commit_info,
)
from .common import extract_normal, extract_with_base
def extract_single_commit(
ctx: Context,
commit_hash: str,
verbose: bool = False,
force: bool = False,
include_binary: bool = False,
base: Optional[str] = None,
) -> int:
"""Extract patches from a single commit
Args:
ctx: Build context
commit_hash: Commit to extract
verbose: Show detailed output
force: Overwrite existing patches
include_binary: Include binary files
base: If provided, extract full diff from base for files in commit
Returns:
Number of patches successfully extracted
"""
# Step 1: Validate commit
if not validate_commit_exists(commit_hash, ctx.chromium_src):
raise GitError(f"Commit not found: {commit_hash}")
# Get commit info for logging
commit_info = get_commit_info(commit_hash, ctx.chromium_src)
if commit_info and verbose:
log_info(
f" Author: {commit_info['author_name']} <{commit_info['author_email']}>"
)
log_info(f" Subject: {commit_info['subject']}")
if base:
# With --base: Get files from commit, but diff from base
return extract_with_base(ctx, commit_hash, base, verbose, force, include_binary)
else:
# Normal behavior: diff against parent
return extract_normal(ctx, commit_hash, verbose, force, include_binary)
class ExtractCommitModule(CommandModule):
"""Extract patches from a single commit"""
produces = []
requires = []
description = "Extract patches from a single commit"
def validate(self, ctx: Context) -> None:
"""Validate git repository"""
import shutil
if not shutil.which("git"):
raise ValidationError("Git is not available in PATH")
if not validate_git_repository(ctx.chromium_src):
raise ValidationError(f"Not a git repository: {ctx.chromium_src}")
def execute(
self,
ctx: Context,
commit: str,
output: Optional[Path] = None,
interactive: bool = True,
verbose: bool = False,
force: bool = False,
include_binary: bool = False,
base: Optional[str] = None,
) -> None:
"""Execute extract commit
Args:
commit: Git commit reference (e.g., HEAD)
output: Output directory (unused, kept for compatibility)
interactive: Interactive mode (unused, kept for compatibility)
verbose: Show detailed output
force: Overwrite existing patches
include_binary: Include binary files
base: Extract full diff from base commit for files in COMMIT
"""
try:
count = extract_single_commit(
ctx,
commit_hash=commit,
verbose=verbose,
force=force,
include_binary=include_binary,
base=base,
)
if count == 0:
log_warning(f"No patches extracted from {commit}")
else:
log_success(f"Successfully extracted {count} patches from {commit}")
except GitError as e:
raise RuntimeError(f"Git error: {e}")