From 362aefaa160e1052cd5a35dd829f0076b155654a Mon Sep 17 00:00:00 2001 From: Malte Langkabel Date: Tue, 3 Dec 2019 18:26:02 +0100 Subject: [PATCH] logic: improve usability of shallow indexing ui (#823) * added "--shallow" command line option to request shallow indexing * modified behavior of Sourcetrail to always perform a deep index if not explicitly specified differently by the user --- src/app/main.cpp | 3 +- src/lib/app/Application.cpp | 11 +++--- src/lib/app/Application.h | 2 +- src/lib/project/Project.cpp | 9 +++-- src/lib/project/Project.h | 2 +- src/lib/project/RefreshInfo.h | 2 +- .../utility/commandline/CommandLineParser.cpp | 37 ++++++++++--------- .../utility/commandline/CommandLineParser.h | 6 +-- .../commands/CommandlineCommandIndex.cpp | 15 ++++++-- .../messaging/type/MessageLoadProject.h | 4 +- 10 files changed, 52 insertions(+), 39 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index 795a3eec..a6f96797 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -169,7 +169,8 @@ int main(int argc, char *argv[]) MessageLoadProject( commandLineParser.getProjectFilePath(), false, - commandLineParser.getRefreshMode() + commandLineParser.getRefreshMode(), + commandLineParser.getShallowIndexingRequested() ).dispatch(); } diff --git a/src/lib/app/Application.cpp b/src/lib/app/Application.cpp index f13ffa25..71f518c5 100644 --- a/src/lib/app/Application.cpp +++ b/src/lib/app/Application.cpp @@ -255,7 +255,7 @@ void Application::handleMessage(MessageLoadProject* message) if (message->settingsChanged && m_hasGUI) { m_project->setStateOutdated(); - refreshProject(REFRESH_ALL_FILES); + refreshProject(REFRESH_ALL_FILES, message->shallowIndexingRequested); } } else @@ -316,7 +316,7 @@ void Application::handleMessage(MessageLoadProject* message) if (message->refreshMode != REFRESH_NONE) { - refreshProject(message->refreshMode); + refreshProject(message->refreshMode, message->shallowIndexingRequested); } } } @@ -325,7 +325,8 @@ void Application::handleMessage(MessageRefresh* message) { TRACE("app refresh"); - refreshProject(message->all ? REFRESH_ALL_FILES : REFRESH_UPDATED_FILES); + refreshProject( + message->all ? REFRESH_ALL_FILES : REFRESH_UPDATED_FILES, false); } void Application::handleMessage(MessageRefreshUI* message) @@ -409,11 +410,11 @@ void Application::loadWindow(bool showStartWindow) } } -void Application::refreshProject(RefreshMode refreshMode) +void Application::refreshProject(RefreshMode refreshMode, bool shallowIndexingRequested) { if (m_project && checkSharedMemory()) { - m_project->refresh(refreshMode, getDialogView(DialogView::UseCase::INDEXING)); + m_project->refresh(getDialogView(DialogView::UseCase::INDEXING), refreshMode, shallowIndexingRequested); if (!m_hasGUI && !m_project->isIndexing()) { diff --git a/src/lib/app/Application.h b/src/lib/app/Application.h index d59363a9..7422a559 100644 --- a/src/lib/app/Application.h +++ b/src/lib/app/Application.h @@ -79,7 +79,7 @@ private: void loadWindow(bool showStartWindow); - void refreshProject(RefreshMode refreshMode); + void refreshProject(RefreshMode refreshMode, bool shallowIndexingRequested); void updateRecentProjects(const FilePath& projectSettingsFilePath); void logStorageStats() const; diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index c9359e26..4394f4c8 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -272,7 +272,7 @@ void Project::load(std::shared_ptr dialogView) } } -void Project::refresh(RefreshMode refreshMode, std::shared_ptr dialogView) +void Project::refresh(std::shared_ptr dialogView, RefreshMode refreshMode, bool shallowIndexingRequested) { if (m_refreshStage != RefreshStageType::NONE) { @@ -399,8 +399,7 @@ void Project::refresh(RefreshMode refreshMode, std::shared_ptr dialo } } - const bool useShallowIndexing = allowsShallowIndexing && - (!isLoaded() || m_state == PROJECT_STATE_EMPTY); + const bool useShallowIndexing = allowsShallowIndexing && shallowIndexingRequested; if (m_hasGUI) { @@ -422,7 +421,9 @@ void Project::refresh(RefreshMode refreshMode, std::shared_ptr dialo } else { - buildIndex(getRefreshInfo(refreshMode), dialogView); + RefreshInfo info = getRefreshInfo(refreshMode); + info.shallow = useShallowIndexing; + buildIndex(info, dialogView); } } diff --git a/src/lib/project/Project.h b/src/lib/project/Project.h index 7c01882a..e24cea3f 100644 --- a/src/lib/project/Project.h +++ b/src/lib/project/Project.h @@ -37,7 +37,7 @@ public: void load(std::shared_ptr dialogView); - void refresh(RefreshMode refreshMode, std::shared_ptr dialogView); + void refresh(std::shared_ptr dialogView, RefreshMode refreshMode, bool shallowIndexingRequested); RefreshInfo getRefreshInfo(RefreshMode mode) const; diff --git a/src/lib/project/RefreshInfo.h b/src/lib/project/RefreshInfo.h index 9f259f16..6036ad95 100644 --- a/src/lib/project/RefreshInfo.h +++ b/src/lib/project/RefreshInfo.h @@ -20,7 +20,7 @@ struct RefreshInfo std::set nonIndexedFilesToClear; RefreshMode mode = REFRESH_NONE; - bool shallow = true; + bool shallow = false; }; #endif // REFRESH_INFO_H diff --git a/src/lib/utility/commandline/CommandLineParser.cpp b/src/lib/utility/commandline/CommandLineParser.cpp index 5ece73bc..bc0981d3 100644 --- a/src/lib/utility/commandline/CommandLineParser.cpp +++ b/src/lib/utility/commandline/CommandLineParser.cpp @@ -17,31 +17,27 @@ namespace po = boost::program_options; namespace commandline { CommandLineParser::CommandLineParser(const std::string& version): m_version(version) -{ - setup(); -} - -CommandLineParser::~CommandLineParser() {} - -void CommandLineParser::setup() { po::options_description options("Options"); - options.add_options()("help,h", "Print this help message")( - "version,v", "Version of Sourcetrail")( - "project-file", po::value(), "Open Sourcetrail with this project (.srctrlprj)"); + options.add_options() + ("help,h", "Print this help message") + ("version,v", "Version of Sourcetrail") + ("project-file", po::value(), "Open Sourcetrail with this project (.srctrlprj)"); m_options.add(options); m_positional.add("project-file", 1); - addCommand(std::make_unique(this)); - addCommand(std::make_unique(this)); + m_commands.push_back(std::make_unique(this)); + m_commands.push_back(std::make_unique(this)); - for (auto& command: m_commands) + for (auto& command : m_commands) { command->setup(); } } +CommandLineParser::~CommandLineParser() {} + void CommandLineParser::preparse(int argc, char** argv) { std::vector args; @@ -148,11 +144,6 @@ void CommandLineParser::setProjectFile(const FilePath& filepath) processProjectfile(); } -void CommandLineParser::addCommand(std::unique_ptr command) -{ - m_commands.push_back(std::move(command)); -} - void CommandLineParser::printHelp() const { std::cout << "Usage:\n Sourcetrail [command] [option...] [positional arguments]\n\n"; @@ -240,6 +231,11 @@ void CommandLineParser::incompleteRefresh() m_refreshMode = REFRESH_UPDATED_AND_INCOMPLETE_FILES; } +void CommandLineParser::setShallowIndexingRequested(bool enabled) +{ + m_shallowIndexingRequested = enabled; +} + const FilePath& CommandLineParser::getProjectFilePath() const { return m_projectFile; @@ -250,4 +246,9 @@ RefreshMode CommandLineParser::getRefreshMode() const return m_refreshMode; } +bool CommandLineParser::getShallowIndexingRequested() const +{ + return m_shallowIndexingRequested; +} + } // namespace commandline diff --git a/src/lib/utility/commandline/CommandLineParser.h b/src/lib/utility/commandline/CommandLineParser.h index dbfbebe5..90e66c6e 100644 --- a/src/lib/utility/commandline/CommandLineParser.h +++ b/src/lib/utility/commandline/CommandLineParser.h @@ -22,8 +22,6 @@ public: CommandLineParser(const std::string& version); ~CommandLineParser(); - void setup(); - void preparse(int argc, char** argv); void preparse(std::vector& args); void parse(); @@ -36,14 +34,15 @@ public: void fullRefresh(); void incompleteRefresh(); + void setShallowIndexingRequested(bool enabled = true); const FilePath& getProjectFilePath() const; void setProjectFile(const FilePath& filepath); RefreshMode getRefreshMode() const; + bool getShallowIndexingRequested() const; private: - void addCommand(std::unique_ptr command); void processProjectfile(); void printHelp() const; @@ -56,6 +55,7 @@ private: const std::string m_version; FilePath m_projectFile; RefreshMode m_refreshMode = REFRESH_UPDATED_FILES; + bool m_shallowIndexingRequested = false; bool m_quit = false; bool m_withoutGUI = false; diff --git a/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp b/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp index 95f74229..1943ce0b 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp +++ b/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp @@ -19,10 +19,12 @@ CommandlineCommandIndex::~CommandlineCommandIndex() {} void CommandlineCommandIndex::setup() { po::options_description options("Config Options"); - options.add_options()("help,h", "Print this help message")( - "incomplete,i", "Also reindex incomplete files (files with errors)")( - "full,f", "Index full project (omit to only index new/changed files)")( - "project-file", po::value(), "Project file to index (.srctrlprj)"); + options.add_options() + ("help,h", "Print this help message") + ("incomplete,i", "Also reindex incomplete files (files with errors)") + ("full,f", "Index full project (omit to only index new/changed files)") + ("shallow,s", "Build a shallow index is supported by the project") + ("project-file", po::value(), "Project file to index (.srctrlprj)"); m_options.add(options); m_positional.add("project-file", 1); @@ -61,6 +63,11 @@ CommandlineCommand::ReturnStatus CommandlineCommandIndex::parse(std::vectorincompleteRefresh(); } + if (vm.count("shallow")) + { + m_parser->setShallowIndexingRequested(); + } + if (vm.count("project-file")) { m_parser->setProjectFile(FilePath(vm["project-file"].as())); diff --git a/src/lib/utility/messaging/type/MessageLoadProject.h b/src/lib/utility/messaging/type/MessageLoadProject.h index 2d770d90..174fdd28 100644 --- a/src/lib/utility/messaging/type/MessageLoadProject.h +++ b/src/lib/utility/messaging/type/MessageLoadProject.h @@ -10,10 +10,11 @@ class MessageLoadProject: public Message { public: MessageLoadProject( - const FilePath& filePath, bool settingsChanged = false, RefreshMode refreshMode = REFRESH_NONE) + const FilePath& filePath, bool settingsChanged = false, RefreshMode refreshMode = REFRESH_NONE, bool shallowIndexingRequested = false) : projectSettingsFilePath(filePath) , settingsChanged(settingsChanged) , refreshMode(refreshMode) + , shallowIndexingRequested(shallowIndexingRequested) { } @@ -32,6 +33,7 @@ public: const FilePath projectSettingsFilePath; const bool settingsChanged; const RefreshMode refreshMode; + const bool shallowIndexingRequested; }; #endif // MESSAGE_LOAD_PROJECT_H