11#include < iostream>
22#include < ostream>
3+ #include < set>
34#include < string>
45
56#include < git2.h>
@@ -71,20 +72,81 @@ enum class output_format
7172 SHORT = 2
7273};
7374
74- void print_entries (git_status_t status, status_list_wrapper& sl, bool head_selector, output_format of, bool add_root) // TODO: add different mods
75+ // void print_entries(git_status_t status, status_list_wrapper& sl, bool head_selector, output_format of,
76+ // std::set<std::string>* tracked_dir_set = nullptr)
77+ // {
78+ // const auto& entry_list = sl.get_entry_list(status);
79+ // if (!entry_list.empty())
80+ // {
81+ // for (auto* entry : entry_list)
82+ // {
83+ // if ((of == output_format::DEFAULT) || (of == output_format::LONG))
84+ // {
85+ // std::cout << status_msg_map.at(status).long_mod << "\t";
86+ // }
87+ // else if (of == output_format::SHORT)
88+ // {
89+ // std::cout << status_msg_map.at(status).short_mod;
90+ // }
91+
92+ // git_diff_delta* diff_delta;
93+ // if (head_selector)
94+ // {
95+ // diff_delta = entry->head_to_index;
96+ // }
97+ // else
98+ // {
99+ // diff_delta = entry->index_to_workdir;
100+ // }
101+ // const char* old_path = diff_delta->old_file.path;
102+ // const char* new_path = diff_delta->new_file.path;
103+ // if (tracked_dir_set)
104+ // {
105+ // const size_t first_slash_idx = std::string_view(old_path).find('/');
106+ // if (std::string::npos != first_slash_idx)
107+ // {
108+ // auto directory = std::string_view(old_path).substr(0, first_slash_idx);
109+ // tracked_dir_set->insert(std::string(directory));
110+ // }
111+ // }
112+ // if (old_path && new_path && std::strcmp(old_path, new_path))
113+ // {
114+ // std::cout << old_path << " -> " << new_path << std::endl;
115+ // }
116+ // else
117+ // {
118+ // if (old_path)
119+ // {
120+ // std::cout << old_path << std::endl;
121+ // }
122+ // else
123+ // {
124+ // std::cout << new_path << std::endl;
125+ // }
126+ // }
127+ // }
128+ // }
129+ // else
130+ // {}
131+ // }
132+ //
133+ std::vector<std::pair<std::string, std::string>> get_entries_to_print (git_status_t status, status_list_wrapper& sl,
134+ bool head_selector, output_format of, std::set<std::string>* tracked_dir_set = nullptr )
75135{
136+ std::vector<std::pair<std::string, std::string>> entries_to_print{};
76137 const auto & entry_list = sl.get_entry_list (status);
77138 if (!entry_list.empty ())
78139 {
79140 for (auto * entry : entry_list)
80141 {
142+ std::string bla;
81143 if ((of == output_format::DEFAULT) || (of == output_format::LONG))
82144 {
83- std::cout << status_msg_map.at (status).long_mod << " \t " ;
145+ bla = status_msg_map.at (status).long_mod + " \t " ;
84146 }
85147 else if (of == output_format::SHORT)
86148 {
87- std::cout << status_msg_map.at (status).short_mod ;
149+ bla = status_msg_map.at (status).short_mod ;
88150 }
89151
90152 git_diff_delta* diff_delta;
@@ -98,35 +160,45 @@ void print_entries(git_status_t status, status_list_wrapper& sl, bool head_selec
98160 }
99161 const char * old_path = diff_delta->old_file .path ;
100162 const char * new_path = diff_delta->new_file .path ;
101- if (add_root)
163+ std::string blou;
164+ if (tracked_dir_set)
102165 {
103166 const size_t first_slash_idx = std::string_view (old_path).find (' /' );
104- const char * directory;
105167 if (std::string::npos != first_slash_idx)
106168 {
107- directory = std::string_view (old_path).substr (0 , first_slash_idx). c_str ( );
108- sl. dir_set . insert (directory);
169+ auto directory = std::string_view (old_path).substr (0 , first_slash_idx);
170+ tracked_dir_set-> insert (std::string ( directory) );
109171 }
110172 }
111173 if (old_path && new_path && std::strcmp (old_path, new_path))
112174 {
113- std::cout << old_path << " -> " << new_path << std::endl ;
175+ blou = std::string ( old_path) + " -> " + std::string (new_path) ;
114176 }
115177 else
116178 {
117179 if (old_path)
118180 {
119- std::cout << old_path << std::endl ;
181+ blou = old_path;
120182 }
121183 else
122184 {
123- std::cout << new_path << std::endl ;
185+ blou = new_path;
124186 }
125187 }
188+ entries_to_print.push_back ({bla, blou});
126189 }
127190 }
128191 else
129192 {}
193+ return entries_to_print;
194+ }
195+
196+ void print_entries (std::vector<std::pair<std::string, std::string>> entries_to_print)
197+ {
198+ for (auto e: entries_to_print)
199+ {
200+ std::cout << e.first << e.second << std::endl;
201+ }
130202}
131203
132204void status_subcommand::run ()
@@ -137,6 +209,11 @@ void status_subcommand::run()
137209 auto sl = status_list_wrapper::status_list (repo);
138210 auto branch_name = reference_wrapper::get_ref_name (repo);
139211
212+ std::set<std::string>* tracked_dir_set{};
213+ std::set<std::string>* untracked_dir_set{};
214+ std::vector<std::string> untracked_to_print{};
215+ std::vector<std::string> ignored_to_print{};
216+
140217 output_format of = output_format::DEFAULT;
141218 if (short_flag)
142219 {
@@ -170,11 +247,11 @@ void status_subcommand::run()
170247 {
171248 std::cout << tobecommited_header << std::endl;
172249 }
173- print_entries (GIT_STATUS_INDEX_NEW, sl, true , of, true );
174- print_entries (GIT_STATUS_INDEX_MODIFIED, sl, true , of, true );
175- print_entries (GIT_STATUS_INDEX_DELETED, sl, true , of, true );
176- print_entries (GIT_STATUS_INDEX_RENAMED, sl, true , of, true );
177- print_entries (GIT_STATUS_INDEX_TYPECHANGE, sl, true , of, true );
250+ print_entries (get_entries_to_print ( GIT_STATUS_INDEX_NEW, sl, true , of, tracked_dir_set) );
251+ print_entries (get_entries_to_print ( GIT_STATUS_INDEX_MODIFIED, sl, true , of, tracked_dir_set) );
252+ print_entries (get_entries_to_print ( GIT_STATUS_INDEX_DELETED, sl, true , of, tracked_dir_set) );
253+ print_entries (get_entries_to_print ( GIT_STATUS_INDEX_RENAMED, sl, true , of, tracked_dir_set) );
254+ print_entries (get_entries_to_print ( GIT_STATUS_INDEX_TYPECHANGE, sl, true , of, tracked_dir_set) );
178255 if (is_long)
179256 {
180257 std::cout << std::endl;
@@ -187,10 +264,10 @@ void status_subcommand::run()
187264 {
188265 std::cout << notstagged_header << std::endl;
189266 }
190- print_entries (GIT_STATUS_WT_MODIFIED, sl, false , of, true );
191- print_entries (GIT_STATUS_WT_DELETED, sl, false , of, true );
192- print_entries (GIT_STATUS_WT_TYPECHANGE, sl, false , of, true );
193- print_entries (GIT_STATUS_WT_RENAMED, sl, false , of, true );
267+ print_entries (get_entries_to_print ( GIT_STATUS_WT_MODIFIED, sl, false , of, tracked_dir_set) );
268+ print_entries (get_entries_to_print ( GIT_STATUS_WT_DELETED, sl, false , of, tracked_dir_set) );
269+ print_entries (get_entries_to_print ( GIT_STATUS_WT_TYPECHANGE, sl, false , of, tracked_dir_set) );
270+ print_entries (get_entries_to_print ( GIT_STATUS_WT_RENAMED, sl, false , of, tracked_dir_set) );
194271 if (is_long)
195272 {
196273 std::cout << std::endl;
@@ -203,7 +280,30 @@ void status_subcommand::run()
203280 {
204281 std::cout << untracked_header << std::endl;
205282 }
206- print_entries (GIT_STATUS_WT_NEW, sl, false , of, false );
283+ std::vector<std::pair<std::string, std::string>> untracked_untries_to_print{};
284+ for (auto e: get_entries_to_print (GIT_STATUS_WT_NEW, sl, false , of))
285+ {
286+ const size_t first_slash_idx = std::string_view (e.second ).find (' /' );
287+ if (std::string::npos != first_slash_idx)
288+ {
289+ auto directory = std::string_view (e.second ).substr (0 , first_slash_idx);
290+ if (auto directory in tracked_dir_set)
291+ {
292+
293+ }
294+ else
295+ {
296+ if (auto directory in untracked_dir_set)
297+ {}
298+ else
299+ {
300+ untracked_untries_to_print.push_back ({e.first , directory});
301+ untracked_dir_set->insert (std::string (directory));
302+ }
303+ }
304+ }
305+ }
306+ print_entries (untracked_untries_to_print);
207307 if (is_long)
208308 {
209309 std::cout << std::endl;
@@ -216,7 +316,7 @@ void status_subcommand::run()
216316 {
217317 std::cout << ignored_header << std::endl;
218318 }
219- print_entries (GIT_STATUS_IGNORED, sl, false , of, false );
319+ print_entries (get_entries_to_print ( GIT_STATUS_IGNORED, sl, false , of)); // TODO: same as untracked
220320 if (is_long)
221321 {
222322 std::cout << std::endl;
0 commit comments