Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Use git apply to apply src/electron/patches/*.patch #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ deps = {
"vendor/node": "https://github.com/brave/node.git@7535fd34c36a40403743af5bf71c5b79b3f0bb6d",
"vendor/requests": "https://github.com/kennethreitz/requests@e4d59bedfd3c7f4f254f4f5d036587bcd8152458",
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
}

hooks = [
Expand Down
24 changes: 6 additions & 18 deletions script/apply-patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
PATCHES_DIR = os.path.join(SOURCE_ROOT, 'patches')
VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
SRC_DIR = os.path.join(SOURCE_ROOT, '..', '..', 'src')
PATCH_PY = os.path.join(VENDOR_DIR, 'python-patch', 'patch.py')
GIT_EXE = 'git'


def main():
Expand All @@ -19,35 +18,24 @@ def main():

sys.stderr.write(error + '\n')
sys.stderr.flush()
revert_changes_for_dir(PATCHES_DIR)
return 1


def apply_patches_for_dir(directory):
for root, dirs, files in os.walk(directory):
prefix = os.path.relpath(root, directory)
target = os.path.join(SRC_DIR, prefix)
args = [sys.executable, PATCH_PY, '--directory', target, '--quiet']
args = [GIT_EXE, 'apply', '--unsafe-paths', '--directory=' +
os.path.normpath(target)]
for name in sorted(files):
if not name.endswith('.patch'):
continue
patch = os.path.join(root, name)
if subprocess.call(args + [patch]):
args += [patch]
print(' '.join(args))
if subprocess.call(args):
return '{0} failed to apply'.format(os.path.basename(patch))


def revert_changes_for_dir(directory):
for root, dirs, files in reversed(list(os.walk(directory))):
prefix = os.path.relpath(root, directory)
target = os.path.join(SRC_DIR, prefix)
args = [sys.executable, PATCH_PY, '--directory', target, '--quiet',
'--revert']
for name in reversed(sorted(files)):
if not name.endswith('.patch'):
continue
patch = os.path.join(root, name)
subprocess.call(args + [patch])


if __name__ == '__main__':
sys.exit(main())