Skip to content

Instantly share code, notes, and snippets.

@sivel
Created December 6, 2016 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivel/ce61ff595c0f3bf077b7a42ec3492f22 to your computer and use it in GitHub Desktop.
Save sivel/ce61ff595c0f3bf077b7a42ec3492f22 to your computer and use it in GitHub Desktop.
Migrate mailbox patch for ansible repo merge
import re
import sys
import requests
DIFF_GIT_RE = re.compile(r'^(diff --git a/)([^ ]+ b/)([^ ]+)$', re.M)
STAT_RE = re.compile(r'^(\s+)([^ ]+\s+\|\s+\d+\s+[+-]+)$', re.M)
MINUS_PLUS_RE = re.compile(r'^((?:-|\+){3} [ab]/)(.+)$', re.M)
r = requests.get('%s.patch' % sys.argv[1])
r.raise_for_status()
patch = r.text
patch = DIFF_GIT_RE.sub(
r'\1lib/ansible/modules/\2lib/ansible/modules/\3',
patch
)
patch = STAT_RE.sub(r'\1lib/ansible/modules/\2', patch)
patch = MINUS_PLUS_RE.sub(r'\1lib/ansible/modules/\2', patch)
print patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment