This is an automated email from the ASF dual-hosted git repository.

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new 97bde421d refactor: use fmt:join to simplify code (#1680)
97bde421d is described below

commit 97bde421d7717001f6dfc67debfb9dfde1186274
Author: Yingchun Lai <[email protected]>
AuthorDate: Mon Nov 13 15:07:27 2023 +0800

    refactor: use fmt:join to simplify code (#1680)
    
    This is a patch to simplify code, also to check whether the previous 
patch(5e9a2a9dcaa8be988e1ea8e745bd7fc8621e2609) works.
    
    Note: In `{{{}}}`, `{{` and `}}` are used to escape, the left `{}` is used 
for `replacement fields`,
    see https://fmt.dev/latest/syntax.html.
---
 src/client/replication_ddl_client.cpp | 27 +++------------------------
 1 file changed, 3 insertions(+), 24 deletions(-)

diff --git a/src/client/replication_ddl_client.cpp 
b/src/client/replication_ddl_client.cpp
index a8a6cf7db..023464251 100644
--- a/src/client/replication_ddl_client.cpp
+++ b/src/client/replication_ddl_client.cpp
@@ -34,7 +34,6 @@
 #include <fstream>
 #include <iomanip>
 #include <iostream>
-#include <set>
 
 #include "backup_types.h"
 #include "common//duplication_common.h"
@@ -46,6 +45,7 @@
 #include "common/replication_common.h"
 #include "common/replication_enums.h"
 #include "fmt/core.h"
+#include "fmt/format.h"
 #include "meta/meta_rpc_types.h"
 #include "runtime/api_layer1.h"
 #include "runtime/rpc/group_address.h"
@@ -1138,34 +1138,13 @@ dsn::error_code 
replication_ddl_client::enable_backup_policy(const std::string &
     }
 }
 
-// help functions
-
-// TODO (yingchun) use join
-template <typename T>
-// make sure T support cout << T;
-std::string print_set(const std::set<T> &set)
-{
-    std::stringstream ss;
-    ss << "{";
-    auto begin = set.begin();
-    auto end = set.end();
-    for (auto it = begin; it != end; it++) {
-        if (it != begin) {
-            ss << ", ";
-        }
-        ss << *it;
-    }
-    ss << "}";
-    return ss.str();
-}
-
 static void print_policy_entry(const policy_entry &entry)
 {
     dsn::utils::table_printer tp;
     tp.add_row_name_and_data("    name", entry.policy_name);
     tp.add_row_name_and_data("    backup_provider_type", 
entry.backup_provider_type);
     tp.add_row_name_and_data("    backup_interval", 
entry.backup_interval_seconds + "s");
-    tp.add_row_name_and_data("    app_ids", print_set(entry.app_ids));
+    tp.add_row_name_and_data("    app_ids", fmt::format("{{{}}}", 
fmt::join(entry.app_ids, ", ")));
     tp.add_row_name_and_data("    start_time", entry.start_time);
     tp.add_row_name_and_data("    status", entry.is_disable ? "disabled" : 
"enabled");
     tp.add_row_name_and_data("    backup_history_count", 
entry.backup_history_count_to_keep);
@@ -1188,7 +1167,7 @@ static void print_backup_entry(const backup_entry &bentry)
     tp.add_row_name_and_data("    id", bentry.backup_id);
     tp.add_row_name_and_data("    start_time", start_time);
     tp.add_row_name_and_data("    end_time", end_time);
-    tp.add_row_name_and_data("    app_ids", print_set(bentry.app_ids));
+    tp.add_row_name_and_data("    app_ids", fmt::format("{{{}}}", 
fmt::join(bentry.app_ids, ", ")));
     tp.output(std::cout);
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to