-
Notifications
You must be signed in to change notification settings - Fork 81
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
Refactor FileData to be more modular and more testable #1369
Comments
As far as strategy this time, I think I'm going to try to wrap all of the filedata functions into a single big class to begin with, and then work on splitting things out of that class into separate files and/or classes. The pieces of So I see these as the main steps:
|
I was working on milestone 5 and ran into a conundrum. Gonna write it out here in case other folks have ideas (especially @qarkai, since this fundamentally a C++ lifetime management question): Background contextI decided to approach this by creating a struct FileDataContext {
#ifdef DEBUG_FILEDATA
gint global_file_data_count = 0;
#endif
GHashTable *file_data_pool = nullptr;
GHashTable *file_data_planned_change_hash = nullptr;
};
class IFileDataContext {
public:
virtual FileDataContext &context() = 0;
};
class GlobalFileDataContext : public IFileDataContext {
private:
static GlobalFileDataContext get_instance() {
…
public:
FileDataContext &context() override { return context; }
private:
std::mutex instance_lock_;
GlobalFileDataContext *instance_ = nullptr; // GUARDED_BY(instance_lock_);
FileDataContext context;
};
class FileData {
private:
FileData() = delete;
FileDataContext *context = nullptr; // TODO(xsdg): Move to bottom of class.
… The issueThe
Or, more broadly, how should we deal with cases where code within Some ideas
|
AFAIU |
Forgot to annotate the PRs, but these PRs were relevant to this issue:
|
Currently, FileData is implemented as
filedata.h
(295 lines) andfiledata.cc
(3,581 lines).filedata.h
declares 102 functions, andfiledata.cc
also includes 57 static functions.The purpose of this bug is to lay out the desired end state, since it will take jumping through some hoops to actually get there from how things are implemented right now, while keeping everything functioning during the refactor.
The ideal end state has the following traits:
changeinfo.cc
,core.cc
,filelist.cc
,filter.cc
,metadata.cc
,sidecar.cc
,sidecar_change_info.cc
, andutil.cc
. That seems like a reasonable place to start.file_data_new_dir(const gchar *path_utf8)
) and a more modern C++-style API (something likeFileData::new_for_dir(const gchar *path_utf8)
static GHashTable *file_data_pool
) should at the very least become protected members (so that they're no longer accessible outside of theFileData
class), and should ideally be encapsulated in some way, so that unit tests don't interfere with each other and to make it easier to make things thread-safe.The text was updated successfully, but these errors were encountered: