32
32
from bzrlib.revision import NULL_REVISION
33
from bzrlib.revisionspec import (
33
from bzrlib.revisionspec import RevisionInfo
37
34
from bzrlib.transport import get_transport
38
35
from bzrlib.upgrade import upgrade
39
36
from lazr.delegates import delegates
97
92
from lp.code.mail.branch import BranchMailer
98
93
from lp.code.model.branch import Branch
99
94
from lp.code.model.branchmergeproposal import BranchMergeProposal
100
from lp.code.model.diff import StaticDiff
101
95
from lp.code.model.revision import RevisionSet
102
96
from lp.codehosting.scanner.bzrsync import BzrSync
103
97
from lp.codehosting.vfs import (
285
279
return [format_address_for_person(self.requester)]
288
class BranchDiffJob(BranchJobDerived):
289
"""A Job that calculates the a diff related to a Branch."""
291
implements(IBranchDiffJob)
292
classProvides(IBranchDiffJobSource)
295
def create(cls, branch, from_revision_spec, to_revision_spec):
296
"""See `IBranchDiffJobSource`."""
297
metadata = cls.getMetadata(from_revision_spec, to_revision_spec)
298
branch_job = BranchJob(branch, BranchJobType.STATIC_DIFF, metadata)
299
return cls(branch_job)
302
def getMetadata(from_revision_spec, to_revision_spec):
304
'from_revision_spec': from_revision_spec,
305
'to_revision_spec': to_revision_spec,
309
def from_revision_spec(self):
310
return self.metadata['from_revision_spec']
313
def to_revision_spec(self):
314
return self.metadata['to_revision_spec']
316
def _get_revision_id(self, bzr_branch, spec_string):
317
spec = RevisionSpec.from_string(spec_string)
318
return spec.as_revision_id(bzr_branch)
321
"""See IBranchDiffJob."""
322
bzr_branch = self.branch.getBzrBranch()
323
from_revision_id = self._get_revision_id(
324
bzr_branch, self.from_revision_spec)
325
to_revision_id = self._get_revision_id(
326
bzr_branch, self.to_revision_spec)
327
static_diff = StaticDiff.acquire(
328
from_revision_id, to_revision_id, bzr_branch.repository)
332
282
class BranchScanJob(BranchJobDerived):
333
283
"""A Job that scans a branch for new revisions."""
447
397
shutil.rmtree(upgrade_branch_path)
450
class RevisionMailJob(BranchDiffJob):
451
"""A Job that calculates the a diff related to a Branch."""
400
class RevisionMailJob(BranchJobDerived):
401
"""A Job that sends a mail for a scan of a Branch."""
453
403
implements(IRevisionMailJob)
457
407
class_job_type = BranchJobType.REVISION_MAIL
461
cls, branch, revno, from_address, body, perform_diff, subject):
410
def create(cls, branch, revno, from_address, body, subject):
462
411
"""See `IRevisionMailJobSource`."""
465
414
'from_address': from_address,
467
'perform_diff': perform_diff,
468
416
'subject': subject,
470
if isinstance(revno, int) and revno > 0:
471
from_revision_spec = str(revno - 1)
472
to_revision_spec = str(revno)
474
from_revision_spec = None
475
to_revision_spec = None
476
metadata.update(BranchDiffJob.getMetadata(from_revision_spec,
478
418
branch_job = BranchJob(branch, BranchJobType.REVISION_MAIL, metadata)
479
419
return cls(branch_job)
483
revno = self.metadata['revno']
484
if isinstance(revno, int):
423
return self.metadata['revno']
489
426
def from_address(self):
490
427
return str(self.metadata['from_address'])
493
def perform_diff(self):
494
return self.metadata['perform_diff']
498
431
return self.metadata['body']
504
437
def getMailer(self):
505
438
"""Return a BranchMailer for this job."""
506
if self.perform_diff and self.to_revision_spec is not None:
507
diff = BranchDiffJob.run(self)
509
diff_text = diff.diff.text
512
439
return BranchMailer.forRevision(
513
440
self.branch, self.revno, self.from_address, self.body,
514
diff_text, self.subject)
517
444
"""See `IRevisionMailJob`."""