Rev 4708: First cut at a file for converting .plan files into .BASE files. in http://bazaar.launchpad.net/~jameinel/bzr/2.0-40412-show-base-weave
John Arbash Meinel
john at arbash-meinel.com
Thu Dec 3 23:06:06 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.0-40412-show-base-weave
------------------------------------------------------------
revno: 4708
revision-id: john at arbash-meinel.com-20091203230552-vdkdxp3ly4rl3773
parent: pqm at pqm.ubuntu.com-20091202024309-7eblqn2luitz3tzs
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.0-40412-show-base-weave
timestamp: Thu 2009-12-03 17:05:52 -0600
message:
First cut at a file for converting .plan files into .BASE files.
-------------- next part --------------
=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py 2009-10-27 09:45:35 +0000
+++ b/bzrlib/merge.py 2009-12-03 23:05:52 +0000
@@ -1431,8 +1431,9 @@
plan = list(plan)
trans_id = self.tt.trans_id_file_id(file_id)
name = self.tt.final_name(trans_id) + '.plan'
- contents = ('%10s|%s' % l for l in plan)
+ contents = ('%11s|%s' % l for l in plan)
self.tt.new_file(name, self.tt.final_parent(trans_id), contents)
+ import pdb; pdb.set_trace()
textmerge = PlanWeaveMerge(plan, '<<<<<<< TREE\n',
'>>>>>>> MERGE-SOURCE\n')
return textmerge.merge_lines(self.reprocess)
@@ -1442,6 +1443,7 @@
If conflicts are encountered, .THIS and .OTHER files will be emitted,
and a conflict will be noted.
"""
+ import pdb; pdb.set_trace()
lines, conflicts = self._merged_lines(file_id)
lines = list(lines)
# Note we're checking whether the OUTPUT is binary in this case,
=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py 2009-08-26 05:38:16 +0000
+++ b/bzrlib/tree.py 2009-12-03 23:05:52 +0000
@@ -442,6 +442,7 @@
def _get_plan_merge_data(self, file_id, other, base):
from bzrlib import versionedfile
+ import pdb; pdb.set_trace()
vf = versionedfile._PlanMergeVersionedFile(file_id)
last_revision_a = self._get_file_revision(file_id, vf, 'this:')
last_revision_b = other._get_file_revision(file_id, vf, 'other:')
=== added file 'plan_to_base.py'
--- a/plan_to_base.py 1970-01-01 00:00:00 +0000
+++ b/plan_to_base.py 2009-12-03 23:05:52 +0000
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+# Copyright (C) 2009 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""A script that converts a bzr merge .plan file into a .BASE file."""
+
+import sys
+
+
+def plan_lines_to_base_lines(plan_lines):
+ _ghost_warning = False
+ base_lines = []
+ for line in plan_lines:
+ action, content = line.split('|', 1)
+ action = action.strip()
+ if action in ('killed-a', 'killed-b', 'killed-both', 'unchanged'):
+ # If lines were removed by a or b or both, then they must have been
+ # in the base. if unchanged, then they are copied from the base
+ base_lines.append(content)
+ elif action in ('killed-base', 'irrelevant', 'ghost-a', 'ghost-b',
+ 'new-a', 'new-b'):
+ # The first 4 are ones that are always suppressed
+ # the last 2 are lines that are in A or B, but *not* in BASE, so we
+ # ignore them
+ continue
+ else:
+ sys.stderr.write('Unknown action: %s\n' % (action,))
+ return base_lines
+
+
+def plan_file_to_base_file(plan_filename):
+ if not plan_filename.endswith('.plan'):
+ sys.stderr.write('"%s" does not look like a .plan file\n'
+ % (plan_filename,))
+ return
+ plan_file = open(plan_filename, 'rb')
+ try:
+ plan_lines = plan_file.readlines()
+ finally:
+ plan_file.close()
+ base_filename = plan_filename[:-4] + 'BASE'
+ base_lines = plan_lines_to_base_lines(plan_lines)
+ f = open(base_filename, 'wb')
+ try:
+ f.writelines(base_lines)
+ finally:
+ f.close()
+
+
+def main(args):
+ import optparse
+ p = optparse.OptionParser('%prog foo.plan*')
+
+ opts, args = p.parse_args(args)
+ if len(args) < 1:
+ sys.stderr.write('You must supply exactly a .plan file.\n')
+ return 1
+ for arg in args:
+ plan_file_to_base_file(arg)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
More information about the bazaar-commits
mailing list