Skip to content

Commit

Permalink
watchman: watchman::to -> folly::to
Browse files Browse the repository at this point in the history
Summary:
Now that we require folly, we can use folly's implementation of `to`.

The watchman implementation had a blanket conversion for pointer types,
so we have to explicitly cast pointers to uintptr_t in the folly
implementation.

Reviewed By: chadaustin

Differential Revision: D17783427

fbshipit-source-id: 959f18876ce8faf022db37d3343a9c07a991926b
  • Loading branch information
wez authored and facebook-github-bot committed Oct 31, 2019
1 parent d6cebe5 commit 153fccf
Show file tree
Hide file tree
Showing 33 changed files with 94 additions and 103 deletions.
2 changes: 1 addition & 1 deletion ChildProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ ChildProcess::ChildProcess(std::vector<w_string_piece> args, Options&& options)
throw std::system_error(
errno,
std::generic_category(),
watchman::to<std::string>("failed to chdir to ", options.cwd_));
folly::to<std::string>("failed to chdir to ", options.cwd_));
}
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions ContentHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "FileSystem.h"
#include "Logging.h"

using folly::to;

namespace watchman {

using HashValue = typename ContentHashCache::HashValue;
Expand Down
4 changes: 2 additions & 2 deletions CookieSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ folly::Future<folly::Unit> CookieSync::sync() {
throw std::system_error(
errcode,
std::generic_category(),
to<std::string>(
folly::to<std::string>(
"sync: creat(", path_str, ") failed: ", strerror(errcode)));
}
log(DBG, "sync created cookie file ", path_str, "\n");
Expand All @@ -77,7 +77,7 @@ void CookieSync::syncToNow(std::chrono::milliseconds timeout) {
auto cookie = sync();

if (!cookie.wait(timeout).isReady()) {
auto why = to<std::string>(
auto why = folly::to<std::string>(
"syncToNow: timed out waiting for cookie file to be "
"observed by watcher within ",
timeout.count(),
Expand Down
10 changes: 5 additions & 5 deletions FileDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void checkCanonicalBaseName(const char* path) {
throw std::system_error(
errno,
std::generic_category(),
to<std::string>(
folly::to<std::string>(
"checkCanonicalBaseName(", path, "): getattrlist failed"));
}

Expand All @@ -178,7 +178,7 @@ static void checkCanonicalBaseName(const char* path) {
throw std::system_error(
ENOENT,
std::generic_category(),
to<std::string>(
folly::to<std::string>(
"checkCanonicalBaseName(",
path,
"): (",
Expand All @@ -203,7 +203,7 @@ static void checkCanonicalBaseName(const char* path) {
throw std::system_error(
ENOENT,
std::generic_category(),
to<std::string>(
folly::to<std::string>(
"checkCanonicalBaseName(",
path,
"): no match found in parent dir"));
Expand Down Expand Up @@ -243,7 +243,7 @@ FileDescriptor openFileHandle(
if (fd == -1) {
int err = errno;
throw std::system_error(
err, std::generic_category(), to<std::string>("open: ", path));
err, std::generic_category(), folly::to<std::string>("open: ", path));
}
FileDescriptor file(fd);
#else // _WIN32
Expand Down Expand Up @@ -330,7 +330,7 @@ FileDescriptor openFileHandle(
throw std::system_error(
ENOENT,
std::generic_category(),
to<std::string>(
folly::to<std::string>(
"open(",
path,
"): opened path doesn't match canonical path ",
Expand Down
4 changes: 2 additions & 2 deletions InMemoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ void InMemoryView::startThreads(const std::shared_ptr<w_root_t>& root) {
auto self = std::static_pointer_cast<InMemoryView>(shared_from_this());
w_log(W_LOG_DBG, "starting threads for %p %s\n", this, root_path.c_str());
std::thread notifyThreadInstance([self, root]() {
w_set_thread_name("notify ", self.get(), " ", self->root_path);
w_set_thread_name("notify ", uintptr_t(self.get()), " ", self->root_path);
try {
self->notifyThread(root);
} catch (const std::exception& e) {
Expand All @@ -730,7 +730,7 @@ void InMemoryView::startThreads(const std::shared_ptr<w_root_t>& root) {

// And now start the IO thread
std::thread ioThreadInstance([self, root]() {
w_set_thread_name("io ", self.get(), " ", self->root_path);
w_set_thread_name("io ", uintptr_t(self.get()), " ", self->root_path);
try {
self->ioThread(root);
} catch (const std::exception& e) {
Expand Down
2 changes: 1 addition & 1 deletion Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ void logPrintf(enum LogLevel level, Args&&... args) {

template <typename... Args>
const char* w_set_thread_name(Args&&... args) {
auto name = watchman::to<std::string>(std::forward<Args>(args)...);
auto name = folly::to<std::string>(std::forward<Args>(args)...);
return watchman::Log::setThreadName(std::move(name));
}
16 changes: 8 additions & 8 deletions cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const char* cfg_get_string(const char* name, const char* defval) {

if (val) {
if (!val.isString()) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Expected config value ", name, " to be a string"));
}
return json_string_value(val);
Expand Down Expand Up @@ -224,7 +224,7 @@ json_int_t cfg_get_int(const char* name, json_int_t defval) {

if (val) {
if (!val.isInt()) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Expected config value ", name, " to be an integer"));
}
return val.asInt();
Expand All @@ -238,7 +238,7 @@ bool cfg_get_bool(const char* name, bool defval) {

if (val) {
if (!val.isBool()) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Expected config value ", name, " to be a boolean"));
}
return val.asBool();
Expand All @@ -252,7 +252,7 @@ double cfg_get_double(const char* name, double defval) {

if (val) {
if (!val.isNumber()) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Expected config value ", name, " to be a number"));
}
return json_real_value(val);
Expand Down Expand Up @@ -353,7 +353,7 @@ const char* Configuration::getString(const char* name, const char* defval)

if (val) {
if (!val.isString()) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Expected config value ", name, " to be a string"));
}
return json_string_value(val);
Expand All @@ -367,7 +367,7 @@ json_int_t Configuration::getInt(const char* name, json_int_t defval) const {

if (val) {
if (!val.isInt()) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Expected config value ", name, " to be an integer"));
}
return val.asInt();
Expand All @@ -381,7 +381,7 @@ bool Configuration::getBool(const char* name, bool defval) const {

if (val) {
if (!val.isBool()) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Expected config value ", name, " to be a boolean"));
}
return val.asBool();
Expand All @@ -395,7 +395,7 @@ double Configuration::getDouble(const char* name, double defval) const {

if (val) {
if (!val.isNumber()) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Expected config value ", name, " to be a number"));
}
return json_real_value(val);
Expand Down
12 changes: 6 additions & 6 deletions checksock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ void check_clock_command(watchman_stream* client, json_ref& root) {
root,
json_object({{"sync_timeout", json_integer(20000)}})});
if (!buf.pduEncodeToStream(is_bser, 0, cmd, client)) {
throw std::runtime_error(watchman::to<std::string>(
"Failed to send clock PDU: ", strerror(errno)));
throw std::runtime_error(
folly::to<std::string>("Failed to send clock PDU: ", strerror(errno)));
}

buf.clear();
auto result = decodeNext(client, buf, jerr);
if (!result) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Failed to decode clock response: ", jerr.text, " ", strerror(errno)));
}

// Check for error in the response
auto error = result.get_default("error");
if (error) {
throw std::runtime_error(
watchman::to<std::string>("Clock error : ", json_to_w_string(error)));
folly::to<std::string>("Clock error : ", json_to_w_string(error)));
}

// We use presence of "clock" as success
Expand All @@ -109,14 +109,14 @@ json_ref get_watch_list(watchman_stream* client) {
json_error_t jerr;

if (!buf.pduEncodeToStream(is_bser, 0, cmd, client)) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Failed to send watch-list PDU: ", strerror(errno)));
}

buf.clear();
auto result = decodeNext(client, buf, jerr);
if (!result) {
throw std::runtime_error(watchman::to<std::string>(
throw std::runtime_error(folly::to<std::string>(
"Failed to decode watch-list response: ",
jerr.text,
" error: ",
Expand Down
4 changes: 2 additions & 2 deletions cmds/heapprof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ static void cmd_debug_prof_dump(
resp.set(
"prof.dump",
w_string_to_json(
watchman::to<std::string>(
"mallctl prof.dump returned: ", folly::errnoStr(result).c_str())
folly::to<std::string>(
"mallctl prof.dump returned: ", folly::errnoStr(result))
.c_str()));
send_and_dispose_response(client, std::move(resp));
}
Expand Down
1 change: 1 addition & 0 deletions cmds/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using namespace watchman;
using ms = std::chrono::milliseconds;
using folly::to;
using watchman::ClientStateAssertion;
using watchman::ClientStateDisposition;

Expand Down
4 changes: 2 additions & 2 deletions cmds/subscribe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ static void cmd_subscribe(

// Connect the root to our subscription
{
auto client_id = watchman::to<std::string>(client);
auto client_stream = watchman::to<std::string>(client->stm.get());
auto client_id = folly::to<std::string>(uintptr_t(client));
auto client_stream = folly::to<std::string>(uintptr_t(client->stm.get()));
auto info_json = json_object(
{{"name", w_string_to_json(sub->name)},
{"query", sub->query->query_spec},
Expand Down
8 changes: 4 additions & 4 deletions listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ static void client_thread(std::shared_ptr<watchman_client> client) noexcept {
client->stm->setNonBlock(true);
w_set_thread_name(
"client=",
client.get(),
uintptr_t(client.get()),
":stm=",
client->stm.get(),
uintptr_t(client->stm.get()),
":pid=",
client->stm->getPeerProcessID());

Expand Down Expand Up @@ -295,9 +295,9 @@ static void client_thread(std::shared_ptr<watchman_client> client) noexcept {
disconnected:
w_set_thread_name(
"NOT_CONN:client=",
client.get(),
uintptr_t(client.get()),
":stm=",
client->stm.get(),
uintptr_t(client->stm.get()),
":pid=",
client->stm->getPeerProcessID());
// Remove the client from the map before we tear it down, as this makes
Expand Down
6 changes: 3 additions & 3 deletions log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static void crash_handler(int signo, siginfo_t* si, void*) {
}

if (si) {
auto msg = watchman::to<std::string>(
auto msg = folly::to<std::string>(
"Terminating due to signal ",
signo,
" ",
Expand All @@ -305,11 +305,11 @@ static void crash_handler(int signo, siginfo_t* si, void*) {
" ",
reason,
" (",
si->si_value.sival_ptr,
uintptr_t(si->si_value.sival_ptr),
")\n");
ignore_result(write(STDERR_FILENO, msg.data(), msg.size()));
} else {
auto msg = watchman::to<std::string>(
auto msg = folly::to<std::string>(
"Terminating due to signal ",
signo,
" ",
Expand Down
11 changes: 5 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static bool lock_pidfile(void) {
return false;
}

auto pidString = watchman::to<std::string>(mypid);
auto pidString = folly::to<std::string>(mypid);
ignore_result(write(fd.fd(), pidString.data(), pidString.size()));
fsync(fd.fd());

Expand Down Expand Up @@ -547,7 +547,7 @@ static void spawn_via_launchd(void) {

compute_file_name(pid_file, compute_user_name(), "pid", "pidfile");

auto plist_content = watchman::to<std::string>(
auto plist_content = folly::to<std::string>(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
Expand Down Expand Up @@ -677,8 +677,7 @@ static void compute_file_name(
#endif
;

auto state_dir =
watchman::to<std::string>(state_parent, "/", user, "-state");
auto state_dir = folly::to<std::string>(state_parent, "/", user, "-state");

if (mkdir(state_dir.c_str(), 0700) == 0 || errno == EEXIST) {
#ifndef _WIN32
Expand Down Expand Up @@ -788,7 +787,7 @@ static void compute_file_name(
exit(1);
}

str = watchman::to<std::string>(state_dir, "/", suffix);
str = folly::to<std::string>(state_dir, "/", suffix);
}

#ifndef _WIN32
Expand Down Expand Up @@ -848,7 +847,7 @@ static void setup_sock_name(void) {

#ifdef _WIN32
if (!sock_name) {
sock_name = watchman::to<std::string>("\\\\.\\pipe\\watchman-", user);
sock_name = folly::to<std::string>("\\\\.\\pipe\\watchman-", user);
}
#else
compute_file_name(sock_name, user, "sock", "sockname");
Expand Down
2 changes: 1 addition & 1 deletion opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ bool w_getopt(
}

if (o->is_daemon) {
auto value = watchman::to<std::string>(
auto value = folly::to<std::string>(
"--", o->optname, "=", optarg ? optarg : "");
// we deliberately leak this value to the caller
daemon_argv[num_daemon++] = strdup(value.c_str());
Expand Down
8 changes: 4 additions & 4 deletions query/glob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static bool add_glob(
bool had_specials;

if (glob_str.piece().pathIsAbsolute()) {
throw QueryParseError(watchman::to<std::string>(
throw QueryParseError(folly::to<std::string>(
"glob `",
glob_str,
"` is an absolute path. All globs must be relative paths!"));
Expand Down Expand Up @@ -389,7 +389,7 @@ void InMemoryView::globGeneratorTree(

void InMemoryView::globGenerator(w_query* query, struct w_query_ctx* ctx)
const {
w_string_t* relative_root;
w_string relative_root;

if (query->relative_root) {
relative_root = query->relative_root;
Expand All @@ -401,9 +401,9 @@ void InMemoryView::globGenerator(w_query* query, struct w_query_ctx* ctx)

const auto dir = resolveDir(view, relative_root);
if (!dir) {
throw QueryExecError(watchman::to<std::string>(
throw QueryExecError(folly::to<std::string>(
"glob_generator could not resolve ",
w_string_piece(relative_root),
relative_root,
", check your "
"relative_root parameter!"));
}
Expand Down
2 changes: 1 addition & 1 deletion query/intcompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void parse_int_compare(const json_ref& term, struct w_query_int_compare* comp) {
}

if (!found) {
throw QueryParseError(watchman::to<std::string>(
throw QueryParseError(folly::to<std::string>(
"integer comparator opname `", opname, "' is invalid"));
}

Expand Down
Loading

0 comments on commit 153fccf

Please sign in to comment.