Created
August 3, 2018 04:23
-
-
Save upsuper/dd630d3835f93476d86b7293f8ee2584 to your computer and use it in GitHub Desktop.
A filter script of `hg transplant` for coordinated landing for Stylo development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# - * - coding: UTF-8 - * - | |
import sys | |
from subprocess import Popen, PIPE | |
SERVO_PATH = r'c:\\mozilla-source\\servo' | |
msg = sys.argv[1] | |
patch = sys.argv[2] | |
patch_for_gecko = [] | |
patch_for_servo = [] | |
with open(patch, 'rb') as f: | |
in_servo_change = False | |
for line in f: | |
if line.startswith('diff --git a/servo/'): | |
in_servo_change = True | |
elif line.startswith('diff --git a/'): | |
in_servo_change = False | |
if in_servo_change: | |
patch_for_servo.append(line) | |
else: | |
patch_for_gecko.append(line) | |
def run_command(cmd, input=None): | |
if input is None: | |
p = Popen(cmd) | |
else: | |
p = Popen(cmd, stdin=PIPE) | |
input(p.stdin) | |
p.stdin.close() | |
p.wait() | |
if p.returncode != 0: | |
raise RuntimeError("Fail to execute {}".format(cmd)) | |
if patch_for_servo: | |
with open(patch, 'wb') as f: | |
f.write(''.join(patch_for_gecko)) | |
with open(msg, 'rb') as f: | |
for line in f: | |
if not line.startswith('#'): | |
msg = line | |
break | |
msg = msg.split() | |
while True: | |
last_part = msg.pop() | |
if not (last_part.startswith('r?') or last_part.startswith('r=')): | |
msg.append(last_part) | |
break | |
def write_patch(stdin): | |
for line in patch_for_servo: | |
stdin.write(line) | |
run_command(['patch', '-p2', '-d', SERVO_PATH], write_patch) | |
run_command(['git', '-C', SERVO_PATH, 'add', '-A']) | |
run_command(['git', '-C', SERVO_PATH, 'commit', '-am', ' '.join(msg)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment