Gentoo Archives: gentoo-commits

From: "M. B." <tomboy64@××××.cn>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/user/tbc:master commit in: tools/
Date: Sat, 28 May 2016 12:05:05
Message-Id: 1464436919.446ee0a58356465f62f6f2c69ce86643fee8cc1f.tomboy64@gentoo
1 commit: 446ee0a58356465f62f6f2c69ce86643fee8cc1f
2 Author: Matthew Brewer <tomboy64 <AT> sina <DOT> cn>
3 AuthorDate: Fri May 27 22:43:58 2016 +0000
4 Commit: M. B. <tomboy64 <AT> sina <DOT> cn>
5 CommitDate: Sat May 28 12:01:59 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/user/tbc.git/commit/?id=446ee0a5
7
8 new tool for git-edits step-by-step
9
10 tools/ortrta.sh | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 1 file changed, 107 insertions(+)
12
13 diff --git a/tools/ortrta.sh b/tools/ortrta.sh
14 new file mode 100755
15 index 0000000..7b1d950
16 --- /dev/null
17 +++ b/tools/ortrta.sh
18 @@ -0,0 +1,107 @@
19 +#!/bin/bash
20 +
21 +# Shell script to perform `git rebase -i <argument>`
22 +# License: WTFPL2
23 +
24 +errorout() {
25 + echo "Failed: $1"
26 + exit 1
27 +}
28 +
29 +repoman_this() {
30 + local ebuilds=( $(git diff --numstat HEAD^ | cut -f3 | grep '\.ebuild') )
31 + local dirs=()
32 + for i in ${ebuilds[@]}; do
33 + local dir=$(dirname ${i})
34 + local inIt=0
35 + for j in ${dirs[@]}; do
36 + if [[ "${j}" == "${dir}" ]]; then
37 + inIt=1
38 + break;
39 + fi
40 + done
41 + if [[ ${inIt} -eq 0 ]]; then
42 + dirs+="${dir}"
43 + pushd ${dir}
44 + repoman full
45 + popd 2>&1 > /dev/null
46 + fi
47 + done
48 + git add *
49 + git commit --amend --no-edit
50 + echo
51 + git rebase --continue 2>&1 | head -n1
52 +}
53 +
54 +choose() {
55 + while [[ true ]]; do
56 + echo -n "(e)dit, (r)epoman full all ebuilds, (c)ontinue or e(x)it? "
57 + read -n1 -r response
58 +
59 + printf '\r'
60 + tput el
61 + echo
62 +
63 + case ${response} in
64 + e )
65 + exit 0
66 + ;;
67 + c )
68 + git rebase --continue 2>&1 | head -n1
69 + return
70 + ;;
71 + r )
72 + repoman_this
73 + return
74 + ;;
75 + x )
76 + echo "Aborting rebase..."
77 + git rebase --abort
78 + echo "Exiting."
79 + exit 0
80 + ;;
81 + * )
82 + echo "Wrong key. Try again."
83 + ;;
84 + esac
85 + done
86 +}
87 +
88 +resume() {
89 + count=$(GIT_EDITOR='cat' git rebase --edit-todo | grep -v '^#' | wc -l)
90 + while [[ ${count} -ge 0 ]]; do
91 + git diff --color --stat HEAD^ | cat
92 + echo "left: ${count}"
93 + count=$(( count - 1 ))
94 + choose
95 + done
96 + if [[ $(LC_ALL=C git rebase --edit-todo 2>&1 | \
97 + grep -v '^#\|No rebase in progress?' | \
98 + wc -l) \
99 + -eq 0 ]]; then
100 + echo "Done."
101 + else
102 + echo "Something went wrong here, there's still commits to process."
103 + fi
104 +}
105 +
106 +commence() {
107 + input=$1
108 + START=${input:=master}
109 + GIT_EDITOR='vim -c "%s/pick/edit/g | wq"' git rebase -i ${START} || errorout "git rebase -i ${START}"
110 + resume
111 +}
112 +
113 +STATUS=$(LC_ALL=C git status | head -n1 | grep -c 'interactive rebase in progress')
114 +
115 +case ${STATUS} in
116 + 1)
117 + resume
118 + ;;
119 + 0)
120 + commence $1
121 + ;;
122 + *)
123 + errorout "Invalid status \"${STATUS}\"."
124 + ;;
125 +esac