Skip to content

Commit dadcf62

Browse files
committed
code cleanup (compiler & attributes)
1 parent 7e2494a commit dadcf62

7 files changed

+26
-25
lines changed

src/core/OSTreeTUI.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void OSTreeTUI::RefreshCommitComponents() {
186186

187187
commitComponents.clear();
188188
commitComponents.push_back(TrashBin::TrashBinComponent(*this));
189-
int i{0};
189+
size_t i{0};
190190
parseVisibleCommitMap();
191191
for (auto& hash : visibleCommitViewMap) {
192192
commitComponents.push_back(CommitRender::CommitComponent(i, hash, *this));
@@ -300,7 +300,8 @@ void OSTreeTUI::parseVisibleCommitMap() {
300300
void OSTreeTUI::adjustScrollToSelectedCommit() {
301301
// try to scroll it to the middle
302302
int windowHeight = screen.dimy() - 4;
303-
int scollOffsetToFitCommitToTop = -selectedCommit * CommitRender::COMMIT_WINDOW_HEIGHT;
303+
int scollOffsetToFitCommitToTop =
304+
-static_cast<int>(selectedCommit) * CommitRender::COMMIT_WINDOW_HEIGHT;
304305
int newScroll =
305306
scollOffsetToFitCommitToTop + windowHeight / 2 - CommitRender::COMMIT_WINDOW_HEIGHT;
306307
// adjust if on edges

src/core/commit.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ Element DefaultRenderState(const WindowRenderState& state,
7575
/// https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp
7676
class CommitComponentImpl : public ComponentBase, public WindowOptions {
7777
public:
78-
explicit CommitComponentImpl(int position, std::string commit, OSTreeTUI& ostreetui)
79-
: commitPosition(position),
78+
explicit CommitComponentImpl(size_t position, std::string commit, OSTreeTUI& ostreetui)
79+
: drag_initial_x(1),
80+
drag_initial_y(static_cast<int>(position) * COMMIT_WINDOW_HEIGHT),
81+
commitPosition(position),
8082
hash(std::move(commit)),
8183
ostreetui(ostreetui),
8284
commit(ostreetui.GetOstreeRepo().GetCommitList().at(hash)),
83-
newVersion(this->commit.version),
84-
drag_initial_y(position * COMMIT_WINDOW_HEIGHT),
85-
drag_initial_x(1) {
85+
newVersion(this->commit.version) {
8686
inner = Renderer([&] {
8787
return vbox({
8888
text(ostreetui.GetOstreeRepo().GetCommitList().at(hash).subject),
@@ -183,12 +183,10 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
183183
}
184184
} else if (ostreetui.GetViewMode() == ViewMode::COMMIT_DROP &&
185185
ostreetui.GetModeHash() == hash) {
186-
const auto& commitList = ostreetui.GetOstreeRepo().GetCommitList();
187-
auto commit = commitList.at(hash);
188186
startDeletionWindow(ostreetui.GetOstreeRepo().IsMostRecentCommitOnBranch(hash));
189187
}
190188

191-
auto element = ComponentBase::Render();
189+
ftxui::Element element = ComponentBase::Render();
192190

193191
const WindowRenderState state = {element, title(), Active(), drag_};
194192

@@ -371,7 +369,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
371369
bool drag_ = false;
372370

373371
// ostree-tui specific members
374-
int commitPosition;
372+
size_t commitPosition;
375373
std::string hash;
376374
OSTreeTUI& ostreetui;
377375

@@ -445,7 +443,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
445443

446444
} // namespace
447445

448-
ftxui::Component CommitComponent(int position, const std::string& commit, OSTreeTUI& ostreetui) {
446+
ftxui::Component CommitComponent(size_t position, const std::string& commit, OSTreeTUI& ostreetui) {
449447
return ftxui::Make<CommitComponentImpl>(position, commit, ostreetui);
450448
}
451449

src/core/commit.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ constexpr int COMMIT_WINDOW_HEIGHT{4};
3232
constexpr int COMMIT_WINDOW_WIDTH{32};
3333
constexpr int PROMOTION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 11};
3434
constexpr int PROMOTION_WINDOW_WIDTH{COMMIT_WINDOW_WIDTH + 8};
35-
constexpr int DELETION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 9};
35+
constexpr int DELETION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 8};
3636
constexpr int DELETION_WINDOW_WIDTH{COMMIT_WINDOW_WIDTH + 8};
3737
// render tree types
3838
enum RenderTree : uint8_t {
@@ -51,7 +51,7 @@ enum RenderTree : uint8_t {
5151
*
5252
* @return UI Component
5353
*/
54-
[[nodiscard]] ftxui::Component CommitComponent(int position,
54+
[[nodiscard]] ftxui::Component CommitComponent(size_t position,
5555
const std::string& commit,
5656
OSTreeTUI& ostreetui);
5757

src/core/manager.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ BranchBoxManager::BranchBoxManager(OSTreeTUI& ostreetui,
5353
std::unordered_map<std::string, bool>& visibleBranches) {
5454
using namespace ftxui;
5555

56-
CheckboxOption cboption = {.on_change = [&] { ostreetui.RefreshCommitListComponent(); }};
56+
CheckboxOption cboption = CheckboxOption::Simple();
57+
cboption.on_change = [&] { ostreetui.RefreshCommitListComponent(); };
58+
// CheckboxOption cboption = {.on_change = [&] { ostreetui.RefreshCommitListComponent(); }};
5759

5860
// branch visibility
5961
for (const auto& branch : repo.GetBranches()) {

src/core/trashBin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class TrashBinComponentImpl : public ComponentBase, public WindowOptions {
8787
return element;
8888
}
8989

90-
bool OnEvent(Event event) final { return false; }
90+
bool OnEvent(Event /*event*/) final { return false; }
9191

9292
private:
9393
OSTreeTUI& ostreetui;

src/util/cpplibostree.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ bool OSTreeRepo::ResetBranchHeadAndPrune(const std::string& branch) {
365365
}
366366

367367
bool OSTreeRepo::runCLICommand(const std::string& command) {
368-
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose);
368+
std::unique_ptr<FILE, int (*)(FILE*)> pipe(popen(command.c_str(), "r"), &pclose);
369369
if (!pipe) {
370370
return false;
371371
}

src/util/cpplibostree.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ class OSTreeRepo {
9191
OstreeRepo* _c();
9292

9393
/// Getter
94-
const std::string& GetRepoPath() const;
94+
[[nodiscard]] const std::string& GetRepoPath() const;
9595
/// Getter
96-
const CommitList& GetCommitList() const;
96+
[[nodiscard]] const CommitList& GetCommitList() const;
9797
/// Getter
98-
const std::vector<std::string>& GetBranches() const;
98+
[[nodiscard]] const std::vector<std::string>& GetBranches() const;
9999

100100
// Methods
101101

@@ -115,7 +115,7 @@ class OSTreeRepo {
115115
* @return true if the commit is signed
116116
* @return false if the commit is not signed
117117
*/
118-
static bool IsCommitSigned(const Commit& commit);
118+
[[nodiscard]] static bool IsCommitSigned(const Commit& commit);
119119

120120
// read & write access to OSTree repo:
121121

@@ -166,23 +166,23 @@ class OSTreeRepo {
166166
* @param branch Branch to get most recent commit from.
167167
* @return Most recent commit of the specified branch.
168168
*/
169-
const Commit& GetMostRecentCommitOfBranch(const std::string& branch) const;
169+
[[nodiscard]] const Commit& GetMostRecentCommitOfBranch(const std::string& branch) const;
170170

171171
/**
172172
* @brief Checks if commit is the most recent commit on its branch
173173
*
174174
* @param commit Commit to check.
175175
* @return True, if commit is most recent on its branch.
176176
*/
177-
bool IsMostRecentCommitOnBranch(const Commit& commit) const;
177+
[[nodiscard]] bool IsMostRecentCommitOnBranch(const Commit& commit) const;
178178

179179
/**
180180
* @brief Checks if commit is the most recent commit on its branch
181181
*
182182
* @param hash Hash of the commit to check.
183183
* @return True, if commit is most recent on its branch.
184184
*/
185-
bool IsMostRecentCommitOnBranch(const std::string& hash) const;
185+
[[nodiscard]] bool IsMostRecentCommitOnBranch(const std::string& hash) const;
186186

187187
private:
188188
/**
@@ -217,7 +217,7 @@ class OSTreeRepo {
217217
*
218218
* @return std::string All branch names, separated by spaces
219219
*/
220-
std::string getBranchesAsString();
220+
[[nodiscard]] std::string getBranchesAsString();
221221

222222
/**
223223
* @brief Parse a libostree GVariant commit to a C++ commit struct.

0 commit comments

Comments
 (0)