~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-03 16:23:09 UTC
  • mfrom: (1736 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: aaron.bentley@utoronto.ca-20060603162309-c975ca9ea9fea344
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from bzrlib.revision import (common_ancestor, MultipleRevisionSources,
16
16
                             NULL_REVISION)
17
17
from bzrlib.revisionspec import RevisionSpec
18
 
from bzrlib.trace import note
19
 
from bzrlib import urlutils
20
18
 
21
19
 
22
20
class cmd_send_changeset(Command):
66
64
 
67
65
    You can apply it to another tree using 'bzr merge'.
68
66
 
69
 
    bzr bundle-revisions
70
 
        - Generate a bundle relative to a remembered location
71
 
    bzr bundle-revisions BASE
 
67
    bzr bundle
 
68
        - Bundle for the last commit
 
69
    bzr bundle BASE
72
70
        - Bundle to apply the current tree into BASE
73
 
    bzr bundle-revisions --revision A
74
 
        - Bundle to apply revision A to remembered location 
75
 
    bzr bundle-revisions --revision A..B
 
71
    bzr bundle --revision A
 
72
        - Bundle for revision A
 
73
    bzr bundle --revision A..B
76
74
        - Bundle to transform A into B
 
75
    bzr bundle --revision A..B BASE
 
76
        - Bundle to transform revision A of BASE into revision B
 
77
          of the local tree
77
78
    """
78
 
    takes_options = ['verbose', 'revision', 'remember',
79
 
                     Option("output", help="write bundle to specified file",
80
 
                            type=unicode)]
 
79
    takes_options = ['verbose', 'revision']
81
80
    takes_args = ['base?']
82
81
    aliases = ['bundle']
83
82
 
84
 
    def run(self, base=None, revision=None, output=None, remember=False):
 
83
    def run(self, base=None, revision=None):
85
84
        from bzrlib import user_encoding
86
85
        from bzrlib.bundle.serializer import write_bundle
87
86
 
 
87
        if base is None:
 
88
            base_branch = None
 
89
        else:
 
90
            base_branch = Branch.open(base)
 
91
 
 
92
        # We don't want to lock the same branch across
 
93
        # 2 different branches
88
94
        target_branch = Branch.open_containing(u'.')[0]
89
 
 
90
 
        if base is None:
91
 
            base_specified = False
92
 
        else:
93
 
            base_specified = True
94
 
 
 
95
        if base_branch is not None and target_branch.base == base_branch.base:
 
96
            base_branch = None
 
97
 
 
98
        base_revision = None
95
99
        if revision is None:
96
100
            target_revision = target_branch.last_revision()
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.')
 
101
        elif len(revision) == 1:
 
102
            target_revision = revision[0].in_history(target_branch).rev_id
 
103
            if base_branch is not None:
 
104
                base_revision = base_branch.last_revision()
 
105
        elif len(revision) == 2:
 
106
            target_revision = revision[1].in_history(target_branch).rev_id
 
107
            if base_branch is not None:
 
108
                base_revision = revision[0].in_history(base_branch).rev_id
 
109
            else:
103
110
                base_revision = revision[0].in_history(target_branch).rev_id
104
111
        else:
105
112
            raise errors.BzrCommandError('--revision takes 1 or 2 parameters')
106
113
 
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.')
 
114
        if revision is None or len(revision) == 1:
 
115
            if base_branch is not None:
 
116
                target_branch.repository.fetch(base_branch.repository, 
 
117
                                               base_branch.last_revision())
 
118
                base_revision = common_ancestor(base_branch.last_revision(),
 
119
                                                target_revision,
 
120
                                                target_branch.repository)
 
121
                if base_revision is None:
 
122
                    base_revision = NULL_REVISION
 
123
 
 
124
        if base_revision is None:
 
125
            rev = target_branch.repository.get_revision(target_revision)
 
126
            if rev.parent_ids:
 
127
                base_revision = rev.parent_ids[0]
 
128
            else:
 
129
                base_revision = NULL_REVISION
 
130
 
 
131
        if base_branch is not None:
134
132
            target_branch.repository.fetch(base_branch.repository, 
135
 
                                           base_branch.last_revision())
136
 
            base_revision = common_ancestor(base_branch.last_revision(),
137
 
                                            target_revision,
138
 
                                            target_branch.repository)
139
 
 
140
 
 
141
 
        if output is not None:
142
 
            fileobj = file(output, 'wb')
143
 
        else:
144
 
            fileobj = sys.stdout
 
133
                                           revision_id=base_revision)
 
134
            del base_branch
145
135
        write_bundle(target_branch.repository, target_revision, base_revision,
146
 
                     fileobj)
 
136
                     sys.stdout)
147
137
 
148
138
 
149
139
class cmd_verify_changeset(Command):