~jan0sch/smederee

Showing details for patch 5e6336d56e858d320ba819823f2d003f39744d5a.
2022-08-07 (Sun), 1:34 PM - Jens Grassel - 5e6336d56e858d320ba819823f2d003f39744d5a

darcs: rewrite darcs module to use the os-lib

Summary of changes
2 files modified with 15 lines added and 25 lines removed
  • build.sbt with 1 added and 0 removed lines
  • modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala with 14 added and 25 removed lines
diff -rN -u old-smederee/build.sbt new-smederee/build.sbt
--- old-smederee/build.sbt	2025-03-12 16:14:31.076759058 +0000
+++ new-smederee/build.sbt	2025-03-12 16:14:31.076759058 +0000
@@ -68,6 +68,7 @@
         library.catsCore,
         library.catsEffect,
         library.logback,
+        library.osLib,
         library.munit             % IntegrationTest,
         library.munitCatsEffect   % IntegrationTest,
         library.munitDiscipline   % IntegrationTest,
diff -rN -u old-smederee/modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala new-smederee/modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala
--- old-smederee/modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala	2025-03-12 16:14:31.076759058 +0000
+++ new-smederee/modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala	2025-03-12 16:14:31.076759058 +0000
@@ -54,15 +54,12 @@
     */
   def initialize(basePath: Path)(repositoryName: String)(options: Chain[String]): F[DarcsCommandOutput] = {
     log.trace(s"Execute $darcsBinary initialize $basePath/$repositoryName with $options")
-    var stdout    = Chain.empty[String]
-    var stderr    = Chain.empty[String]
-    val logger    = ProcessLogger(line => stdout = stdout.append(line), line => stderr = stderr.append(line))
-    val directory = Paths.get(basePath.toString, repositoryName)
+    val directory       = Paths.get(basePath.toString, repositoryName)
     val darcsOptions    = List("initialize") ::: options.toList ::: List(directory.toString)
-    val externalCommand = Process(darcsBinary.toString, darcsOptions)
+    val externalCommand = os.proc(darcsBinary.toString, darcsOptions)
     for {
-      exitValue <- Sync[F].delay(externalCommand.!(logger))
-    } yield DarcsCommandOutput(exitValue, stdout, stderr)
+      process <- Sync[F].delay(externalCommand.call(check = false))
+    } yield DarcsCommandOutput(process.exitCode, Chain(process.out.text()), Chain(process.err.text()))
   }
 
   /** Run the darcs log command on the given repository and return the output.
@@ -78,16 +75,12 @@
     */
   def log(basePath: Path)(repositoryName: String)(options: Chain[String]): F[DarcsCommandOutput] = {
     log.trace(s"Execute $darcsBinary log in $basePath/$repositoryName with $options")
-    var stdout    = Chain.empty[String]
-    var stderr    = Chain.empty[String]
-    val logger    = ProcessLogger(line => stdout = stdout.append(line), line => stderr = stderr.append(line))
-    val directory = Paths.get(basePath.toString, repositoryName)
-    val darcsOptions = List("log") ::: options.toList
-    val externalCommand =
-      Process("cd", List(directory.toString)).#&&(Process(darcsBinary.toString, darcsOptions))
+    val directory       = Paths.get(basePath.toString, repositoryName)
+    val darcsOptions    = List("log") ::: options.toList
+    val externalCommand = os.proc(darcsBinary.toString, darcsOptions)
     for {
-      exitValue <- Sync[F].delay(externalCommand.!(logger))
-    } yield DarcsCommandOutput(exitValue, stdout, stderr)
+      process <- Sync[F].delay(externalCommand.call(cwd = os.Path(directory), check = false))
+    } yield DarcsCommandOutput(process.exitCode, Chain(process.out.text()), Chain(process.err.text()))
   }
 
   /** Run the darcs whatsnew command on the given repository and return the output.
@@ -103,16 +96,12 @@
     */
   def whatsnew(basePath: Path)(repositoryName: String)(options: Chain[String]): F[DarcsCommandOutput] = {
     log.trace(s"Execute $darcsBinary whatsnew in $basePath/$repositoryName with $options")
-    var stdout    = Chain.empty[String]
-    var stderr    = Chain.empty[String]
-    val logger    = ProcessLogger(line => stdout = stdout.append(line), line => stderr = stderr.append(line))
-    val directory = Paths.get(basePath.toString, repositoryName)
-    val darcsOptions = List("whatsnew") ::: options.toList
-    val externalCommand =
-      Process("cd", List(directory.toString)).#&&(Process(darcsBinary.toString, darcsOptions))
+    val directory       = Paths.get(basePath.toString, repositoryName)
+    val darcsOptions    = List("whatsnew") ::: options.toList
+    val externalCommand = os.proc(darcsBinary.toString, darcsOptions)
     for {
-      exitValue <- Sync[F].delay(externalCommand.!(logger))
-    } yield DarcsCommandOutput(exitValue, stdout, stderr)
+      process <- Sync[F].delay(externalCommand.call(cwd = os.Path(directory), check = false))
+    } yield DarcsCommandOutput(process.exitCode, Chain(process.out.text()), Chain(process.err.text()))
   }
 
 }