# # # patch "cmd_automate.cc" # from [31490dcba1e859909b03f69fedfcc7ffe1ca0faa] # to [12ac852434d7da216115bcddac1c47986449fcc1] # # patch "cmd_diff_log.cc" # from [509da14568d804c8e3fb741cc676f0979fe33e6f] # to [3c3f91765800b2dd861a997b400c4053fd6969a6] # # patch "monotone.texi" # from [5e2bb7643436006b6bf4a7883eb6ac40eb4efdda] # to [49e39037ce032c7b65fdf42e5fde18b6fb911735] # # patch "options_list.hh" # from [93e1285e0f6cd24e045a53bdb689af5739f94e9c] # to [be7e3a4c58245de8cdd8c88a1bfcb54ff5dc8821] # # patch "tests/automate_content_diff/__driver__.lua" # from [49eb0b60c12eefb624af0e586d6bd860ac03cfb4] # to [274e9b78eab4715e2d793b1db848bc872b0ad173] # ============================================================ --- cmd_automate.cc 31490dcba1e859909b03f69fedfcc7ffe1ca0faa +++ cmd_automate.cc 12ac852434d7da216115bcddac1c47986449fcc1 @@ -68,7 +68,7 @@ namespace commands { } } -static string const interface_version = "8.0"; +static string const interface_version = "8.1"; // Major or minor number only increments once for each monotone release; // check the most recent release before incrementing this. ============================================================ --- cmd_diff_log.cc 509da14568d804c8e3fb741cc676f0979fe33e6f +++ cmd_diff_log.cc 3c3f91765800b2dd861a997b400c4053fd6969a6 @@ -480,6 +480,33 @@ prepare_diff(app_state & app, revheader = header.str(); } +void dump_header(std::string const & revs, + cset const & changes, + std::ostream & out, + bool show_if_empty) +{ + data summary; + write_cset(changes, summary); + if (summary().empty() && !show_if_empty) + return; + + vector lines; + split_into_lines(summary(), lines); + cout << "#\n"; + if (!summary().empty()) + { + out << revs << "#\n"; + for (vector::iterator i = lines.begin(); + i != lines.end(); ++i) + out << "# " << *i << '\n'; + } + else + { + out << "# " << _("no changes") << '\n'; + } + out << "#\n"; +} + CMD(diff, "diff", "di", CMD_REF(informative), N_("[PATH]..."), N_("Shows current differences"), N_("Compares the current tree with the files in the repository and " @@ -503,24 +530,10 @@ CMD(diff, "diff", "di", CMD_REF(informat prepare_diff(app, db, included, args, new_is_archived, revs); - data summary; - write_cset(included, summary); - - vector lines; - split_into_lines(summary(), lines); - cout << "#\n"; - if (!summary().empty()) + if (!app.opts.without_header) { - cout << revs << "#\n"; - for (vector::iterator i = lines.begin(); - i != lines.end(); ++i) - cout << "# " << *i << '\n'; + dump_header(revs, included, cout, true); } - else - { - cout << "# " << _("no changes") << '\n'; - } - cout << "#\n"; if (app.opts.diff_format == external_diff) { @@ -541,13 +554,13 @@ CMD(diff, "diff", "di", CMD_REF(informat // Added in: 4.0 // Purpose: Availability of mtn diff as automate command. // -// Output format: Like mtn diff, but with the header part omitted (as this is -// doubles the output of automate get_revision). If no content changes happened, -// the output is empty. All file operations beside mtn add are omitted, -// as they don't change the content of the file. +// Output format: Like mtn diff, but with the header part omitted by default. +// If no content changes happened, the output is empty. All file operations +// beside mtn add are omitted, as they don't change the content of the file. CMD_AUTOMATE(content_diff, N_("[FILE [...]]"), N_("Calculates diffs of files"), "", + options::opts::with_header | options::opts::without_header | options::opts::revision | options::opts::depth | options::opts::exclude) { @@ -558,6 +571,12 @@ CMD_AUTOMATE(content_diff, N_("[FILE [.. prepare_diff(app, db, included, args, new_is_archived, dummy_header); + + if (app.opts.with_header) + { + dump_header(dummy_header, included, cout, false); + } + dump_diffs(app.lua, db, included, output, app.opts.diff_format, new_is_archived, !app.opts.no_show_encloser); } ============================================================ --- monotone.texi 5e2bb7643436006b6bf4a7883eb6ac40eb4efdda +++ monotone.texi 49e39037ce032c7b65fdf42e5fde18b6fb911735 @@ -7898,13 +7898,19 @@ @section Automation 4.0 address@hidden Updated in: + +8.1 + +Added @option{--with-header} option. + @item Purpose: Prints the content changes between two revisions or a revision and the current workspace. This command differs from @command{mtn diff} in that way that it only -outputs content changes and keeps quite on renames or drops, as the header of address@hidden diff} is omitted (this is what @command{mtn automate get_revision} -already provides). +outputs content changes and keeps quiet on renames or drops by default, as the +header of @command{mtn diff} is omitted unless @option{--with-header} is given +and is omitted regardless if there are no changes. @item Sample output: ============================================================ --- options_list.hh 93e1285e0f6cd24e045a53bdb689af5739f94e9c +++ options_list.hh be7e3a4c58245de8cdd8c88a1bfcb54ff5dc8821 @@ -234,6 +234,25 @@ OPTION(diff_options, no_show_encloser, f } #endif +OPTVAR(diff_options, bool, without_header, false); +OPTVAR(diff_options, bool, with_header, false); +OPTION(diff_options, without_header, false, "without-header", + gettext_noop("show the matching cset in the diff header")) +#ifdef option_bodies +{ + with_header = false; + without_header = true; +} +#endif +OPTION(diff_options, with_header, false, "with-header", + gettext_noop("do not show the matching cset in the diff header")) +#ifdef option_bodies +{ + with_header = true; + without_header = false; +} +#endif + OPT(diffs, "diffs", bool, false, gettext_noop("print diffs along with logs")) #ifdef option_bodies { ============================================================ --- tests/automate_content_diff/__driver__.lua 49eb0b60c12eefb624af0e586d6bd860ac03cfb4 +++ tests/automate_content_diff/__driver__.lua 274e9b78eab4715e2d793b1db848bc872b0ad173 @@ -4,6 +4,8 @@ check(fsize("stdout") == 0 and fsize("st -- check output if there are no changes check(mtn("automate", "content_diff"), 0, true, true) check(fsize("stdout") == 0 and fsize("stderr") == 0) +check(mtn("automate", "content_diff", "--with-header"), 0, true, true) +check(fsize("stdout") == 0 and fsize("stderr") == 0) -- check non-existing path check(mtn("automate", "content_diff", "non_existing"), 1, true, true) @@ -30,6 +32,10 @@ check(fsize("stdout") ~= 0) check(fsize("stdout") ~= 0) check(mtn("automate", "content_diff", "-r", R1, "-r", R2), 0, true, true) check(fsize("stdout") ~= 0) +check(not qgrep("# patch", "stdout")) +check(mtn("automate", "content_diff", "-r", R1, "-r", R2, "--with-header"), 0, true, true) +check(fsize("stdout") ~= 0) +check(qgrep("# patch", "stdout")) -- three and more should not check(mtn("automate", "content_diff", "-r", R1, "-r", R2, "-r", R3), 1, true, true)