# 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/.
import re import tempfile
from wptrunner import update as wptupdate from wptrunner.update.tree import Commit, CommitMessage, get_unique_name
# TODO: The extra methods for upstreaming patches from a # hg checkout
class GitTree(wptupdate.tree.GitTree): def __init__(self, *args, **kwargs): """Extension of the basic GitTree with extra methods for
transfering patches"""
commit_cls = kwargs.pop("commit_cls", Commit)
wptupdate.tree.GitTree.__init__(self, *args, **kwargs)
self.commit_cls = commit_cls
def create_branch(self, name, ref=None): """Create a named branch,
:param name: String representing the branch name.
:param ref: None to use current HEAD or rev that the branch should point to"""
args = [] if ref isnotNone: if hasattr(ref, "sha1"):
ref = ref.sha1
args.append(ref)
self.git("branch", name, *args)
def commits_by_message(self, message, path=None): """List of commits with messages containing a given string.
:param message: The string that must be contained in the message.
:param path: Path to a file or directory the commit touches """
args = ["--pretty=format:%H", "--reverse", "-z", "--grep=%s" % message] if path isnotNone:
args.append("--")
args.append(path)
data = self.git("log", *args) return [self.commit_cls(self, sha1) for sha1 in data.split("\0")]
def log(self, base_commit=None, path=None): """List commits touching a certian path from a given base commit.
:base_param commit: Commit object for the base commit from which to log
:param path: Path that the commits must touch """
args = ["--pretty=format:%H", "--reverse", "-z"] if base_commit isnotNone:
args.append("%s.." % base_commit.sha1) if path isnotNone:
args.append("--")
args.append(path)
data = self.git("log", *args) return [self.commit_cls(self, sha1) for sha1 in data.split("\0") if sha1]
def import_patch(self, patch): """Import a patch file into the tree and commit it
:param patch: a Patch object containing the patch to import """
with tempfile.NamedTemporaryFile() as f:
f.write(patch.diff)
f.flush()
f.seek(0)
self.git("apply", "--index", f.name)
self.git("commit", "-m", patch.message.text, "--author=%s" % patch.full_author)
def rebase(self, ref, continue_rebase=False): """Rebase the current branch onto another commit.
:param ref: A Commit object for the commit to rebase onto
:param continue_rebase: Continue an in-progress rebase""" if continue_rebase:
args = ["--continue"] else: if hasattr(ref, "sha1"):
ref = ref.sha1
args = [ref]
self.git("rebase", *args)
def push(self, remote, local_ref, remote_ref, force=False): """Push local changes to a remote.
:param remote: URL of the remote to push to
:param local_ref: Local branch to push
:param remote_ref: Name of the remote branch to push to
:param force: Do a force push """
args = [] if force:
args.append("-f")
args.extend([remote, "%s:%s" % (local_ref, remote_ref)])
self.git("push", *args)
def unique_branch_name(self, prefix): """Get an unused branch name in the local tree
:param prefix: Prefix to use at the start of the branch name"""
branches = [
ref[len("refs/heads/") :] for sha1, ref in self.list_refs() if ref.startswith("refs/heads/")
] return get_unique_name(branches, prefix)
if self._backout_re.match(self.full_summary):
self.backouts = self._backout_re.findall(self.full_summary) else:
self.backouts = []
m = self._bug_re.match(self.full_summary) if m isnotNone:
self.bug, self.summary, self.reviewer = m.groups() else:
self.bug, self.summary, self.reviewer = None, self.full_summary, None
class GeckoCommit(Commit):
msg_cls = GeckoCommitMessage
def export_patch(self, path=None): """Convert a commit in the tree to a Patch with the bug number and
reviewer stripped from the message"""
args = ["--binary", "--patch", "--format=format:", "%s" % (self.sha1,)] if path isnotNone:
args.append("--")
args.append(path)
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 ist noch experimentell.