#include <boost/algorithm/string.hpp>
#include <snapper/AppUtil.h>
+#include <snapper/SystemCmd.h>
#include "utils/text.h"
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;
+}
{
cout << _(" Comparing snapshots:") << endl
<< _("\tsnapper diff <number1>..<number2> [files]") << endl
+ << endl
+ << _(" Options for 'diff' command:") << endl
+ << _("\t--diff-cmd <command>\t\tCommand used for comparing files.") << endl
+ << _("\t--extensions, -x <options>\tExtra options passed to the diff command.") << endl
<< endl;
}
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<unsigned int, unsigned int> nums(read_nums(getopts.popArg()));
MyComparison comparison(*conn, nums, true);
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<string> lines = cmd.stdout();
- for (vector<string>::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
{
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<string> lines = cmd.stdout();
- for (vector<string>::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));
}
}
}
<replaceable>number2</replaceable>. 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.</para>
+ <variablelist>
+ <varlistentry>
+ <term><option>--diff-cmd</option> <replaceable>command</replaceable></term>
+ <listitem>
+ <para>Command used for comparing files. The default is
+ <filename>/usr/bin/diff --new-file --unified</filename>. The two files to
+ compare are passed as parameters to the command.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-x, --extensions</option> <replaceable>options</replaceable></term>
+ <listitem>
+ <para>Extra options passed to the diff command.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
</listitem>
</varlistentry>