~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/foreign.py

  • Committer: Jelmer Vernooij
  • Date: 2008-11-25 03:08:14 UTC
  • mto: This revision was merged to the branch mainline in revision 3860.
  • Revision ID: jelmer@samba.org-20081125030814-90fce65a9h7ffmmb
Remove dpush() implementation for now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
        raise NotImplementedError(self.revision_id_bzr_to_foreign)
99
99
 
100
100
 
101
 
class ForeignBranch(Branch):
102
 
    """Branch that exists in a foreign version control system."""
103
 
 
104
 
    def __init__(self, mapping):
105
 
        self.mapping = mapping
106
 
        super(ForeignBranch, self).__init__()
107
 
 
108
 
    def dpull(self, source, stop_revision=None):
109
 
        """Pull deltas from another branch.
110
 
 
111
 
        :note: This does not, like pull, retain the revision ids from 
112
 
        the source branch and will, rather than adding bzr-specific metadata,
113
 
        push only those semantics of the revision that can be natively 
114
 
        represented in this branch.
115
 
 
116
 
        :param source: Source branch
117
 
        :param stop_revision: Revision to pull, defaults to last revision.
118
 
        """
119
 
        raise NotImplementedError(self.pull)
120
 
 
121
 
 
122
 
class cmd_dpush(Command):
123
 
    """Push diffs into a foreign version control system without any 
124
 
    Bazaar-specific metadata.
125
 
 
126
 
    This will afterwards rebase the local Bazaar branch on the remote
127
 
    branch unless the --no-rebase option is used, in which case 
128
 
    the two branches will be out of sync. 
129
 
    """
130
 
    takes_args = ['location?']
131
 
    takes_options = ['remember', Option('directory',
132
 
            help='Branch to push from, '
133
 
                 'rather than the one containing the working directory.',
134
 
            short_name='d',
135
 
            type=unicode,
136
 
            ),
137
 
            Option('no-rebase', help="Don't rebase after push")]
138
 
 
139
 
    def run(self, location=None, remember=False, directory=None, 
140
 
            no_rebase=False):
141
 
        from bzrlib import urlutils
142
 
        from bzrlib.bzrdir import BzrDir
143
 
        from bzrlib.errors import BzrCommandError, NoWorkingTree
144
 
        from bzrlib.trace import info
145
 
        from bzrlib.workingtree import WorkingTree
146
 
 
147
 
        if directory is None:
148
 
            directory = "."
149
 
        try:
150
 
            source_wt = WorkingTree.open_containing(directory)[0]
151
 
            source_branch = source_wt.branch
152
 
        except NoWorkingTree:
153
 
            source_branch = Branch.open_containing(directory)[0]
154
 
            source_wt = None
155
 
        stored_loc = source_branch.get_push_location()
156
 
        if location is None:
157
 
            if stored_loc is None:
158
 
                raise BzrCommandError("No push location known or specified.")
159
 
            else:
160
 
                display_url = urlutils.unescape_for_display(stored_loc,
161
 
                        self.outf.encoding)
162
 
                self.outf.write("Using saved location: %s\n" % display_url)
163
 
                location = stored_loc
164
 
 
165
 
        bzrdir = BzrDir.open(location)
166
 
        target_branch = bzrdir.open_branch()
167
 
        target_branch.lock_write()
168
 
        if not isinstance(target_branch, ForeignBranch):
169
 
            info("target branch is not a foreign branch, using regular push.")
170
 
            target_branch.pull(source_branch)
171
 
            no_rebase = True
172
 
        else:
173
 
            revid_map = target_branch.dpull(source_branch)
174
 
        # We successfully created the target, remember it
175
 
        if source_branch.get_push_location() is None or remember:
176
 
            source_branch.set_push_location(target_branch.base)
177
 
        if not no_rebase:
178
 
            _, old_last_revid = source_branch.last_revision_info()
179
 
            new_last_revid = revid_map[old_last_revid]
180
 
            if source_wt is not None:
181
 
                source_wt.pull(target_branch, overwrite=True, 
182
 
                               stop_revision=new_last_revid)
183
 
            else:
184
 
                source_branch.pull(target_branch, overwrite=True, 
185
 
                                   stop_revision=new_last_revid)
186
 
 
187
 
 
188
101
class ForeignRevision(Revision):
189
102
    """A Revision from a Foreign repository. Remembers 
190
103
    information about foreign revision id and mapping.