Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  files_changed.py

  Sprache: Python
 

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

"""
Support for optimizing tasks based on the set of files that have changed.
"""

import functools
import logging
import os
from subprocess import CalledProcessError

from mozpack.path import join as join_path
from mozpack.path import match as mozpackmatch
from mozversioncontrol import InvalidRepoPath, get_repository_object

from gecko_taskgraph import GECKO
from gecko_taskgraph.util.hg import get_json_pushchangedfiles

logger = logging.getLogger(__name__)


@functools.cache
def get_changed_files(repository, revision):
    """
    Get the set of files changed in the push headed by the given revision.
    Responses are cached, so multiple calls with the same arguments are OK.
    """
    try:
        return get_json_pushchangedfiles(repository, revision)["files"]
    except KeyError:
        # We shouldn't hit this error in CI.
        if os.environ.get("MOZ_AUTOMATION"):
            raise

        # We're likely on an unpublished commit, grab changed files from
        # version control.
        return get_locally_changed_files(GECKO)


def check(params, file_patterns):
    """Determine whether any of the files changed in the indicated push to
    https://hg.mozilla.org match any of the given file patterns."""
    repository = params.get("head_repository")
    revision = params.get("head_rev")
    if not repository or not revision:
        logger.warning(
            "Missing `head_repository` or `head_rev` parameters; "
            "assuming all files have changed"
        )
        return True

    changed_files = get_changed_files(repository, revision)

    if "comm_head_repository" in params:
        repository = params.get("comm_head_repository")
        revision = params.get("comm_head_rev")
        if not revision:
            logger.warning(
                "Missing `comm_head_rev` parameters; assuming all files have changed"
            )
            return True

        changed_files |= {
            join_path("comm", file) for file in get_changed_files(repository, revision)
        }

    for pattern in file_patterns:
        for path in changed_files:
            if mozpackmatch(path, pattern):
                return True

    return False


def _get_locally_changed_files(repo):
    try:
        vcs = get_repository_object(repo)
        s = set(vcs.get_outgoing_files("AM"))
        return s
    except (InvalidRepoPath, CalledProcessError):
        return set()


class PreloadedGetLocallyChangedFiles:
    """
    Function-like class that performs eager computation of _get_locally_changed_files
    for what looks the default repo.

    The rationale is the following:
    - computing _get_locally_changed_files is relatively slow (~600ms)
    - it's already done through an external command

    So we do that in a background thread as soon as possible, so that at the
    point when we need the result, it's already "prefetched".
    """

    def __init__(self):
        self.preloaded_repo = None
        self.preloading_thread = None
        self.preloaded_answer = None

    def preload(self, repo):
        """
        Fire off preloading of get_locally_changed_files(repo).

        For the sake of simplicity, there can be only one preloaded repo.
        """
        import threading
        from pathlib import Path

        if self.preloaded_repo is not None:
            raise ValueError("Can only preload one repo")

        self.preloaded_repo = Path(repo)

        def preloading():
            self.preloaded_answer = _get_locally_changed_files(self.preloaded_repo)

        self.preloading_thread = threading.Thread(target=preloading, daemon=True)
        self.preloading_thread.start()

    @functools.cache
    def __call__(self, repo):
        if repo == self.preloaded_repo:
            # A thread can be joined many times, but it's going to happen only
            # once, thanks to @memoize.
            self.preloading_thread.join()
            return self.preloaded_answer
        return _get_locally_changed_files(repo)


get_locally_changed_files = PreloadedGetLocallyChangedFiles()

Messung V0.5 in Prozent
C=90 H=93 G=91

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002