~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (C) 2006 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""builtin bzr commands relating to individual weave files

These should never normally need to be used by end users, but might be
of interest in debugging or data recovery.
"""

import sys

from bzrlib.commands import Command
from bzrlib.trace import warning

class cmd_weave_list(Command):
    """List the revision ids present in a weave, in alphabetical order"""

    hidden = True
    takes_args = ['weave_filename']

    def run(self, weave_filename):
        from bzrlib.weavefile import read_weave
        weave = read_weave(file(weave_filename, 'rb'))
        names = weave.versions()
        names.sort()
        print '\n'.join(names)


class cmd_weave_join(Command):
    """Join the contents of two weave files.

    The resulting weave is sent to stdout.

    This command is only intended for bzr developer use.
    """

    hidden = True
    takes_args = ['weave1', 'weave2']

    def run(self, weave1, weave2):
        from bzrlib.weavefile import read_weave, write_weave
        w1 = read_weave(file(weave1, 'rb'))
        w2 = read_weave(file(weave2, 'rb'))
        w1.join(w2)
        write_weave(w1, sys.stdout)


class cmd_weave_plan_merge(Command):
    """Show the plan for merging two versions within a weave"""
    hidden = True
    takes_args = ['weave_file', 'revision_a', 'revision_b']

    def run(self, weave_file, revision_a, revision_b):
        from bzrlib.weavefile import read_weave
        w = read_weave(file(weave_file, 'rb'))
        for state, line in w.plan_merge(revision_a, revision_b):
            # make sure to print every line with a newline, even if it doesn't
            # really have one
            if not line:
                continue
            if line[-1] != '\n':
                state += '!eol'
                line += '\n'
            if '\n' in line[:-1]:
                warning("line in weave contains embedded newline: %r" % line)
            print '%15s | %s' % (state, line),

class cmd_weave_merge_text(Command):
    """Debugging command to merge two texts of a weave"""
    hidden = True
    takes_args = ['weave_file', 'revision_a', 'revision_b']

    def run(self, weave_file, revision_a, revision_b):
        from bzrlib.weavefile import read_weave
        w = read_weave(file(weave_file, 'rb'))
        p = w.plan_merge(revision_a, revision_b)
        sys.stdout.writelines(w.weave_merge(p))