| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Codecov Report❌ Patch coverage is 91.61677% with 14 lines in your changes missing coverage. Please review.
@@ Coverage Diff @@
## main #149 +/- ##
==========================================
- Coverage 88.30% 86.65% -1.65%
==========================================
Files 61 61
Lines 2737 2841 +104
Branches 332 356 +24
==========================================
+ Hits 2417 2462 +45
- Misses 320 379 +59 ☔ View full report in Codecov by Harness.
|
Sorry, something went wrong.
| for (git_status_t status : index_statuses) | ||
| { | ||
| const auto& list = sl.get_entry_list(status); | ||
| for (auto* entry : list) | ||
| { | ||
| git_diff_delta* dd = entry->head_to_index; | ||
| const char* old_path = dd->old_file.path; | ||
| const char* new_path = dd->new_file.path; | ||
| update_tracked_dir_set(old_path, &tracked_dir_set); | ||
| std::string item = get_print_item(old_path, new_path); | ||
| auto& ce = combined[item]; | ||
| ce.item = item; | ||
| ce.index_status = status; | ||
| } | ||
| } |
There was a problem hiding this comment.
This can be factorized with a local lambda:
auto update_status_map = [&sl, &tracked_dir_set](const git_status_t* status_array, bool index)
{
for (git_status_t status : status_array)
{
const auto& list = sl.get_entry_list(status);
for (auto* entry : list)
{
git_diff_delta* dd = index ? entry->head_to_index : entry->index_to_workdi;
const char* old_path = dd->old_file.path;
const char* new_path = dd->new_file.path;
update_tracked_dir_set(old_path, &tracked_dir_set);
std::string item = get_print_item(old_path, new_path);
auto& ce = combined[item];
ce.item = item;
ce.index_status = status;
}
}
};And then you can use it like:
update_status_map(index_statues, true);
update_status_map(worktree_statues, false);
Sorry, something went wrong.
for more information, see https://pre-commit.ci
| return combined; | ||
| } | ||
|
|
||
| void print_combined_short(const std::unordered_map<std::string, combined_entry>& map, bool is_coloured) |
There was a problem hiding this comment.
map is a bit too vague for an agrument name.
Sorry, something went wrong.
| else | ||
| { | ||
| std::cout << "?? " << it << std::endl; | ||
| } |
There was a problem hiding this comment.
Following our in-person discussion yesterday, you can simplify this with the following struct:
struct redify_t
{
explicit redify_t(bool is_coloured)
: m_is_coloured(is_coloured)
{}
template <class T>
std::ostream& operator<<(std::ostream& out, const T& arg)
{
if (m_is_coloured)
{
out << termcolor::red < arg << termcolor::reset;
}
else
{
out << arg;
}
return out;
}
};Instantiate it at the beginning of the method, and then use it as termcolor::red:
void print_combined_short(const std::unordered_map<std::string, combined_entry>& map, bool is_coloured)
{
redify_t redify(is_coloured);
// ...
for (const auto& it : untracked_items)
{
std::cout << redify("?? ") << std::endl;
}
}
Sorry, something went wrong.
There was a problem hiding this comment.
I just realized you may need the same one for the green colour, so one wy to avoid code duplication is to add a template parameter to the redify_t struct, something like:
// I guess this is defined somewhere, but in case of:
enum class colour
{
red,
green,
};
template <colour C>
struct colourify_t
{
// as before
// Only difference is here:
template <class T>
std::ostream& operator<<(std::ostream& out, const T& arg)
{
if (m_is_coloured)
{
if constexpr(C == coulour::red)
{
out << termcolor::red < arg << termcolor::reset;
}
else
{
out << termcolor::green < arg << termcolor::reset;
}
}
else
{
out << arg;
}
return out;
}
};
using redify_t = colourify_t<colour::red>;
using greenify_t = colourify_t<colour::green>;
Sorry, something went wrong.
There was a problem hiding this comment.
Not sure that's worth it as it's longer than the code it would replace (I could only use it twice as is). I'll make another change to align it with the other print functions.
Sorry, something went wrong.
| if (untracked_dir_set.contains(directory)) | ||
| { | ||
| } | ||
| else |
There was a problem hiding this comment.
| if (untracked_dir_set.contains(directory)) | |
| { | |
| } | |
| else | |
| if (!untracked_dir_set.contains(directory)) |
Sorry, something went wrong.
| ) | ||
| { | ||
| std::vector<print_entry> not_tracked_entries_to_print{}; | ||
| for (auto e : entries_to_print) |
There was a problem hiding this comment.
| for (auto e : entries_to_print) | |
| for (const auto& e : entries_to_print) |
Sorry, something went wrong.
| { | ||
| const size_t first_slash_idx = e.item.find('/'); | ||
| if (std::string::npos != first_slash_idx) | ||
| for (auto e : entries_to_print) |
There was a problem hiding this comment.
| for (auto e : entries_to_print) | |
| for (const auto& e : entries_to_print) |
Sorry, something went wrong.
for more information, see https://pre-commit.ci
| Back | FazBrowse Home | New Git URL |
Fix status --short