Files
Fast-Export/plugins/branch_name_in_commit/__init__.py

24 lines
957 B
Python
Raw Normal View History

2018-12-05 09:24:15 -08:00
def build_filter(args):
return Filter(args)
class Filter:
def __init__(self, args):
args = {arg: True for arg in args.split(',')}
self.start = args.pop('start', False)
self.end = args.pop('end', False)
self.sameline = args.pop('sameline', False)
self.skip_master = args.pop('skipmaster', False)
2018-12-05 09:24:15 -08:00
if self.sameline and not self.start:
raise ValueError("sameline option only allowed if 'start' given")
if args:
raise ValueError("Unknown args: " + ','.join(args))
def commit_message_filter(self, commit_data):
if not (self.skip_master and commit_data['branch'] == 'master'):
if self.start:
sep = ': ' if self.sameline else '\n'
commit_data['desc'] = commit_data['branch'] + sep + commit_data['desc']
if self.end:
commit_data['desc'] = commit_data['desc'] + '\n' + commit_data['branch']