Skip to content

Commit b7359bf

Browse files
committed
Optimize diff for selected files
1 parent 9dc6c71 commit b7359bf

4 files changed

Lines changed: 15 additions & 17 deletions

File tree

client/snapper/MyFiles.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,4 @@ namespace snapper
101101
}
102102
}
103103

104-
105-
void
106-
MyFiles::bulk_process(FILE* file, GetOpts& get_opts, std::function<void(File& file)> callback)
107-
{
108-
bool all = !file && get_opts.num_args() == 0;
109-
bulk_process(get_requested_files(file, get_opts), all, callback);
110-
}
111-
112104
}

client/snapper/MyFiles.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ namespace snapper
4141
void bulk_process(const vector<string>& filenames, bool all,
4242
std::function<void(File& file)> callback);
4343

44-
void bulk_process(FILE* file, GetOpts& get_opts, std::function<void(File& file)> callback);
45-
4644
};
4745

4846
}

client/snapper/cmd-diff.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,16 @@ namespace snapper
9898
pair<ProxySnapshots::const_iterator, ProxySnapshots::const_iterator> range =
9999
snapshots.findNums(get_opts.pop_arg());
100100

101-
ProxyComparison comparison = snapper->createComparison(*range.first, *range.second, true);
101+
bool selected = file || get_opts.num_args() > 0;
102+
vector<string> filenames = MyFiles::get_requested_files(file, get_opts);
103+
104+
ProxyComparison comparison = selected ?
105+
snapper->createComparison(*range.first, *range.second, true, filenames) :
106+
snapper->createComparison(*range.first, *range.second, true);
102107

103108
MyFiles files(comparison.getFiles());
104109

105-
files.bulk_process(file, get_opts, [differ](const File& file) {
110+
files.bulk_process(filenames, !selected, [differ](const File& file) {
106111
differ.run(file.getAbsolutePath(LOC_PRE), file.getAbsolutePath(LOC_POST));
107112
});
108113
}

client/snapper/cmd-xadiff.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,25 @@ namespace snapper
8686
pair<ProxySnapshots::const_iterator, ProxySnapshots::const_iterator> range =
8787
snapshots.findNums(get_opts.pop_arg());
8888

89-
ProxyComparison comparison = snapper->createComparison(*range.first, *range.second, true);
89+
bool selected = get_opts.num_args() > 0;
90+
vector<string> filenames = MyFiles::get_requested_files(NULL, get_opts);
91+
92+
ProxyComparison comparison = selected ?
93+
snapper->createComparison(*range.first, *range.second, true, filenames) :
94+
snapper->createComparison(*range.first, *range.second, true);
9095

9196
MyFiles files(comparison.getFiles());
9297

93-
if (get_opts.num_args() == 0)
98+
if (!selected)
9499
{
95100
for (Files::const_iterator it1 = files.begin(); it1 != files.end(); ++it1)
96101
if (it1->getPreToPostStatus() & XATTRS)
97102
print_xadiff(it1->getAbsolutePath(LOC_PRE), it1->getAbsolutePath(LOC_POST));
98103
}
99104
else
100105
{
101-
while (get_opts.num_args() > 0)
106+
for (const string& name : filenames)
102107
{
103-
string name = get_opts.pop_arg();
104-
105108
Files::const_iterator it1 = files.findAbsolutePath(name);
106109
if (it1 == files.end())
107110
continue;

0 commit comments

Comments
 (0)