Skip to content

Commit

Permalink
Reformat.
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamc committed Jun 24, 2022
1 parent e4fc6a3 commit 07c3330
Show file tree
Hide file tree
Showing 191 changed files with 1,140 additions and 576 deletions.
45 changes: 30 additions & 15 deletions src/libcmd/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ static constexpr Command::Category catNixInstallation = 102;
static constexpr auto installablesCategory =
"Options that change the interpretation of installables";

struct NixMultiCommand : virtual MultiCommand, virtual Command {
struct NixMultiCommand : virtual MultiCommand, virtual Command
{
nlohmann::json toJSON() override;
};

/* A command that requires a Nix store. */
struct StoreCommand : virtual Command {
struct StoreCommand : virtual Command
{
StoreCommand();
void run() override;
ref<Store> getStore();
Expand All @@ -43,7 +45,8 @@ struct StoreCommand : virtual Command {

/* A command that copies something between `--from` and `--to`
stores. */
struct CopyCommand : virtual StoreCommand {
struct CopyCommand : virtual StoreCommand
{
std::string srcUri, dstUri;

CopyCommand();
Expand All @@ -53,7 +56,8 @@ struct CopyCommand : virtual StoreCommand {
ref<Store> getDstStore();
};

struct EvalCommand : virtual StoreCommand, MixEvalArgs {
struct EvalCommand : virtual StoreCommand, MixEvalArgs
{
bool startReplOnEvalErrors = false;

EvalCommand();
Expand All @@ -70,15 +74,17 @@ struct EvalCommand : virtual StoreCommand, MixEvalArgs {
std::shared_ptr<EvalState> evalState;
};

struct MixFlakeOptions : virtual Args, EvalCommand {
struct MixFlakeOptions : virtual Args, EvalCommand
{
flake::LockFlags lockFlags;

MixFlakeOptions();

virtual std::optional<FlakeRef> getFlakeRefForCompletion() { return {}; }
};

struct SourceExprCommand : virtual Args, MixFlakeOptions {
struct SourceExprCommand : virtual Args, MixFlakeOptions
{
std::optional<Path> file;
std::optional<std::string> expr;
bool readOnlyMode = false;
Expand All @@ -103,7 +109,8 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions {

/* A command that operates on a list of "installables", which can be
store paths, attribute paths, Nix expressions, etc. */
struct InstallablesCommand : virtual Args, SourceExprCommand {
struct InstallablesCommand : virtual Args, SourceExprCommand
{
std::vector<std::shared_ptr<Installable>> installables;

InstallablesCommand();
Expand All @@ -119,7 +126,8 @@ struct InstallablesCommand : virtual Args, SourceExprCommand {
};

/* A command that operates on exactly one "installable" */
struct InstallableCommand : virtual Args, SourceExprCommand {
struct InstallableCommand : virtual Args, SourceExprCommand
{
std::shared_ptr<Installable> installable;

InstallableCommand(bool supportReadOnlyMode = false);
Expand All @@ -136,7 +144,8 @@ struct InstallableCommand : virtual Args, SourceExprCommand {
};

/* A command that operates on zero or more store paths. */
struct BuiltPathsCommand : public InstallablesCommand {
struct BuiltPathsCommand : public InstallablesCommand
{
private:
bool recursive = false;
bool all = false;
Expand All @@ -156,7 +165,8 @@ struct BuiltPathsCommand : public InstallablesCommand {
bool useDefaultInstallables() override { return !all; }
};

struct StorePathsCommand : public BuiltPathsCommand {
struct StorePathsCommand : public BuiltPathsCommand
{
StorePathsCommand(bool recursive = false);

using BuiltPathsCommand::run;
Expand All @@ -167,7 +177,8 @@ struct StorePathsCommand : public BuiltPathsCommand {
};

/* A command that operates on exactly one store path. */
struct StorePathCommand : public StorePathsCommand {
struct StorePathCommand : public StorePathsCommand
{
using StorePathsCommand::run;

virtual void run(ref<Store> store, const StorePath &storePath) = 0;
Expand All @@ -176,7 +187,8 @@ struct StorePathCommand : public StorePathsCommand {
};

/* A helper class for registering commands globally. */
struct RegisterCommand {
struct RegisterCommand
{
typedef std::map<std::vector<std::string>, std::function<ref<Command>()>>
Commands;
static Commands *commands;
Expand Down Expand Up @@ -208,7 +220,8 @@ static RegisterCommand registerCommand2(std::vector<std::string> &&name)
filename:lineno. */
Strings editorFor(const Path &file, uint32_t line);

struct MixProfile : virtual StoreCommand {
struct MixProfile : virtual StoreCommand
{
std::optional<Path> profile;

MixProfile();
Expand All @@ -221,11 +234,13 @@ struct MixProfile : virtual StoreCommand {
void updateProfile(const BuiltPaths &buildables);
};

struct MixDefaultProfile : MixProfile {
struct MixDefaultProfile : MixProfile
{
MixDefaultProfile();
};

struct MixEnvironment : virtual Args {
struct MixEnvironment : virtual Args
{

StringSet keep, unset;
Strings stringsEnv;
Expand Down
3 changes: 2 additions & 1 deletion src/libcmd/common-eval-args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Store;
class EvalState;
class Bindings;

struct MixEvalArgs : virtual Args {
struct MixEvalArgs : virtual Args
{
MixEvalArgs();

Bindings *getAutoArgs(EvalState &state);
Expand Down
6 changes: 4 additions & 2 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ static StorePath getDeriver(ref<Store> store, const Installable &i,
return *derivers.begin();
}

struct InstallableStorePath : Installable {
struct InstallableStorePath : Installable
{
ref<Store> store;
StorePath storePath;

Expand Down Expand Up @@ -446,7 +447,8 @@ StorePathSet InstallableValue::toDrvPaths(ref<Store> store)
return res;
}

struct InstallableAttrPath : InstallableValue {
struct InstallableAttrPath : InstallableValue
{
SourceExprCommand &cmd;
RootValue v;
std::string attrPath;
Expand Down
18 changes: 12 additions & 6 deletions src/libcmd/installables.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class EvalCache;
class AttrCursor;
} // namespace eval_cache

struct App {
struct App
{
std::vector<StorePathWithOutputs> context;
Path program;
// FIXME: add args, sandbox settings, metadata, ...
};

struct UnresolvedApp {
struct UnresolvedApp
{
App unresolved;
App resolve(ref<Store> evalStore, ref<Store> store);
};
Expand All @@ -52,7 +54,8 @@ enum class OperateOn {
Derivation
};

struct Installable {
struct Installable
{
virtual ~Installable() {}

virtual std::string what() const = 0;
Expand Down Expand Up @@ -117,12 +120,14 @@ struct Installable {
const std::vector<std::shared_ptr<Installable>> &installables);
};

struct InstallableValue : Installable {
struct InstallableValue : Installable
{
ref<EvalState> state;

InstallableValue(ref<EvalState> state) : state(state) {}

struct DerivationInfo {
struct DerivationInfo
{
StorePath drvPath;
std::set<std::string> outputsToInstall;
std::optional<NixInt> priority;
Expand All @@ -135,7 +140,8 @@ struct InstallableValue : Installable {
StorePathSet toDrvPaths(ref<Store> store) override;
};

struct InstallableFlake : InstallableValue {
struct InstallableFlake : InstallableValue
{
FlakeRef flakeRef;
Strings attrPaths;
Strings prefixes;
Expand Down
3 changes: 2 additions & 1 deletion src/libcmd/legacy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace nix {

typedef std::function<void(int, char **)> MainFunction;

struct RegisterLegacyCommand {
struct RegisterLegacyCommand
{
typedef std::map<std::string, MainFunction> Commands;
static Commands *commands;

Expand Down
3 changes: 2 additions & 1 deletion src/libcmd/markdown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ std::string renderMarkdownToTerminal(std::string_view markdown)
{
int windowWidth = getWindowSize().second;

struct lowdown_opts opts {
struct lowdown_opts opts
{
.type = LOWDOWN_TERM, .maxdepth = 20,
.cols = (size_t)std::max(windowWidth - 5, 60), .hmargin = 0,
.vmargin = 0,
Expand Down
3 changes: 2 additions & 1 deletion src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,8 @@ void runRepl(ref<EvalState> evalState, const ValMap &extraEnv)
repl->mainLoop({});
}

struct CmdRepl : StoreCommand, MixEvalArgs {
struct CmdRepl : StoreCommand, MixEvalArgs
{
std::vector<std::string> files;

CmdRepl()
Expand Down
9 changes: 6 additions & 3 deletions src/libexpr/attr-set.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class EvalState;
struct Value;

/* Map one attribute name to its value. */
struct Attr {
struct Attr
{
/* the placement of `name` and `pos` in this struct is important.
both of them are uint32 wrappers, they are next to each other
to make sure that Attr has no padding on 64 bit machines. that
Expand All @@ -36,7 +37,8 @@ static_assert(
by its size and its capacity, the capacity being the number of Attr
elements allocated after this structure, while the size corresponds to
the number of elements already inserted in this structure. */
class Bindings {
class Bindings
{
public:
typedef uint32_t size_t;
PosIdx pos;
Expand Down Expand Up @@ -109,7 +111,8 @@ class Bindings {
/* A wrapper around Bindings that ensures that its always in sorted
order at the end. The only way to consume a BindingsBuilder is to
call finish(), which sorts the bindings. */
class BindingsBuilder {
class BindingsBuilder
{
Bindings *bindings;

public:
Expand Down
6 changes: 4 additions & 2 deletions src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ create table if not exists Attributes (
);
)sql";

struct AttrDb {
struct AttrDb
{
std::atomic_bool failed{false};

const Store &cfg;

struct State {
struct State
{
SQLite db;
SQLiteStmt insertAttribute;
SQLiteStmt insertAttributeWithContext;
Expand Down
21 changes: 14 additions & 7 deletions src/libexpr/eval-cache.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ MakeError(CachedEvalError, EvalError);
struct AttrDb;
class AttrCursor;

class EvalCache : public std::enable_shared_from_this<EvalCache> {
class EvalCache : public std::enable_shared_from_this<EvalCache>
{
friend class AttrCursor;

std::shared_ptr<AttrDb> db;
Expand Down Expand Up @@ -44,15 +45,20 @@ enum AttrType {
Int = 8,
};

struct placeholder_t {
struct placeholder_t
{
};
struct missing_t {
struct missing_t
{
};
struct misc_t {
struct misc_t
{
};
struct failed_t {
struct failed_t
{
};
struct int_t {
struct int_t
{
NixInt x;
};
typedef uint64_t AttrId;
Expand All @@ -63,7 +69,8 @@ typedef std::variant<std::vector<Symbol>, string_t, placeholder_t, missing_t,
misc_t, failed_t, bool, int_t, std::vector<std::string>>
AttrValue;

class AttrCursor : public std::enable_shared_from_this<AttrCursor> {
class AttrCursor : public std::enable_shared_from_this<AttrCursor>
{
friend class EvalCache;

ref<EvalCache> root;
Expand Down
3 changes: 2 additions & 1 deletion src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ static void *oomHandler(size_t requested)
throw std::bad_alloc();
}

class BoehmGCStackAllocator : public StackAllocator {
class BoehmGCStackAllocator : public StackAllocator
{
boost::coroutines2::protected_fixedsize_stack stack{
// We allocate 8 MB, the default max stack size on NixOS.
// A smaller stack might be quicker to allocate but reduces the stack
Expand Down
Loading

0 comments on commit 07c3330

Please sign in to comment.