Skip to content

Commit 8936979

Browse files
author
marc
committed
use fmt as short name for google::protobuf for formatting functions
1 parent 59a0893 commit 8936979

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

c-deps/libroach/ccl/key_manager.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "key_manager.h"
1010
#include <cryptopp/modes.h>
1111
#include <google/protobuf/stubs/stringprintf.h>
12-
13-
using google::protobuf::StringPrintf;
12+
#include "../fmt.h"
1413

1514
static std::string kFilenamePlain = "plain";
1615

@@ -34,7 +33,7 @@ static rocksdb::Status KeyFromFile(rocksdb::Env* env, const std::string& path, E
3433
// Check that the length is valid for AES.
3534
auto key_length = contents.size();
3635
if (key_length != 16 && key_length != 24 && key_length != 32) {
37-
return rocksdb::Status::InvalidArgument(StringPrintf(
36+
return rocksdb::Status::InvalidArgument(fmt::StringPrintf(
3837
"key in file %s is %llu bytes long, AES keys can be 16, 24, or 32 bytes", path.c_str(), key_length));
3938
}
4039

c-deps/libroach/db.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "encoding.h"
3232
#include "env_switching.h"
3333
#include "eventlistener.h"
34+
#include "fmt.h"
3435
#include "keys.h"
3536
#include "protos/roachpb/data.pb.h"
3637
#include "protos/roachpb/internal.pb.h"
@@ -372,11 +373,11 @@ DBStatus ToDBStatus(const rocksdb::Status& status) {
372373
return ToDBString(status.ToString());
373374
}
374375

375-
DBStatus FmtStatus(const char* fmt, ...) {
376+
DBStatus FmtStatus(const char* fmt_str, ...) {
376377
va_list ap;
377-
va_start(ap, fmt);
378+
va_start(ap, fmt_str);
378379
std::string str;
379-
google::protobuf::StringAppendV(&str, fmt, ap);
380+
fmt::StringAppendV(&str, fmt_str, ap);
380381
va_end(ap);
381382
return ToDBString(str);
382383
}
@@ -1342,17 +1343,17 @@ DBString DBEngine::GetUserProperties() {
13421343
auto ts_min = userprops.find("crdb.ts.min");
13431344
if (ts_min != userprops.end() && !ts_min->second.empty()) {
13441345
if (!DecodeHLCTimestamp(rocksdb::Slice(ts_min->second), sst->mutable_ts_min())) {
1345-
google::protobuf::SStringPrintf(all.mutable_error(), "unable to decode crdb.ts.min value '%s' in table %s",
1346-
rocksdb::Slice(ts_min->second).ToString(true).c_str(), sst->path().c_str());
1346+
fmt::SStringPrintf(all.mutable_error(), "unable to decode crdb.ts.min value '%s' in table %s",
1347+
rocksdb::Slice(ts_min->second).ToString(true).c_str(), sst->path().c_str());
13471348
break;
13481349
}
13491350
}
13501351

13511352
auto ts_max = userprops.find("crdb.ts.max");
13521353
if (ts_max != userprops.end() && !ts_max->second.empty()) {
13531354
if (!DecodeHLCTimestamp(rocksdb::Slice(ts_max->second), sst->mutable_ts_max())) {
1354-
google::protobuf::SStringPrintf(all.mutable_error(), "unable to decode crdb.ts.max value '%s' in table %s",
1355-
rocksdb::Slice(ts_max->second).ToString(true).c_str(), sst->path().c_str());
1355+
fmt::SStringPrintf(all.mutable_error(), "unable to decode crdb.ts.max value '%s' in table %s",
1356+
rocksdb::Slice(ts_max->second).ToString(true).c_str(), sst->path().c_str());
13561357
break;
13571358
}
13581359
}
@@ -1744,7 +1745,7 @@ DBStatus DBCompact(DBEngine* db) {
17441745
return ToDBStatus(db->rep->CompactRange(options, NULL, NULL));
17451746
}
17461747

1747-
DBStatus DBApproximateDiskBytes(DBEngine* db, DBKey start, DBKey end, uint64_t *size) {
1748+
DBStatus DBApproximateDiskBytes(DBEngine* db, DBKey start, DBKey end, uint64_t* size) {
17481749
const std::string start_key(EncodeKey(start));
17491750
const std::string end_key(EncodeKey(end));
17501751
const rocksdb::Range r(start_key, end_key);

c-deps/libroach/fmt.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 The Cockroach Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12+
// implied. See the License for the specific language governing
13+
// permissions and limitations under the License.
14+
15+
#pragma once
16+
17+
#include <google/protobuf/stubs/stringprintf.h>
18+
19+
namespace fmt = google::protobuf;

c-deps/libroach/testutils.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
#include <gtest/gtest.h>
1717
#include <rocksdb/status.h>
1818
#include <string>
19-
20-
using google::protobuf::StringPrintf;
19+
#include "fmt.h"
2120

2221
namespace testutils {
2322

@@ -27,18 +26,18 @@ rocksdb::Status compareErrorMessage(rocksdb::Status status, const char* err_msg)
2726
if (status.ok()) {
2827
return rocksdb::Status::OK();
2928
}
30-
return rocksdb::Status::InvalidArgument(StringPrintf("expected success, got error \"%s\"", status.getState()));
29+
return rocksdb::Status::InvalidArgument(fmt::StringPrintf("expected success, got error \"%s\"", status.getState()));
3130
}
3231

3332
// Expected failure.
3433
if (status.ok()) {
35-
return rocksdb::Status::InvalidArgument(StringPrintf("expected error \"%s\", got success", err_msg));
34+
return rocksdb::Status::InvalidArgument(fmt::StringPrintf("expected error \"%s\", got success", err_msg));
3635
}
3736
if (strcmp(err_msg, status.getState()) == 0) {
3837
return rocksdb::Status::OK();
3938
}
4039
return rocksdb::Status::InvalidArgument(
41-
StringPrintf("expected error \"%s\", got \"%s\"", err_msg, status.getState()));
40+
fmt::StringPrintf("expected error \"%s\", got \"%s\"", err_msg, status.getState()));
4241
}
4342

4443
rocksdb::Status compareErrorMessage(rocksdb::Status status, std::string err_msg) {

0 commit comments

Comments
 (0)