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

Merge new bzr-foreign.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
        pass
66
66
 
67
67
 
68
 
class cmd_dpush(Command):
69
 
    """Push diffs into a foreign branch without any bzr-specific metadata.
70
 
 
71
 
    This will afterwards rebase the local Bazaar branch on the remote
72
 
    branch unless the --no-rebase option is used, in which case 
73
 
    the two branches will be out of sync. 
74
 
    """
75
 
    takes_args = ['location?']
76
 
    takes_options = ['remember', Option('directory',
77
 
            help='Branch to push from, '
78
 
                 'rather than the one containing the working directory.',
79
 
            short_name='d',
80
 
            type=unicode,
81
 
            ),
82
 
            Option("idmap-file", help="Write map with old and new revision ids.", type=str),
83
 
            Option('no-rebase', help="Don't rebase after push")]
84
 
 
85
 
    def run(self, location=None, remember=False, directory=None, 
86
 
            no_rebase=False, idmap_file=None):
87
 
        from bzrlib import urlutils
88
 
        from bzrlib.bzrdir import BzrDir
89
 
        from bzrlib.errors import BzrCommandError, NoWorkingTree
90
 
        from bzrlib.inventory import Inventory
91
 
        from bzrlib.revision import NULL_REVISION
92
 
        from bzrlib.trace import info
93
 
        from bzrlib.workingtree import WorkingTree
94
 
        from upgrade import update_workinginv_fileids
95
 
 
96
 
        def get_inv(wt, revid):
97
 
            if revid == NULL_REVISION:
98
 
                return Inventory()
99
 
            else:
100
 
                return wt.branch.repository.get_inventory(revid)
101
 
 
102
 
        if directory is None:
103
 
            directory = "."
104
 
        try:
105
 
            source_wt = WorkingTree.open_containing(directory)[0]
106
 
            source_branch = source_wt.branch
107
 
        except NoWorkingTree:
108
 
            source_branch = Branch.open_containing(directory)[0]
109
 
            source_wt = None
110
 
        stored_loc = source_branch.get_push_location()
111
 
        if location is None:
112
 
            if stored_loc is None:
113
 
                raise BzrCommandError("No push location known or specified.")
114
 
            else:
115
 
                display_url = urlutils.unescape_for_display(stored_loc,
116
 
                        self.outf.encoding)
117
 
                self.outf.write("Using saved location: %s\n" % display_url)
118
 
                location = stored_loc
119
 
 
120
 
        bzrdir = BzrDir.open(location)
121
 
        target_branch = bzrdir.open_branch()
122
 
        target_branch.lock_write()
123
 
        try:
124
 
            if getattr(target_branch, "dpull", None) is None:
125
 
                info("target branch is not a foreign branch, using regular push.")
126
 
                target_branch.pull(source_branch)
127
 
                no_rebase = True
128
 
            else:
129
 
                revid_map = target_branch.dpull(source_branch)
130
 
                if idmap_file:
131
 
                    f = open(idmap_file, "w")
132
 
                    try:
133
 
                        f.write("".join(["%s\t%s\n" % item for item in revid_map.iteritems()]))
134
 
                    finally:
135
 
                        f.close()
136
 
            # We successfully created the target, remember it
137
 
            if source_branch.get_push_location() is None or remember:
138
 
                source_branch.set_push_location(target_branch.base)
139
 
            if not no_rebase:
140
 
                _, old_last_revid = source_branch.last_revision_info()
141
 
                new_last_revid = revid_map[old_last_revid]
142
 
                if source_wt is not None:
143
 
                    source_wt.pull(target_branch, overwrite=True, 
144
 
                                   stop_revision=new_last_revid)
145
 
                    source_wt.lock_write()
146
 
                    try:
147
 
                        update_workinginv_fileids(source_wt, 
148
 
                            get_inv(source_wt, old_last_revid), 
149
 
                            get_inv(source_wt, new_last_revid))
150
 
                    finally:
151
 
                        source_wt.unlock()
152
 
                else:
153
 
                    source_branch.pull(target_branch, overwrite=True, 
154
 
                                       stop_revision=new_last_revid)
155
 
        finally:
156
 
            target_branch.unlock()
157
 
 
158
 
 
159
68
class cmd_foreign_mapping_upgrade(Command):
160
69
    """Upgrade revisions mapped from a foreign version control system.
161
70