git: 2f68f6474e41 - main - git-arc: Add list mode support for the update command

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Mon, 06 May 2024 17:49:20 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=2f68f6474e4174999bcbab531b9b221c8671f544

commit 2f68f6474e4174999bcbab531b9b221c8671f544
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-05-06 17:49:04 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-05-06 17:49:04 +0000

    git-arc: Add list mode support for the update command
    
    This can be particularly useful to do bulk-updates of multiple commits
    using the same message, e.g.
    
      git arc update -lm "Move function xyz to libfoo" main..myfeature
    
    Similar to the list mode for the create command, git arc will list all
    the candidate revisions with a single prompt.  Once that is confirmed,
    all the revisions are updated without showing the diffs or pausing
    further prompts.
    
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D45050
---
 tools/tools/git/git-arc.1  | 19 ++++++++++++++++---
 tools/tools/git/git-arc.sh | 37 ++++++++++++++++++++++++++++---------
 2 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/tools/tools/git/git-arc.1 b/tools/tools/git/git-arc.1
index e449875c5043..5ada942d13a9 100644
--- a/tools/tools/git/git-arc.1
+++ b/tools/tools/git/git-arc.1
@@ -50,6 +50,7 @@
 .Op Ar commit ... Ns | Ns Ar commit-range
 .Nm
 .Cm update
+.Op Fl l
 .Op Fl m Ar message
 .Op Ar commit ... Ns | Ns Ar commit-range
 .Sh DESCRIPTION
@@ -117,6 +118,11 @@ each revision.
 If an empty message is supplied via
 .Fl m ,
 then no notes will be added when updating Differential Revisions.
+.Pp
+If
+.Fl l
+is used, display list of commits to be updated and wait for confirmation
+of the list rather than prompting for each commit.
 .El
 .Sh CONFIGURATION
 These are manipulated by
@@ -138,9 +144,9 @@ Defaults to false.
 Always use
 .Dq list mode
 .Pq Fl l
-with create.
-In this mode, the list of git revisions to create reviews for
-is listed with a single prompt before creating reviews.
+with create and update.
+In this mode, the list of git revisions to use
+is listed with a single prompt before creating or updating reviews.
 The diffs for individual commits are not shown.
 Defaults to false.
 .It Va arc.verbose
@@ -227,6 +233,13 @@ List the status of reviews for all the commits in the branch
 .Bd -literal -offset indent
 $ git arc list main..feature
 .Ed
+.Pp
+Update reviews for all commits in the branch
+.Dq feature
+after rebasing:
+.Bd -literal -offset indent
+$ git arc update -lm "Rebase" main..feature
+.Ed
 .Sh SEE ALSO
 .Xr build 7 ,
 .Xr development 7
diff --git a/tools/tools/git/git-arc.sh b/tools/tools/git/git-arc.sh
index 1c828f3194af..e8da1f1ed32a 100644
--- a/tools/tools/git/git-arc.sh
+++ b/tools/tools/git/git-arc.sh
@@ -53,7 +53,7 @@ Commands:
   list <commit>|<commit range>
   patch [-c] <diff1> [<diff2> ...]
   stage [-b branch] [<commit>|<commit range>]
-  update [-m message] [<commit>|<commit range>]
+  update [-l] [-m message] [<commit>|<commit range>]
 
 Description:
   Create or manage FreeBSD Phabricator reviews based on git commits.  There
@@ -100,11 +100,11 @@ Config Variables:
     arc.browse [bool]  -- Try to open newly created reviews in a browser tab.
                           Defaults to false.
 
-    arc.list [bool]    -- Always use "list mode" (-l) with create.  In this
-                          mode, the list of git revisions to create reviews for
-                          is listed with a single prompt before creating
-                          reviews.  The diffs for individual commits are not
-                          shown.
+    arc.list [bool]    -- Always use "list mode" (-l) with create and update.
+			  In this mode, the list of git revisions to use
+                          is listed with a single prompt before creating or
+                          updating reviews.  The diffs for individual commits
+			  are not shown.
 
     arc.verbose [bool] -- Verbose output.  Equivalent to the -v flag.
 
@@ -669,10 +669,18 @@ gitarc__stage()
 
 gitarc__update()
 {
-    local commit commits diff have_msg msg
+    local commit commits diff doprompt have_msg list o msg
 
-    while getopts m: o; do
+    list=
+    if [ "$(git config --bool --get arc.list 2>/dev/null || echo false)" != "false" ]; then
+        list=1
+    fi
+    doprompt=1
+    while getopts lm: o; do
         case "$o" in
+        l)
+            list=1
+            ;;
         m)
             msg="$OPTARG"
             have_msg=1
@@ -685,10 +693,21 @@ gitarc__update()
     shift $((OPTIND-1))
 
     commits=$(build_commit_list "$@")
+
+    if [ "$list" ]; then
+        for commit in ${commits}; do
+            git --no-pager show --oneline --no-patch "$commit"
+        done | git_pager
+        if ! prompt; then
+            return
+        fi
+        doprompt=
+    fi
+
     for commit in ${commits}; do
         diff=$(commit2diff "$commit")
 
-        if ! show_and_prompt "$commit"; then
+        if [ "$doprompt" ] && ! show_and_prompt "$commit"; then
             break
         fi