Skip to content

Commit

Permalink
reset patched repos before re-syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Apr 6, 2020
1 parent 199e302 commit 3c2acc0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Expand Up @@ -218,6 +218,7 @@ step-gclient-sync: &step-gclient-sync
"$CIRCLE_REPOSITORY_URL"
if ! gclient sync --with_branch_heads --with_tags; then
python src/electron/script/reset_patched_repos.py
if ELECTRON_USE_THREE_WAY_MERGE_FOR_PATCHES=1 gclient sync -f --with_branch_heads --with_tags; then
# Re-export all the new patches now that they've been nicely 3-way
# merged
Expand Down
44 changes: 25 additions & 19 deletions script/lib/git.py
Expand Up @@ -126,7 +126,7 @@ def reset(repo):


def commit(repo, author, message):
""" Commit whatever in the index is now."""
"""Commit whatever in the index is now."""

# Let's setup committer info so git won't complain about it being missing.
# TODO: Is there a better way to set committer's name and email?
Expand All @@ -143,27 +143,33 @@ def commit(repo, author, message):
committed_successfully = (return_code == 0)
return committed_successfully

def get_upstream_head(repo):
args = [
'git',
'-C',
repo,
'rev-parse',
'--verify',
'refs/patches/upstream-head',
]
return subprocess.check_output(args).strip()

def get_commit_count(repo, commit_range):
args = [
'git',
'-C',
repo,
'rev-list',
'--count',
commit_range
]
return int(subprocess.check_output(args).strip())

def guess_base_commit(repo):
"""Guess which commit the patches might be based on"""
try:
args = [
'git',
'-C',
repo,
'rev-parse',
'--verify',
'refs/patches/upstream-head',
]
upstream_head = subprocess.check_output(args).strip()
args = [
'git',
'-C',
repo,
'rev-list',
'--count',
upstream_head + '..',
]
num_commits = subprocess.check_output(args).strip()
upstream_head = get_upstream_head(repo)
num_commits = get_commit_count(repo, upstream_head + '..')
return [upstream_head, num_commits]
except subprocess.CalledProcessError:
args = [
Expand Down
31 changes: 31 additions & 0 deletions script/reset_patched_repos.py
@@ -0,0 +1,31 @@
#!/usr/bin/env python

import argparse
import json
import subprocess


def reset_patched_repos(dirs):
for patch_dir, repo in dirs.iteritems():
args = ['git', '-C', repo, 'am', '--abort']
subprocess.call(args) # ignore failure
args = ['git', '-C', repo, 'checkout', 'refs/patches/upstream-head']
subprocess.call(args) # ignore failure


def parse_args():
parser = argparse.ArgumentParser(description='Reset patched repos')
parser.add_argument('config', nargs='+',
type=argparse.FileType('r'),
help='patches\' config(s) in the JSON format')
return parser.parse_args()


def main():
configs = parse_args().config
for config_json in configs:
reset_patched_repos(json.load(config_json))


if __name__ == '__main__':
main()

0 comments on commit 3c2acc0

Please sign in to comment.