Skip to content

Commit

Permalink
code cleanup (compiler & attributes)
Browse files Browse the repository at this point in the history
  • Loading branch information
forgottosave committed Dec 3, 2024
1 parent 7e2494a commit dadcf62
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/core/OSTreeTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void OSTreeTUI::RefreshCommitComponents() {

commitComponents.clear();
commitComponents.push_back(TrashBin::TrashBinComponent(*this));
int i{0};
size_t i{0};
parseVisibleCommitMap();
for (auto& hash : visibleCommitViewMap) {
commitComponents.push_back(CommitRender::CommitComponent(i, hash, *this));
Expand Down Expand Up @@ -300,7 +300,8 @@ void OSTreeTUI::parseVisibleCommitMap() {
void OSTreeTUI::adjustScrollToSelectedCommit() {
// try to scroll it to the middle
int windowHeight = screen.dimy() - 4;
int scollOffsetToFitCommitToTop = -selectedCommit * CommitRender::COMMIT_WINDOW_HEIGHT;
int scollOffsetToFitCommitToTop =
-static_cast<int>(selectedCommit) * CommitRender::COMMIT_WINDOW_HEIGHT;
int newScroll =
scollOffsetToFitCommitToTop + windowHeight / 2 - CommitRender::COMMIT_WINDOW_HEIGHT;
// adjust if on edges
Expand Down
18 changes: 8 additions & 10 deletions src/core/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ Element DefaultRenderState(const WindowRenderState& state,
/// https://github.com/ArthurSonzogni/FTXUI/blob/main/src/ftxui/component/window.cpp
class CommitComponentImpl : public ComponentBase, public WindowOptions {
public:
explicit CommitComponentImpl(int position, std::string commit, OSTreeTUI& ostreetui)
: commitPosition(position),
explicit CommitComponentImpl(size_t position, std::string commit, OSTreeTUI& ostreetui)
: drag_initial_x(1),
drag_initial_y(static_cast<int>(position) * COMMIT_WINDOW_HEIGHT),
commitPosition(position),
hash(std::move(commit)),
ostreetui(ostreetui),
commit(ostreetui.GetOstreeRepo().GetCommitList().at(hash)),
newVersion(this->commit.version),
drag_initial_y(position * COMMIT_WINDOW_HEIGHT),
drag_initial_x(1) {
newVersion(this->commit.version) {
inner = Renderer([&] {
return vbox({
text(ostreetui.GetOstreeRepo().GetCommitList().at(hash).subject),
Expand Down Expand Up @@ -183,12 +183,10 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
}
} else if (ostreetui.GetViewMode() == ViewMode::COMMIT_DROP &&
ostreetui.GetModeHash() == hash) {
const auto& commitList = ostreetui.GetOstreeRepo().GetCommitList();
auto commit = commitList.at(hash);
startDeletionWindow(ostreetui.GetOstreeRepo().IsMostRecentCommitOnBranch(hash));
}

auto element = ComponentBase::Render();
ftxui::Element element = ComponentBase::Render();

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

Expand Down Expand Up @@ -371,7 +369,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
bool drag_ = false;

// ostree-tui specific members
int commitPosition;
size_t commitPosition;
std::string hash;
OSTreeTUI& ostreetui;

Expand Down Expand Up @@ -445,7 +443,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {

} // namespace

ftxui::Component CommitComponent(int position, const std::string& commit, OSTreeTUI& ostreetui) {
ftxui::Component CommitComponent(size_t position, const std::string& commit, OSTreeTUI& ostreetui) {
return ftxui::Make<CommitComponentImpl>(position, commit, ostreetui);
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/commit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ constexpr int COMMIT_WINDOW_HEIGHT{4};
constexpr int COMMIT_WINDOW_WIDTH{32};
constexpr int PROMOTION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 11};
constexpr int PROMOTION_WINDOW_WIDTH{COMMIT_WINDOW_WIDTH + 8};
constexpr int DELETION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 9};
constexpr int DELETION_WINDOW_HEIGHT{COMMIT_WINDOW_HEIGHT + 8};
constexpr int DELETION_WINDOW_WIDTH{COMMIT_WINDOW_WIDTH + 8};
// render tree types
enum RenderTree : uint8_t {
Expand All @@ -51,7 +51,7 @@ enum RenderTree : uint8_t {
*
* @return UI Component
*/
[[nodiscard]] ftxui::Component CommitComponent(int position,
[[nodiscard]] ftxui::Component CommitComponent(size_t position,
const std::string& commit,
OSTreeTUI& ostreetui);

Expand Down
4 changes: 3 additions & 1 deletion src/core/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ BranchBoxManager::BranchBoxManager(OSTreeTUI& ostreetui,
std::unordered_map<std::string, bool>& visibleBranches) {
using namespace ftxui;

CheckboxOption cboption = {.on_change = [&] { ostreetui.RefreshCommitListComponent(); }};
CheckboxOption cboption = CheckboxOption::Simple();
cboption.on_change = [&] { ostreetui.RefreshCommitListComponent(); };
// CheckboxOption cboption = {.on_change = [&] { ostreetui.RefreshCommitListComponent(); }};

// branch visibility
for (const auto& branch : repo.GetBranches()) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/trashBin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TrashBinComponentImpl : public ComponentBase, public WindowOptions {
return element;
}

bool OnEvent(Event event) final { return false; }
bool OnEvent(Event /*event*/) final { return false; }

private:
OSTreeTUI& ostreetui;
Expand Down
2 changes: 1 addition & 1 deletion src/util/cpplibostree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ bool OSTreeRepo::ResetBranchHeadAndPrune(const std::string& branch) {
}

bool OSTreeRepo::runCLICommand(const std::string& command) {
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose);
std::unique_ptr<FILE, int (*)(FILE*)> pipe(popen(command.c_str(), "r"), &pclose);
if (!pipe) {
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions src/util/cpplibostree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ class OSTreeRepo {
OstreeRepo* _c();

/// Getter
const std::string& GetRepoPath() const;
[[nodiscard]] const std::string& GetRepoPath() const;
/// Getter
const CommitList& GetCommitList() const;
[[nodiscard]] const CommitList& GetCommitList() const;
/// Getter
const std::vector<std::string>& GetBranches() const;
[[nodiscard]] const std::vector<std::string>& GetBranches() const;

// Methods

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

// read & write access to OSTree repo:

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

/**
* @brief Checks if commit is the most recent commit on its branch
*
* @param commit Commit to check.
* @return True, if commit is most recent on its branch.
*/
bool IsMostRecentCommitOnBranch(const Commit& commit) const;
[[nodiscard]] bool IsMostRecentCommitOnBranch(const Commit& commit) const;

/**
* @brief Checks if commit is the most recent commit on its branch
*
* @param hash Hash of the commit to check.
* @return True, if commit is most recent on its branch.
*/
bool IsMostRecentCommitOnBranch(const std::string& hash) const;
[[nodiscard]] bool IsMostRecentCommitOnBranch(const std::string& hash) const;

private:
/**
Expand Down Expand Up @@ -217,7 +217,7 @@ class OSTreeRepo {
*
* @return std::string All branch names, separated by spaces
*/
std::string getBranchesAsString();
[[nodiscard]] std::string getBranchesAsString();

/**
* @brief Parse a libostree GVariant commit to a C++ commit struct.
Expand Down

0 comments on commit dadcf62

Please sign in to comment.