Skip to content

Commit 3b3f289

Browse files
committed
add no-discard attribute & small code cleanups
1 parent 4eebcfe commit 3b3f289

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

src/core/OSTreeTUI.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ bool OSTreeTUI::SetPromotionMode(bool active, const std::string& hash, bool SetP
231231
}
232232

233233
bool OSTreeTUI::PromoteCommit(const std::string& hash,
234-
const std::string& branch,
234+
const std::string& targetBranch,
235235
const std::vector<std::string>& metadataStrings,
236236
const std::string& newSubject,
237237
bool keepMetadata) {
238238
bool success =
239-
ostreeRepo.PromoteCommit(hash, branch, metadataStrings, newSubject, keepMetadata);
239+
ostreeRepo.PromoteCommit(hash, targetBranch, metadataStrings, newSubject, keepMetadata);
240240
SetPromotionMode(false);
241241
// reload repository
242242
if (success) {
@@ -324,11 +324,11 @@ const std::unordered_map<std::string, ftxui::Color>& OSTreeTUI::GetBranchColorMa
324324
return branchColorMap;
325325
}
326326

327-
const int& OSTreeTUI::GetScrollOffset() const {
327+
int OSTreeTUI::GetScrollOffset() const {
328328
return scrollOffset;
329329
}
330330

331-
const bool& OSTreeTUI::GetInPromotionSelection() const {
331+
bool OSTreeTUI::GetInPromotionSelection() const {
332332
return inPromotionSelection;
333333
}
334334

@@ -384,7 +384,7 @@ int OSTreeTUI::showHelp(const std::string& caller, const std::string& errorMessa
384384
int OSTreeTUI::showVersion() {
385385
using namespace ftxui;
386386

387-
auto versionText = text("ostree-tui 0.2.1");
387+
auto versionText = text("ostree-tui 0.3.0");
388388

389389
auto screen = Screen::Create(Dimension::Fit(versionText));
390390
Render(screen, versionText);

src/core/OSTreeTUI.hpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ class OSTreeTUI {
6666
* @brief Promotes a commit, by passing it to the cpplibostree and refreshing the UI.
6767
*
6868
* @param hash Hash of commit to be promoted.
69-
* @param branch Branch to promote the commit to.
69+
* @param targetBranch Branch to promote the commit to.
7070
* @param metadataStrings Optional additional metadata-strings to be set.
7171
* @param newSubject New commit subject.
7272
* @param keepMetadata Keep metadata of old commit.
7373
* @return promotion success
7474
*/
7575
bool PromoteCommit(const std::string& hash,
76-
const std::string& branch,
76+
const std::string& targetBranch,
7777
const std::vector<std::string>& metadataStrings = {},
7878
const std::string& newSubject = "",
7979
bool keepMetadata = true);
@@ -91,20 +91,20 @@ class OSTreeTUI {
9191
void SetSelectedCommit(size_t selectedCommit);
9292

9393
// non-const GETTER
94-
std::vector<std::string>& GetColumnToBranchMap();
95-
ftxui::ScreenInteractive& GetScreen();
94+
[[nodiscard]] std::vector<std::string>& GetColumnToBranchMap();
95+
[[nodiscard]] ftxui::ScreenInteractive& GetScreen();
9696

9797
// GETTER
98-
const cpplibostree::OSTreeRepo& GetOstreeRepo() const;
99-
const size_t& GetSelectedCommit() const;
100-
const std::string& GetPromotionBranch() const;
101-
const std::unordered_map<std::string, bool>& GetVisibleBranches() const;
102-
const std::vector<std::string>& GetColumnToBranchMap() const;
103-
const std::vector<std::string>& GetVisibleCommitViewMap() const;
104-
const std::unordered_map<std::string, ftxui::Color>& GetBranchColorMap() const;
105-
const int& GetScrollOffset() const;
106-
const bool& GetInPromotionSelection() const;
107-
const std::string& GetPromotionHash() const;
98+
[[nodiscard]] const cpplibostree::OSTreeRepo& GetOstreeRepo() const;
99+
[[nodiscard]] const size_t& GetSelectedCommit() const;
100+
[[nodiscard]] const std::string& GetPromotionBranch() const;
101+
[[nodiscard]] const std::unordered_map<std::string, bool>& GetVisibleBranches() const;
102+
[[nodiscard]] const std::vector<std::string>& GetColumnToBranchMap() const;
103+
[[nodiscard]] const std::vector<std::string>& GetVisibleCommitViewMap() const;
104+
[[nodiscard]] const std::unordered_map<std::string, ftxui::Color>& GetBranchColorMap() const;
105+
[[nodiscard]] int GetScrollOffset() const;
106+
[[nodiscard]] bool GetInPromotionSelection() const;
107+
[[nodiscard]] const std::string& GetPromotionHash() const;
108108

109109
private:
110110
// model

src/core/commit.hpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ enum RenderTree : uint8_t {
4949
*
5050
* @return UI Component
5151
*/
52-
ftxui::Component CommitComponent(int position, const std::string& commit, OSTreeTUI& ostreetui);
52+
[[nodiscard]] ftxui::Component CommitComponent(int position,
53+
const std::string& commit,
54+
OSTreeTUI& ostreetui);
5355

5456
/**
5557
* @brief Creates a Renderer for the commit section.
@@ -59,8 +61,9 @@ ftxui::Component CommitComponent(int position, const std::string& commit, OSTree
5961
* @param selectedCommit Commit that should be marked as selected.
6062
* @return UI Element
6163
*/
62-
ftxui::Element commitRender(OSTreeTUI& ostreetui,
63-
const std::unordered_map<std::string, ftxui::Color>& branchColorMap);
64+
[[nodiscard]] ftxui::Element commitRender(
65+
OSTreeTUI& ostreetui,
66+
const std::unordered_map<std::string, ftxui::Color>& branchColorMap);
6467

6568
/**
6669
* @brief Builds a commit-tree line.
@@ -71,9 +74,10 @@ ftxui::Element commitRender(OSTreeTUI& ostreetui,
7174
* @param branchColorMap Branch colors to use.
7275
* @return UI Element, one commit-tree line.
7376
*/
74-
ftxui::Element addTreeLine(const RenderTree& treeLineType,
75-
const cpplibostree::Commit& commit,
76-
const std::unordered_map<std::string, int>& usedBranches,
77-
const std::unordered_map<std::string, ftxui::Color>& branchColorMap);
77+
[[nodiscard]] ftxui::Element addTreeLine(
78+
const RenderTree& treeLineType,
79+
const cpplibostree::Commit& commit,
80+
const std::unordered_map<std::string, int>& usedBranches,
81+
const std::unordered_map<std::string, ftxui::Color>& branchColorMap);
7882

7983
} // namespace CommitRender

src/core/manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ftxui::Component Manager::getManagerRenderer() {
4242
return managerRenderer;
4343
}
4444

45-
const int& Manager::getTabIndex() const {
45+
int Manager::getTabIndex() const {
4646
return tab_index;
4747
}
4848

src/core/manager.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Manager {
3535

3636
public:
3737
ftxui::Component getManagerRenderer();
38-
const int& getTabIndex() const;
38+
int getTabIndex() const;
3939
};
4040

4141
class CommitInfoManager {
@@ -46,13 +46,10 @@ class CommitInfoManager {
4646
* @param displayCommit Commit to display the information of.
4747
* @return ftxui::Element
4848
*/
49-
static ftxui::Element renderInfoView(const cpplibostree::Commit& displayCommit);
49+
[[nodiscard]] static ftxui::Element renderInfoView(const cpplibostree::Commit& displayCommit);
5050
};
5151

5252
class BranchBoxManager {
53-
public:
54-
ftxui::Component branchBoxes = ftxui::Container::Vertical({});
55-
5653
public:
5754
BranchBoxManager(OSTreeTUI& ostreetui,
5855
cpplibostree::OSTreeRepo& repo,
@@ -63,5 +60,8 @@ class BranchBoxManager {
6360
*
6461
* @return ftxui::Element
6562
*/
66-
ftxui::Element branchBoxRender();
63+
[[nodiscard]] ftxui::Element branchBoxRender();
64+
65+
public:
66+
ftxui::Component branchBoxes = ftxui::Container::Vertical({});
6767
};

0 commit comments

Comments
 (0)