~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave_commands.py

  • Committer: Martin Pool
  • Date: 2006-03-24 11:12:04 UTC
  • mto: This revision was merged to the branch mainline in revision 1626.
  • Revision ID: mbp@sourcefrog.net-20060324111204-447e9b834705153f
New 'weave-plan-merge' and 'weave-merge-text' commands lifted from weave.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import sys
24
24
 
25
25
from bzrlib.commands import Command
 
26
from bzrlib.trace import mutter, warning
26
27
 
27
28
class cmd_weave_list(Command):
28
29
    """List the revision ids present in a weave, in alphabetical order"""
55
56
        w2 = read_weave(file(weave2, 'rb'))
56
57
        w1.join(w2)
57
58
        write_weave(w1, sys.stdout)
 
59
 
 
60
 
 
61
class cmd_weave_plan_merge(Command):
 
62
    """Show the plan for merging two versions within a weave"""
 
63
    hidden = True
 
64
    takes_args = ['weave_file', 'revision_a', 'revision_b']
 
65
 
 
66
    def run(self, weave_file, revision_a, revision_b):
 
67
        from bzrlib.weavefile import read_weave, write_weave
 
68
        w = read_weave(file(weave_file, 'rb'))
 
69
        for state, line in w.plan_merge(revision_a, revision_b):
 
70
            # make sure to print every line with a newline, even if it doesn't
 
71
            # really have one
 
72
            if not line:
 
73
                continue
 
74
            if line[-1] != '\n':
 
75
                state += '!eol'
 
76
                line += '\n'
 
77
            if '\n' in line[:-1]:
 
78
                warning("line in weave contains embedded newline: %r" % line)
 
79
            print '%15s | %s' % (state, line),
 
80
 
 
81
class cmd_weave_merge_text(Command):
 
82
    """Debugging command to merge two texts of a weave"""
 
83
    hidden = True
 
84
    takes_args = ['weave_file', 'revision_a', 'revision_b']
 
85
 
 
86
    def run(self, weave_file, revision_a, revision_b):
 
87
        from bzrlib.weavefile import read_weave, write_weave
 
88
        w = read_weave(file(weave_file, 'rb'))
 
89
        p = w.plan_merge(revision_a, revision_b)
 
90
        sys.stdout.writelines(w.weave_merge(p))