Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b261a8e

Browse files
committed
Include common header in all scripts
Build final scripts by concatenating common.sh with the script body.
1 parent ddbecf1 commit b261a8e

File tree

7 files changed

+218
-184
lines changed

7 files changed

+218
-184
lines changed

‎Makefile‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ LN = ln
77
BINS = \
88
git-dot \
99
git-synth \
10-
git-ptt
10+
git-ptt \
11+
git-set-message \
12+
git-mark
1113

1214
all: $(BINS)
1315

16+
git-mark: common.sh git-mark.in.sh
17+
cat $^ > $@
18+
chmod 755 $@
19+
20+
git-ptt: common.sh git-ptt.in.sh
21+
cat $^ > $@
22+
chmod 755 $@
23+
24+
git-set-message: common.sh git-set-message.in.sh
25+
cat $^ > $@
26+
chmod 755 $@
27+
1428
install: all
1529
$(INSTALL) -m 755 git-dot $(bindir)/
1630
$(INSTALL) -m 755 git-synth $(bindir)/

‎common.sh‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
verbose=0
4+
5+
DIE() {
6+
echo "ERROR: $*" >&2
7+
exit 1
8+
}
9+
10+
LOG() {
11+
local level=1ドル
12+
shift
13+
14+
if [[ $verbose -gt $level ]]; then
15+
echo "${0##*/}: $*" >&2
16+
fi
17+
}
18+
19+
set -eu

‎git-mark‎

Lines changed: 0 additions & 78 deletions
This file was deleted.

‎git-mark.in.sh‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
OPTS_SPEC="\
2+
${0##*/} [<options>] [<ref> [...]]
3+
4+
Mark or unmark the subject line of the named commits
5+
(or HEAD if unspecified).
6+
--
7+
h,help Show the help
8+
9+
m,mark Add the mark
10+
u,unmark Remove the mark
11+
M,set-mark=MARK Set the mark to MARK
12+
v,verbose Increase logging verbosity
13+
"
14+
15+
mark=$(git config --get --default WIP mark.default)
16+
17+
case 0ドル in
18+
(*unmark)
19+
mode=unmark
20+
;;
21+
22+
(*)
23+
mode=mark
24+
;;
25+
esac
26+
27+
eval "$(git rev-parse --parseopt -- "$@" <<<$OPTS_SPEC || echo exit $?)"
28+
29+
while (( $# > 0 )); do
30+
case 1ドル in
31+
(-u) mode=unmark
32+
shift
33+
;;
34+
35+
(-m) mode=mark
36+
shift
37+
;;
38+
39+
(-M) mark=2ドル
40+
shift 2
41+
;;
42+
43+
(-v) let verbose+=1
44+
shift
45+
;;
46+
47+
(--) shift
48+
break
49+
;;
50+
51+
(-*) DIE "unknown option: 1ドル"
52+
;;
53+
esac
54+
done
55+
56+
tmpdir=$(mktemp -d commitXXXXXX)
57+
trap "rm -rf $tmpdir" EXIT
58+
59+
for refspec in "${@:-HEAD}"; do
60+
rev=$(git rev-parse --verify -q ${refspec})
61+
[[ $rev ]] || DIE "invalid refspec: $refspec"
62+
63+
LOG 2 "processing $refspec ($rev)"
64+
65+
git cat-file -p $rev | sed '1,/^$/d' | tee $tmpdir/modified > $tmpdir/orig
66+
if [[ $mode == mark ]]; then
67+
if ! sed -n 1p $tmpdir/orig | grep -q '\['"$mark"']'; then
68+
sed '1 s/^/['"$mark"'] /' $tmpdir/orig > $tmpdir/modified
69+
fi
70+
else
71+
sed '1 s/^\['"$mark"'] //' $tmpdir/orig > $tmpdir/modified
72+
fi
73+
74+
if ! diff $tmpdir/orig $tmpdir/modified > /dev/null; then
75+
LOG 0 "modifying commit $refspec (${rev:0:10})"
76+
git set-message -F $tmpdir/modified $rev > $tmpdir/out 2> $tmpdir/err ||
77+
DIE "failed to modify mark: $(cat $tmpdir/err)"
78+
git show -q $(cat $tmpdir/out)
79+
fi
80+
done

‎git-ptt‎

Lines changed: 0 additions & 72 deletions
This file was deleted.

‎git-ptt.in.sh‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
OPTS_SPEC="\
2+
${0##*/} [<options>] <refspec>
3+
4+
Push a series of commits to multiple remote branches based
5+
on their x-branch trailer.
6+
--
7+
h,help Show the help
8+
9+
q,query Show targets but do not push
10+
f,force Push using --force-with-lease
11+
F,FORCE Push using --force
12+
v,verbose Increase logging verbosity
13+
r,remote=REMOTE Push to remote <REMOTE>
14+
"
15+
16+
force=
17+
remote=$(git config --get --default origin ptt.remote)
18+
query_only=0
19+
shortlen=10
20+
marker=x-branch
21+
22+
eval "$(git rev-parse --parseopt -- "$@" <<<$OPTS_SPEC || echo exit $?)"
23+
24+
while (( $# > 0 )); do
25+
case 1ドル in
26+
(-f) force="--force-with-lease"
27+
shift
28+
;;
29+
30+
(-F) force="--force"
31+
shift
32+
;;
33+
34+
(-r) remote="2ドル"
35+
shift 2
36+
;;
37+
38+
(-q) query_only=1
39+
shift
40+
;;
41+
42+
(-v) let verbose+=1
43+
shift
44+
;;
45+
46+
(--) shift
47+
break
48+
;;
49+
50+
(-*) DIE "unknown option: 1ドル"
51+
;;
52+
esac
53+
done
54+
shift $(( OPTIND - 1 ))
55+
56+
(( $# == 1 )) || DIE "missing refspec"
57+
58+
for rev in $(git rev-list "1ドル" | tac ); do
59+
LOG 2 "processing $rev"
60+
61+
target=($(git show $rev -q --format="%(trailers:key=${marker},valueonly=true)"))
62+
63+
if (( ${#target[*]} > 1 )); then
64+
DIE "multiple ${marker} directives in $rev"
65+
elif (( ${#target[*]} == 0 )); then
66+
continue
67+
fi
68+
69+
target_rev=$(git rev-parse --verify -q ${remote}/${target} || echo none)
70+
71+
if [[ $target_rev == $rev ]]; then
72+
target_rev_color=green
73+
else
74+
target_rev_color=red
75+
fi
76+
target_rev_fmt="%C${target_rev_color}${target_rev:0:$shortlen}%Creset"
77+
rev_fmt="${rev:0:$shortlen}"
78+
79+
git show -q --format="* %s%n ${rev_fmt} -> ${target_rev_fmt} %Cblue${remote}/${target}%Creset" $rev
80+
(( $query_only )) && continue
81+
git push ${force} ${remote} ${rev}:refs/heads/${target}
82+
done

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /