/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.5.1 by John Arbash Meinel
Just an initial working step.
1
#!/usr/bin/env python
2
"""\
3
This is an attempt to take the internal delta object, and represent
4
it as a single-file text-only changeset.
5
This should have commands for both generating a changeset,
6
and for applying a changeset.
7
"""
8
9
import bzrlib, bzrlib.commands
10
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
11
class cmd_send_changeset(bzrlib.commands.Command):
12
    """Send a bundled up changset via mail.
13
14
    If no revision has been specified, the last commited change will
15
    be sent.
16
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
17
    Subject of the mail can be specified by the --message option,
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
18
    otherwise information from the changeset log will be used.
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
19
20
    A editor will be spawned where the user may enter a description
21
    of the changeset.  The description can be read from a file with
22
    the --file FILE option.
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
23
    """
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
24
    takes_options = ['revision', 'message', 'file', 'diff-options']
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
25
    takes_args = ['to?']
26
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
27
    def run(self, to=None, message=None, revision=None, file=None,
28
            diff_options=None):
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
29
        from tempfile import TemporaryFile
30
        from bzrlib import find_branch
31
        from bzrlib.commands import BzrCommandError
32
        import gen_changeset
33
        import send_changeset
34
        import sys
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
35
        import StringIO
36
        
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
37
        if isinstance(revision, (list, tuple)):
38
            if len(revision) > 1:
39
                raise BzrCommandError('We do not support rollup-changesets yet.')
40
            revision = revision[0]
41
42
        b = find_branch('.')
43
44
        if not to:
45
            try:
46
                to = b.controlfile('x-send-address', 'rb').read().strip('\n')
47
            except:
48
                raise BzrCommandError('destination address is not known')
49
50
        if not revision:
51
            revision = b.revno()
52
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
53
        send_changeset.send_changeset(b, revision, to, message, file,
54
                                      diff_options)
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
55
0.5.1 by John Arbash Meinel
Just an initial working step.
56
class cmd_changeset(bzrlib.commands.Command):
57
    """Generate a bundled up changeset.
58
59
    This changeset contains all of the meta-information of a
60
    diff, rather than just containing the patch information.
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
61
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
62
    It will store it into FILENAME if supplied, otherwise it writes
63
    to stdout
64
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
65
    Right now, rollup changesets, or working tree changesets are
66
    not supported. This will only generate a changeset that has been
67
    committed. You can use "--revision" to specify a certain change
68
    to display.
0.5.1 by John Arbash Meinel
Just an initial working step.
69
    """
0.5.27 by John Arbash Meinel
Now capable of generating rollup changesets.
70
    takes_options = ['revision']
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
71
    takes_args = ['filename?']
0.5.1 by John Arbash Meinel
Just an initial working step.
72
    aliases = ['cset']
73
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
74
    def run(self, revision=None, filename=None):
0.5.1 by John Arbash Meinel
Just an initial working step.
75
        from bzrlib import find_branch
76
        import gen_changeset
77
        import sys
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
78
        import codecs
79
80
        if filename is None or filename == '-':
81
            outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
82
        else:
83
            f = open(filename, 'wb')
84
            outf = codecs.getwriter(bzrlib.user_encoding)(f, errors='replace')
0.5.1 by John Arbash Meinel
Just an initial working step.
85
0.5.27 by John Arbash Meinel
Now capable of generating rollup changesets.
86
        if not isinstance(revision, (list, tuple)):
87
            revision = [revision]
88
        b = find_branch('.')
0.5.1 by John Arbash Meinel
Just an initial working step.
89
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
90
        gen_changeset.show_changeset(b, revision, to_file=outf)
0.5.1 by John Arbash Meinel
Just an initial working step.
91
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
92
class cmd_verify_changeset(bzrlib.commands.Command):
93
    """Read a written changeset, and make sure it is valid.
94
95
    """
96
    takes_args = ['filename?']
97
98
    def run(self, filename=None):
99
        import sys, read_changeset
100
        if filename is None or filename == '-':
101
            f = sys.stdin
102
        else:
103
            f = open(filename, 'rb')
104
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
105
        cset_info = read_changeset.read_changeset(f)
106
        print cset_info
107
        cset = cset_info.get_changeset()
108
        print cset.entries
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
109
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
110
class cmd_apply_changeset(bzrlib.commands.Command):
111
    """Read in the given changeset, and apply it to the
112
    current tree.
113
114
    """
115
    takes_args = ['filename?']
116
    takes_options = []
117
0.5.18 by John Arbash Meinel
Some minor fixups
118
    def run(self, filename=None, reverse=False, auto_commit=False):
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
119
        from bzrlib import find_branch
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
120
        import sys
121
        import apply_changeset
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
122
123
        b = find_branch('.') # Make sure we are in a branch
124
        if filename is None or filename == '-':
125
            f = sys.stdin
126
        else:
0.5.29 by John Arbash Meinel
Added a file to put the changeset into.
127
            f = open(filename, 'U') # Universal newlines
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
128
0.5.17 by John Arbash Meinel
adding apply-changset, plus more meta information.
129
        apply_changeset.apply_changeset(b, f, reverse=reverse,
130
                auto_commit=auto_commit)
0.5.15 by John Arbash Meinel
Created an apply-changeset function, and modified output for better parsing.
131
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
132
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
133
bzrlib.commands.register_command(cmd_changeset)
134
bzrlib.commands.register_command(cmd_verify_changeset)
135
bzrlib.commands.register_command(cmd_apply_changeset)
136
bzrlib.commands.register_command(cmd_send_changeset)
137
138
bzrlib.commands.OPTIONS['reverse'] = None
139
bzrlib.commands.OPTIONS['auto-commit'] = None
140
cmd_apply_changeset.takes_options.append('reverse')
141
cmd_apply_changeset.takes_options.append('auto-commit')