mercurial/mdiff.py
changeset 49284 d44e3c45f0e4
parent 48946 642e31cb55f0
child 49897 a78dfb1ad60e
equal deleted inserted replaced
49283:44b26349127b 49284:d44e3c45f0e4
   376         if opts.showfunc:
   376         if opts.showfunc:
   377             lastpos, func = lastfunc
   377             lastpos, func = lastfunc
   378             # walk backwards from the start of the context up to the start of
   378             # walk backwards from the start of the context up to the start of
   379             # the previous hunk context until we find a line starting with an
   379             # the previous hunk context until we find a line starting with an
   380             # alphanumeric char.
   380             # alphanumeric char.
   381             for i in pycompat.xrange(astart - 1, lastpos - 1, -1):
   381             for i in range(astart - 1, lastpos - 1, -1):
   382                 if l1[i][0:1].isalnum():
   382                 if l1[i][0:1].isalnum():
   383                     func = b' ' + l1[i].rstrip()
   383                     func = b' ' + l1[i].rstrip()
   384                     # split long function name if ASCII. otherwise we have no
   384                     # split long function name if ASCII. otherwise we have no
   385                     # idea where the multi-byte boundary is, so just leave it.
   385                     # idea where the multi-byte boundary is, so just leave it.
   386                     if encoding.isasciistr(func):
   386                     if encoding.isasciistr(func):
   400 
   400 
   401         hunkrange = astart, alen, bstart, blen
   401         hunkrange = astart, alen, bstart, blen
   402         hunklines = (
   402         hunklines = (
   403             [b"@@ -%d,%d +%d,%d @@%s\n" % (hunkrange + (func,))]
   403             [b"@@ -%d,%d +%d,%d @@%s\n" % (hunkrange + (func,))]
   404             + delta
   404             + delta
   405             + [b' ' + l1[x] for x in pycompat.xrange(a2, aend)]
   405             + [b' ' + l1[x] for x in range(a2, aend)]
   406         )
   406         )
   407         # If either file ends without a newline and the last line of
   407         # If either file ends without a newline and the last line of
   408         # that file is part of a hunk, a marker is printed. If the
   408         # that file is part of a hunk, a marker is printed. If the
   409         # last line of both files is identical and neither ends in
   409         # last line of both files is identical and neither ends in
   410         # a newline, print only one marker. That's the only case in
   410         # a newline, print only one marker. That's the only case in
   411         # which the hunk can end in a shared line without a newline.
   411         # which the hunk can end in a shared line without a newline.
   412         skip = False
   412         skip = False
   413         if not t1.endswith(b'\n') and astart + alen == len(l1) + 1:
   413         if not t1.endswith(b'\n') and astart + alen == len(l1) + 1:
   414             for i in pycompat.xrange(len(hunklines) - 1, -1, -1):
   414             for i in range(len(hunklines) - 1, -1, -1):
   415                 if hunklines[i].startswith((b'-', b' ')):
   415                 if hunklines[i].startswith((b'-', b' ')):
   416                     if hunklines[i].startswith(b' '):
   416                     if hunklines[i].startswith(b' '):
   417                         skip = True
   417                         skip = True
   418                     hunklines[i] += b'\n'
   418                     hunklines[i] += b'\n'
   419                     hunklines.insert(i + 1, diffhelper.MISSING_NEWLINE_MARKER)
   419                     hunklines.insert(i + 1, diffhelper.MISSING_NEWLINE_MARKER)
   420                     break
   420                     break
   421         if not skip and not t2.endswith(b'\n') and bstart + blen == len(l2) + 1:
   421         if not skip and not t2.endswith(b'\n') and bstart + blen == len(l2) + 1:
   422             for i in pycompat.xrange(len(hunklines) - 1, -1, -1):
   422             for i in range(len(hunklines) - 1, -1, -1):
   423                 if hunklines[i].startswith(b'+'):
   423                 if hunklines[i].startswith(b'+'):
   424                     hunklines[i] += b'\n'
   424                     hunklines[i] += b'\n'
   425                     hunklines.insert(i + 1, diffhelper.MISSING_NEWLINE_MARKER)
   425                     hunklines.insert(i + 1, diffhelper.MISSING_NEWLINE_MARKER)
   426                     break
   426                     break
   427         yield hunkrange, hunklines
   427         yield hunkrange, hunklines