~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/commands.py

[merge] bzr.dev 1827

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
                             NULL_REVISION)
17
17
from bzrlib.revisionspec import RevisionSpec
18
18
from bzrlib.trace import note
 
19
from bzrlib import urlutils
19
20
 
20
21
 
21
22
class cmd_send_changeset(Command):
66
67
    You can apply it to another tree using 'bzr merge'.
67
68
 
68
69
    bzr bundle-revisions
69
 
        - Bundle for the last commit
 
70
        - Generate a bundle relative to a remembered location
70
71
    bzr bundle-revisions BASE
71
72
        - Bundle to apply the current tree into BASE
72
73
    bzr bundle-revisions --revision A
73
 
        - Bundle for revision A
 
74
        - Bundle to apply revision A to remembered location 
74
75
    bzr bundle-revisions --revision A..B
75
76
        - Bundle to transform A into B
76
 
    bzr bundle-revisions --revision A..B BASE
77
 
        - Bundle to transform revision A of BASE into revision B
78
 
          of the local tree
79
77
    """
80
78
    takes_options = ['verbose', 'revision', 'remember',
81
79
                     Option("output", help="write bundle to specified file",
88
86
        from bzrlib.bundle.serializer import write_bundle
89
87
 
90
88
        target_branch = Branch.open_containing(u'.')[0]
91
 
        submit_branch = target_branch.get_submit_branch()
92
89
 
93
90
        if base is None:
94
91
            base_specified = False
95
 
            base = submit_branch
96
 
            note('Using saved location: %s' % base)
97
92
        else:
98
93
            base_specified = True
99
94
 
100
 
        if base is None:
101
 
            base = target_branch.get_parent()
102
 
            if base is None:
103
 
                raise errors.BzrCommandError("No base branch known or"
104
 
                                             " specified.")
105
 
            else:
106
 
                note('Using saved location: %s' % base)
107
 
        base_branch = Branch.open(base)
108
 
 
109
 
        # We don't want to lock the same branch across
110
 
        # 2 different branches
111
 
        if target_branch.base == base_branch.base:
112
 
            base_branch = target_branch 
113
 
        if submit_branch is None or remember:
114
 
            if base_specified:
115
 
                target_branch.set_submit_branch(base_branch.base)
116
 
            elif remember:
117
 
                raise errors.BzrCommandError('--remember requires a branch to'
118
 
                                             ' be specified.')
119
 
 
120
 
        base_revision = None
121
95
        if revision is None:
122
96
            target_revision = target_branch.last_revision()
123
 
        elif len(revision) == 1:
124
 
            target_revision = revision[0].in_history(target_branch).rev_id
125
 
            if base_branch is not None:
126
 
                base_revision = base_branch.last_revision()
127
 
        elif len(revision) == 2:
128
 
            target_revision = revision[1].in_history(target_branch).rev_id
129
 
            if base_branch is not None:
130
 
                base_revision = revision[0].in_history(base_branch).rev_id
131
 
            else:
 
97
        elif len(revision) < 3:
 
98
            target_revision = revision[-1].in_history(target_branch).rev_id
 
99
            if len(revision) == 2:
 
100
                if base_specified:
 
101
                    raise errors.BzrCommandError('Cannot specify base as well'
 
102
                                                 ' as two revision arguments.')
132
103
                base_revision = revision[0].in_history(target_branch).rev_id
133
104
        else:
134
105
            raise errors.BzrCommandError('--revision takes 1 or 2 parameters')
135
106
 
136
 
        if revision is None or len(revision) == 1:
137
 
            if base_branch is not None:
138
 
                target_branch.repository.fetch(base_branch.repository, 
139
 
                                               base_branch.last_revision())
140
 
                base_revision = common_ancestor(base_branch.last_revision(),
141
 
                                                target_revision,
142
 
                                                target_branch.repository)
143
 
                if base_revision is None:
144
 
                    base_revision = NULL_REVISION
145
 
 
146
 
        if base_revision is None:
147
 
            rev = target_branch.repository.get_revision(target_revision)
148
 
            if rev.parent_ids:
149
 
                base_revision = rev.parent_ids[0]
150
 
            else:
151
 
                base_revision = NULL_REVISION
152
 
 
153
 
        if base_branch is not None:
 
107
        if revision is None or len(revision) < 2:
 
108
            submit_branch = target_branch.get_submit_branch()
 
109
            if base is None:
 
110
                base = submit_branch
 
111
            if base is None:
 
112
                base = target_branch.get_parent()
 
113
            if base is None:
 
114
                raise errors.BzrCommandError("No base branch known or"
 
115
                                             " specified.")
 
116
            elif not base_specified:
 
117
                # FIXME:
 
118
                # note() doesn't pay attention to terminal_encoding() so
 
119
                # we must format with 'ascii' to be safe
 
120
                note('Using saved location: %s',
 
121
                     urlutils.unescape_for_display(base, 'ascii'))
 
122
            base_branch = Branch.open(base)
 
123
 
 
124
            # We don't want to lock the same branch across
 
125
            # 2 different branches
 
126
            if target_branch.base == base_branch.base:
 
127
                base_branch = target_branch 
 
128
            if submit_branch is None or remember:
 
129
                if base_specified:
 
130
                    target_branch.set_submit_branch(base_branch.base)
 
131
                elif remember:
 
132
                    raise errors.BzrCommandError('--remember requires a branch'
 
133
                                                 ' to be specified.')
154
134
            target_branch.repository.fetch(base_branch.repository, 
155
 
                                           revision_id=base_revision)
156
 
            del base_branch
 
135
                                           base_branch.last_revision())
 
136
            base_revision = common_ancestor(base_branch.last_revision(),
 
137
                                            target_revision,
 
138
                                            target_branch.repository)
 
139
 
157
140
 
158
141
        if output is not None:
159
142
            fileobj = file(output, 'wb')