Skip to content

Commit 2b92a09

Browse files
authored
Consts / defaults (#45)
* no const on return * defaulting
1 parent 2dca29b commit 2b92a09

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

README.noformat

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Used by macros KOUT and KLOG : see inc/usage.hpp
4141

4242
Key KUL_GIT_CO
4343
Type string
44-
Default ""
44+
Default "--depth 10 --recursive --shallow-submodules"
4545
Description - Add string to git clone as arguments
4646

4747
Key KUL_SVN_CO

inc/mkn/kul/assert.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct Assert {
5252
}
5353
};
5454

55-
void abort_if(bool b) {
55+
void inline abort_if(bool b) {
5656
if (b) std::abort();
5757
}
5858

inc/mkn/kul/os/nixish/env.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4343
#include <algorithm>
4444
#include <fstream>
4545
#include <thread>
46+
#include <cassert>
4647

4748
#include <limits.h>
4849

@@ -65,7 +66,13 @@ inline std::string GET(char const* c, std::string default_ = "") {
6566
char const* r = getenv(c);
6667
return std::string(r ? r : default_);
6768
}
68-
inline void SET(char const* var, char const* val) { setenv(var, val, 1); }
69+
inline void SET(char const* var, char const* val = nullptr) {
70+
assert(var);
71+
if (val and strlen(val) > 0)
72+
setenv(var, val, 1);
73+
else
74+
unsetenv(var);
75+
}
6976
inline char SEP() { return ':'; }
7077

7178
inline std::string CWD() {

inc/mkn/kul/os/win/env.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ inline std::string GET(char const* c, std::string default_ = "") {
8383
return default_;
8484
}
8585

86-
inline void SET(char const* var, char const* val) {
87-
_putenv(std::string(std::string(var) + "=" + std::string(val)).c_str());
86+
inline void SET(char const* var, char const* val = nullptr) {
87+
if (val and strlen(val) > 0)
88+
_putenv(std::string(std::string(var) + "=" + std::string(val)).c_str());
89+
else // unset
90+
_putenv(std::string(std::string(var) + "=").c_str());
8891
}
8992

9093
inline char SEP() { return ';'; }

inc/mkn/kul/scm.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ class Git : public SCM {
117117
KTHROW(Exception) override {
118118
Dir dr(d, true);
119119
mkn::kul::Process p("git");
120-
p << "clone" << mkn::kul::env::GET("KUL_GIT_CO") << r;
120+
std::string defaults = "--depth 10 --recursive --shallow-submodules";
121+
p << "clone" << mkn::kul::env::GET("KUL_GIT_CO", defaults) << r;
121122
if (!v.empty()) p.arg("-b").arg(v);
122123
try {
123124
p.arg(d).start();

inc/mkn/kul/yaml.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class File : public Item {
163163
}
164164
virtual ~File() {}
165165
std::string const& file() const { return f; }
166-
const virtual Validator validator() const = 0;
166+
virtual Validator validator() const = 0;
167167

168168
protected:
169169
void reload() KTHROW(Exception) {
@@ -178,7 +178,7 @@ class File : public Item {
178178
File(std::string const& f) KTHROW(Exception) : f(f) { reload(); }
179179

180180
private:
181-
const std::string f; // file
181+
std::string const f; // file
182182
};
183183
} // namespace yaml
184184
} // namespace kul

0 commit comments

Comments
 (0)