1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:48:11 +00:00

AK+Everywhere: Remove the null state of DeprecatedString

This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
This commit is contained in:
Ali Mohammad Pur 2023-10-10 15:00:58 +03:30 committed by Ali Mohammad Pur
parent daf6d8173c
commit aeee98b3a1
189 changed files with 597 additions and 652 deletions

View file

@ -24,7 +24,7 @@ GitRepo::CreateResult GitRepo::try_to_create(DeprecatedString const& repository_
RefPtr<GitRepo> GitRepo::initialize_repository(DeprecatedString const& repository_root)
{
auto res = command_wrapper({ "init" }, repository_root);
if (res.is_null())
if (!res.has_value())
return {};
VERIFY(git_repo_exists(repository_root));
@ -42,25 +42,25 @@ Vector<DeprecatedString> GitRepo::unstaged_files() const
Vector<DeprecatedString> GitRepo::staged_files() const
{
auto raw_result = command({ "diff", "--cached", "--name-only" });
if (raw_result.is_null())
if (!raw_result.has_value())
return {};
return parse_files_list(raw_result);
return parse_files_list(*raw_result);
}
Vector<DeprecatedString> GitRepo::modified_files() const
{
auto raw_result = command({ "ls-files", "--modified", "--exclude-standard" });
if (raw_result.is_null())
if (!raw_result.has_value())
return {};
return parse_files_list(raw_result);
return parse_files_list(*raw_result);
}
Vector<DeprecatedString> GitRepo::untracked_files() const
{
auto raw_result = command({ "ls-files", "--others", "--exclude-standard" });
if (raw_result.is_null())
if (!raw_result.has_value())
return {};
return parse_files_list(raw_result);
return parse_files_list(*raw_result);
}
Vector<DeprecatedString> GitRepo::parse_files_list(DeprecatedString const& raw_result)
@ -73,12 +73,12 @@ Vector<DeprecatedString> GitRepo::parse_files_list(DeprecatedString const& raw_r
return files;
}
DeprecatedString GitRepo::command(Vector<DeprecatedString> const& command_parts) const
Optional<DeprecatedString> GitRepo::command(Vector<DeprecatedString> const& command_parts) const
{
return command_wrapper(command_parts, m_repository_root);
}
DeprecatedString GitRepo::command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir)
Optional<DeprecatedString> GitRepo::command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir)
{
auto const result = Core::command("git", command_parts, LexicalPath(chdir));
if (result.is_error() || result.value().exit_code != 0)
@ -88,27 +88,27 @@ DeprecatedString GitRepo::command_wrapper(Vector<DeprecatedString> const& comman
bool GitRepo::git_is_installed()
{
return !command_wrapper({ "--help" }, "/").is_null();
return command_wrapper({ "--help" }, "/").has_value();
}
bool GitRepo::git_repo_exists(DeprecatedString const& repo_root)
{
return !command_wrapper({ "status" }, repo_root).is_null();
return command_wrapper({ "status" }, repo_root).has_value();
}
bool GitRepo::stage(DeprecatedString const& file)
{
return !command({ "add", file }).is_null();
return command({ "add", file }).has_value();
}
bool GitRepo::unstage(DeprecatedString const& file)
{
return !command({ "reset", "HEAD", "--", file }).is_null();
return command({ "reset", "HEAD", "--", file }).has_value();
}
bool GitRepo::commit(DeprecatedString const& message)
{
return !command({ "commit", "-m", message }).is_null();
return command({ "commit", "-m", message }).has_value();
}
Optional<DeprecatedString> GitRepo::original_file_content(DeprecatedString const& file) const
@ -124,10 +124,10 @@ Optional<DeprecatedString> GitRepo::unstaged_diff(DeprecatedString const& file)
bool GitRepo::is_tracked(DeprecatedString const& file) const
{
auto res = command({ "ls-files", file });
if (res.is_null())
if (!res.has_value())
return false;
return !res.is_empty();
return !res->is_empty();
}
}