Skip to content

Commit

Permalink
Upgrade ClangFormat to v19.1.0 (#180)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Sep 23, 2024
1 parent 8e77853 commit 4047dcf
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
CXX: ${{ matrix.platform.cxx }}
steps:
- name: Install ClangFormat
run: pip install clang-format==18.1.0
run: pip install clang-format==19.1.0

- name: Install dependencies (GNU/Linux)
if: runner.os == 'linux'
Expand Down
7 changes: 4 additions & 3 deletions src/bucket/bucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ auto Bucket::upsert_json(const std::string &key,
return promise.get_future();
}

auto Bucket::fetch_or_upsert(const std::string &key,
std::function<sourcemeta::jsontoolkit::JSON()>
callback) -> std::future<ResponseJSON> {
auto Bucket::fetch_or_upsert(
const std::string &key,
std::function<sourcemeta::jsontoolkit::JSON()> callback)
-> std::future<ResponseJSON> {
std::promise<ResponseJSON> promise;
auto maybe_response{this->fetch_json(key).get()};
if (maybe_response.has_value()) {
Expand Down
26 changes: 14 additions & 12 deletions src/bucket/include/sourcemeta/hydra/bucket_aws_sigv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ aws_sigv4(const http::Method method, const sourcemeta::jsontoolkit::URI &url,
const std::chrono::system_clock::time_point now)
-> std::map<std::string, std::string>;

auto SOURCEMETA_HYDRA_BUCKET_EXPORT
aws_sigv4_scope(std::string_view datastamp, std::string_view region,
std::ostream &output) -> void;
auto SOURCEMETA_HYDRA_BUCKET_EXPORT aws_sigv4_scope(std::string_view datastamp,
std::string_view region,
std::ostream &output)
-> void;

auto SOURCEMETA_HYDRA_BUCKET_EXPORT
aws_sigv4_key(std::string_view secret_key, std::string_view region,
std::string_view datastamp) -> std::string;
auto SOURCEMETA_HYDRA_BUCKET_EXPORT aws_sigv4_key(std::string_view secret_key,
std::string_view region,
std::string_view datastamp)
-> std::string;

auto SOURCEMETA_HYDRA_BUCKET_EXPORT
aws_sigv4_canonical(const http::Method method, std::string_view host,
Expand All @@ -47,13 +49,13 @@ aws_sigv4_canonical(const http::Method method, std::string_view host,
// MM: Two-digit month (01-12)
// DD: Two-digit day (01-31)
// Example: 20230913 (September 13, 2023)
auto SOURCEMETA_HYDRA_BUCKET_EXPORT
aws_sigv4_datastamp(const std::chrono::system_clock::time_point time,
std::ostream &output) -> void;
auto SOURCEMETA_HYDRA_BUCKET_EXPORT aws_sigv4_datastamp(
const std::chrono::system_clock::time_point time, std::ostream &output)
-> void;

auto SOURCEMETA_HYDRA_BUCKET_EXPORT
aws_sigv4_iso8601(const std::chrono::system_clock::time_point time,
std::ostream &output) -> void;
auto SOURCEMETA_HYDRA_BUCKET_EXPORT aws_sigv4_iso8601(
const std::chrono::system_clock::time_point time, std::ostream &output)
-> void;

} // namespace sourcemeta::hydra

Expand Down
5 changes: 3 additions & 2 deletions src/http/include/sourcemeta/hydra/http_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ enum class Method {
/// output << sourcemeta::hydra::http::Method::GET;
/// assert(output.str() == "GET");
/// ```
auto SOURCEMETA_HYDRA_HTTP_EXPORT
operator<<(std::ostream &stream, const Method method) -> std::ostream &;
auto SOURCEMETA_HYDRA_HTTP_EXPORT operator<<(std::ostream &stream,
const Method method)
-> std::ostream &;

/// @ingroup http
/// Construct a HTTP method from a string. Note that casing is not supported.
Expand Down
5 changes: 3 additions & 2 deletions src/http/include/sourcemeta/hydra/http_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ enum class Status : std::uint16_t {
};

/// @ingroup http
auto SOURCEMETA_HYDRA_HTTP_EXPORT
operator<<(std::ostream &stream, const Status value) -> std::ostream &;
auto SOURCEMETA_HYDRA_HTTP_EXPORT operator<<(std::ostream &stream,
const Status value)
-> std::ostream &;

} // namespace sourcemeta::hydra::http

Expand Down
4 changes: 2 additions & 2 deletions src/httpclient/request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ auto ClientRequest::capture(std::initializer_list<std::string> headers)

auto ClientRequest::capture() -> void { this->capture_all_ = true; }

auto ClientRequest::header(std::string_view key,
std::string_view value) -> void {
auto ClientRequest::header(std::string_view key, std::string_view value)
-> void {
this->stream.header(key, value);
}

Expand Down
28 changes: 14 additions & 14 deletions src/httpclient/stream_curl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ inline auto handle_curl(CURLcode code) -> void {
}
}

auto callback_on_response_body(const void *const data, const std::size_t size,
const std::size_t count,
const sourcemeta::hydra::http::ClientStream
*const request) noexcept -> std::size_t {
auto callback_on_response_body(
const void *const data, const std::size_t size, const std::size_t count,
const sourcemeta::hydra::http::ClientStream *const request) noexcept
-> std::size_t {
const std::size_t total_size{size * count};
if (request->internal->on_data) {
try {
Expand All @@ -61,10 +61,10 @@ auto callback_on_response_body(const void *const data, const std::size_t size,
return total_size;
}

auto callback_on_header(const void *const data, const std::size_t size,
const std::size_t count,
sourcemeta::hydra::http::ClientStream
*const request) noexcept -> std::size_t {
auto callback_on_header(
const void *const data, const std::size_t size, const std::size_t count,
sourcemeta::hydra::http::ClientStream *const request) noexcept
-> std::size_t {
const std::size_t total_size{size * count};
const std::string_view line{static_cast<const char *>(data), total_size};
const std::size_t colon{line.find(':')};
Expand Down Expand Up @@ -130,10 +130,10 @@ auto callback_on_header(const void *const data, const std::size_t size,
return total_size;
}

auto callback_on_request_body(char *buffer, const std::size_t size,
const std::size_t count,
sourcemeta::hydra::http::ClientStream
*const request) noexcept -> std::size_t {
auto callback_on_request_body(
char *buffer, const std::size_t size, const std::size_t count,
sourcemeta::hydra::http::ClientStream *const request) noexcept
-> std::size_t {
assert(buffer);
assert(request->internal->on_body);
const std::size_t total_size{size * count};
Expand Down Expand Up @@ -242,8 +242,8 @@ auto ClientStream::on_body(BodyCallback callback) noexcept -> void {
this->internal->on_body = std::move(callback);
}

auto ClientStream::header(std::string_view key,
std::string_view value) -> void {
auto ClientStream::header(std::string_view key, std::string_view value)
-> void {
std::stringstream stream;
stream << key << ": " << value;
const std::string result{stream.str()};
Expand Down
8 changes: 4 additions & 4 deletions src/httpserver/httpserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ static auto wrap_route(
logger << line.str();
}

static auto
default_handler(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto default_handler(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
response.status(sourcemeta::hydra::http::Status::NOT_IMPLEMENTED);
response.end();
}
Expand Down
4 changes: 2 additions & 2 deletions src/httpserver/include/sourcemeta/hydra/httpserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class SOURCEMETA_HYDRA_HTTPSERVER_EXPORT Server {
///
/// server.run(3000);
/// ```
auto route(const Method method, std::string &&path,
RouteCallback &&callback) -> void;
auto route(const Method method, std::string &&path, RouteCallback &&callback)
-> void;

/// Set a handler that responds to HTTP requests that do not match any other
/// registered routes. For example:
Expand Down
4 changes: 2 additions & 2 deletions src/httpserver/response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ auto ServerResponse::status(const Status status_code) -> void {

auto ServerResponse::status() const -> Status { return this->code; }

auto ServerResponse::header(std::string_view key,
std::string_view value) -> void {
auto ServerResponse::header(std::string_view key, std::string_view value)
-> void {
this->headers.emplace(key, value);
}

Expand Down
4 changes: 2 additions & 2 deletions src/httpserver/static.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
namespace sourcemeta::hydra::http {

auto serve_file(const std::filesystem::path &file_path,
const ServerRequest &request,
ServerResponse &response) -> void {
const ServerRequest &request, ServerResponse &response)
-> void {
assert(request.method() == sourcemeta::hydra::http::Method::GET ||
request.method() == sourcemeta::hydra::http::Method::HEAD);

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/httpclient/request_1_1_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include "environment.h"

static auto
body(sourcemeta::hydra::http::ClientResponse &response) -> std::string {
static auto body(sourcemeta::hydra::http::ClientResponse &response)
-> std::string {
std::ostringstream result;
std::copy(
std::istreambuf_iterator<std::ostringstream::char_type>(response.body()),
Expand Down
82 changes: 41 additions & 41 deletions test/e2e/httpserver/stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ static auto on_throw(const sourcemeta::hydra::http::ServerLogger &,
throw std::runtime_error("Crash!");
}

static auto
on_x_foo(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_x_foo(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
response.status(sourcemeta::hydra::http::Status::OK);
if (request.header("x-foo").has_value()) {
response.header("x-foo", request.header("x-foo").value());
Expand All @@ -54,10 +54,10 @@ on_x_foo(const sourcemeta::hydra::http::ServerLogger &,
response.end();
}

static auto
on_query_foo(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_query_foo(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
response.status(sourcemeta::hydra::http::Status::OK);
if (request.query("foo").has_value()) {
response.header("x-foo", request.query("foo").value());
Expand All @@ -66,19 +66,19 @@ on_query_foo(const sourcemeta::hydra::http::ServerLogger &,
response.end();
}

static auto
on_otherwise(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_otherwise(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
response.status(sourcemeta::hydra::http::Status::NOT_IMPLEMENTED);
assert(response.status() == sourcemeta::hydra::http::Status::NOT_IMPLEMENTED);
response.end();
}

static auto
on_parameters(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_parameters(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
response.status(sourcemeta::hydra::http::Status::OK);
std::ostringstream result;
result << request.parameter(0);
Expand All @@ -89,10 +89,10 @@ on_parameters(const sourcemeta::hydra::http::ServerLogger &,
response.end(result.str());
}

static auto
on_encodings(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_encodings(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
sourcemeta::jsontoolkit::JSON document{
sourcemeta::jsontoolkit::JSON::make_array()};
const auto accept_encoding{request.header_list("accept-encoding")};
Expand All @@ -107,19 +107,19 @@ on_encodings(const sourcemeta::hydra::http::ServerLogger &,
response.end(document);
}

static auto
on_force_gzip(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_force_gzip(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
response.status(sourcemeta::hydra::http::Status::OK);
response.encoding(sourcemeta::hydra::http::ServerContentEncoding::GZIP);
response.end("I am compressed");
}

static auto
on_cache_me(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_cache_me(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
const auto timestamp{
sourcemeta::hydra::http::from_gmt("Wed, 21 Oct 2015 11:28:00 GMT")};
const auto checksum{"711d2f4adab4515e4036c48bf58eb975"};
Expand Down Expand Up @@ -153,10 +153,10 @@ on_etag_quoted(const sourcemeta::hydra::http::ServerLogger &,
response.end("Cache me!");
}

static auto
on_schema(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_schema(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
// Purposely not very well formatted
const auto schema = sourcemeta::jsontoolkit::parse(R"JSON({
"type": "string", "$schema": "https://json-schema.org/draft/2019-09/schema"
Expand Down Expand Up @@ -184,10 +184,10 @@ static auto on_text(const sourcemeta::hydra::http::ServerLogger &,
}
}

static auto
on_static(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response) -> void {
static auto on_static(const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &request,
sourcemeta::hydra::http::ServerResponse &response)
-> void {
const std::filesystem::path file_path{STATIC_PATH + request.path().substr(7)};
if (!std::filesystem::exists(file_path)) {
response.status(sourcemeta::hydra::http::Status::NOT_FOUND);
Expand All @@ -198,11 +198,11 @@ on_static(const sourcemeta::hydra::http::ServerLogger &,
sourcemeta::hydra::http::serve_file(file_path, request, response);
}

static auto
on_error(std::exception_ptr error,
const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response) noexcept -> void {
static auto on_error(std::exception_ptr error,
const sourcemeta::hydra::http::ServerLogger &,
const sourcemeta::hydra::http::ServerRequest &,
sourcemeta::hydra::http::ServerResponse &response) noexcept
-> void {
response.status(sourcemeta::hydra::http::Status::BAD_REQUEST);
try {
std::rethrow_exception(error);
Expand Down

0 comments on commit 4047dcf

Please sign in to comment.