git: 311f95ce3d41 - stable/14 - mfc-candidates: move pretty printing into lua

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Thu, 01 Aug 2024 16:07:18 UTC
The branch stable/14 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=311f95ce3d4111eff1a6242be55adf52283b3e5e

commit 311f95ce3d4111eff1a6242be55adf52283b3e5e
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2024-04-16 16:49:05 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-08-01 15:11:45 +0000

    mfc-candidates: move pretty printing into lua
    
    d51c59002367 moved the MFC hash matching logic into a lua utility
    script but left the output formatting in the shell script. Simplify this
    slightly by just printing the formatted output from lua.
    
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D44836
    
    (cherry picked from commit 793745fad866f65863ab3b16a17bdf18dc779efd)
---
 tools/tools/git/candidatematch.lua | 10 +++++++++-
 tools/tools/git/mfc-candidates.sh  |  7 +------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/tools/tools/git/candidatematch.lua b/tools/tools/git/candidatematch.lua
index 98c247fca339..481c1f38fea1 100755
--- a/tools/tools/git/candidatematch.lua
+++ b/tools/tools/git/candidatematch.lua
@@ -36,6 +36,14 @@ local function set_difference(set1, set2)
 	return result
 end
 
+-- Execute a command and print to stdout
+local function exec_command(command)
+	local handle = io.popen(command)
+	local output = handle:read("a")
+	handle:close()
+	io.write(output)
+end
+
 -- Main function
 local function main()
 	local from_file = arg[1]
@@ -59,7 +67,7 @@ local function main()
 
 	-- Print the result
 	for _, hash in ipairs(result_hashes) do
-		print(hash)
+		exec_command("git show --pretty='%h %s' --no-patch " .. hash)
 	end
 end
 
diff --git a/tools/tools/git/mfc-candidates.sh b/tools/tools/git/mfc-candidates.sh
index dd88710a4a4a..bc1ad602cb1c 100644
--- a/tools/tools/git/mfc-candidates.sh
+++ b/tools/tools/git/mfc-candidates.sh
@@ -149,7 +149,6 @@ canonicalize_hashes()
 workdir=$(mktemp -d /tmp/find-mfc.XXXXXXXXXX)
 from_list=$workdir/commits-from
 to_list=$workdir/commits-to
-candidate_list=$workdir/candidates
 
 if [ -n "$exclude_file" ]; then
 	exclude_list=$workdir/commits-exclude
@@ -160,10 +159,6 @@ commits_from "$@" > $from_list
 commits_to "$@" > $to_list
 
 /usr/libexec/flua $(dirname $0)/candidatematch.lua \
-    $from_list $to_list $exclude_list > $candidate_list
-
-while read hash; do
-	git show --pretty='%h %s' --no-patch $hash
-done < $candidate_list
+    $from_list $to_list $exclude_list
 
 rm -rf "$workdir"