Skip to content

Commit

Permalink
watchman: json_is_true(o) -> o.asBool()
Browse files Browse the repository at this point in the history
Summary: This also helps make the api more folly::dynamic-alike

Reviewed By: chadaustin

Differential Revision: D14102884

fbshipit-source-id: 201b4b697d58be4dbb3c59cc0c91d87ac9d9969f
  • Loading branch information
wez authored and facebook-github-bot committed Feb 19, 2019
1 parent 265f549 commit 061e6ab
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions cfg.cpp
Expand Up @@ -161,7 +161,7 @@ json_ref cfg_compute_root_files(bool* enforcing) {
w_log(W_LOG_FATAL,
"Expected config value enforce_root_files to be boolean\n");
}
*enforcing = json_is_true(ref);
*enforcing = ref.asBool();
}

ref = cfg_get_json("root_files");
Expand Down Expand Up @@ -237,7 +237,7 @@ bool cfg_get_bool(const char* name, bool defval) {
if (!val.isBool()) {
w_log(W_LOG_FATAL, "Expected config value %s to be a boolean\n", name);
}
return json_is_true(val);
return val.asBool();
}

return defval;
Expand Down Expand Up @@ -272,7 +272,7 @@ double cfg_get_double(const char* name, double defval) {
"Expected config value %s." #PROP " to be a boolean\n", \
name); \
} \
if (json_is_true(perm)) { \
if (perm.asBool()) { \
ret |= S_IR##SUFFIX; \
if (write_bits) { \
ret |= S_IW##SUFFIX; \
Expand Down Expand Up @@ -376,7 +376,7 @@ bool Configuration::getBool(const char* name, bool defval) const {
if (!val.isBool()) {
w_log(W_LOG_FATAL, "Expected config value %s to be a boolean\n", name);
}
return json_is_true(val);
return val.asBool();
}

return defval;
Expand Down
2 changes: 1 addition & 1 deletion cmds/debug.cpp
Expand Up @@ -144,7 +144,7 @@ static void cmd_debug_set_subscriptions_paused(
for (auto& it : paused_map) {
auto sub_iter = client->subscriptions.find(it.first);
bool old_paused = sub_iter->second->debug_paused;
bool new_paused = json_is_true(it.second);
bool new_paused = it.second.asBool();
sub_iter->second->debug_paused = new_paused;
states.set(
it.first,
Expand Down
2 changes: 1 addition & 1 deletion cmds/trigger.cpp
Expand Up @@ -251,7 +251,7 @@ watchman_trigger_command::watchman_trigger_command(
return;
}

append_files = json_is_true(trig.get_default("append_files", json_false()));
append_files = trig.get_default("append_files", json_false()).asBool();
if (append_files) {
// This is unfortunately a bit of a hack. When appending files to the
// command line we need a list of just the file names. We would normally
Expand Down
2 changes: 2 additions & 0 deletions thirdparty/jansson/jansson.h
Expand Up @@ -171,6 +171,8 @@ class json_ref {
inline bool isDouble() const {
return type() == JSON_REAL;
}

bool asBool() const;
};

#if JSON_INTEGER_IS_LONG_LONG
Expand Down
11 changes: 11 additions & 0 deletions thirdparty/jansson/value.cpp
Expand Up @@ -72,6 +72,17 @@ json_t::json_t(json_type type) : type(type), refcount(1) {}
json_t::json_t(json_type type, json_t::SingletonHack&&)
: type(type), refcount(-1) {}

bool json_ref::asBool() const {
switch (type()) {
case JSON_TRUE:
return true;
case JSON_FALSE:
return false;
default:
throw std::domain_error("asBool called on non-boolean");
}
}

/*** object ***/

const std::unordered_map<w_string, json_ref>& json_ref::object() const {
Expand Down
4 changes: 2 additions & 2 deletions watcher/eden.cpp
Expand Up @@ -980,8 +980,8 @@ class EdenView : public QueryableView {
}

// More glob flags/functionality:
auto noescape = json_is_true(
query->query_spec.get_default("glob_noescape", json_false()));
auto noescape =
query->query_spec.get_default("glob_noescape", json_false()).asBool();
if (noescape) {
throw QueryExecError(
"glob_noescape is not supported for the eden watcher");
Expand Down

0 comments on commit 061e6ab

Please sign in to comment.