Blame SOURCES/0012-common-mltools-move-the-code-for-machine-readable-up.patch

46b2f6
From 692a752cf3e552790ada8cc07f937036adaa8bf0 Mon Sep 17 00:00:00 2001
46b2f6
From: Pino Toscano <ptoscano@redhat.com>
46b2f6
Date: Thu, 21 Mar 2019 17:16:37 +0100
46b2f6
Subject: [PATCH] common/mltools: move the code for machine readable up
46b2f6
46b2f6
Move the code for handling machine readable up in the file, so it can be
46b2f6
used by other functions.
46b2f6
46b2f6
Only code motion, no behaviour changes.
46b2f6
46b2f6
(cherry picked from commit 8b06ea0ebc9534e4fda9cc9a33c98f939401af79)
46b2f6
---
46b2f6
 common/mltools/tools_utils.ml | 60 +++++++++++++++++------------------
46b2f6
 1 file changed, 30 insertions(+), 30 deletions(-)
46b2f6
46b2f6
diff --git a/common/mltools/tools_utils.ml b/common/mltools/tools_utils.ml
46b2f6
index 24641369e..5a35708cd 100644
46b2f6
--- a/common/mltools/tools_utils.ml
46b2f6
+++ b/common/mltools/tools_utils.ml
46b2f6
@@ -33,6 +33,36 @@ external c_inspect_decrypt : Guestfs.t -> int64 -> (string * key_store_key) list
46b2f6
 external c_set_echo_keys : unit -> unit = "guestfs_int_mllib_set_echo_keys" "noalloc"
46b2f6
 external c_set_keys_from_stdin : unit -> unit = "guestfs_int_mllib_set_keys_from_stdin" "noalloc"
46b2f6
 
46b2f6
+type machine_readable_fn = {
46b2f6
+  pr : 'a. ('a, unit, string, unit) format4 -> 'a;
46b2f6
+} (* [@@unboxed] *)
46b2f6
+
46b2f6
+type machine_readable_output_type =
46b2f6
+  | NoOutput
46b2f6
+  | Channel of out_channel
46b2f6
+  | File of string
46b2f6
+let machine_readable_output = ref NoOutput
46b2f6
+let machine_readable_channel = ref None
46b2f6
+let machine_readable () =
46b2f6
+  let chan =
46b2f6
+    if !machine_readable_channel = None then (
46b2f6
+      let chan =
46b2f6
+        match !machine_readable_output with
46b2f6
+        | NoOutput -> None
46b2f6
+        | Channel chan -> Some chan
46b2f6
+        | File f -> Some (open_out f) in
46b2f6
+      machine_readable_channel := chan
46b2f6
+    );
46b2f6
+    !machine_readable_channel
46b2f6
+  in
46b2f6
+  match chan with
46b2f6
+  | None -> None
46b2f6
+  | Some chan ->
46b2f6
+    let pr fs =
46b2f6
+      ksprintf (output_string chan) fs
46b2f6
+    in
46b2f6
+    Some { pr }
46b2f6
+
46b2f6
 (* ANSI terminal colours. *)
46b2f6
 let istty chan =
46b2f6
   Unix.isatty (Unix.descr_of_out_channel chan)
46b2f6
@@ -236,36 +266,6 @@ let human_size i =
46b2f6
     )
46b2f6
   )
46b2f6
 
46b2f6
-type machine_readable_fn = {
46b2f6
-  pr : 'a. ('a, unit, string, unit) format4 -> 'a;
46b2f6
-} (* [@@unboxed] *)
46b2f6
-
46b2f6
-type machine_readable_output_type =
46b2f6
-  | NoOutput
46b2f6
-  | Channel of out_channel
46b2f6
-  | File of string
46b2f6
-let machine_readable_output = ref NoOutput
46b2f6
-let machine_readable_channel = ref None
46b2f6
-let machine_readable () =
46b2f6
-  let chan =
46b2f6
-    if !machine_readable_channel = None then (
46b2f6
-      let chan =
46b2f6
-        match !machine_readable_output with
46b2f6
-        | NoOutput -> None
46b2f6
-        | Channel chan -> Some chan
46b2f6
-        | File f -> Some (open_out f) in
46b2f6
-      machine_readable_channel := chan
46b2f6
-    );
46b2f6
-    !machine_readable_channel
46b2f6
-  in
46b2f6
-  match chan with
46b2f6
-  | None -> None
46b2f6
-  | Some chan ->
46b2f6
-    let pr fs =
46b2f6
-      ksprintf (output_string chan) fs
46b2f6
-    in
46b2f6
-    Some { pr }
46b2f6
-
46b2f6
 type cmdline_options = {
46b2f6
   getopt : Getopt.t;
46b2f6
   ks : key_store;
46b2f6
-- 
d60042
2.25.4
46b2f6