1
1
#include < iostream>
2
2
#include < ostream>
3
+ #include < set>
3
4
#include < string>
4
5
5
6
#include < git2.h>
@@ -71,20 +72,81 @@ enum class output_format
71
72
SHORT = 2
72
73
};
73
74
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 )
75
135
{
136
+ std::vector<std::pair<std::string, std::string>> entries_to_print{};
76
137
const auto & entry_list = sl.get_entry_list (status);
77
138
if (!entry_list.empty ())
78
139
{
79
140
for (auto * entry : entry_list)
80
141
{
142
+ std::string bla;
81
143
if ((of == output_format::DEFAULT) || (of == output_format::LONG))
82
144
{
83
- std::cout << status_msg_map.at (status).long_mod << " \t " ;
145
+ bla = status_msg_map.at (status).long_mod + " \t " ;
84
146
}
85
147
else if (of == output_format::SHORT)
86
148
{
87
- std::cout << status_msg_map.at (status).short_mod ;
149
+ bla = status_msg_map.at (status).short_mod ;
88
150
}
89
151
90
152
git_diff_delta* diff_delta;
@@ -98,35 +160,45 @@ void print_entries(git_status_t status, status_list_wrapper& sl, bool head_selec
98
160
}
99
161
const char * old_path = diff_delta->old_file .path ;
100
162
const char * new_path = diff_delta->new_file .path ;
101
- if (add_root)
163
+ std::string blou;
164
+ if (tracked_dir_set)
102
165
{
103
166
const size_t first_slash_idx = std::string_view (old_path).find (' /' );
104
- const char * directory;
105
167
if (std::string::npos != first_slash_idx)
106
168
{
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) );
109
171
}
110
172
}
111
173
if (old_path && new_path && std::strcmp (old_path, new_path))
112
174
{
113
- std::cout << old_path << " -> " << new_path << std::endl ;
175
+ blou = std::string ( old_path) + " -> " + std::string (new_path) ;
114
176
}
115
177
else
116
178
{
117
179
if (old_path)
118
180
{
119
- std::cout << old_path << std::endl ;
181
+ blou = old_path;
120
182
}
121
183
else
122
184
{
123
- std::cout << new_path << std::endl ;
185
+ blou = new_path;
124
186
}
125
187
}
188
+ entries_to_print.push_back ({bla, blou});
126
189
}
127
190
}
128
191
else
129
192
{}
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
+ }
130
202
}
131
203
132
204
void status_subcommand::run ()
@@ -137,6 +209,11 @@ void status_subcommand::run()
137
209
auto sl = status_list_wrapper::status_list (repo);
138
210
auto branch_name = reference_wrapper::get_ref_name (repo);
139
211
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
+
140
217
output_format of = output_format::DEFAULT;
141
218
if (short_flag)
142
219
{
@@ -170,11 +247,11 @@ void status_subcommand::run()
170
247
{
171
248
std::cout << tobecommited_header << std::endl;
172
249
}
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) );
178
255
if (is_long)
179
256
{
180
257
std::cout << std::endl;
@@ -187,10 +264,10 @@ void status_subcommand::run()
187
264
{
188
265
std::cout << notstagged_header << std::endl;
189
266
}
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) );
194
271
if (is_long)
195
272
{
196
273
std::cout << std::endl;
@@ -203,7 +280,30 @@ void status_subcommand::run()
203
280
{
204
281
std::cout << untracked_header << std::endl;
205
282
}
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);
207
307
if (is_long)
208
308
{
209
309
std::cout << std::endl;
@@ -216,7 +316,7 @@ void status_subcommand::run()
216
316
{
217
317
std::cout << ignored_header << std::endl;
218
318
}
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
220
320
if (is_long)
221
321
{
222
322
std::cout << std::endl;
0 commit comments