2
# Copyright (C) 2009 Canonical Ltd
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""A script that converts a bzr merge .plan file into a .BASE file."""
23
def plan_lines_to_base_lines(plan_lines):
24
_ghost_warning = False
26
for line in plan_lines:
27
action, content = line.split('|', 1)
28
action = action.strip()
29
if action in ('killed-a', 'killed-b', 'killed-both', 'unchanged'):
30
# If lines were removed by a or b or both, then they must have been
31
# in the base. if unchanged, then they are copied from the base
32
base_lines.append(content)
33
elif action in ('killed-base', 'irrelevant', 'ghost-a', 'ghost-b',
35
# The first 4 are ones that are always suppressed
36
# the last 2 are lines that are in A or B, but *not* in BASE, so we
40
sys.stderr.write('Unknown action: %s\n' % (action,))
44
def plan_file_to_base_file(plan_filename):
45
if not plan_filename.endswith('.plan'):
46
sys.stderr.write('"%s" does not look like a .plan file\n'
49
plan_file = open(plan_filename, 'rb')
51
plan_lines = plan_file.readlines()
54
base_filename = plan_filename[:-4] + 'BASE'
55
base_lines = plan_lines_to_base_lines(plan_lines)
56
f = open(base_filename, 'wb')
58
f.writelines(base_lines)
65
p = optparse.OptionParser('%prog foo.plan*')
67
opts, args = p.parse_args(args)
69
sys.stderr.write('You must supply exactly a .plan file.\n')
72
plan_file_to_base_file(arg)
75
if __name__ == '__main__':
76
sys.exit(main(sys.argv[1:]))