Skip to content
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

Added an option to return the number of changed files #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 67 additions & 38 deletions src/GitStatusCache/src/StatusController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void StatusController::RecordGetStatusTime(uint64_t nanosecondsInGetStatus)
m_maxNanosecondsInGetStatus = (std::max)(nanosecondsInGetStatus, m_maxNanosecondsInGetStatus);
}

std::string StatusController::GetStatus(const rapidjson::Document& document, const std::string& request)
std::string StatusController::GetStatus(const rapidjson::Document& document, const std::string& request, bool concise)
{
if (!document.HasMember("Path") || !document["Path"].IsString())
{
Expand Down Expand Up @@ -132,43 +132,64 @@ std::string StatusController::GetStatus(const rapidjson::Document& document, con
AddUintToJson(writer, "AheadBy", statusToReport.AheadBy);
AddUintToJson(writer, "BehindBy", statusToReport.BehindBy);

AddArrayToJson(writer, "IndexAdded", statusToReport.IndexAdded);
AddArrayToJson(writer, "IndexModified", statusToReport.IndexModified);
AddArrayToJson(writer, "IndexDeleted", statusToReport.IndexDeleted);
AddArrayToJson(writer, "IndexTypeChange", statusToReport.IndexTypeChange);
writer.String("IndexRenamed");
writer.StartArray();
for (const auto& value : statusToReport.IndexRenamed)
{
writer.StartObject();
writer.String("Old");
writer.String(value.first.c_str());
writer.String("New");
writer.String(value.second.c_str());
writer.EndObject();
}
writer.EndArray();

AddArrayToJson(writer, "WorkingAdded", statusToReport.WorkingAdded);
AddArrayToJson(writer, "WorkingModified", statusToReport.WorkingModified);
AddArrayToJson(writer, "WorkingDeleted", statusToReport.WorkingDeleted);
AddArrayToJson(writer, "WorkingTypeChange", statusToReport.WorkingTypeChange);
writer.String("WorkingRenamed");
writer.StartArray();
for (const auto& value : statusToReport.WorkingRenamed)
{
writer.StartObject();
writer.String("Old");
writer.String(value.first.c_str());
writer.String("New");
writer.String(value.second.c_str());
writer.EndObject();
}
writer.EndArray();
AddArrayToJson(writer, "WorkingUnreadable", statusToReport.WorkingUnreadable);

AddArrayToJson(writer, "Ignored", statusToReport.Ignored);
AddArrayToJson(writer, "Conflicted", statusToReport.Conflicted);
if (concise)
{
AddUintToJson(writer, "IndexAdded", statusToReport.IndexAdded.size());
AddUintToJson(writer, "IndexModified", statusToReport.IndexModified.size());
AddUintToJson(writer, "IndexDeleted", statusToReport.IndexDeleted.size());
AddUintToJson(writer, "IndexTypeChange", statusToReport.IndexTypeChange.size());
AddUintToJson(writer, "IndexRenamed", statusToReport.IndexRenamed.size());

AddUintToJson(writer, "WorkingAdded", statusToReport.WorkingAdded.size());
AddUintToJson(writer, "WorkingModified", statusToReport.WorkingModified.size());
AddUintToJson(writer, "WorkingDeleted", statusToReport.WorkingDeleted.size());
AddUintToJson(writer, "WorkingTypeChange", statusToReport.WorkingTypeChange.size());
AddUintToJson(writer, "WorkingRenamed", statusToReport.WorkingRenamed.size());
AddUintToJson(writer, "WorkingUnreadable", statusToReport.WorkingUnreadable.size());

AddUintToJson(writer, "Ignored", statusToReport.Ignored.size());
AddUintToJson(writer, "Conflicted", statusToReport.Conflicted.size());
}
else
{
AddArrayToJson(writer, "IndexAdded", statusToReport.IndexAdded);
AddArrayToJson(writer, "IndexModified", statusToReport.IndexModified);
AddArrayToJson(writer, "IndexDeleted", statusToReport.IndexDeleted);
AddArrayToJson(writer, "IndexTypeChange", statusToReport.IndexTypeChange);
writer.String("IndexRenamed");
writer.StartArray();
for (const auto& value : statusToReport.IndexRenamed)
{
writer.StartObject();
writer.String("Old");
writer.String(value.first.c_str());
writer.String("New");
writer.String(value.second.c_str());
writer.EndObject();
}
writer.EndArray();

AddArrayToJson(writer, "WorkingAdded", statusToReport.WorkingAdded);
AddArrayToJson(writer, "WorkingModified", statusToReport.WorkingModified);
AddArrayToJson(writer, "WorkingDeleted", statusToReport.WorkingDeleted);
AddArrayToJson(writer, "WorkingTypeChange", statusToReport.WorkingTypeChange);
writer.String("WorkingRenamed");
writer.StartArray();
for (const auto& value : statusToReport.WorkingRenamed)
{
writer.StartObject();
writer.String("Old");
writer.String(value.first.c_str());
writer.String("New");
writer.String(value.second.c_str());
writer.EndObject();
}
writer.EndArray();
AddArrayToJson(writer, "WorkingUnreadable", statusToReport.WorkingUnreadable);

AddArrayToJson(writer, "Ignored", statusToReport.Ignored);
AddArrayToJson(writer, "Conflicted", statusToReport.Conflicted);
}

writer.String("Stashes");
writer.StartArray();
Expand Down Expand Up @@ -282,6 +303,14 @@ std::string StatusController::HandleRequest(const std::string& request)
return result;
}

if (boost::iequals(action, "GetConciseStatus"))
{
boost::timer::cpu_timer timer;
auto result = GetStatus(document, request, true);
RecordGetStatusTime(timer.elapsed().wall);
return result;
}

if (boost::iequals(action, "GetCacheStatistics"))
return GetCacheStatistics();

Expand Down
2 changes: 1 addition & 1 deletion src/GitStatusCache/src/StatusController.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class StatusController : boost::noncopyable
/**
* Retrieves current git status.
*/
std::string GetStatus(const rapidjson::Document& document, const std::string& request);
std::string GetStatus(const rapidjson::Document& document, const std::string& request, bool concise = false);

/**
* Retrieves information about cache's performance.
Expand Down