From: Arvin Schnell Date: Thu, 2 Oct 2014 12:47:39 +0000 (+0200) Subject: - allow to specify command for comparing file X-Git-Tag: v0.2.5~9^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2de0f89931c4da5274b3b543be042c661aeaea69;p=thirdparty%2Fsnapper.git - allow to specify command for comparing file --- diff --git a/client/misc.cc b/client/misc.cc index 1d40ad77..a8f3e0d3 100644 --- a/client/misc.cc +++ b/client/misc.cc @@ -27,6 +27,7 @@ #include #include +#include #include "utils/text.h" @@ -209,3 +210,27 @@ username(uid_t uid) return username; } + + +Differ::Differ() + : command(DIFFBIN " --new-file --unified"), extensions() +{ +} + + +void +Differ::run(const string& f1, const string& f2) const +{ + string tmp = command; + if (!extensions.empty()) + tmp += " " + extensions; + tmp += " " + quote(f1) + " " + quote(f2); + + SystemCmd cmd(tmp); + + for (const string& line : cmd.stdout()) + cout << line << endl; + + for (const string& line : cmd.stderr()) + cerr << line << endl; +} diff --git a/client/misc.h b/client/misc.h index 65728ef4..6280a8e7 100644 --- a/client/misc.h +++ b/client/misc.h @@ -49,3 +49,14 @@ read_configdata(const list& l, const map& old = map.. [files]") << endl + << endl + << _(" Options for 'diff' command:") << endl + << _("\t--diff-cmd \t\tCommand used for comparing files.") << endl + << _("\t--extensions, -x \tExtra options passed to the diff command.") << endl << endl; } @@ -971,15 +975,29 @@ help_diff() void command_diff(DBus::Connection* conn, Snapper* snapper) { - GetOpts::parsed_opts opts = getopts.parse("diff", GetOpts::no_options); + const struct option options[] = { + { "diff-cmd", required_argument, 0, 0 }, + { "extensions", required_argument, 0, 'x' }, + { 0, 0, 0, 0 } + }; + + GetOpts::parsed_opts opts = getopts.parse("diff", options); if (getopts.numArgs() < 1) { cerr << _("Command 'diff' needs at least one argument.") << endl; exit(EXIT_FAILURE); } + Differ differ; + GetOpts::parsed_opts::const_iterator opt; + if ((opt = opts.find("diff-cmd")) != opts.end()) + differ.command = opt->second; + + if ((opt = opts.find("extensions")) != opts.end()) + differ.extensions = opt->second; + pair nums(read_nums(getopts.popArg())); MyComparison comparison(*conn, nums, true); @@ -988,14 +1006,7 @@ command_diff(DBus::Connection* conn, Snapper* snapper) if (getopts.numArgs() == 0) { for (Files::const_iterator it1 = files.begin(); it1 != files.end(); ++it1) - { - SystemCmd cmd(DIFFBIN " --unified --new-file " + quote(it1->getAbsolutePath(LOC_PRE)) + - " " + quote(it1->getAbsolutePath(LOC_POST)), false); - - const vector lines = cmd.stdout(); - for (vector::const_iterator it2 = lines.begin(); it2 != lines.end(); ++it2) - cout << it2->c_str() << endl; - } + differ.run(it1->getAbsolutePath(LOC_PRE), it1->getAbsolutePath(LOC_POST)); } else { @@ -1004,15 +1015,8 @@ command_diff(DBus::Connection* conn, Snapper* snapper) string name = getopts.popArg(); Files::const_iterator it1 = files.findAbsolutePath(name); - if (it1 == files.end()) - continue; - - SystemCmd cmd(DIFFBIN " --unified --new-file " + quote(it1->getAbsolutePath(LOC_PRE)) + - " " + quote(it1->getAbsolutePath(LOC_POST)), false); - - const vector lines = cmd.stdout(); - for (vector::const_iterator it2 = lines.begin(); it2 != lines.end(); ++it2) - cout << it2->c_str() << endl; + if (it1 != files.end()) + differ.run(it1->getAbsolutePath(LOC_PRE), it1->getAbsolutePath(LOC_POST)); } } } diff --git a/doc/snapper.xml.in b/doc/snapper.xml.in index 45a09168..4f907a3a 100644 --- a/doc/snapper.xml.in +++ b/doc/snapper.xml.in @@ -477,6 +477,22 @@ number2. This will show a diff of the content of files and directories that have been created, modified or deleted in the time between the two snapshots have been made. + + + command + + Command used for comparing files. The default is + /usr/bin/diff --new-file --unified. The two files to + compare are passed as parameters to the command. + + + + options + + Extra options passed to the diff command. + + + diff --git a/package/snapper.changes b/package/snapper.changes index c30e0bf0..42c11c10 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Thu Oct 02 14:46:37 CEST 2014 - aschnell@suse.de + +- allow to specify command for comparing file + ------------------------------------------------------------------- Mon Sep 29 11:55:37 CEST 2014 - aschnell@suse.de