Skip to content

Commit 9793960

Browse files
committed
git-arc: Add patch -b option
With the new patch -b option, switch to a new branch before applying changes from Differential revisions. While here, do some minor clean-up: - Fix a check to determine whether `arc patch` ran successfully. - Always ensure at least one argument is supplied to `git arc patch`. Sponsored by: The FreeBSD Foundation Reviewed by: imp, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D54024
1 parent fd131b4 commit 9793960

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

tools/tools/git/git-arc.sh

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Usage: git arc [-vy] <command> <arguments>
5959
Commands:
6060
create [-l] [-r <reviewer1>[,<reviewer2>...]] [-s subscriber[,...]] [<commit>|<commit range>]
6161
list <commit>|<commit range>
62-
patch [-c] <diff1> [<diff2> ...]
62+
patch [-bc] <diff1> [<diff2> ...]
6363
stage [-b branch] [<commit>|<commit range>]
6464
update [-l] [-m message] [<commit>|<commit range>]
6565
@@ -75,8 +75,10 @@ Description:
7575
create -- Create new Differential revisions from the specified commits.
7676
list -- Print the associated Differential revisions for the specified
7777
commits.
78-
patch -- Try to apply a patch from a Differential revision to the
79-
currently checked out tree.
78+
patch -- Apply patches from Differential revisions. By default, patches
79+
are applied to the currently checked-out tree, unless -b is
80+
supplied, in which case a new branch is first created. The -c
81+
option commits the applied patch using the review's metadata.
8082
stage -- Prepare a series of commits to be pushed to the upstream FreeBSD
8183
repository. The commits are cherry-picked to a branch (main by
8284
default), review tags are added to the commit log message, and
@@ -146,6 +148,11 @@ Examples:
146148
147149
$ git arc patch -c D12345
148150
151+
Apply the patches in reviews D12345 and D12346 in a new branch, and commit
152+
them using the review titles, summaries and authors.
153+
154+
$ git arc patch -bc D12345 D12346
155+
149156
List the status of reviews for all the commits in the branch "feature":
150157
151158
$ git arc list main..feature
@@ -567,6 +574,26 @@ find_author()
567574
echo "${a}"
568575
}
569576

577+
patch_branch()
578+
{
579+
local base new suffix
580+
581+
if [ $# -eq 1 ]; then
582+
base="gitarc-$1"
583+
else
584+
base="gitarc-$(printf "%s-" "$@" | sed 's/-$//')"
585+
fi
586+
587+
new="$base"
588+
suffix=1
589+
while git show-ref --quiet --branches "$new"; do
590+
new="${base}_$suffix"
591+
suffix=$((suffix + 1))
592+
done
593+
594+
git checkout -b "$new"
595+
}
596+
570597
patch_commit()
571598
{
572599
local diff reviewid review_data authorid user_data user_addr user_name
@@ -626,15 +653,16 @@ patch_commit()
626653

627654
gitarc__patch()
628655
{
629-
local rev commit
630-
631-
if [ $# -eq 0 ]; then
632-
err_usage
633-
fi
656+
local branch commit rev
634657

658+
branch=false
635659
commit=false
636-
while getopts c o; do
660+
while getopts bc o; do
637661
case "$o" in
662+
b)
663+
require_clean_work_tree "patch -b"
664+
branch=true
665+
;;
638666
c)
639667
require_clean_work_tree "patch -c"
640668
commit=true
@@ -646,10 +674,18 @@ gitarc__patch()
646674
done
647675
shift $((OPTIND-1))
648676

677+
if [ $# -eq 0 ]; then
678+
err_usage
679+
fi
680+
681+
if ${branch}; then
682+
patch_branch "$@"
683+
fi
649684
for rev in "$@"; do
650-
arc patch --skip-dependencies --nocommit --nobranch --force "$rev"
685+
if ! arc patch --skip-dependencies --nobranch --nocommit --force "$rev"; then
686+
break
687+
fi
651688
echo "Applying ${rev}..."
652-
[ $? -eq 0 ] || break
653689
if ${commit}; then
654690
patch_commit $rev
655691
fi

0 commit comments

Comments
 (0)