-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a remote command for batch duplicate finding. #1524
base: master
Are you sure you want to change the base?
Conversation
|
||
#include "similar.h" | ||
|
||
class pic { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
FileData *fd = static_cast<FileData *>(work->data); | ||
std::string name(fd->path); | ||
pics[name] = std::unique_ptr<pic>(new pic(fd->path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should generally be using std::make_unique
to create unique_ptr
s. See the example section in
https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
For context when referring to language docs, Geeqie is using C++14 (as can be seen in the meson.build
project section)
DEBUG_1("processing %d files in set", pics.size()); | ||
|
||
// Compute similarity score for every pair, build equivalence sets. | ||
for (auto a = pics.begin(); a != pics.end(); ++a) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use meaningful variable names for temporaries. Maybe left_iter
and right_iter
? left_pic
and right_pic
? Doesn't have to be those, but the meanings should be self-evident from the name.
if (similarity < options->duplicates_similarity_threshold) | ||
continue; | ||
a->second->equivalent.insert(b->second->equivalent.begin(), b->second->equivalent.end()); | ||
for (auto const &f: a->second->equivalent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaningful variable name
} | ||
|
||
std::set<std::string> printed; | ||
for (auto const &f: pics) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaningful variable name
continue; | ||
std::vector<const char *> cmd; | ||
cmd.push_back(options->duplicates_program); | ||
for (auto const &e: f.second->equivalent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaningful variable name
pid_t pid = fork(); | ||
if (pid == -1) { | ||
perror("fork"); | ||
exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit()
is not called directly from anywhere else in this file, and geeqie does not generally use perror
. The best course of action here is likely to log an error and return. See an example here:
Line 541 in 8cdab99
static void gr_lw_id(const gchar *text, GIOChannel *, gpointer) |
With that said, it's probably a lot safer to use an API like https://docs.gtk.org/gio/ctor.Subprocess.new.html instead of fork
ing directly. That said, @qarkai is our resident expert on glib APIs, so I would defer to him.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Geeqie uses g_spawn_async_with_pipes()
for external editor. See editor_command_one()
in src/editors.cc:1053
.
|
||
class pic { | ||
public: | ||
pic(char const *cname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class violates the rule of 3/5/0. See:
https://en.cppreference.com/w/cpp/language/rule_of_three
'pic.h', | ||
'pic.cc', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'pic.h', | |
'pic.cc', | |
'pic.cc', | |
'pic.h', |
|
||
#include "pic.h" | ||
|
||
pic::pic(char const *cname): name(cname), equivalent{name}, sim(NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use nullptr
instead of NULL
where applicable.
|
||
#include <set> | ||
#include <string> | ||
#include <gdk-pixbuf/gdk-pixbuf.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <gdk-pixbuf/gdk-pixbuf.h> | |
#include <gdk-pixbuf/gdk-pixbuf.h> |
@@ -21,9 +21,11 @@ | |||
|
|||
#include "remote.h" | |||
|
|||
#include <stdio.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <stdio.h> |
Already included as <cstdio>
.
g_error_free(err); | ||
return; | ||
} | ||
sim = image_sim_new_from_pixbuf(buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving sim
initialization to static method or anonymous function.
n = thresh; | ||
if (n < 0 || n > 100) | ||
{ | ||
printf_term(TRUE, "Image similarity threshold out of range (%d to %d)\n", 0, 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Range limits are duplicated on line 701. Consider moving them to constants.
Probably would be useful to print thresh
value here.
|
||
static void gr_duplicates_program(const gchar *text, GIOChannel *, gpointer) | ||
{ | ||
g_strdup(options->duplicates_program); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g_strdup(options->duplicates_program); | |
g_free(options->duplicates_program); |
static void gr_process_duplicates(const gchar *, GIOChannel *, gpointer data) | ||
{ | ||
auto remote_data = static_cast<RemoteData *>(data); | ||
std::map<std::string, std::unique_ptr<pic>> pics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use tab for indentation.
auto remote_data = static_cast<RemoteData *>(data); | ||
std::map<std::string, std::unique_ptr<pic>> pics; | ||
GList *work = remote_data->file_list; | ||
while (work) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using for
loop to reduce scope of work
.
std::map<std::string, std::unique_ptr<pic>> pics; | ||
GList *work = remote_data->file_list; | ||
while (work) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix braces indentation all over PR.
In the latest commit, the command line handling has changed. The attached .diff are the changes I think are necessary to conform with the new code: |
Revised .diff file. You can run the project static tests locally before making a pull request by: |
Here is my first stab at it. I know I at least need to adjust for the accepted coding style, but please let me know if there are any other major things that need changing.
Based on https://github.com/porridge/image-duplicate-finder
Closes: #1520