~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/foreign.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-12 21:44:27 UTC
  • mto: This revision was merged to the branch mainline in revision 4737.
  • Revision ID: john@arbash-meinel.com-20091012214427-zddi1kmc2jlf7v31
Py_ssize_t and its associated function typedefs are not available w/ python 2.4

So we define them in python-compat.h
Even further, gcc issued a warning for:
static int
_workaround_pyrex_096()
So we changed it to:
_workaround_pyrex_096(void)

Also, some python api funcs were incorrectly defined as 'char *' when they meant
'const char *'. Work around that with a (char *) cast, to avoid compiler warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
from bzrlib.branch import (
22
22
    Branch,
 
23
    InterBranch,
23
24
    )
24
25
from bzrlib.commands import Command, Option
25
26
from bzrlib.repository import Repository
28
29
lazy_import(globals(), """
29
30
from bzrlib import (
30
31
    errors,
 
32
    osutils,
31
33
    registry,
32
34
    transform,
33
35
    )
34
36
""")
35
37
 
36
38
class VcsMapping(object):
37
 
    """Describes the mapping between the semantics of Bazaar and a foreign VCS.
 
39
    """Describes the mapping between the semantics of Bazaar and a foreign vcs.
38
40
 
39
41
    """
40
42
    # Whether this is an experimental mapping that is still open to changes.
120
122
class ForeignVcs(object):
121
123
    """A foreign version control system."""
122
124
 
123
 
    branch_format = None
124
 
 
125
 
    repository_format = None
126
 
 
127
 
    def __init__(self, mapping_registry, abbreviation=None):
128
 
        """Create a new foreign vcs instance.
129
 
 
130
 
        :param mapping_registry: Registry with mappings for this VCS.
131
 
        :param abbreviation: Optional abbreviation ('bzr', 'svn', 'git', etc)
132
 
        """
133
 
        self.abbreviation = abbreviation
 
125
    def __init__(self, mapping_registry):
134
126
        self.mapping_registry = mapping_registry
135
127
 
136
128
    def show_foreign_revid(self, foreign_revid):
141
133
        """
142
134
        return { }
143
135
 
144
 
    def serialize_foreign_revid(self, foreign_revid):
145
 
        """Serialize a foreign revision id for this VCS.
146
 
 
147
 
        :param foreign_revid: Foreign revision id
148
 
        :return: Bytestring with serialized revid, will not contain any 
149
 
            newlines.
150
 
        """
151
 
        raise NotImplementedError(self.serialize_foreign_revid)
152
 
 
153
136
 
154
137
class ForeignVcsRegistry(registry.Registry):
155
138
    """Registry for Foreign VCSes.
223
206
        """Get the default mapping for this repository."""
224
207
        raise NotImplementedError(self.get_default_mapping)
225
208
 
 
209
    def get_inventory_xml(self, revision_id):
 
210
        """See Repository.get_inventory_xml()."""
 
211
        return self.serialise_inventory(self.get_inventory(revision_id))
 
212
 
 
213
    def get_inventory_sha1(self, revision_id):
 
214
        """Get the sha1 for the XML representation of an inventory.
 
215
 
 
216
        :param revision_id: Revision id of the inventory for which to return
 
217
         the SHA1.
 
218
        :return: XML string
 
219
        """
 
220
 
 
221
        return osutils.sha_string(self.get_inventory_xml(revision_id))
 
222
 
 
223
    def get_revision_xml(self, revision_id):
 
224
        """Return the XML representation of a revision.
 
225
 
 
226
        :param revision_id: Revision for which to return the XML.
 
227
        :return: XML string
 
228
        """
 
229
        return self._serializer.write_revision_to_string(
 
230
            self.get_revision(revision_id))
 
231
 
226
232
 
227
233
class ForeignBranch(Branch):
228
234
    """Branch that exists in a foreign version control system."""
257
263
 
258
264
 
259
265
class cmd_dpush(Command):
260
 
    __doc__ = """Push into a different VCS without any custom bzr metadata.
 
266
    """Push into a different VCS without any custom bzr metadata.
261
267
 
262
268
    This will afterwards rebase the local branch on the remote
263
269
    branch unless the --no-rebase option is used, in which case 
294
300
        except NoWorkingTree:
295
301
            source_branch = Branch.open(directory)
296
302
            source_wt = None
297
 
        if source_wt is not None:
298
 
            source_wt.check_changed_or_out_of_date(
299
 
                strict, 'dpush_strict',
300
 
                more_error='Use --no-strict to force the push.',
301
 
                more_warning='Uncommitted changes will not be pushed.')
 
303
        if strict is None:
 
304
            strict = source_branch.get_config(
 
305
                ).get_user_option_as_bool('dpush_strict')
 
306
        if strict is None: strict = True # default value
 
307
        if strict and source_wt is not None:
 
308
            if (source_wt.has_changes()):
 
309
                raise errors.UncommittedChanges(
 
310
                    source_wt, more='Use --no-strict to force the push.')
 
311
            if source_wt.last_revision() != source_wt.branch.last_revision():
 
312
                # The tree has lost sync with its branch, there is little
 
313
                # chance that the user is aware of it but he can still force
 
314
                # the push with --no-strict
 
315
                raise errors.OutOfDateTree(
 
316
                    source_wt, more='Use --no-strict to force the push.')
302
317
        stored_loc = source_branch.get_push_location()
303
318
        if location is None:
304
319
            if stored_loc is None:
314
329
        target_branch.lock_write()
315
330
        try:
316
331
            try:
317
 
                push_result = source_branch.push(target_branch, lossy=True)
 
332
                push_result = source_branch.lossy_push(target_branch)
318
333
            except errors.LossyPushToSameVCS:
319
334
                raise BzrCommandError("%r and %r are in the same VCS, lossy "
320
335
                    "push not necessary. Please use regular push." %
337
352
            push_result.report(self.outf)
338
353
        finally:
339
354
            target_branch.unlock()
 
355
 
 
356
 
 
357
class InterToForeignBranch(InterBranch):
 
358
 
 
359
    def lossy_push(self, stop_revision=None):
 
360
        """Push deltas into another branch.
 
361
 
 
362
        :note: This does not, like push, retain the revision ids from 
 
363
            the source branch and will, rather than adding bzr-specific 
 
364
            metadata, push only those semantics of the revision that can be 
 
365
            natively represented by this branch' VCS.
 
366
 
 
367
        :param target: Target branch
 
368
        :param stop_revision: Revision to push, defaults to last revision.
 
369
        :return: BranchPushResult with an extra member revidmap: 
 
370
            A dictionary mapping revision ids from the target branch 
 
371
            to new revision ids in the target branch, for each 
 
372
            revision that was pushed.
 
373
        """
 
374
        raise NotImplementedError(self.lossy_push)