Skip to content

Commit 139e8ca

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 96bd4f2 commit 139e8ca

1 file changed

Lines changed: 59 additions & 46 deletions

File tree

src/subcommand/status_subcommand.cpp

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "status_subcommand.hpp"
22

3+
#include <algorithm>
34
#include <iostream>
45
#include <ostream>
56
#include <set>
67
#include <string>
78
#include <unordered_map>
8-
#include <algorithm>
99

1010
#include <git2.h>
1111
#include <termcolor/termcolor.hpp>
@@ -43,8 +43,8 @@ namespace
4343
ignored_header = "Ignored files:\n (use \"git add -f <file>...\" to include in what will be committed)\n";
4444
const std::string
4545
notstagged_header = "Changes not staged for commit:\n (use \"git add <file>...\" to update what will be committed)\n";
46-
// TODO: add the following ot notstagged_header after "checkout <file>" is implemented: (use \"git checkout --
47-
// <file>...\" to discard changes in working directory)\n";
46+
// TODO: add the following ot notstagged_header after "checkout <file>" is implemented: (use \"git
47+
// checkout -- <file>...\" to discard changes in working directory)\n";
4848
const std::string unmerged_header = "Unmerged paths:\n (use \"git add <file>...\" to mark resolution)\n";
4949
const std::string nothingtocommit_message = "no changes added to commit (use \"git add\" and/or \"git commit -a\")";
5050
const std::string treeclean_message = "Nothing to commit, working tree clean";
@@ -87,23 +87,23 @@ namespace
8787
{
8888
switch (status)
8989
{
90-
case GIT_STATUS_INDEX_NEW:
91-
case GIT_STATUS_WT_NEW:
92-
return 'A';
93-
case GIT_STATUS_INDEX_MODIFIED:
94-
case GIT_STATUS_WT_MODIFIED:
95-
return 'M';
96-
case GIT_STATUS_INDEX_DELETED:
97-
case GIT_STATUS_WT_DELETED:
98-
return 'D';
99-
case GIT_STATUS_INDEX_RENAMED:
100-
case GIT_STATUS_WT_RENAMED:
101-
return 'R';
102-
case GIT_STATUS_INDEX_TYPECHANGE:
103-
case GIT_STATUS_WT_TYPECHANGE:
104-
return 'T';
105-
default:
106-
return ' ';
90+
case GIT_STATUS_INDEX_NEW:
91+
case GIT_STATUS_WT_NEW:
92+
return 'A';
93+
case GIT_STATUS_INDEX_MODIFIED:
94+
case GIT_STATUS_WT_MODIFIED:
95+
return 'M';
96+
case GIT_STATUS_INDEX_DELETED:
97+
case GIT_STATUS_WT_DELETED:
98+
return 'D';
99+
case GIT_STATUS_INDEX_RENAMED:
100+
case GIT_STATUS_WT_RENAMED:
101+
return 'R';
102+
case GIT_STATUS_INDEX_TYPECHANGE:
103+
case GIT_STATUS_WT_TYPECHANGE:
104+
return 'T';
105+
default:
106+
return ' ';
107107
}
108108
}
109109

@@ -134,13 +134,13 @@ namespace
134134
return entry_item;
135135
}
136136

137-
std::unordered_map<std::string, combined_entry> build_combined_status_map(
138-
status_list_wrapper& sl,
139-
std::set<std::string>& tracked_dir_set)
137+
std::unordered_map<std::string, combined_entry>
138+
build_combined_status_map(status_list_wrapper& sl, std::set<std::string>& tracked_dir_set)
140139
{
141140
std::unordered_map<std::string, combined_entry> combined;
142141

143-
auto update_status_map = [&sl, &tracked_dir_set, &combined](const git_status_t(&status_array)[5] , bool index)
142+
auto update_status_map =
143+
[&sl, &tracked_dir_set, &combined](const git_status_t(&status_array)[5], bool index)
144144
{
145145
for (git_status_t status : status_array)
146146
{
@@ -167,14 +167,20 @@ namespace
167167
};
168168

169169
const git_status_t index_statuses[] = {
170-
GIT_STATUS_INDEX_NEW, GIT_STATUS_INDEX_MODIFIED, GIT_STATUS_INDEX_DELETED,
171-
GIT_STATUS_INDEX_RENAMED, GIT_STATUS_INDEX_TYPECHANGE
170+
GIT_STATUS_INDEX_NEW,
171+
GIT_STATUS_INDEX_MODIFIED,
172+
GIT_STATUS_INDEX_DELETED,
173+
GIT_STATUS_INDEX_RENAMED,
174+
GIT_STATUS_INDEX_TYPECHANGE
172175
};
173176
update_status_map(index_statuses, true);
174177

175178
const git_status_t worktree_statuses[] = {
176-
GIT_STATUS_WT_NEW, GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_DELETED,
177-
GIT_STATUS_WT_TYPECHANGE, GIT_STATUS_WT_RENAMED
179+
GIT_STATUS_WT_NEW,
180+
GIT_STATUS_WT_MODIFIED,
181+
GIT_STATUS_WT_DELETED,
182+
GIT_STATUS_WT_TYPECHANGE,
183+
GIT_STATUS_WT_RENAMED
178184
};
179185
update_status_map(worktree_statuses, false);
180186

@@ -185,18 +191,24 @@ namespace
185191
{
186192
std::vector<std::string> keys;
187193
keys.reserve(map.size());
188-
for (auto const& kv : map)
194+
for (const auto& kv : map)
189195
{
190196
keys.push_back(kv.first);
191197
}
192198
std::sort(keys.begin(), keys.end());
193199

194-
struct normal_row {char idx; char wt; std::string item;};
200+
struct normal_row
201+
{
202+
char idx;
203+
char wt;
204+
std::string item;
205+
};
206+
195207
std::vector<normal_row> normal_rows;
196208
std::vector<std::string> untracked_items;
197209
std::vector<std::string> ignored_items;
198210

199-
for (auto const& k : keys)
211+
for (const auto& k : keys)
200212
{
201213
const auto& ce = map.at(k);
202214

@@ -206,7 +218,8 @@ namespace
206218
untracked_items.push_back(ce.item);
207219
continue;
208220
}
209-
if ((ce.workdir_status & GIT_STATUS_IGNORED || ce.index_status & GIT_STATUS_IGNORED) && ce.index_status == 0)
221+
if ((ce.workdir_status & GIT_STATUS_IGNORED || ce.index_status & GIT_STATUS_IGNORED)
222+
&& ce.index_status == 0)
210223
{
211224
ignored_items.push_back(ce.item);
212225
continue;
@@ -218,7 +231,7 @@ namespace
218231
normal_rows.push_back({idx, wt, ce.item});
219232
}
220233

221-
for (auto const& r : normal_rows)
234+
for (const auto& r : normal_rows)
222235
{
223236
if (is_coloured)
224237
{
@@ -233,7 +246,7 @@ namespace
233246
}
234247

235248
std::sort(untracked_items.begin(), untracked_items.end());
236-
for (auto const& it : untracked_items)
249+
for (const auto& it : untracked_items)
237250
{
238251
if (is_coloured)
239252
{
@@ -246,7 +259,7 @@ namespace
246259
}
247260

248261
std::sort(ignored_items.begin(), ignored_items.end());
249-
for (auto const& it : ignored_items)
262+
for (const auto& it : ignored_items)
250263
{
251264
if (is_coloured)
252265
{
@@ -355,31 +368,31 @@ void print_tracking_info(repository_wrapper& repo, status_list_wrapper& sl, bool
355368
if (tracking_info.ahead > 0 && tracking_info.behind == 0)
356369
{
357370
std::cout << "Your branch is ahead of '" << tracking_info.upstream_name << "' by "
358-
<< tracking_info.ahead << " commit" << (tracking_info.ahead > 1 ? "s" : "") << "."
359-
<< std::endl;
371+
<< tracking_info.ahead << " commit" << (tracking_info.ahead > 1 ? "s" : "") << "."
372+
<< std::endl;
360373
std::cout << " (use \"git push\" to publish your local commits)" << std::endl;
361374
}
362375
else if (tracking_info.ahead == 0 && tracking_info.behind > 0)
363376
{
364377
std::cout << "Your branch is behind '" << tracking_info.upstream_name << "' by "
365-
<< tracking_info.behind << " commit" << (tracking_info.behind > 1 ? "s" : "") << "."
366-
<< std::endl;
378+
<< tracking_info.behind << " commit" << (tracking_info.behind > 1 ? "s" : "") << "."
379+
<< std::endl;
367380
std::cout << " (use \"git pull\" to update your local branch)" << std::endl;
368381
}
369382
else if (tracking_info.ahead > 0 && tracking_info.behind > 0)
370383
{
371384
std::cout << "Your branch and '" << tracking_info.upstream_name << "' have diverged,"
372-
<< std::endl;
385+
<< std::endl;
373386
std::cout << "and have " << tracking_info.ahead << " and " << tracking_info.behind
374-
<< " different commit"
375-
<< ((tracking_info.ahead + tracking_info.behind) > 2 ? "s" : "")
376-
<< " each, respectively." << std::endl;
387+
<< " different commit"
388+
<< ((tracking_info.ahead + tracking_info.behind) > 2 ? "s" : "")
389+
<< " each, respectively." << std::endl;
377390
std::cout << " (use \"git pull\" to merge the remote branch into yours)" << std::endl;
378391
}
379392
else // ahead == 0 && behind == 0
380393
{
381394
std::cout << "Your branch is up to date with '" << tracking_info.upstream_name << "'."
382-
<< std::endl;
395+
<< std::endl;
383396
}
384397
std::cout << std::endl;
385398
}
@@ -392,11 +405,11 @@ void print_tracking_info(repository_wrapper& repo, status_list_wrapper& sl, bool
392405
if (sl.has_unmerged_header())
393406
{
394407
std::cout << "You have unmerged paths.\n (fix conflicts and run \"git commit\")\n (use \"git merge --abort\" to abort the merge)\n"
395-
<< std::endl;
408+
<< std::endl;
396409
}
397410
}
398411
else if (branch_flag)
399-
{
412+
{
400413
if (tracking_info.has_upstream)
401414
{
402415
std::cout << "..." << termcolor::red << tracking_info.upstream_name << termcolor::reset;

0 commit comments

Comments
 (0)