@@ -138,45 +138,43 @@ static std::unordered_map<std::string, combined_entry> build_combined_status_map
138138{
139139 std::unordered_map<std::string, combined_entry> combined;
140140
141+ auto update_status_map = [&sl, &tracked_dir_set, &combined](const git_status_t (&status_array)[5 ] , bool index)
142+ {
143+ for (git_status_t status : status_array)
144+ {
145+ const auto & list = sl.get_entry_list (status);
146+ for (auto * entry : list)
147+ {
148+ git_diff_delta* dd = index ? entry->head_to_index : entry->index_to_workdir ;
149+ const char * old_path = dd->old_file .path ;
150+ const char * new_path = dd->new_file .path ;
151+ update_tracked_dir_set (old_path, &tracked_dir_set);
152+ std::string item = get_print_item (old_path, new_path);
153+ auto & ce = combined[item];
154+ ce.item = item;
155+ if (index)
156+ {
157+ ce.index_status = status;
158+ }
159+ else
160+ {
161+ ce.workdir_status = status;
162+ }
163+ }
164+ }
165+ };
166+
141167 const git_status_t index_statuses[] = {
142168 GIT_STATUS_INDEX_NEW, GIT_STATUS_INDEX_MODIFIED, GIT_STATUS_INDEX_DELETED,
143169 GIT_STATUS_INDEX_RENAMED, GIT_STATUS_INDEX_TYPECHANGE
144170 };
145- for (git_status_t status : index_statuses)
146- {
147- const auto & list = sl.get_entry_list (status);
148- for (auto * entry : list)
149- {
150- git_diff_delta* dd = entry->head_to_index ;
151- const char * old_path = dd->old_file .path ;
152- const char * new_path = dd->new_file .path ;
153- update_tracked_dir_set (old_path, &tracked_dir_set);
154- std::string item = get_print_item (old_path, new_path);
155- auto & ce = combined[item];
156- ce.item = item;
157- ce.index_status = status;
158- }
159- }
171+ update_status_map (index_statuses, true );
160172
161173 const git_status_t worktree_statuses[] = {
162174 GIT_STATUS_WT_NEW, GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_DELETED,
163175 GIT_STATUS_WT_TYPECHANGE, GIT_STATUS_WT_RENAMED
164176 };
165- for (git_status_t status : worktree_statuses)
166- {
167- const auto & list = sl.get_entry_list (status);
168- for (auto * entry : list)
169- {
170- git_diff_delta* dd = entry->index_to_workdir ;
171- const char * old_path = dd->old_file .path ;
172- const char * new_path = dd->new_file .path ;
173- update_tracked_dir_set (old_path, &tracked_dir_set);
174- std::string item = get_print_item (old_path, new_path);
175- auto & ce = combined[item];
176- ce.item = item;
177- ce.workdir_status = status;
178- }
179- }
177+ update_status_map (worktree_statuses, false );
180178
181179 return combined;
182180}
@@ -185,7 +183,10 @@ static void print_combined_short(const std::unordered_map<std::string, combined_
185183{
186184 std::vector<std::string> keys;
187185 keys.reserve (map.size ());
188- for (auto const & kv : map) keys.push_back (kv.first );
186+ for (auto const & kv : map)
187+ {
188+ keys.push_back (kv.first );
189+ }
189190 std::sort (keys.begin (), keys.end ());
190191
191192 struct normal_row {char idx; char wt; std::string item;};
@@ -234,7 +235,7 @@ static void print_combined_short(const std::unordered_map<std::string, combined_
234235 {
235236 if (is_coloured)
236237 {
237- std::cout << termcolor::red << " ??" << termcolor::reset << " " << it << std::endl;
238+ std::cout << termcolor::red << " ?? " << termcolor::reset << it << std::endl;
238239 }
239240 else
240241 {
@@ -247,7 +248,7 @@ static void print_combined_short(const std::unordered_map<std::string, combined_
247248 {
248249 if (is_coloured)
249250 {
250- std::cout << termcolor::red << " !!" << termcolor::reset << " " << it << std::endl;
251+ std::cout << termcolor::red << " !! " << termcolor::reset << it << std::endl;
251252 }
252253 else
253254 {
0 commit comments