~rom1-chal/bzr-builder/merge-all-what-can-be

« back to all changes in this revision

Viewing changes to recipe.py

  • Committer: Romain Chalumeau
  • Date: 2010-09-20 13:02:20 UTC
  • Revision ID: rchalumeau@echo.fr-20100920130220-4hxn3575fi5llfka
* Report ing in a different module
* report argument added to RecipeBranch
* ReST formatted report

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    urlutils,
31
31
    )
32
32
from bzrlib.plugins.builder.reporting import *
33
 
    
34
33
 
35
34
try:
36
35
    from bzrlib.errors import NoWhoami
178
177
        try:
179
178
            conflicts = tree_to.conflicts()
180
179
            if len(conflicts) > 0:
181
 
                # FIXME: better reporting
182
 
                e = UnresolvedConflicts(tree_to)
183
 
                GLOBAL_REPORT['unresolvedconflicts'] = e
184
 
                raise e
 
180
                # FIXME: Send an empty exception to be caught by caller and transform into report
 
181
                raise ExistingConflictsInTree()
185
182
        except:
186
183
            if created_br_to:
187
184
                br_to.unlock()
231
228
        if (merger.base_rev_id == merger.other_rev_id and
232
229
                merger.other_rev_id is not None):
233
230
            # Nothing to do.
234
 
            GLOBAL_REPORT[child_branch.url] = AlreadyMergedReport(child_branch, tree_to)
 
231
            child_branch.report = AlreadyMergedReport(child_branch, tree_to)
235
232
            return
236
233
        conflict_count = merger.do_merge()
237
234
        merger.set_pending()
 
235
        print "mergig %s" % child_branch.url
238
236
        if conflict_count:
239
 
            # Storing in the dict GLOBAL_REPORT the conflict
240
 
            GLOBAL_REPORT[child_branch.url] = ConflictsFromMerge(child_branch, tree_to)
 
237
            # Reporting the conflict
 
238
            
 
239
            e = ConflictsFromMerge(child_branch, tree_to)
 
240
            child_branch.report = e
241
241
            if ignore_on_failure : 
242
242
                # If the parameter --merge_what_can_be is set, we revert the changes and report the conflicts
243
243
                tree_to.lock_tree_write()
244
244
                tree_to.revert()
245
245
                tree_to.unlock()
246
 
                trace.note('Conflicts detected while merging %s but ignored. Continuing... %s' % (child_branch.url, br_to.base) )
 
246
                trace.note('Conflicts detected while merging but ignored. Continuing... ')
247
247
                return 
248
248
            # else, we just raise an exception which will stop the build
249
249
            else:
250
 
                raise ConflictsFromMerge(child_branch, tree_to)
 
250
                raise e
251
251
        config = br_to.get_config()
252
252
        try:
253
253
            committer = config.username()
257
257
                urlutils.unescape_for_display(child_branch.url, 'utf-8'),
258
258
                committer=committer)
259
259
        # Storing in the dict GLOBAL_REPORT the merged branch
260
 
        GLOBAL_REPORT[child_branch.url] = MergeReport(child_branch, tree_to)
 
260
        #GLOBAL_REPORT.add(MergeReport(child_branch, tree_to))
 
261
        child_branch.report = MergeReport(child_branch, tree_to)
261
262
        trace.note("Merged %s and committed" % urlutils.unescape_for_display(child_branch.url, 'utf-8'))
262
263
        
263
264
    finally:
326
327
        tree_to, br_to = pull_or_branch(tree_to, br_to, base_branch.branch,
327
328
                to_transport, revision_id,
328
329
                possible_transports=possible_transports)
 
330
    # The base_branch is unknown in pull_or_branch, so catch the exception to complete it and raise
 
331
    except ExistingConflictsInTree:
 
332
        e = UnresolvedConflicts(base_branch, tree_to)
 
333
        base_branch.report = e
 
334
        raise e
329
335
    finally:
330
336
        base_branch.branch.unlock()
331
337
    return tree_to, br_to
438
444
        try:
439
445
            tree_to, br_to = update_branch(base_branch, tree_to, br_to,
440
446
                    to_transport, possible_transports=possible_transports)
 
447
            base_branch.report = NestReport(base_branch, tree_to)
441
448
            for instruction in base_branch.child_branches:
442
449
                instruction.apply(target_path, tree_to, br_to)
443
450
        finally:
447
454
    finally:
448
455
        if tree_to is not None:
449
456
            tree_to.unlock()
450
 
            GLOBAL_REPORT[base_branch.url] = NestReport(base_branch, tree_to)
451
457
    
452
458
 
453
459
 
479
485
        self.recipe_branch = recipe_branch
480
486
        self.nest_path = nest_path
481
487
        self.ignore_on_failure = ignore_on_failure
482
 
        print 'je traite : %s - %s' % (self.recipe_branch.url, str(self.nest_path))
483
 
 
 
488
        
484
489
    def apply(self, target_path, tree_to, br_to, possible_transports=None):
485
490
        raise NotImplementedError(self.apply)
486
491
 
560
565
        self.child_branches = []
561
566
        self.revid = None
562
567
        self.branch = None
563
 
 
 
568
        # Attributes for reporting
 
569
        self.parent = None
 
570
        # The report attribute will get an object inhenrated from Report class
 
571
        self.report = UndoneAction(self)
 
572
        
564
573
    def merge_branch(self, branch, ignore_on_failure=False):
565
574
        """Merge a child branch in to this one.
566
575
 
567
576
        :param branch: the RecipeBranch to merge.
568
577
        """
 
578
        branch.parent = self
569
579
        self.child_branches.append(MergeInstruction(branch, ignore_on_failure=ignore_on_failure))
570
580
 
571
581
    def nest_part_branch(self, branch, subpath=None, target_subdir=None):
655
665
        super(BaseRecipeBranch, self).__init__(None, url, revspec=revspec)
656
666
        self.deb_version = deb_version
657
667
        self.format = format
658
 
 
 
668
        
659
669
    def substitute_revno(self, branch_name, get_revno_cb):
660
670
        """Substitute the revno for the given branch name in deb_version.
661
671
 
670
680
            subst_string = REVNO_VAR
671
681
        else:
672
682
            subst_string = REVNO_PARAM_VAR % branch_name
 
683
        
673
684
        if subst_string in self.deb_version:
674
685
            revno = get_revno_cb()
675
686
            if revno is None:
676
687
                raise errors.BzrCommandError("Can't substitute revno of "
677
 
                        "branch %s in deb-version, as it's revno can't be "
 
688
                        "branch %s in deb-version, as it's revno can't be "  
 
689
 
678
690
                        "determined")
679
691
            self.deb_version = self.deb_version.replace(subst_string, revno)
680
692
 
728
740
                    # the manifest must not have the ignored conflicted branches as they have been reverted.
729
741
                    # So if the class of the child_branch in GLOBAL_REPORT is a conflict one, 
730
742
                    # we must not write it to manifest file
731
 
                    if GLOBAL_REPORT[child_branch.url].__class__ is not ConflictsFromMerge:
 
743
                    # if child_branch.url in GLOBAL_REPORT.display_in_manifest:
 
744
                    if child_branch.report.__class__ not in [UnresolvedConflicts, ConflictsFromMerge, UndoneAction]:
732
745
                        manifest += "%s%s %s %s%s\n" % \
733
746
                                 ("  " * indent_level, MERGE_INSTRUCTION,
734
747
                                  child_branch.name,
735
748
                                  child_branch.url, revid_part)
 
749
                    #else:
 
750
                    #    manifest += "# %s%s %s %s%s\n" % \
 
751
                    #            ("  " * indent_level, MERGE_INSTRUCTION,
 
752
                    #              child_branch.name,
 
753
                    #              child_branch.url, revid_part)
 
754
        
736
755
        return manifest
737
756
 
738
757