68
class cmd_dpush(Command):
69
"""Push diffs into a foreign branch without any bzr-specific metadata.
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.
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.',
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")]
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
96
def get_inv(wt, revid):
97
if revid == NULL_REVISION:
100
return wt.branch.repository.get_inventory(revid)
102
if directory is None:
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]
110
stored_loc = source_branch.get_push_location()
112
if stored_loc is None:
113
raise BzrCommandError("No push location known or specified.")
115
display_url = urlutils.unescape_for_display(stored_loc,
117
self.outf.write("Using saved location: %s\n" % display_url)
118
location = stored_loc
120
bzrdir = BzrDir.open(location)
121
target_branch = bzrdir.open_branch()
122
target_branch.lock_write()
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)
129
revid_map = target_branch.dpull(source_branch)
131
f = open(idmap_file, "w")
133
f.write("".join(["%s\t%s\n" % item for item in revid_map.iteritems()]))
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)
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()
147
update_workinginv_fileids(source_wt,
148
get_inv(source_wt, old_last_revid),
149
get_inv(source_wt, new_last_revid))
153
source_branch.pull(target_branch, overwrite=True,
154
stop_revision=new_last_revid)
156
target_branch.unlock()
159
68
class cmd_foreign_mapping_upgrade(Command):
160
69
"""Upgrade revisions mapped from a foreign version control system.