diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-02-25 09:21:04 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-02-25 09:21:04 +0100 |
commit | 9d4697453fc760597befa2e3eb887d2d6d375492 (patch) | |
tree | d37565fc9c50cec7b0d2951a5601cfc0222b2524 | |
parent | 59683733f5e1e5acecf26bff2a7255126e04eb76 (diff) |
ExprAttrs::show(): Show attrs in sorted order
Issue #6160.
-rw-r--r-- | src/libexpr/nixexpr.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 2d2cd96cd..27ea0f2ad 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -103,11 +103,18 @@ void ExprAttrs::show(std::ostream & str) const { if (recursive) str << "rec "; str << "{ "; - for (auto & i : attrs) - if (i.second.inherited) - str << "inherit " << i.first << " " << "; "; + typedef const decltype(attrs)::value_type * Attr; + std::vector<Attr> sorted; + for (auto & i : attrs) sorted.push_back(&i); + std::sort(sorted.begin(), sorted.end(), [](Attr a, Attr b) { + return (const std::string &) a->first < (const std::string &) b->first; + }); + for (auto & i : sorted) { + if (i->second.inherited) + str << "inherit " << i->first << " " << "; "; else - str << i.first << " = " << *i.second.e << "; "; + str << i->first << " = " << *i->second.e << "; "; + } for (auto & i : dynamicAttrs) str << "\"${" << *i.nameExpr << "}\" = " << *i.valueExpr << "; "; str << "}"; |