mercurial/patch.py
changeset 26557 23f3f1cbd53b
parent 26556 2bef84fad19f
child 26558 fe52cd049f01
equal deleted inserted replaced
26556:2bef84fad19f 26557:23f3f1cbd53b
   148             return headersplit(stream, cur)
   148             return headersplit(stream, cur)
   149         # Not enough info, keep reading
   149         # Not enough info, keep reading
   150 
   150 
   151     # if we are here, we have a very plain patch
   151     # if we are here, we have a very plain patch
   152     return remainder(cur)
   152     return remainder(cur)
       
   153 
       
   154 ## Some facility for extensible patch parsing:
       
   155 # list of pairs ("header to match", "data key")
       
   156 patchheadermap = []
   153 
   157 
   154 def extract(ui, fileobj):
   158 def extract(ui, fileobj):
   155     '''extract patch from data read from fileobj.
   159     '''extract patch from data read from fileobj.
   156 
   160 
   157     patch can be a normal patch or contained in an email message.
   161     patch can be a normal patch or contained in an email message.
   236                             data['branch'] = line[9:]
   240                             data['branch'] = line[9:]
   237                         elif line.startswith("# Node ID "):
   241                         elif line.startswith("# Node ID "):
   238                             data['nodeid'] = line[10:]
   242                             data['nodeid'] = line[10:]
   239                         elif line.startswith("# Parent "):
   243                         elif line.startswith("# Parent "):
   240                             parents.append(line[9:].lstrip())
   244                             parents.append(line[9:].lstrip())
   241                         elif not line.startswith("# "):
   245                         elif line.startswith("# "):
       
   246                             for header, key in patchheadermap:
       
   247                                 prefix = '# %s ' % header
       
   248                                 if line.startswith(prefix):
       
   249                                     data[key] = line[len(prefix):]
       
   250                         else:
   242                             hgpatchheader = False
   251                             hgpatchheader = False
   243                     elif line == '---':
   252                     elif line == '---':
   244                         ignoretext = True
   253                         ignoretext = True
   245                     if not hgpatchheader and not ignoretext:
   254                     if not hgpatchheader and not ignoretext:
   246                         cfp.write(line)
   255                         cfp.write(line)