mercurial/simplemerge.py
changeset 26069 09d6725cbc60
parent 25974 241a1324a180
child 26223 ed12abab068e
equal deleted inserted replaced
26068:05e7f57c74ac 26069:09d6725cbc60
    98         if len(self.a) > 0:
    98         if len(self.a) > 0:
    99             if self.a[0].endswith('\r\n'):
    99             if self.a[0].endswith('\r\n'):
   100                 newline = '\r\n'
   100                 newline = '\r\n'
   101             elif self.a[0].endswith('\r'):
   101             elif self.a[0].endswith('\r'):
   102                 newline = '\r'
   102                 newline = '\r'
   103         if name_a:
   103         if name_a and start_marker:
   104             start_marker = start_marker + ' ' + name_a
   104             start_marker = start_marker + ' ' + name_a
   105         if name_b:
   105         if name_b and end_marker:
   106             end_marker = end_marker + ' ' + name_b
   106             end_marker = end_marker + ' ' + name_b
   107         if name_base and base_marker:
   107         if name_base and base_marker:
   108             base_marker = base_marker + ' ' + name_base
   108             base_marker = base_marker + ' ' + name_base
   109         merge_regions = self.merge_regions()
   109         merge_regions = self.merge_regions()
   110         for t in merge_regions:
   110         for t in merge_regions:
   118             elif what == 'b':
   118             elif what == 'b':
   119                 for i in range(t[1], t[2]):
   119                 for i in range(t[1], t[2]):
   120                     yield self.b[i]
   120                     yield self.b[i]
   121             elif what == 'conflict':
   121             elif what == 'conflict':
   122                 self.conflicts = True
   122                 self.conflicts = True
   123                 yield start_marker + newline
   123                 if start_marker is not None:
       
   124                     yield start_marker + newline
   124                 for i in range(t[3], t[4]):
   125                 for i in range(t[3], t[4]):
   125                     yield self.a[i]
   126                     yield self.a[i]
   126                 if base_marker is not None:
   127                 if base_marker is not None:
   127                     yield base_marker + newline
   128                     yield base_marker + newline
   128                     for i in range(t[1], t[2]):
   129                     for i in range(t[1], t[2]):
   129                         yield self.base[i]
   130                         yield self.base[i]
   130                 yield mid_marker + newline
   131                 if mid_marker is not None:
       
   132                     yield mid_marker + newline
   131                 for i in range(t[5], t[6]):
   133                 for i in range(t[5], t[6]):
   132                     yield self.b[i]
   134                     yield self.b[i]
   133                 yield end_marker + newline
   135                 if end_marker is not None:
       
   136                     yield end_marker + newline
   134             else:
   137             else:
   135                 raise ValueError(what)
   138                 raise ValueError(what)
   136 
   139 
   137     def merge_groups(self):
   140     def merge_groups(self):
   138         """Yield sequence of line groups.  Each one is a tuple:
   141         """Yield sequence of line groups.  Each one is a tuple:
   351                 ui.warn(_('warning: %s\n') % msg)
   354                 ui.warn(_('warning: %s\n') % msg)
   352             if not opts.get('text'):
   355             if not opts.get('text'):
   353                 raise util.Abort(msg)
   356                 raise util.Abort(msg)
   354         return text
   357         return text
   355 
   358 
   356     name_a = local
   359     mode = opts.get('mode','merge')
   357     name_b = other
   360     if mode == 'union':
   358     name_base = None
   361         name_a = None
   359     labels = opts.get('label', [])
   362         name_b = None
   360     if len(labels) > 0:
   363         name_base = None
   361         name_a = labels[0]
   364     else:
   362     if len(labels) > 1:
   365         name_a = local
   363         name_b = labels[1]
   366         name_b = other
   364     if len(labels) > 2:
   367         name_base = None
   365         name_base = labels[2]
   368         labels = opts.get('label', [])
   366     if len(labels) > 3:
   369         if len(labels) > 0:
   367         raise util.Abort(_("can only specify three labels."))
   370             name_a = labels[0]
       
   371         if len(labels) > 1:
       
   372             name_b = labels[1]
       
   373         if len(labels) > 2:
       
   374             name_base = labels[2]
       
   375         if len(labels) > 3:
       
   376             raise util.Abort(_("can only specify three labels."))
   368 
   377 
   369     try:
   378     try:
   370         localtext = readfile(local)
   379         localtext = readfile(local)
   371         basetext = readfile(base)
   380         basetext = readfile(base)
   372         othertext = readfile(other)
   381         othertext = readfile(other)
   380     else:
   389     else:
   381         out = sys.stdout
   390         out = sys.stdout
   382 
   391 
   383     m3 = Merge3Text(basetext, localtext, othertext)
   392     m3 = Merge3Text(basetext, localtext, othertext)
   384     extrakwargs = {}
   393     extrakwargs = {}
   385     if name_base is not None:
   394     if mode == 'union':
       
   395         extrakwargs['start_marker'] = None
       
   396         extrakwargs['mid_marker'] = None
       
   397         extrakwargs['end_marker'] = None
       
   398     elif name_base is not None:
   386         extrakwargs['base_marker'] = '|||||||'
   399         extrakwargs['base_marker'] = '|||||||'
   387         extrakwargs['name_base'] = name_base
   400         extrakwargs['name_base'] = name_base
   388     for line in m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs):
   401     for line in m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs):
   389         out.write(line)
   402         out.write(line)
   390 
   403 
   391     if not opts.get('print'):
   404     if not opts.get('print'):
   392         out.close()
   405         out.close()
   393 
   406 
   394     if m3.conflicts:
   407     if m3.conflicts and not mode == 'union':
   395         if not opts.get('quiet'):
   408         if not opts.get('quiet'):
   396             ui.warn(_("warning: conflicts during merge.\n"))
   409             ui.warn(_("warning: conflicts during merge.\n"))
   397         return 1
   410         return 1