~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/commands.py

  • Committer: Aaron Bentley
  • Date: 2006-06-29 16:24:56 UTC
  • mto: This revision was merged to the branch mainline in revision 1823.
  • Revision ID: abentley@panoramicfeedback.com-20060629162456-9dbd1c2795d474dd
More notes on 'note'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
1
#!/usr/bin/env python
16
2
"""\
17
3
This is an attempt to take the internal delta object, and represent
18
4
it as a single-file text-only changeset.
22
8
 
23
9
import sys
24
10
 
25
 
from bzrlib.lazy_import import lazy_import
26
 
lazy_import(globals(), """
27
 
from bzrlib import (
28
 
    branch,
29
 
    errors,
30
 
    revision as _mod_revision,
31
 
    urlutils,
32
 
    )
33
 
""")
34
 
 
35
 
from bzrlib.commands import Command
 
11
from bzrlib.branch import Branch
 
12
from bzrlib.commands import Command, register_command
 
13
import bzrlib.errors as errors
36
14
from bzrlib.option import Option
 
15
from bzrlib.revision import (common_ancestor, MultipleRevisionSources,
 
16
                             NULL_REVISION)
 
17
from bzrlib.revisionspec import RevisionSpec
37
18
from bzrlib.trace import note
 
19
from bzrlib import urlutils
38
20
 
39
21
 
40
22
class cmd_send_changeset(Command):
62
44
                raise BzrCommandError('We do not support rollup-changesets yet.')
63
45
            revision = revision[0]
64
46
 
65
 
        b = branch.Branch.open_containing('.')
 
47
        b = Branch.open_containing('.')
66
48
 
67
49
        if not to:
68
50
            try:
86
68
 
87
69
    bzr bundle-revisions
88
70
        - Generate a bundle relative to a remembered location
89
 
 
90
71
    bzr bundle-revisions BASE
91
72
        - Bundle to apply the current tree into BASE
92
 
 
93
73
    bzr bundle-revisions --revision A
94
74
        - Bundle to apply revision A to remembered location 
95
 
 
96
75
    bzr bundle-revisions --revision A..B
97
76
        - Bundle to transform A into B
98
77
    """
99
 
    takes_options = ['revision', 'remember',
100
 
                     Option("output",
101
 
                            help="Write bundle to specified file.",
102
 
                            type=unicode),
103
 
                     ]
 
78
    takes_options = ['verbose', 'revision', 'remember',
 
79
                     Option("output", help="write bundle to specified file",
 
80
                            type=unicode)]
104
81
    takes_args = ['base?']
105
82
    aliases = ['bundle']
106
 
    encoding_type = 'exact'
107
83
 
108
84
    def run(self, base=None, revision=None, output=None, remember=False):
109
85
        from bzrlib import user_encoding
110
86
        from bzrlib.bundle.serializer import write_bundle
111
87
 
112
 
        target_branch = branch.Branch.open_containing(u'.')[0]
 
88
        target_branch = Branch.open_containing(u'.')[0]
113
89
 
114
90
        if base is None:
115
91
            base_specified = False
117
93
            base_specified = True
118
94
 
119
95
        if revision is None:
120
 
            target_revision = _mod_revision.ensure_null(
121
 
                target_branch.last_revision())
 
96
            target_revision = target_branch.last_revision()
122
97
        elif len(revision) < 3:
123
98
            target_revision = revision[-1].in_history(target_branch).rev_id
124
99
            if len(revision) == 2:
144
119
                # we must format with 'ascii' to be safe
145
120
                note('Using saved location: %s',
146
121
                     urlutils.unescape_for_display(base, 'ascii'))
147
 
            base_branch = branch.Branch.open(base)
 
122
            base_branch = Branch.open(base)
148
123
 
149
124
            # We don't want to lock the same branch across
150
125
            # 2 different branches
156
131
                elif remember:
157
132
                    raise errors.BzrCommandError('--remember requires a branch'
158
133
                                                 ' to be specified.')
159
 
            base_last_revision = _mod_revision.ensure_null(
160
 
                base_branch.last_revision())
161
134
            target_branch.repository.fetch(base_branch.repository, 
162
 
                base_last_revision)
163
 
            graph = target_branch.repository.get_graph()
164
 
            base_revision = graph.find_unique_lca(base_last_revision,
165
 
                                                  target_revision)
 
135
                                           base_branch.last_revision())
 
136
            base_revision = common_ancestor(base_branch.last_revision(),
 
137
                                            target_revision,
 
138
                                            target_branch.repository)
 
139
 
166
140
 
167
141
        if output is not None:
168
142
            fileobj = file(output, 'wb')
169
143
        else:
170
144
            fileobj = sys.stdout
171
 
        target_branch.repository.lock_read()
172
 
        try:
173
 
            write_bundle(target_branch.repository, target_revision,
174
 
                         base_revision, fileobj)
175
 
        finally:
176
 
            target_branch.repository.unlock()
 
145
        write_bundle(target_branch.repository, target_revision, base_revision,
 
146
                     fileobj)
177
147
 
178
148
 
179
149
class cmd_verify_changeset(Command):
186
156
        from read_changeset import read_changeset
187
157
        #from bzrlib.xml import serializer_v4
188
158
 
189
 
        b, relpath = branch.Branch.open_containing('.')
 
159
        b, relpath = Branch.open_containing('.')
190
160
 
191
161
        if filename is None or filename == '-':
192
162
            f = sys.stdin