From fbb042e3bbfe0796b0986fa0ffa9cde75c6e3bce Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 28 Nov 2007 15:12:59 -0800 Subject: [PATCH] Ensure the "name:" key shows up first in metadata output. This isn't necessary, but is nice for readability. --- metadata.cc | 23 +++++++++++++++++++++++ util.cc | 19 ------------------- util.h | 3 --- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/metadata.cc b/metadata.cc index 86d02aa..dac3d20 100644 --- a/metadata.cc +++ b/metadata.cc @@ -9,6 +9,7 @@ #include #include +#include #include "metadata.h" #include "ref.h" @@ -16,6 +17,7 @@ #include "util.h" using std::list; +using std::map; using std::string; using std::ostream; using std::ostringstream; @@ -63,6 +65,27 @@ static int pathcmp(const char *path1, const char *path2) return pathcmp(slash1 + 1, slash2 + 1); } +/* Encode a dictionary of string key/value pairs into a sequence of lines of + * the form "key: value". If it exists, the key "name" is treated specially + * and will be listed first. */ +static string encode_dict(const map& dict) +{ + string result; + + if (dict.find("name") != dict.end()) { + result += "name: " + dict.at("name") + "\n"; + } + + for (map::const_iterator i = dict.begin(); + i != dict.end(); ++i) { + if (i->first == "name") + continue; + result += i->first + ": " + i->second + "\n"; + } + + return result; +} + MetadataWriter::MetadataWriter(TarSegmentStore *store, const char *path, const char *snapshot_name, diff --git a/util.cc b/util.cc index 1f922df..38f1f1d 100644 --- a/util.cc +++ b/util.cc @@ -98,22 +98,3 @@ long long parse_int(const string &s) { return strtoll(s.c_str(), NULL, 0); } - -/* Encode a dictionary of string key/value pairs into a sequence of lines of - * the form "key: value". */ -string encode_dict(const map& dict) -{ - string result; - for (map::const_iterator i = dict.begin(); - i != dict.end(); ++i) { - result += i->first + ": " + i->second + "\n"; - } - return result; -} - -/* Output a dictionary of string key/value pairs to the given output stream. - * The format is a sequence of lines of the form "key: value". */ -void dict_output(ostream &o, const map& dict) -{ - o << encode_dict(dict); -} diff --git a/util.h b/util.h index bb36333..735ea60 100644 --- a/util.h +++ b/util.h @@ -15,9 +15,6 @@ std::string uri_encode(const std::string &in); std::string uri_decode(const std::string &in); std::string encode_int(long long n, int base=10); -std::string encode_dict(const std::map& dict); -void dict_output(std::ostream &o, - const std::map& dict); long long parse_int(const std::string &s); -- 2.20.1