mercurial/mdiff.py
changeset 15141 16dc9a32ca04
parent 12751 8eb758ea738c
child 15437 8f08b635cdce
child 15462 2b1ec74c961f
equal deleted inserted replaced
15140:353a1ba928f6 15141:16dc9a32ca04
   155         ret = l - opts.context
   155         ret = l - opts.context
   156         if ret < 0:
   156         if ret < 0:
   157             return 0
   157             return 0
   158         return ret
   158         return ret
   159 
   159 
       
   160     lastfunc = [0, '']
   160     def yieldhunk(hunk):
   161     def yieldhunk(hunk):
   161         (astart, a2, bstart, b2, delta) = hunk
   162         (astart, a2, bstart, b2, delta) = hunk
   162         aend = contextend(a2, len(l1))
   163         aend = contextend(a2, len(l1))
   163         alen = aend - astart
   164         alen = aend - astart
   164         blen = b2 - bstart + aend - a2
   165         blen = b2 - bstart + aend - a2
   165 
   166 
   166         func = ""
   167         func = ""
   167         if opts.showfunc:
   168         if opts.showfunc:
   168             # walk backwards from the start of the context
   169             lastpos, func = lastfunc
   169             # to find a line starting with an alphanumeric char.
   170             # walk backwards from the start of the context up to the start of
   170             for x in xrange(astart - 1, -1, -1):
   171             # the previous hunk context until we find a line starting with an
   171                 t = l1[x].rstrip()
   172             # alphanumeric char.
   172                 if funcre.match(t):
   173             for i in xrange(astart - 1, lastpos - 1, -1):
   173                     func = ' ' + t[:40]
   174                 if l1[i][0].isalnum():
       
   175                     func = ' ' + l1[i].rstrip()[:40]
       
   176                     lastfunc[1] = func
   174                     break
   177                     break
       
   178             # by recording this hunk's starting point as the next place to
       
   179             # start looking for function lines, we avoid reading any line in
       
   180             # the file more than once.
       
   181             lastfunc[0] = astart
   175 
   182 
   176         yield "@@ -%d,%d +%d,%d @@%s\n" % (astart + 1, alen,
   183         yield "@@ -%d,%d +%d,%d @@%s\n" % (astart + 1, alen,
   177                                            bstart + 1, blen, func)
   184                                            bstart + 1, blen, func)
   178         for x in delta:
   185         for x in delta:
   179             yield x
   186             yield x
   180         for x in xrange(a2, aend):
   187         for x in xrange(a2, aend):
   181             yield ' ' + l1[x]
   188             yield ' ' + l1[x]
   182 
       
   183     if opts.showfunc:
       
   184         funcre = re.compile('\w')
       
   185 
   189 
   186     # bdiff.blocks gives us the matching sequences in the files.  The loop
   190     # bdiff.blocks gives us the matching sequences in the files.  The loop
   187     # below finds the spaces between those matching sequences and translates
   191     # below finds the spaces between those matching sequences and translates
   188     # them into diff output.
   192     # them into diff output.
   189     #
   193     #