# # # add_dir "tests/diff_reverse" # # add_file "tests/diff_reverse/__driver__.lua" # content [e174ee4ebe94c2af95edf48fd2f30029f95a8958] # # patch "cmd_diff_log.cc" # from [ddcd0dfc3c690b04ce83cb0fb68b8cce2795137e] # to [1595b889561fe5cd2f14fb0ad37acfa1483949a0] # # patch "monotone.texi" # from [b788c4a30206f2eacd2011dac65f79584488bd1a] # to [faf359c7d44bb4922b5487495cda7da5d784e2bf] # # patch "options_list.hh" # from [fe3b7714d2c58e05d75fefc8d28bbe5935d22051] # to [9c3cd1b82269f3c1261a687ff327335b3e7b9fbf] # # patch "txt2c.cc" # from [b23798126943239eaff66187b8828e153ec2c8d8] # to [ce222c5c631cce47040a85f23f6256fe18387cd1] # ============================================================ --- tests/diff_reverse/__driver__.lua e174ee4ebe94c2af95edf48fd2f30029f95a8958 +++ tests/diff_reverse/__driver__.lua e174ee4ebe94c2af95edf48fd2f30029f95a8958 @@ -0,0 +1,28 @@ +-- Test --reverse option for diff + +mtn_setup() + +addfile("file1", "1: data 1\n") +commit() +rev = base_revision() + +writefile("file1", "1: data 2\n") + +-- illegal --reverse option +check(mtn("diff", "--reverse"), 1, false, true) +check(qgrep("--reverse only allowed with exactly one revision", "stderr")) + +check(mtn("diff", "--reverse", rev, rev), 1, false, true) +check(qgrep("--reverse only allowed with exactly one revision", "stderr")) + +-- no --reverse option +check(mtn("diff", "--revision=" .. rev), 0, true, false) +check(qgrep("from \\[614d24f144edd2ef92ad9f8bc6d25bcf77e04101\\]", "stdout")) +check(qgrep("to \\[50812c5d2dcc96a92cea9c1c6ee7fd093774a4ea\\]", "stdout")) + +check(mtn("diff", "--reverse", "--revision=" .. rev), 0, true, false) +check(qgrep("to \\[614d24f144edd2ef92ad9f8bc6d25bcf77e04101\\]", "stdout")) +check(qgrep("from \\[50812c5d2dcc96a92cea9c1c6ee7fd093774a4ea\\]", "stdout")) + + +-- end of file ============================================================ --- cmd_diff_log.cc ddcd0dfc3c690b04ce83cb0fb68b8cce2795137e +++ cmd_diff_log.cc 1595b889561fe5cd2f14fb0ad37acfa1483949a0 @@ -1,4 +1,5 @@ -// Copyright (C) 2002 Graydon Hoare +// Copyright (C) 2009 Stephen Leake +// Copyright (C) 2002, 2009 Graydon Hoare // // This program is made available under the GNU GPL version 2.0 or // greater. See the accompanying file COPYING for details. @@ -361,12 +362,18 @@ prepare_diff(app_state & app, ostringstream header; cset excluded; + // The resulting diff is output in 'included'. Not clear what 'excluded' + // is for. + // initialize before transaction so we have a database to work with. project_t project(db); E(app.opts.revision_selectors.size() <= 2, origin::user, F("more than two revisions given")); + E(!app.opts.reverse || app.opts.revision_selectors.size() == 1, origin::user, + F("--reverse only allowed with exactly one revision")); + if (app.opts.revision_selectors.empty()) { roster_t old_roster, restricted_roster, new_roster; @@ -422,8 +429,17 @@ prepare_diff(app_state & app, make_restricted_roster(old_roster, new_roster, restricted_roster, mask); - make_cset(old_roster, restricted_roster, included); - make_cset(restricted_roster, new_roster, excluded); + if (app.opts.reverse) + { + // FIXME: this breaks something in graph.cc + make_cset(new_roster, restricted_roster, excluded); + make_cset(restricted_roster, old_roster, included); + } + else + { + make_cset(old_roster, restricted_roster, included); + make_cset(restricted_roster, new_roster, excluded); + } new_is_archived = false; header << "# old_revision [" << r_old_id << "]\n"; ============================================================ --- monotone.texi b788c4a30206f2eacd2011dac65f79584488bd1a +++ monotone.texi faf359c7d44bb4922b5487495cda7da5d784e2bf @@ -5498,22 +5498,26 @@ @section Informative @itemx mtn diff --context [--no-show-encloser] @itemx mtn diff --external address@hidden @itemx mtn diff @var{pathname...} address@hidden mtn diff address@hidden address@hidden mtn diff [--reverse] address@hidden @itemx mtn diff address@hidden @var{pathname...} @itemx mtn diff address@hidden address@hidden @itemx mtn diff address@hidden address@hidden @var{pathname...} These commands print out GNU ``unified diff format'' textual difference listings between various manifest versions. With no @option{--revision} -options, @command{diff} will print the differences between the -base revision and the current revision in the workspace. +options, @command{diff} will print the difference from the +base revision to the current revision in the workspace. With one @option{--revision} option, @command{diff} will print the -differences between the revision @var{id} and the current revision in -the workspace. With two @option{--revision} options @command{diff} -will print the differences between revisions @var{id1} and @var{id2}, -ignoring any workspace. +difference from the revision @var{id} to the current revision in the +workspace. If @option{--reverse} is given, the order of the diff is +reversed. +With two @option{--revision} options @command{diff} will print the +difference from revision @var{id1} to @var{id2}, ignoring any +workspace. + + In all cases, monotone will print a textual summary -- identical to the summary presented by @command{mtn status} -- of the logical differences between revisions in lines proceeding the diff. These ============================================================ --- options_list.hh fe3b7714d2c58e05d75fefc8d28bbe5935d22051 +++ options_list.hh 9c3cd1b82269f3c1261a687ff327335b3e7b9fbf @@ -1,5 +1,5 @@ // Copyright (C) 2006 Timothy Brownawell -// 2008 Stephen Leake +// 2008-2009 Stephen Leake // // This program is made available under the GNU GPL version 2.0 or // greater. See the accompanying file COPYING for details. @@ -217,6 +217,14 @@ OPTION(diff_options, external_diff_args, } #endif +OPTVAR(diff_options, bool, reverse, false) +OPTION(diff_options, reverse, false, "reverse", + gettext_noop("reverse order of diff")) +#ifdef option_bodies +{ + reverse = true; +} +#endif OPTVAR(diff_options, diff_type, diff_format, unified_diff) OPTION(diff_options, diff_context, false, "context", gettext_noop("use context diff format")) ============================================================ --- txt2c.cc b23798126943239eaff66187b8828e153ec2c8d8 +++ txt2c.cc ce222c5c631cce47040a85f23f6256fe18387cd1 @@ -150,6 +150,9 @@ atomic_update_if_changed(char const *ofn throw ioerror(tfname, "write"); } + if (remove(ofname)) + throw ioerror(ofname, "remove"); + if (rename(tfname.c_str(), ofname)) throw ioerror(ofname, "rename"); }