/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 __init__.py

  • Committer: Jelmer Vernooij
  • Date: 2008-08-29 15:16:27 UTC
  • mto: (0.219.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20080829151627-r3mhlflwdgtioy1c
Import dpush.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Foreign branch utilities."""
18
18
 
19
19
from bzrlib import errors, registry
 
20
from bzrlib.commands import Command, Option
20
21
 
21
22
 
22
23
class VcsMapping(object):
68
69
    def break_lock(self):
69
70
        pass
70
71
 
 
72
 
 
73
class cmd_dpush(Command):
 
74
    """Push diffs into Subversion without any Bazaar-specific properties set.
 
75
 
 
76
    This will afterwards rebase the local Bazaar branch on the Subversion 
 
77
    branch unless the --no-rebase option is used, in which case 
 
78
    the two branches will be out of sync. 
 
79
    """
 
80
    takes_args = ['location?']
 
81
    takes_options = ['remember', Option('directory',
 
82
            help='Branch to push from, '
 
83
                 'rather than the one containing the working directory.',
 
84
            short_name='d',
 
85
            type=unicode,
 
86
            ),
 
87
            Option('no-rebase', help="Don't rebase after push")]
 
88
 
 
89
    def run(self, location=None, remember=False, directory=None, 
 
90
            no_rebase=False):
 
91
        from bzrlib import urlutils
 
92
        from bzrlib.bzrdir import BzrDir
 
93
        from bzrlib.branch import Branch
 
94
        from bzrlib.errors import BzrCommandError, NoWorkingTree
 
95
        from bzrlib.workingtree import WorkingTree
 
96
 
 
97
        if directory is None:
 
98
            directory = "."
 
99
        try:
 
100
            source_wt = WorkingTree.open_containing(directory)[0]
 
101
            source_branch = source_wt.branch
 
102
        except NoWorkingTree:
 
103
            source_branch = Branch.open_containing(directory)[0]
 
104
            source_wt = None
 
105
        stored_loc = source_branch.get_push_location()
 
106
        if location is None:
 
107
            if stored_loc is None:
 
108
                raise BzrCommandError("No push location known or specified.")
 
109
            else:
 
110
                display_url = urlutils.unescape_for_display(stored_loc,
 
111
                        self.outf.encoding)
 
112
                self.outf.write("Using saved location: %s\n" % display_url)
 
113
                location = stored_loc
 
114
 
 
115
        bzrdir = BzrDir.open(location)
 
116
        target_branch = bzrdir.open_branch()
 
117
        target_branch.lock_write()
 
118
        revid_map = source_branch.dpush(target_branch)
 
119
        # We successfully created the target, remember it
 
120
        if source_branch.get_push_location() is None or remember:
 
121
            source_branch.set_push_location(target_branch.base)
 
122
        if not no_rebase:
 
123
            _, old_last_revid = source_branch.last_revision_info()
 
124
            new_last_revid = revid_map[old_last_revid]
 
125
            if source_wt is not None:
 
126
                source_wt.pull(target_branch, overwrite=True, 
 
127
                               stop_revision=new_last_revid)
 
128
            else:
 
129
                source_branch.pull(target_branch, overwrite=True, 
 
130
                                   stop_revision=new_last_revid)
 
131
 
 
132
 
 
133