[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone.colored-diff: 663b1962226c9d
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone.colored-diff: 663b1962226c9dacd2f691f957229ecf90ed6365 |
Date: |
Mon, 11 Apr 2011 22:45:20 +0200 (CEST) |
revision: 663b1962226c9dacd2f691f957229ecf90ed6365
date: 2011-04-11T20:40:12
author: Richard Hopkins <address@hidden>
branch: net.venge.monotone.colored-diff
changelog:
Fixed output of "mtn diff" for both --colorize and --no-colorize
The binary output is now different to the last revision before Win32 work
started (90a61d2166a6c30e950a0d02f590b83ca9b6b39d), however, visually the
output should identical.
The reason is because everything now goes through the colorizer which means
normal text usually comes along with the reset color - this can be seen as
ANSI codes 39,49,22,23,24 in the output.
manifest:
format_version "1"
new_manifest [986aeed8a87dab11e169bc74de0320a127de3b93]
old_revision [0023a9dead1bbc0354008a529f7abf96f10c73e8]
patch "src/cmd_diff_log.cc"
from [a777dfeab40d7ce6498295026a751e545582688a]
to [c9aa40fd997f22a53476a25b6ca5a85593294c7e]
patch "src/diff_output.cc"
from [db19431f96f35ca8c6b89c129c2a805ddd418f15]
to [efd832d9d022a3c564093df9b37844bfe62f2519]
============================================================
--- src/diff_output.cc db19431f96f35ca8c6b89c129c2a805ddd418f15
+++ src/diff_output.cc efd832d9d022a3c564093df9b37844bfe62f2519
@@ -142,9 +142,9 @@ void walk_hunk_consumer(vector<long, QA(
continue;
cons.advance_to(a);
- while (idx(lines1,a) != *i)
- cons.delete_at(a++);
- while (idx(lines2,b) != *i)
+ while (idx(lines1, a) != *i)
+ cons.delete_at(a++);
+ while (idx(lines2, b) != *i)
cons.insert_at(b++);
}
if (a < lines1.size())
@@ -163,6 +163,20 @@ void walk_hunk_consumer(vector<long, QA(
}
}
+colorizer::purpose
+hunk_to_purpose(string const & hunk)
+{
+ char const & type = hunk[0];
+ if (type == '+')
+ return colorizer::add;
+ else if (type == '-')
+ return colorizer::remove;
+ else if (type == '!')
+ return colorizer::change;
+ else
+ return colorizer::normal;
+}
+
struct unidiff_hunk_writer : public hunk_consumer
{
vector<string> hunk;
@@ -178,22 +192,20 @@ struct unidiff_hunk_writer : public hunk
ostream & ost,
string const & encloser_pattern,
colorizer const & color)
- : hunk_consumer(a, b, ctx, ost, encloser_pattern, color)
+ : hunk_consumer(a, b, ctx, ost, encloser_pattern, color)
{}
};
void unidiff_hunk_writer::insert_at(size_t b_pos)
{
b_len++;
- hunk.push_back(color.colorize(string("+") + b[b_pos],
- colorizer::add));
+ hunk.push_back(string("+") + b[b_pos]);
}
void unidiff_hunk_writer::delete_at(size_t a_pos)
{
a_len++;
- hunk.push_back(color.colorize(string("-") + a[a_pos],
- colorizer::remove));
+ hunk.push_back(string("-") + a[a_pos]);
}
void unidiff_hunk_writer::flush_hunk(size_t pos)
@@ -215,16 +227,16 @@ void unidiff_hunk_writer::flush_hunk(siz
ss << "@@ -0,0";
else
{
- ss << "@@ -" << a_begin+1;
+ ss << "@@ -" << a_begin + 1;
if (a_len > 1)
ss << ',' << a_len;
}
-
+
if (b_len == 0)
ss << " +0,0";
else
{
- ss << " +" << b_begin+1;
+ ss << " +" << b_begin + 1;
if (b_len > 1)
ss << ',' << b_len;
}
@@ -243,11 +255,15 @@ void unidiff_hunk_writer::flush_hunk(siz
find_encloser(a_begin + first_mod, encloser);
ss << " @@";
- ost << color.colorize(ss.str(), colorizer::separator);
- ost << color.colorize(encloser, colorizer::encloser);
- ost << '\n';
+ color.get_ostream() << color.colorize(ss.str(), colorizer::separator);
+ color.get_ostream() << color.colorize(encloser, colorizer::encloser);
+ color.get_ostream() << '\n';
}
- copy(hunk.begin(), hunk.end(), ostream_iterator<string>(ost, "\n"));
+ for (vector<string>::const_iterator i = hunk.begin(); i != hunk.end(); i++)
+ {
+ color.colorize(*i, hunk_to_purpose(*i));
+ color.get_ostream() << "\n";
+ }
}
// reset hunk
@@ -313,8 +329,8 @@ struct cxtdiff_hunk_writer : public hunk
ostream & ost,
string const & encloser_pattern,
colorizer const & colorizer)
- : hunk_consumer(a, b, ctx, ost, encloser_pattern, colorizer),
- have_insertions(false), have_deletions(false)
+ : hunk_consumer(a, b, ctx, ost, encloser_pattern, colorizer),
+ have_insertions(false), have_deletions(false)
{}
};
@@ -375,17 +391,28 @@ void cxtdiff_hunk_writer::flush_hunk(siz
find_encloser(a_begin + min(first_insert, first_delete),
encloser);
- ost << color.colorize("***************", colorizer::separator)
- << color.colorize(encloser, colorizer::encloser) << '\n';
+ color.colorize("***************", colorizer::separator);
+ color.colorize(encloser, colorizer::encloser);
+ color.get_ostream() << '\n';
}
- ost << "*** " << (a_begin + 1) << ',' << (a_begin + a_len) << " ****\n";
+ color.get_ostream() << "*** " << (a_begin + 1) << ',' << (a_begin + a_len) << " ****\n";
if (have_deletions)
- copy(from_file.begin(), from_file.end(), ostream_iterator<string>(ost, "\n"));
+ for (vector<string>::const_iterator i = from_file.begin();
+ i != from_file.end(); i++)
+ {
+ color.colorize(*i, hunk_to_purpose(*i));
+ color.get_ostream() << "\n";
+ }
- ost << "--- " << (b_begin + 1) << ',' << (b_begin + b_len) << " ----\n";
+ color.get_ostream() << "--- " << (b_begin + 1) << ',' << (b_begin + b_len) << " ----\n";
if (have_insertions)
- copy(to_file.begin(), to_file.end(), ostream_iterator<string>(ost, "\n"));
+ for (vector<string>::const_iterator i = to_file.begin();
+ i != to_file.end(); i++)
+ {
+ color.colorize(*i, hunk_to_purpose(*i));
+ color.get_ostream() << "\n";
+ }
}
// reset hunk
@@ -410,33 +437,29 @@ 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 "!"
- colorizer::purpose p = colorizer::normal;
if (inserts.empty() && !deletes.empty())
- {
- prefix = "-";
- p = colorizer::remove;
- }
+ {
+ prefix = "-";
+ }
else if (deletes.empty() && !inserts.empty())
- {
- prefix = "+";
- p = colorizer::add;
- }
+ {
+ prefix = "+";
+ }
else
- {
- prefix = "!";
- p = colorizer::change;
- }
+ {
+ prefix = "!";
+ }
for (vector<size_t>::const_iterator i = deletes.begin();
i != deletes.end(); ++i)
{
- from_file.push_back(color.colorize(prefix + string(" ") + a[*i], p));
+ from_file.push_back(prefix + string(" ") + a[*i]);
a_len++;
}
for (vector<size_t>::const_iterator i = inserts.begin();
i != inserts.end(); ++i)
{
- to_file.push_back(color.colorize(prefix + string(" ") + b[*i], p));
+ to_file.push_back(prefix + string(" ") + b[*i]);
b_len++;
}
@@ -505,11 +528,11 @@ make_diff(string const & filename1,
// If a file has been removed, filename2 will be "/dev/null".
// It doesn't make sense to output that.
if (filename2 == "/dev/null")
- ost << color.colorize(string("# ") + filename1 + " is binary",
- colorizer::comment) << "\n";
+ color.get_ostream() << color.colorize(string("# ") + filename1 + " is binary",
+ colorizer::comment) << "\n";
else
- ost << color.colorize(string("# ") + filename2 + " is binary",
- colorizer::comment) << "\n";
+ color.get_ostream() << color.colorize(string("# ") + filename2 + " is binary",
+ colorizer::comment) << "\n";
return;
}
@@ -533,7 +556,7 @@ make_diff(string const & filename1,
i != lines2.end(); ++i)
right_interned.push_back(in.intern(*i));
- lcs.reserve(min(lines1.size(),lines2.size()));
+ lcs.reserve(min(lines1.size(), lines2.size()));
longest_common_subsequence(left_interned.begin(), left_interned.end(),
right_interned.begin(), right_interned.end(),
back_inserter(lcs));
@@ -596,39 +619,39 @@ make_diff(string const & filename1,
// if the new file name is "/dev/null", nothing else.
switch (type)
{
- case unified_diff:
- {
- ost << color.colorize(string("--- ") + filename1,
- colorizer::remove)
- << '\t' << id1 << '\n';
- ost << color.colorize(string("+++ ") + filename2,
- colorizer::add)
- << '\t' << id2 << '\n';
+ case unified_diff:
+ {
+ color.get_ostream() << color.colorize(string("--- ") + filename1,
+ colorizer::remove)
+ << '\t' << id1 << '\n';
+ color.get_ostream() << color.colorize(string("+++ ") + filename2,
+ colorizer::add)
+ << '\t' << id2 << '\n';
- unidiff_hunk_writer hunks(lines1, lines2, 3, ost, pattern, color);
- walk_hunk_consumer(lcs, left_interned, right_interned, hunks);
- break;
- }
- case context_diff:
- {
- ost << color.colorize(string("*** ") + filename1,
- colorizer::remove)
- << '\t' << id1 << '\n';
- ost << color.colorize(string("--- ") + filename2,
- colorizer::add)
- << '\t' << id2 << '\n';
+ unidiff_hunk_writer hunks(lines1, lines2, 3, ost, pattern, color);
+ walk_hunk_consumer(lcs, left_interned, right_interned, hunks);
+ break;
+ }
+ case context_diff:
+ {
+ color.get_ostream() << color.colorize(string("*** ") + filename1,
+ colorizer::remove)
+ << '\t' << id1 << '\n';
+ color.get_ostream() << color.colorize(string("--- ") + filename2,
+ colorizer::add)
+ << '\t' << id2 << '\n';
- cxtdiff_hunk_writer hunks(lines1, lines2, 3, ost, pattern, color);
- walk_hunk_consumer(lcs, left_interned, right_interned, hunks);
- break;
- }
- default:
- {
- // should never reach this; the external_diff type is not
- // handled by this function.
- I(false);
- }
+ cxtdiff_hunk_writer hunks(lines1, lines2, 3, ost, pattern, color);
+ walk_hunk_consumer(lcs, left_interned, right_interned, hunks);
+ break;
}
+ default:
+ {
+ // should never reach this; the external_diff type is not
+ // handled by this function.
+ I(false);
+ }
+ }
}
============================================================
--- src/cmd_diff_log.cc a777dfeab40d7ce6498295026a751e545582688a
+++ src/cmd_diff_log.cc c9aa40fd997f22a53476a25b6ca5a85593294c7e
@@ -99,7 +99,7 @@ dump_diff(lua_hooks & lua,
{
// 60 is somewhat arbitrary, but less than 80
string patch_sep = string(60, '=');
- output << patch_sep << '\n';
+ colorizer.get_ostream() << patch_sep << '\n';
// see the big comment in diff_output.cc about what paths should be
string left = left_path.as_internal();
@@ -399,23 +399,23 @@ void dump_header(std::string const & rev
vector<string> lines;
split_into_lines(summary(), lines);
- out << colorizer.colorize("#", colorizer::comment) << "\n";
+ colorizer.get_ostream() << colorizer.colorize("#", colorizer::comment) << "\n";
if (!summary().empty())
{
- out << colorizer.colorize(revs, colorizer::comment);
- out << colorizer.colorize("#", colorizer::comment) << "\n";
+ colorizer.get_ostream() << colorizer.colorize(revs, colorizer::comment);
+ colorizer.get_ostream() << colorizer.colorize("#", colorizer::comment) << "\n";
for (vector<string>::iterator i = lines.begin();
i != lines.end(); ++i)
- out << colorizer.colorize(string("# ") + *i,
- colorizer::comment) << "\n";
+ colorizer.get_ostream() << colorizer.colorize(string("# ") + *i,
+ colorizer::comment) << "\n";
}
else
{
- out << colorizer.colorize(string("# ") + _("no changes"),
- colorizer::comment) << "\n";
+ colorizer.get_ostream() << colorizer.colorize(string("# ") + _("no changes"),
+ colorizer::comment) << "\n";
}
- out << colorizer.colorize("#", colorizer::comment) << "\n";
+ colorizer.get_ostream() << colorizer.colorize("#", colorizer::comment) << "\n";
}
CMD_PRESET_OPTIONS(diff)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone.colored-diff: 663b1962226c9dacd2f691f957229ecf90ed6365,
code <=