@@ -37,6 +37,7 @@ FLAGS=""
37
37
PATCH_DIR=" umpf-patches"
38
38
IDENTICAL=false
39
39
STABLE=false
40
+ DEFAULT=false
40
41
FORCE=false
41
42
UPDATE=false
42
43
VERBOSE=false
@@ -173,6 +174,7 @@ usage() {
173
174
usage: $0 [<options>] [--] <command>
174
175
175
176
Mandatory arguments to long options are mandatory for short options too.
177
+ --default answer interactive prompts with the default option
176
178
--auto-rerere automatically try to use rerere after conflicts
177
179
--bb with format-patch: write patch series for bitbake
178
180
--nix with format-patch: write patch series nix
@@ -245,7 +247,7 @@ setup() {
245
247
fi
246
248
247
249
o=" fhilsub:n:p:r:v:"
248
- l=" auto-rerere,bb,nix,flags:,force,help,identical,stable,update,base:,name:,patchdir:,relative:,override:,remote:,local,version:"
250
+ l=" auto-rerere,bb,nix,flags:,default, force,help,identical,stable,update,base:,name:,patchdir:,relative:,override:,remote:,local,version:"
249
251
if ! args=" $( getopt -n umpf -o " ${o} " -l " ${l} " -- " ${@ } " ) " ; then
250
252
usage
251
253
exit 1
@@ -268,6 +270,9 @@ setup() {
268
270
--nix)
269
271
NIX=true
270
272
;;
273
+ --default)
274
+ DEFAULT=true
275
+ ;;
271
276
-f|--force)
272
277
FORCE=true
273
278
;;
@@ -414,6 +419,16 @@ nice_branch() {
414
419
read -r -a replies < <( sed -r -n ' s,^(remotes/([^/]*)/|heads/)?(.*),\3 \2,p' <<< " ${1}" )
415
420
}
416
421
422
+ read_interactive () {
423
+ local prompt=" ${1} " def=" ${2} "
424
+ if ${DEFAULT} && [ -n " ${def} " ]; then
425
+ echo " ${prompt} : ${def} "
426
+ choice=" ${def} "
427
+ else
428
+ read -e -i " ${def} " -p " ${prompt} : " choice
429
+ fi
430
+ }
431
+
417
432
find_branch_rev () {
418
433
local name branch remote
419
434
local -a branches replies
@@ -438,7 +453,7 @@ find_branch_rev() {
438
453
else
439
454
info " Branch not found for '${remote} '. Choose alternative branch:"
440
455
fi
441
- local i=0 def=0
456
+ local i=0 def=0 choice
442
457
for branch in " ${branches[@]} " ; do
443
458
nice_branch " ${branch} "
444
459
echo " ${i} ) ${replies[1]: +${replies[1]} / }${replies[0]} "
@@ -447,8 +462,8 @@ find_branch_rev() {
447
462
fi
448
463
i=$(( i+ 1 ))
449
464
done
450
- read -e -i ${def} -p " branch number: " i
451
- nice_branch " ${branches[$i ]} "
465
+ read_interactive " branch number " " ${def} "
466
+ nice_branch " ${branches[${choice} ]} "
452
467
remote=" ${replies[1]:- refs/ heads} /"
453
468
if [ -z " ${GIT_REMOTE} " ]; then
454
469
GIT_REMOTE=" ${remote} "
@@ -464,16 +479,15 @@ find_branch_rev() {
464
479
bailout " Failed to find '${name} '"
465
480
fi
466
481
for branch in " ${branches[@]} " ; do
467
- local b=" $( ${GIT} rev-parse --verify " ${branch} ^{}" ) "
482
+ local choice b=" $( ${GIT} rev-parse --verify " ${branch} ^{}" ) "
468
483
if [ " ${reply} " == " ${b} " ]; then
469
484
continue
470
485
fi
471
486
if [ " $( ${GIT} merge-base " ${reply} " " ${branch} " ) " == " ${reply} " ]; then
472
487
info " Warning: The following commits are in '${branch} ' but not in '${remote}${name} ':"
473
488
GIT_PAGER=" " ${GIT} log --oneline " ${reply} ...${b} "
474
489
if tty -s; then
475
- local choice=" "
476
- read -e -i n -p " Use ${branch} instead? [y/n]: " choice
490
+ read_interactive " Use ${branch} instead? [y/n]" " n"
477
491
if [ " ${choice} " == " y" ]; then
478
492
reply=" ${b} "
479
493
fi
@@ -489,7 +503,7 @@ list_branch_names() {
489
503
}
490
504
491
505
find_branch_name () {
492
- local head merge mergelog candidate
506
+ local head merge mergelog candidate choice
493
507
local -a branches replies
494
508
head=" ${1} "
495
509
merge=" ${2} "
@@ -511,7 +525,8 @@ find_branch_name() {
511
525
0)
512
526
info " No branch found for ${mergelog} "
513
527
candidate=$( sed -n " s/^[0-9a-f]* Merge.* '\([^ ]*\)' .*/\1/p" <<< " ${mergelog}" )
514
- read -e -i " ${candidate} " -p " topic: " name
528
+ read_interactive " topic" " ${candidate} "
529
+ name=" ${choice} "
515
530
;;
516
531
1)
517
532
nice_branch " ${branches[0]} "
@@ -646,7 +661,9 @@ import_series() {
646
661
647
662
if [ -z " ${BASE} " ]; then
648
663
BASE=" $( ${GIT} describe " ${base_rev} " 2> /dev/null) "
649
- read -e -i " ${BASE} " -p " base: " BASE
664
+ local choice
665
+ read_interactive " base" " ${BASE} "
666
+ BASE=" ${choice} "
650
667
fi
651
668
echo " # umpf-base: ${BASE} " >> " ${series} "
652
669
if [ -n " ${GIT_RELATIVE} " ]; then
@@ -1680,7 +1697,7 @@ apply_to_topic() {
1680
1697
esac
1681
1698
1682
1699
while [ -z " ${topic} " ]; do
1683
- local i=0 ret default
1700
+ local i=0 choice default
1684
1701
for branch in " ${branch_names[@]} " ; do
1685
1702
echo " ${i} ) ${branch} "
1686
1703
if git log --pretty=" format:%s" " ${base} ..${branches[${i}]} " | grep -q " ^${match} $" ; then
@@ -1690,8 +1707,8 @@ apply_to_topic() {
1690
1707
done
1691
1708
echo " s) show patch"
1692
1709
echo " x) skip patch"
1693
- read -e -p " Branch: " -i " ${default} " ret
1694
- case " ${ret } " in
1710
+ read_interactive " Branch" " ${default} "
1711
+ case " ${choice } " in
1695
1712
s)
1696
1713
${GIT} show " ${rev} "
1697
1714
continue
@@ -1700,23 +1717,23 @@ apply_to_topic() {
1700
1717
return
1701
1718
;;
1702
1719
[0-9]* )
1703
- branch=" ${branch_names[${ret }]} "
1720
+ branch=" ${branch_names[${choice }]} "
1704
1721
if [ -z " ${branch} " ]; then
1705
- echo " '$ret ' is not a valid branch number"
1722
+ echo " '${choice} ' is not a valid branch number"
1706
1723
fi
1707
1724
;;
1708
1725
* )
1709
- echo " Invalid command '$ret '"
1726
+ echo " Invalid command '${choice} '"
1710
1727
continue
1711
1728
esac
1712
1729
if ! topic=" $( ${GIT} rev-parse -q --verify " refs/umpf/${branch} ^{}" ) " ; then
1713
- topic=" ${branches[${ret }]} "
1730
+ topic=" ${branches[${choice }]} "
1714
1731
fi
1715
1732
if [ -z " ${topic} " ]; then
1716
1733
local reply
1717
1734
IDENTICAL=false find_branch_rev " ${branch} "
1718
1735
topic=" ${reply} "
1719
- branches[${ret } ]=" ${topic} "
1736
+ branches[${choice } ]=" ${topic} "
1720
1737
fi
1721
1738
echo " ${branch} " > " ${STATE} /distribute-branch"
1722
1739
echo " ${topic} " > " ${STATE} /distribute-topic"
0 commit comments