+/* Find, and write to ENCLOSER, the nearest line before POS which matches + ENCLOSER_PATTERN. We remember the last line scanned, and the matched, to + avoid duplication of effort. */ + +void +hunk_consumer::find_encloser(size_t pos, string & encloser) +{ + typedef vector<string>::const_reverse_iterator riter; + + if (!encloser_re) + return; + + riter last = a.rbegin() + (a.size() - encloser_last_search); + encloser_last_search = pos; + + for (riter i = a.rbegin() + (a.size() - pos); i != last; i++) { + if (boost::regex_search (*i, *encloser_re)) + { + encloser_last_match = a.size() - (i - a.rbegin()); + L(FL("find_encloser: from %u matching line %d, \"%s\"") + % pos % encloser_last_match % *i); + + // the number 40 is chosen to match GNU diff. it could safely be + // increased up to about 60 without overflowing the standard + // terminal width. + encloser = string(" ") + (*i).substr(0, 40); + return; + } + } + + if (encloser_last_match) + { + ssize_t i = encloser_last_match; + L(FL("find_encloser: from %u matching cached %d, \"%s\"") + % pos % i % a[i]); + encloser = string(" ") + a[i].substr(0, 40); + } +} ^^ I think I'd feel more comfortable here with some I()'s scattered around here? It is Clever, and involves Pointers, you see.
+ for (i = hunk.begin(); i != hunk.end(); i++) + if ((*i)[0] != ' ') + { + first_mod = i - hunk.begin(); + break; + } + + find_encloser(a_begin + first_mod, encloser); + ost << " @@" << encloser << endl; ^^ The way the unidiff and context diff writers go back and parse their own output seems a bit... well, odd, anyway? The docs weren't fully updated when the code changed (and had a weird formatting issue, with a line starting with a period). I fixed this. Merged to mainline. -- Nathaniel -- Damn the Solar System. Bad light; planets too distant; pestered with comets; feeble contrivance; could make a better one myself. -- Lord Jeffrey _______________________________________________ Monotone-devel mailing list Monotone-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/monotone-devel