about summary refs log tree commit diff
path: root/third_party/nix/src/libmain
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-19T17·55+0100
committerVincent Ambo <tazjin@google.com>2020-05-19T17·55+0100
commit867055133d3f487e52dd44149f76347c2c28bf10 (patch)
treec367803ad94f024b0052727a2c7a037af169169a /third_party/nix/src/libmain
parentc6a31838cd7e88ebcb01422b329a499d04ab4b6b (diff)
style(3p/nix): Add braces around single-line conditionals r/771
These were not caught by the previous clang-tidy invocation, but were
instead sorted out using amber[0] as such:

    ambr --regex 'if (\(.+\))\s([a-z].*;)' 'if $1 { $2 }'

[0]: https://github.com/dalance/amber
Diffstat (limited to 'third_party/nix/src/libmain')
-rw-r--r--third_party/nix/src/libmain/common-args.cc4
-rw-r--r--third_party/nix/src/libmain/shared.cc40
-rw-r--r--third_party/nix/src/libmain/shared.hh4
-rw-r--r--third_party/nix/src/libmain/stack.cc16
4 files changed, 48 insertions, 16 deletions
diff --git a/third_party/nix/src/libmain/common-args.cc b/third_party/nix/src/libmain/common-args.cc
index 9863eda63bf1..9d6f6445c0e7 100644
--- a/third_party/nix/src/libmain/common-args.cc
+++ b/third_party/nix/src/libmain/common-args.cc
@@ -32,7 +32,9 @@ MixCommonArgs::MixCommonArgs(const string& programName)
   globalConfig.convertToArgs(*this, cat);
 
   // Backward compatibility hack: nix-env already had a --system flag.
-  if (programName == "nix-env") longFlags.erase("system");
+  if (programName == "nix-env") {
+    longFlags.erase("system");
+  }
 
   hiddenCategories.insert(cat);
 }
diff --git a/third_party/nix/src/libmain/shared.cc b/third_party/nix/src/libmain/shared.cc
index dfa5be08979e..3df83733ad08 100644
--- a/third_party/nix/src/libmain/shared.cc
+++ b/third_party/nix/src/libmain/shared.cc
@@ -128,11 +128,15 @@ void initNix() {
   sigemptyset(&act.sa_mask);
   act.sa_handler = SIG_DFL;
   act.sa_flags = 0;
-  if (sigaction(SIGCHLD, &act, 0)) throw SysError("resetting SIGCHLD");
+  if (sigaction(SIGCHLD, &act, 0)) {
+    throw SysError("resetting SIGCHLD");
+  }
 
   /* Install a dummy SIGUSR1 handler for use with pthread_kill(). */
   act.sa_handler = sigHandler;
-  if (sigaction(SIGUSR1, &act, 0)) throw SysError("handling SIGUSR1");
+  if (sigaction(SIGUSR1, &act, 0)) {
+    throw SysError("handling SIGUSR1");
+  }
 
 #if __APPLE__
   /* HACK: on darwin, we need can’t use sigprocmask with SIGWINCH.
@@ -140,7 +144,9 @@ void initNix() {
    * can handle the rest. */
   struct sigaction sa;
   sa.sa_handler = sigHandler;
-  if (sigaction(SIGWINCH, &sa, 0)) throw SysError("handling SIGWINCH");
+  if (sigaction(SIGWINCH, &sa, 0)) {
+    throw SysError("handling SIGWINCH");
+  }
 #endif
 
   /* Register a SIGSEGV handler to detect stack overflows. */
@@ -223,14 +229,18 @@ LegacyArgs::LegacyArgs(
 }
 
 bool LegacyArgs::processFlag(Strings::iterator& pos, Strings::iterator end) {
-  if (MixCommonArgs::processFlag(pos, end)) return true;
+  if (MixCommonArgs::processFlag(pos, end)) {
+    return true;
+  }
   bool res = parseArg(pos, end);
   if (res) ++pos;
   return res;
 }
 
 bool LegacyArgs::processArgs(const Strings& args, bool finish) {
-  if (args.empty()) return true;
+  if (args.empty()) {
+    return true;
+  }
   assert(args.size() == 1);
   Strings ss(args);
   auto pos = ss.begin();
@@ -321,10 +331,16 @@ int handleExceptions(const string& programName, std::function<void()> fun) {
 }
 
 RunPager::RunPager() {
-  if (!isatty(STDOUT_FILENO)) return;
+  if (!isatty(STDOUT_FILENO)) {
+    return;
+  }
   char* pager = getenv("NIX_PAGER");
-  if (!pager) pager = getenv("PAGER");
-  if (pager && ((string)pager == "" || (string)pager == "cat")) return;
+  if (!pager) {
+    pager = getenv("PAGER");
+  }
+  if (pager && ((string)pager == "" || (string)pager == "cat")) {
+    return;
+  }
 
   Pipe toPager;
   toPager.create();
@@ -332,9 +348,13 @@ RunPager::RunPager() {
   pid = startProcess([&]() {
     if (dup2(toPager.readSide.get(), STDIN_FILENO) == -1)
       throw SysError("dupping stdin");
-    if (!getenv("LESS")) setenv("LESS", "FRSXMK", 1);
+    if (!getenv("LESS")) {
+      setenv("LESS", "FRSXMK", 1);
+    }
     restoreSignals();
-    if (pager) execl("/bin/sh", "sh", "-c", pager, nullptr);
+    if (pager) {
+      execl("/bin/sh", "sh", "-c", pager, nullptr);
+    }
     execlp("pager", "pager", nullptr);
     execlp("less", "less", nullptr);
     execlp("more", "more", nullptr);
diff --git a/third_party/nix/src/libmain/shared.hh b/third_party/nix/src/libmain/shared.hh
index e5f4bec6482e..db236a701778 100644
--- a/third_party/nix/src/libmain/shared.hh
+++ b/third_party/nix/src/libmain/shared.hh
@@ -53,7 +53,9 @@ template <class N>
 N getIntArg(const string& opt, Strings::iterator& i,
             const Strings::iterator& end, bool allowUnit) {
   ++i;
-  if (i == end) throw UsageError(format("'%1%' requires an argument") % opt);
+  if (i == end) {
+    throw UsageError(format("'%1%' requires an argument") % opt);
+  }
   string s = *i;
   N multiplier = 1;
   if (allowUnit && !s.empty()) {
diff --git a/third_party/nix/src/libmain/stack.cc b/third_party/nix/src/libmain/stack.cc
index 39866bb48248..0d5b91c163c7 100644
--- a/third_party/nix/src/libmain/stack.cc
+++ b/third_party/nix/src/libmain/stack.cc
@@ -25,7 +25,9 @@ static void sigsegvHandler(int signo, siginfo_t* info, void* ctx) {
 
   if (haveSP) {
     ptrdiff_t diff = (char*)info->si_addr - sp;
-    if (diff < 0) diff = -diff;
+    if (diff < 0) {
+      diff = -diff;
+    }
     if (diff < 4096) {
       char msg[] = "error: stack overflow (possible infinite recursion)\n";
       [[gnu::unused]] auto res = write(2, msg, strlen(msg));
@@ -38,7 +40,9 @@ static void sigsegvHandler(int signo, siginfo_t* info, void* ctx) {
   sigfillset(&act.sa_mask);
   act.sa_handler = SIG_DFL;
   act.sa_flags = 0;
-  if (sigaction(SIGSEGV, &act, 0)) abort();
+  if (sigaction(SIGSEGV, &act, 0)) {
+    abort();
+  }
 }
 
 void detectStackOverflow() {
@@ -50,7 +54,9 @@ void detectStackOverflow() {
   stack.ss_size = 4096 * 4 + MINSIGSTKSZ;
   static auto stackBuf = std::make_unique<std::vector<char>>(stack.ss_size);
   stack.ss_sp = stackBuf->data();
-  if (!stack.ss_sp) throw Error("cannot allocate alternative stack");
+  if (!stack.ss_sp) {
+    throw Error("cannot allocate alternative stack");
+  }
   stack.ss_flags = 0;
   if (sigaltstack(&stack, 0) == -1)
     throw SysError("cannot set alternative stack");
@@ -59,7 +65,9 @@ void detectStackOverflow() {
   sigfillset(&act.sa_mask);
   act.sa_sigaction = sigsegvHandler;
   act.sa_flags = SA_SIGINFO | SA_ONSTACK;
-  if (sigaction(SIGSEGV, &act, 0)) throw SysError("resetting SIGSEGV");
+  if (sigaction(SIGSEGV, &act, 0)) {
+    throw SysError("resetting SIGSEGV");
+  }
 #endif
 }