]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- allow to specify command for comparing file
authorArvin Schnell <aschnell@suse.de>
Thu, 2 Oct 2014 12:47:39 +0000 (14:47 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 2 Oct 2014 12:47:39 +0000 (14:47 +0200)
client/misc.cc
client/misc.h
client/snapper.cc
doc/snapper.xml.in
package/snapper.changes

index 1d40ad7705e56f82c67d02996260a923b90bfdcb..a8f3e0d3ac013fc2057a3789334110825121243f 100644 (file)
@@ -27,6 +27,7 @@
 #include <boost/algorithm/string.hpp>
 
 #include <snapper/AppUtil.h>
+#include <snapper/SystemCmd.h>
 
 #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;
+}
index 65728ef46c97191b26d0a069155abc67234aea09..6280a8e7fa2b47104f3b8a10013f57468ef9de0f 100644 (file)
@@ -49,3 +49,14 @@ read_configdata(const list<string>& l, const map<string, string>& old = map<stri
 
 string
 username(uid_t uid);
+
+
+struct Differ
+{
+    Differ();
+
+    void run(const string& f1, const string& f2) const;
+
+    string command;
+    string extensions;
+};
index 4ef5eb3f35da461482e4331b1b7608ee23f7ed42..b9b6c4c3074b0577da1cba34919f77291eb55082 100644 (file)
@@ -964,6 +964,10 @@ help_diff()
 {
     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;
 }
 
@@ -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<unsigned int, unsigned int> 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<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
     {
@@ -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<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));
        }
     }
 }
index 45a09168854078bc4733586492948f1058fec898..4f907a3acbcb9d34cb58269a953bef43a9415cf1 100644 (file)
          <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>
 
index c30e0bf0354a8f4b8833e4b3684b6cb75fe995b4..42c11c10376f8cc4eaf1d977f4bcd9f88d28fc11 100644 (file)
@@ -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