# # # patch "Makefile.am" # from [eb7cf82ecaf2da8091ede85fe5fe98dd5401928a] # to [73934b04302761f542bb9e214a3ae2938fc13f8a] # # patch "cmd_diff_log.cc" # from [bd55c33e185979f03a6e5fe2d32188fac1dc0676] # to [d5c3600e2eeb7a74ac2c9f73c6cd75cd220c2b2f] # # patch "diff_patch.cc" # from [2016526a3148b6c23a04dd3c50b1af6f5f70a2fd] # to [cc30eb557fae84b48fd261d199d25ff25f355111] # ============================================================ --- Makefile.am eb7cf82ecaf2da8091ede85fe5fe98dd5401928a +++ Makefile.am 73934b04302761f542bb9e214a3ae2938fc13f8a @@ -73,6 +73,7 @@ MOST_SOURCES = \ rev_height.cc rev_height.hh \ asciik.cc asciik.hh \ dates.cc dates.hh \ + color.cc color.hh \ \ lru_writeback_cache.hh hybrid_map.hh \ \ ============================================================ --- cmd_diff_log.cc bd55c33e185979f03a6e5fe2d32188fac1dc0676 +++ cmd_diff_log.cc d5c3600e2eeb7a74ac2c9f73c6cd75cd220c2b2f @@ -16,6 +16,7 @@ #include "asciik.hh" #include "charset.hh" +#include "color.hh" #include "cmd.hh" #include "diff_patch.hh" #include "file_io.hh" @@ -231,7 +232,7 @@ dump_diffs(cset const & cs, bool limit_paths = false) { // 60 is somewhat arbitrary, but less than 80 - string patch_sep = string(60, '='); + string patch_sep = string(color::comment) + string(60, '=') + string(color::std); for (map::const_iterator i = cs.files_added.begin(); @@ -501,7 +502,7 @@ CMD(diff, "diff", "", CMD_REF(informativ vector lines; split_into_lines(summary(), lines); - cout << "#\n"; + cout << color::comment << "#\n"; if (summary().size() > 0) { cout << revs << "#\n"; @@ -513,10 +514,11 @@ CMD(diff, "diff", "", CMD_REF(informativ { cout << "# " << _("no changes") << '\n'; } - cout << "#\n"; + cout << "#\n" << color::std; if (app.opts.diff_format == external_diff) { + //TODO in this case color:: codes should probably not be used also up there do_external_diff(included, app, new_is_archived); } else ============================================================ --- diff_patch.cc 2016526a3148b6c23a04dd3c50b1af6f5f70a2fd +++ diff_patch.cc cc30eb557fae84b48fd261d199d25ff25f355111 @@ -16,6 +16,7 @@ #include #include +#include "color.hh" #include "diff_patch.hh" #include "interner.hh" #include "lcs.hh" @@ -929,13 +930,13 @@ void unidiff_hunk_writer::insert_at(size void unidiff_hunk_writer::insert_at(size_t b_pos) { b_len++; - hunk.push_back(string("+") + b[b_pos]); + hunk.push_back(string(color::add) + string("+") + b[b_pos] + string(color::std)); } void unidiff_hunk_writer::delete_at(size_t a_pos) { a_len++; - hunk.push_back(string("-") + a[a_pos]); + hunk.push_back(string(color::del) + string("-") + a[a_pos] + string(color::std)); } void unidiff_hunk_writer::flush_hunk(size_t pos) @@ -953,10 +954,10 @@ void unidiff_hunk_writer::flush_hunk(siz // write hunk to stream if (a_len == 0) - ost << "@@ -0,0"; + ost << color::strong << "@@ -0,0"; else { - ost << "@@ -" << a_begin+1; + ost << color::strong << "@@ -" << a_begin+1; if (a_len > 1) ost << ',' << a_len; } @@ -982,7 +983,7 @@ void unidiff_hunk_writer::flush_hunk(siz } find_encloser(a_begin + first_mod, encloser); - ost << " @@" << encloser << '\n'; + ost << " @@" << encloser << '\n' << color::std; } copy(hunk.begin(), hunk.end(), ostream_iterator(ost, "\n")); } @@ -1118,14 +1119,14 @@ void cxtdiff_hunk_writer::flush_hunk(siz find_encloser(a_begin + min(first_insert, first_delete), encloser); - ost << "***************" << encloser << '\n'; + ost << color::strong << "***************" << encloser << '\n' << color::std; } - ost << "*** " << (a_begin + 1) << ',' << (a_begin + a_len) << " ****\n"; + ost << color::strong << "*** " << (a_begin + 1) << ',' << (a_begin + a_len) << " ****\n" << color::std; if (have_deletions) copy(from_file.begin(), from_file.end(), ostream_iterator(ost, "\n")); - ost << "--- " << (b_begin + 1) << ',' << (b_begin + b_len) << " ----\n"; + ost << color::strong << "--- " << (b_begin + 1) << ',' << (b_begin + b_len) << " ----\n" << color::std; if (have_insertions) copy(to_file.begin(), to_file.end(), ostream_iterator(ost, "\n")); } @@ -1153,22 +1154,22 @@ void cxtdiff_hunk_writer::flush_pending_ // if we have just insertions to flush, prefix them with "+"; if // just deletions, prefix with "-"; if both, prefix with "!" if (inserts.empty() && !deletes.empty()) - prefix = "-"; + prefix = string(color::del) + string("-"); else if (deletes.empty() && !inserts.empty()) - prefix = "+"; + prefix = string(color::add) + string("+"); else - prefix = "!"; + prefix = string(color::conflict) + string("!"); for (vector::const_iterator i = deletes.begin(); i != deletes.end(); ++i) { - from_file.push_back(prefix + string(" ") + a[*i]); + from_file.push_back(prefix + string(" ") + a[*i] + string(color::std)); a_len++; } for (vector::const_iterator i = inserts.begin(); i != inserts.end(); ++i) { - to_file.push_back(prefix + string(" ") + b[*i]); + to_file.push_back(prefix + string(" ") + b[*i] + string(color::std)); b_len++; } @@ -1233,7 +1234,7 @@ make_diff(string const & filename1, { if (guess_binary(data1()) || guess_binary(data2())) { - ost << "# " << filename2 << " is binary\n"; + ost << color::comment << "# " << filename2 << " is binary\n" << color::std; return; } @@ -1324,8 +1325,9 @@ make_diff(string const & filename1, { case unified_diff: { - ost << "--- " << filename1 << '\t' << id1 << '\n'; - ost << "+++ " << filename2 << '\t' << id2 << '\n'; + ost << color::del << "--- " << filename1 << '\t' << id1 << '\n'; + ost << color::add << "+++ " << filename2 << '\t' << id2 << '\n'; + ost << color::std; unidiff_hunk_writer hunks(lines1, lines2, 3, ost, pattern); walk_hunk_consumer(lcs, left_interned, right_interned, hunks); @@ -1333,8 +1335,9 @@ make_diff(string const & filename1, } case context_diff: { - ost << "*** " << filename1 << '\t' << id1 << '\n'; - ost << "--- " << filename2 << '\t' << id2 << '\n'; + ost << color::del << "*** " << filename1 << '\t' << id1 << '\n'; + ost << color::add << "--- " << filename2 << '\t' << id2 << '\n'; + ost << color::std; cxtdiff_hunk_writer hunks(lines1, lines2, 3, ost, pattern); walk_hunk_consumer(lcs, left_interned, right_interned, hunks);