/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/changeset/commands.py

  • Committer: John Arbash Meinel
  • Date: 2006-01-01 00:53:37 UTC
  • mto: (1185.82.108 w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20060101005337-54e006f2115719a5
Worked out the changeset command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
from bzrlib.branch import Branch
12
12
from bzrlib.revisionspec import RevisionSpec
13
13
from bzrlib.option import Option
 
14
from bzrlib.revision import (common_ancestor, MultipleRevisionSources,
 
15
                             get_intervening_revisions, NULL_REVISION)
 
16
import bzrlib.errors as errors
14
17
 
15
18
class cmd_send_changeset(Command):
16
19
    """Send a bundled up changset via mail.
50
53
 
51
54
        send_changeset(b, revision, to, message, file)
52
55
 
 
56
 
53
57
class cmd_changeset(Command):
54
58
    """Generate a bundled up changeset.
55
59
 
56
60
    This changeset contains all of the meta-information of a
57
61
    diff, rather than just containing the patch information.
58
62
 
59
 
    BASE - This is the target tree with which you want to merge.
60
 
           It will be used as the base for all patches. Anyone
61
 
           wanting to merge the changeset will be required to have BASE
62
 
    TARGET - This is the final revision which is desired to be in the
63
 
             changeset. It defaults to the last committed revision. './@'
64
 
    STARTING-REV-ID - All revisions between STARTING-REV and TARGET will
65
 
                      be bundled up in the changeset. By default this is
66
 
                      chosen as the merge root.
67
 
                      (NOT Implemented yet)
68
 
 
69
 
 
70
 
    If --verbose, renames will be given as an 'add + delete' style patch.
71
 
    If --revision is given, it has several states:
72
 
        --revision A..B A is chosen as the base and B is chosen as the target
73
 
        --revision A    A is chosen as the target, and the base is it's primary parent
74
 
        --revision ..B  B is chosen as the target, and the base is it's primary parent
75
 
        --revision A..  ???
76
 
    --message will replace the global message with the one supplied. Though this
77
 
        will not be saved in the final revision messages.
 
63
    bzr cset
 
64
        - Changeset for the last commit
 
65
    bzr cset BASE
 
66
        - Changeset to apply the current tree into BASE
 
67
    bzr cset --revision A
 
68
        - Changeset for revision A
 
69
    bzr cset --revision A..B
 
70
        - Changeset to transform A into B
 
71
    bzr cset --revision A..B BASE
 
72
        - Changeset to transform revision A of BASE into revision B
 
73
          of the local tree
78
74
    """
79
 
    takes_options = ['verbose', 'revision', 'message']
80
 
    takes_args = ['base?', 'target?', 'starting-rev-id?']
 
75
    takes_options = ['verbose', 'revision']
 
76
    takes_args = ['base?']
81
77
    aliases = ['cset']
82
78
 
83
 
    def run(self, base=None, target=None, starting_rev_id=None,
84
 
            verbose=False, revision=None, message=None):
85
 
        from bzrlib.commands import parse_spec
86
 
        from bzrlib.errors import BzrCommandError
 
79
    def run(self, base=None, revision=None):
87
80
        from bzrlib import user_encoding
88
 
        import gen_changeset
89
 
        import codecs
90
 
 
91
 
        if revision is not None:
92
 
            if (target is not None or base is not None):
93
 
                raise BzrCommandError('--revision superceeds base and target')
94
 
            if len(revision) == 1:
95
 
                target_info = revision[0]
96
 
                base_info = None
97
 
            elif len(revision) == 2:
98
 
                target_info = revision[1]
99
 
                base_info = revision[0]
100
 
            else:
101
 
                raise BzrCommandError('--revision can take at most 2 arguments')
102
 
 
103
 
            target_branch, relpath = Branch.open_containing('.')
104
 
            target_revno, target_rev_id = target_info.in_history(target_branch)
105
 
            base_branch = target_branch
106
 
            if base_info is not None:
107
 
                base_revno, base_rev_id = base_info.in_history(target_branch)
108
 
            else:
109
 
                target_rev = target_branch.get_revision(target_rev_id)
110
 
                if hasattr(target_rev, 'parent_ids'):
111
 
                    base_rev_id = target_rev.parent_ids[0]
112
 
                else:
113
 
                    base_rev_id = target_rev.parents[0].revision_id
114
 
        else:
115
 
            if target is None:
116
 
                target = './@'
117
 
            b_target_path, target_revno = parse_spec(target)
118
 
            target_branch, relpath = Branch.open_containing(b_target_path)
119
 
            if target_revno is None or target_revno == -1:
120
 
                if hasattr(target_branch, 'last_patch'):
121
 
                    target_rev_id = target_branch.last_patch()
122
 
                else:
123
 
                    target_rev_id = target_branch.last_revision()
124
 
            else:
125
 
                target_rev_id = target_branch.get_rev_id(target_revno)
126
 
 
127
 
            if base is None:
128
 
                base_branch = target_branch
129
 
                target_rev = target_branch.get_revision(target_rev_id)
130
 
                if hasattr(target_rev, 'parent_ids'):
131
 
                    base_rev_id = target_rev.parent_ids[0]
132
 
                else:
133
 
                    base_rev_id = target_rev.parents[0].revision_id
134
 
            else:
135
 
                base_path, base_revno = parse_spec(base)
136
 
                base_branch, relpath = Branch.open_containing(base_path)
137
 
                if base_revno is None or base_revno == -1:
138
 
                    if hasattr(target_branch, 'last_patch'):
139
 
                        base_rev_id = target_branch.last_patch()
140
 
                    else:
141
 
                        base_rev_id = target_branch.last_revision()
142
 
                else:
143
 
                    base_rev_id = base_branch.get_rev_id(base_revno)
144
 
 
145
 
        # outf = codecs.getwriter(user_encoding)(sys.stdout,
146
 
        #         errors='replace')
147
 
 
148
 
        if starting_rev_id is not None:
149
 
            raise BzrCommandError('Specifying the STARTING-REV-ID'
150
 
                    ' not yet supported')
151
 
 
152
 
        gen_changeset.show_changeset(base_branch, base_rev_id,
153
 
                target_branch, target_rev_id,
154
 
                starting_rev_id,
155
 
                to_file=sys.stdout, include_full_diff=verbose,
156
 
                message=message)
 
81
        from bzrlib.changeset.serializer import write
 
82
        from bzrlib.fetch import fetch
 
83
 
 
84
        if base is None:
 
85
            base_branch = None
 
86
        else:
 
87
            base_branch = Branch.open(base)
 
88
 
 
89
        # We don't want to lock the same branch across
 
90
        # 2 different branches
 
91
        target_branch = Branch.open_containing(u'.')[0]
 
92
        if base_branch is not None and target_branch.base == base_branch.base:
 
93
            base_branch = None
 
94
 
 
95
        base_revision = None
 
96
        if revision is None:
 
97
            target_revision = target_branch.last_revision()
 
98
            if base_branch is not None:
 
99
                base_revision = base_branch.last_revision()
 
100
        elif len(revision) == 1:
 
101
            target_revision = revision[0].in_history(target_branch).rev_id
 
102
            if base_branch is not None:
 
103
                base_revision = base_branch.last_revision()
 
104
        elif len(revision) == 2:
 
105
            target_revision = revision[0].in_history(target_branch).rev_id
 
106
            if base_branch is not None:
 
107
                base_revision = revision[1].in_history(base_branch).rev_id
 
108
            else:
 
109
                base_revision = revision[1].in_history(target_branch).rev_id
 
110
        else:
 
111
            raise errors.BzrCommandError('--revision takes 1 or 2 parameters')
 
112
 
 
113
        if base_revision is None:
 
114
            rev = target_branch.get_revision(target_revision)
 
115
            if rev.parent_ids:
 
116
                base_revision = rev.parent_ids[0]
 
117
            else:
 
118
                base_revision = NULL_REVISION
 
119
 
 
120
        if base_branch is not None:
 
121
            fetch(target_branch, base_branch, base_revision)
 
122
            del base_branch
 
123
        revision_id_list = get_intervening_revisions(target_revision, base_revision,
 
124
                target_branch, target_branch.revision_history())
 
125
                
 
126
        write(target_branch, revision_id_list, sys.stdout)
 
127
 
157
128
 
158
129
class cmd_verify_changeset(Command):
159
130
    """Read a written changeset, and make sure it is valid.
203
174
        apply_changeset.apply_changeset(b, f, reverse=reverse,
204
175
                auto_commit=auto_commit)
205
176
 
 
177
 
206
178
register_command(cmd_changeset)
207
179
register_command(cmd_verify_changeset)
208
180
register_command(cmd_apply_changeset)