13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
from StringIO import StringIO
136
136
return klass(revision_id, t.as_sha1(), time, timezone, target_branch,
137
137
patch, patch_type, public_branch, message)
139
def get_disk_name(self, branch):
140
"""Generate a suitable basename for storing this directive on disk
142
:param branch: The Branch this merge directive was generated fro
145
revno, revision_id = branch.last_revision_info()
146
if self.revision_id == revision_id:
149
revno = branch.get_revision_id_to_revno_map().get(self.revision_id,
151
nick = re.sub('(\W+)', '-', branch.nick).strip('-')
152
return '%s-%s' % (nick, '.'.join(str(n) for n in revno))
155
140
def _generate_diff(repository, revision_id, ancestor_id):
156
141
tree_1 = repository.revision_tree(ancestor_id)
205
190
StringIO(self.get_raw_bundle()))
206
191
# We don't use the bundle's target revision, because
207
192
# MergeDirective.revision_id is authoritative.
209
info.install_revisions(target_repo, stream_input=False)
210
except errors.RevisionNotPresent:
211
# At least one dependency isn't present. Try installing
212
# missing revisions from the submit branch
215
_mod_branch.Branch.open(self.target_branch)
216
except errors.NotBranchError:
217
raise errors.TargetNotBranch(self.target_branch)
218
missing_revisions = []
219
bundle_revisions = set(r.revision_id for r in
221
for revision in info.real_revisions:
222
for parent_id in revision.parent_ids:
223
if (parent_id not in bundle_revisions and
224
not target_repo.has_revision(parent_id)):
225
missing_revisions.append(parent_id)
226
# reverse missing revisions to try to get heads first
228
unique_missing_set = set()
229
for revision in reversed(missing_revisions):
230
if revision in unique_missing_set:
232
unique_missing.append(revision)
233
unique_missing_set.add(revision)
234
for missing_revision in unique_missing:
235
target_repo.fetch(submit_branch.repository,
237
info.install_revisions(target_repo, stream_input=False)
193
info.install_revisions(target_repo)
239
195
source_branch = _mod_branch.Branch.open(self.source_branch)
240
196
target_repo.fetch(source_branch.repository, self.revision_id)
279
235
_BaseMergeDirective.__init__(self, revision_id, testament_sha1, time,
280
236
timezone, target_branch, patch, source_branch, message)
281
if patch_type not in (None, 'diff', 'bundle'):
282
raise ValueError(patch_type)
237
assert patch_type in (None, 'diff', 'bundle'), patch_type
283
238
if patch_type != 'bundle' and source_branch is None:
284
239
raise errors.NoMergeSource()
285
240
if patch_type is not None and patch is None:
371
326
class MergeDirective2(_BaseMergeDirective):
373
_format_string = 'Bazaar merge directive format 2 (Bazaar 0.90)'
328
_format_string = 'Bazaar merge directive format 2 (Bazaar 0.19)'
375
330
def __init__(self, revision_id, testament_sha1, time, timezone,
376
331
target_branch, patch=None, source_branch=None, message=None,
531
486
self.base_revision_id)
532
487
# Convert line-endings to UNIX
533
488
stored_patch = re.sub('\r\n?', '\n', self.patch)
534
calculated_patch = re.sub('\r\n?', '\n', calculated_patch)
535
489
# Strip trailing whitespace
536
490
calculated_patch = re.sub(' *\n', '\n', calculated_patch)
537
491
stored_patch = re.sub(' *\n', '\n', stored_patch)
558
512
class MergeDirectiveFormatRegistry(registry.Registry):
560
def register(self, directive, format_string=None):
561
if format_string is None:
562
format_string = directive._format_string
563
registry.Registry.register(self, format_string, directive)
514
def register(self, directive):
515
registry.Registry.register(self, directive._format_string, directive)
566
518
_format_registry = MergeDirectiveFormatRegistry()
567
519
_format_registry.register(MergeDirective)
568
520
_format_registry.register(MergeDirective2)
569
_format_registry.register(MergeDirective2,
570
'Bazaar merge directive format 2 (Bazaar 0.19)')