Reimplement :lines: as an HtmlFormatter subclass in code blocks
:lines: is applied to the raw source, before that source being passed to Pygments for highlighting and manipulation.
This has a number of negative effects:
because the sliced section may not be tokenizable on its own, pygments may fail to tokenize it, tokenize it incorrectly, or sphinx may just opt not to pass it to pygments at all (sphinx.highlighting:175)
line numbering becomes useless, as the line numbers are not those of the original file
line emphasis has to be expressed in terms of the sliced result rather than the original file (or patch hunks on the original files)
it is not possible to decorate or otherwise mark "missing" sections of files, the output looks as a single continuous block of code with no hint or indication that part of the content is missing
Meanwhile, since version 0.7 Pygments has built in subclassing hooks to HtmlFormatter which allows performing line-by-line post-processing of the document. It seems that runs before the addition of line numbers (so that idea may not work out), but all in all it could make code blocks more solid, and much simpler on the Sphinx side.