/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 doc/en/user-guide/hooks.txt

  • Committer: Andrew Bennetts
  • Date: 2010-04-22 07:35:06 UTC
  • mto: This revision was merged to the branch mainline in revision 5193.
  • Revision ID: andrew.bennetts@canonical.com-20100422073506-7i5pqyhzdj5pcelx
Create a PerFileMerger helper class that is midway between AbstractPerFileMerger and ConfigurableFileMerger.  It allows the example merge plugin in the docs (the always conflict *.xml files) to be much, much simpler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
  Always conflicts if both branches have changed the file.
78
78
  """
79
79
  
80
 
  from bzrlib.merge import AbstractPerFileMerger, Merger
 
80
  from bzrlib.merge import PerFileMerger, Merger
81
81
  
82
82
  def merge_xml_files_hook(merger):
83
83
      """Hook to merge *.xml files"""
84
84
      return MergeXMLFiles(merger)
85
85
  
86
 
  class MergeXMLFiles(AbstractPerFileMerger):
87
 
  
88
 
      def filename_matches(self, params):
89
 
          inventory = self.merger.this_tree.inventory
90
 
          filename = inventory[params.file_id].name
91
 
          if filename.endswith('.xml'):
92
 
              return filename
93
 
  
94
 
      def merge_contents(self, params):
95
 
          """Merge the contents of a single file."""
96
 
          # First, check whether this custom merge logic should be used. We
97
 
          # expect most files should not be merged by this handler.
98
 
          if (
99
 
              # OTHER is a straight winner, rely on default merge.
100
 
              params.winner == 'other' or
101
 
              # THIS and OTHER aren't both files.
102
 
              not params.is_file_merge() or
103
 
              # The filename doesn't match *.xml
104
 
              not self.filename_matches(params)):
105
 
              return 'not_applicable', None
 
86
  class AlwaysConflictXMLMerger(PerFileMerger):
 
87
  
 
88
      def file_matches(self, params):
 
89
          filename = self.get_filename(params, self.merger.this_tree)
 
90
          return filename.endswith('.xml')
 
91
  
 
92
      def merge_matching(self, params):
106
93
          return 'conflicted', params.this_lines
107
94
  
108
95
  Merger.hooks.install_named_hook(