Last active
December 6, 2018 15:22
-
-
Save wheaties/b3b13de025d06820ece30399ba5470b5 to your computer and use it in GitHub Desktop.
Phabricator hints.json rewrite script
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
#Assumes that the branches already exist | |
#Assumes that files contain the contents of git log --format=oneline | |
import argparse | |
import json | |
parser = argparse.ArgumentParser(description='Phabricator orphan branch file generator') | |
parser.add_argument('original', help='The unmodified original branch git log') | |
parser.add_argument('orphan', help='The rebased --onto branch git log') | |
parser.add_argument('repository', help='The repository') | |
parser.add_argument('--output', '--o', help='output file', default='hints.json') | |
parser.add_argument('--debug', action='store_true') | |
def hash_iter(filename): | |
with open(filename) as contents: | |
for line in contents: | |
if len(line): | |
yield line.split()[0] | |
def generate_content(old, new, repository): | |
for (o, n) in zip(old, new): | |
if o != n: | |
yield dict(repository=repository, hint="rewritten", old=o, new=n) | |
if __name__ == '__main__': | |
args = parser.parse_args() | |
original = hash_iter(args.original) | |
orphan = hash_iter(args.orphan) | |
content = list(generate_content(original, orphan, args.repository)) | |
if args.debug: | |
print(json.dumps(content, indent=2)) | |
else: | |
with open(args.output, 'w') as destination: | |
json.dump(content, destination, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment