git: 9f48ef1fcae5 - main - git-arc: Cope with extra output

From: Warner Losh <imp_at_FreeBSD.org>
Date: Mon, 15 Jan 2024 02:24:29 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=9f48ef1fcae58fe8aa41da4cc59cc93136fe70dd

commit 9f48ef1fcae58fe8aa41da4cc59cc93136fe70dd
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-01-15 02:22:49 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-01-15 02:23:45 +0000

    git-arc: Cope with extra output
    
    On my machine, for reasons beyond my understanding, I get this warning
    two times when running arc:
    
    Warning: Module "openssl" is already loaded in Unknown on line 0
    
    so grep -v ^Warning: on all the arc call-conduit calls to filter them
    out so we can properly parse the JSON with jq.
    
    Sponsored by:           Netflix
    Reviewed by:            markj, jhb
    Differential Revision:  https://reviews.freebsd.org/D36583
---
 tools/tools/git/git-arc.sh | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/tools/git/git-arc.sh b/tools/tools/git/git-arc.sh
index a207899d5fbe..f88cf4b01102 100644
--- a/tools/tools/git/git-arc.sh
+++ b/tools/tools/git/git-arc.sh
@@ -142,6 +142,17 @@ __EOF__
     exit 1
 }
 
+#
+# Filter the output of call-conduit to remove the warnings that are generated
+# for some installations where openssl module is mysteriously installed twice so
+# a warning is generated. It's likely a local config error, but we should work
+# in the face of that.
+#
+arc_call_conduit()
+{
+    arc call-conduit "$@" | grep -v '^Warning: '
+}
+
 #
 # Filter the output of arc list to remove the warnings as above, as well as any
 # stray escape sequences that are in the list (it interferes with the parsing)
@@ -161,7 +172,7 @@ diff2phid()
     fi
 
     echo '{"names":["'"$diff"'"]}' |
-        arc call-conduit -- phid.lookup |
+        arc_call_conduit -- phid.lookup |
         jq -r "select(.response != []) | .response.${diff}.phid"
 }
 
@@ -176,7 +187,7 @@ diff2status()
 
     tmp=$(mktemp)
     echo '{"names":["'"$diff"'"]}' |
-        arc call-conduit -- phid.lookup > "$tmp"
+        arc_call_conduit -- phid.lookup > "$tmp"
     status=$(jq -r "select(.response != []) | .response.${diff}.status" < "$tmp")
     summary=$(jq -r "select(.response != []) |
          .response.${diff}.fullName" < "$tmp")
@@ -280,7 +291,7 @@ create_one_review()
                     "value": ["'"${parentphid}"'"]
                 }
              ]}' |
-            arc call-conduit -- differential.revision.edit >&3
+            arc_call_conduit -- differential.revision.edit >&3
     fi
     rm -f "$msg"
     return 0
@@ -298,13 +309,13 @@ diff2reviewers()
                   "constraints": {"phids": ["'"$reviewid"'"]},
                   "attachments": {"reviewers": true}
               }' |
-        arc call-conduit -- differential.revision.search |
+        arc_call_conduit -- differential.revision.search |
         jq '.response.data[0].attachments.reviewers.reviewers[] | select(.status == "accepted").reviewerPHID')
     if [ -n "$userids" ]; then
         echo '{
                   "constraints": {"phids": ['"$(echo -n "$userids" | tr '[:space:]' ',')"']}
               }' |
-            arc call-conduit -- user.search |
+            arc_call_conduit -- user.search |
             jq -r '.response.data[].fields.username'
     fi
 }