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
This commit is contained in:
Malte Langkabel
2019-12-16 15:53:59 +01:00
committed by Eberhard Graether
parent bc7178f49d
commit 362aefaa16
10 changed files with 52 additions and 39 deletions
+2 -1
View File
@@ -169,7 +169,8 @@ int main(int argc, char *argv[])
MessageLoadProject( MessageLoadProject(
commandLineParser.getProjectFilePath(), commandLineParser.getProjectFilePath(),
false, false,
commandLineParser.getRefreshMode() commandLineParser.getRefreshMode(),
commandLineParser.getShallowIndexingRequested()
).dispatch(); ).dispatch();
} }
+6 -5
View File
@@ -255,7 +255,7 @@ void Application::handleMessage(MessageLoadProject* message)
if (message->settingsChanged && m_hasGUI) if (message->settingsChanged && m_hasGUI)
{ {
m_project->setStateOutdated(); m_project->setStateOutdated();
refreshProject(REFRESH_ALL_FILES); refreshProject(REFRESH_ALL_FILES, message->shallowIndexingRequested);
} }
} }
else else
@@ -316,7 +316,7 @@ void Application::handleMessage(MessageLoadProject* message)
if (message->refreshMode != REFRESH_NONE) 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"); 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) 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()) 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()) if (!m_hasGUI && !m_project->isIndexing())
{ {
+1 -1
View File
@@ -79,7 +79,7 @@ private:
void loadWindow(bool showStartWindow); void loadWindow(bool showStartWindow);
void refreshProject(RefreshMode refreshMode); void refreshProject(RefreshMode refreshMode, bool shallowIndexingRequested);
void updateRecentProjects(const FilePath& projectSettingsFilePath); void updateRecentProjects(const FilePath& projectSettingsFilePath);
void logStorageStats() const; void logStorageStats() const;
+5 -4
View File
@@ -272,7 +272,7 @@ void Project::load(std::shared_ptr<DialogView> dialogView)
} }
} }
void Project::refresh(RefreshMode refreshMode, std::shared_ptr<DialogView> dialogView) void Project::refresh(std::shared_ptr<DialogView> dialogView, RefreshMode refreshMode, bool shallowIndexingRequested)
{ {
if (m_refreshStage != RefreshStageType::NONE) if (m_refreshStage != RefreshStageType::NONE)
{ {
@@ -399,8 +399,7 @@ void Project::refresh(RefreshMode refreshMode, std::shared_ptr<DialogView> dialo
} }
} }
const bool useShallowIndexing = allowsShallowIndexing && const bool useShallowIndexing = allowsShallowIndexing && shallowIndexingRequested;
(!isLoaded() || m_state == PROJECT_STATE_EMPTY);
if (m_hasGUI) if (m_hasGUI)
{ {
@@ -422,7 +421,9 @@ void Project::refresh(RefreshMode refreshMode, std::shared_ptr<DialogView> dialo
} }
else else
{ {
buildIndex(getRefreshInfo(refreshMode), dialogView); RefreshInfo info = getRefreshInfo(refreshMode);
info.shallow = useShallowIndexing;
buildIndex(info, dialogView);
} }
} }
+1 -1
View File
@@ -37,7 +37,7 @@ public:
void load(std::shared_ptr<DialogView> dialogView); void load(std::shared_ptr<DialogView> dialogView);
void refresh(RefreshMode refreshMode, std::shared_ptr<DialogView> dialogView); void refresh(std::shared_ptr<DialogView> dialogView, RefreshMode refreshMode, bool shallowIndexingRequested);
RefreshInfo getRefreshInfo(RefreshMode mode) const; RefreshInfo getRefreshInfo(RefreshMode mode) const;
+1 -1
View File
@@ -20,7 +20,7 @@ struct RefreshInfo
std::set<FilePath> nonIndexedFilesToClear; std::set<FilePath> nonIndexedFilesToClear;
RefreshMode mode = REFRESH_NONE; RefreshMode mode = REFRESH_NONE;
bool shallow = true; bool shallow = false;
}; };
#endif // REFRESH_INFO_H #endif // REFRESH_INFO_H
@@ -17,31 +17,27 @@ namespace po = boost::program_options;
namespace commandline namespace commandline
{ {
CommandLineParser::CommandLineParser(const std::string& version): m_version(version) CommandLineParser::CommandLineParser(const std::string& version): m_version(version)
{
setup();
}
CommandLineParser::~CommandLineParser() {}
void CommandLineParser::setup()
{ {
po::options_description options("Options"); po::options_description options("Options");
options.add_options()("help,h", "Print this help message")( options.add_options()
"version,v", "Version of Sourcetrail")( ("help,h", "Print this help message")
"project-file", po::value<std::string>(), "Open Sourcetrail with this project (.srctrlprj)"); ("version,v", "Version of Sourcetrail")
("project-file", po::value<std::string>(), "Open Sourcetrail with this project (.srctrlprj)");
m_options.add(options); m_options.add(options);
m_positional.add("project-file", 1); m_positional.add("project-file", 1);
addCommand(std::make_unique<commandline::CommandlineCommandConfig>(this)); m_commands.push_back(std::make_unique<commandline::CommandlineCommandConfig>(this));
addCommand(std::make_unique<commandline::CommandlineCommandIndex>(this)); m_commands.push_back(std::make_unique<commandline::CommandlineCommandIndex>(this));
for (auto& command: m_commands) for (auto& command : m_commands)
{ {
command->setup(); command->setup();
} }
} }
CommandLineParser::~CommandLineParser() {}
void CommandLineParser::preparse(int argc, char** argv) void CommandLineParser::preparse(int argc, char** argv)
{ {
std::vector<std::string> args; std::vector<std::string> args;
@@ -148,11 +144,6 @@ void CommandLineParser::setProjectFile(const FilePath& filepath)
processProjectfile(); processProjectfile();
} }
void CommandLineParser::addCommand(std::unique_ptr<CommandlineCommand> command)
{
m_commands.push_back(std::move(command));
}
void CommandLineParser::printHelp() const void CommandLineParser::printHelp() const
{ {
std::cout << "Usage:\n Sourcetrail [command] [option...] [positional arguments]\n\n"; 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; m_refreshMode = REFRESH_UPDATED_AND_INCOMPLETE_FILES;
} }
void CommandLineParser::setShallowIndexingRequested(bool enabled)
{
m_shallowIndexingRequested = enabled;
}
const FilePath& CommandLineParser::getProjectFilePath() const const FilePath& CommandLineParser::getProjectFilePath() const
{ {
return m_projectFile; return m_projectFile;
@@ -250,4 +246,9 @@ RefreshMode CommandLineParser::getRefreshMode() const
return m_refreshMode; return m_refreshMode;
} }
bool CommandLineParser::getShallowIndexingRequested() const
{
return m_shallowIndexingRequested;
}
} // namespace commandline } // namespace commandline
@@ -22,8 +22,6 @@ public:
CommandLineParser(const std::string& version); CommandLineParser(const std::string& version);
~CommandLineParser(); ~CommandLineParser();
void setup();
void preparse(int argc, char** argv); void preparse(int argc, char** argv);
void preparse(std::vector<std::string>& args); void preparse(std::vector<std::string>& args);
void parse(); void parse();
@@ -36,14 +34,15 @@ public:
void fullRefresh(); void fullRefresh();
void incompleteRefresh(); void incompleteRefresh();
void setShallowIndexingRequested(bool enabled = true);
const FilePath& getProjectFilePath() const; const FilePath& getProjectFilePath() const;
void setProjectFile(const FilePath& filepath); void setProjectFile(const FilePath& filepath);
RefreshMode getRefreshMode() const; RefreshMode getRefreshMode() const;
bool getShallowIndexingRequested() const;
private: private:
void addCommand(std::unique_ptr<CommandlineCommand> command);
void processProjectfile(); void processProjectfile();
void printHelp() const; void printHelp() const;
@@ -56,6 +55,7 @@ private:
const std::string m_version; const std::string m_version;
FilePath m_projectFile; FilePath m_projectFile;
RefreshMode m_refreshMode = REFRESH_UPDATED_FILES; RefreshMode m_refreshMode = REFRESH_UPDATED_FILES;
bool m_shallowIndexingRequested = false;
bool m_quit = false; bool m_quit = false;
bool m_withoutGUI = false; bool m_withoutGUI = false;
@@ -19,10 +19,12 @@ CommandlineCommandIndex::~CommandlineCommandIndex() {}
void CommandlineCommandIndex::setup() void CommandlineCommandIndex::setup()
{ {
po::options_description options("Config Options"); po::options_description options("Config Options");
options.add_options()("help,h", "Print this help message")( options.add_options()
"incomplete,i", "Also reindex incomplete files (files with errors)")( ("help,h", "Print this help message")
"full,f", "Index full project (omit to only index new/changed files)")( ("incomplete,i", "Also reindex incomplete files (files with errors)")
"project-file", po::value<std::string>(), "Project file to index (.srctrlprj)"); ("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<std::string>(), "Project file to index (.srctrlprj)");
m_options.add(options); m_options.add(options);
m_positional.add("project-file", 1); m_positional.add("project-file", 1);
@@ -61,6 +63,11 @@ CommandlineCommand::ReturnStatus CommandlineCommandIndex::parse(std::vector<std:
m_parser->incompleteRefresh(); m_parser->incompleteRefresh();
} }
if (vm.count("shallow"))
{
m_parser->setShallowIndexingRequested();
}
if (vm.count("project-file")) if (vm.count("project-file"))
{ {
m_parser->setProjectFile(FilePath(vm["project-file"].as<std::string>())); m_parser->setProjectFile(FilePath(vm["project-file"].as<std::string>()));
@@ -10,10 +10,11 @@ class MessageLoadProject: public Message<MessageLoadProject>
{ {
public: public:
MessageLoadProject( 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) : projectSettingsFilePath(filePath)
, settingsChanged(settingsChanged) , settingsChanged(settingsChanged)
, refreshMode(refreshMode) , refreshMode(refreshMode)
, shallowIndexingRequested(shallowIndexingRequested)
{ {
} }
@@ -32,6 +33,7 @@ public:
const FilePath projectSettingsFilePath; const FilePath projectSettingsFilePath;
const bool settingsChanged; const bool settingsChanged;
const RefreshMode refreshMode; const RefreshMode refreshMode;
const bool shallowIndexingRequested;
}; };
#endif // MESSAGE_LOAD_PROJECT_H #endif // MESSAGE_LOAD_PROJECT_H