Skip to content

Commit 809275e

Browse files
committed
remove guilt dependency
Signed-off-by: MORITA Kazutaka <[email protected]>
1 parent 56f972e commit 809275e

17 files changed

+748
-119
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
INSTALL?=install
22

3-
SCRIPTS = $(filter-out $(wildcard *~),$(wildcard git-q*))
3+
SETUP_SCRIPT = git-qsh-setup
4+
GITQ_SCRIPTS = $(filter-out $(wildcard *~) $(SETUP_SCRIPT), $(wildcard git-q*))
45
GIT_EXEC_PATH = $(shell git --exec-path)
56

67
.PHONY: all
@@ -10,4 +11,5 @@ all:
1011

1112
.PHONY: install
1213
install:
13-
$(INSTALL) -m 755 $(SCRIPTS) $(GIT_EXEC_PATH)
14+
$(INSTALL) -m 755 $(GITQ_SCRIPTS) $(GIT_EXEC_PATH)
15+
$(INSTALL) -m 644 $(SETUP_SCRIPT) $(GIT_EXEC_PATH)

README

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
This repository includes some tiny wrappers for guilt (quilt for git).
1+
This repository includes a series of bash scripts which help to manage
2+
patch emails based on a Mercurial queues-like functionality.
3+
4+
The distinguishing features from other quilt-like tools are:
5+
6+
- Optimized for managing patch emails; a patch name is automaticaly
7+
generated from an email subject, and git-am is used instead of
8+
git-apply to push a patch.
9+
10+
- New and refresh are not provided for simplicity; we can do the same
11+
things more easily with git branch and rebase.
12+
13+
Example:
14+
15+
$ git qinit # initialize
16+
$ git qimport *.eml # import patch emails
17+
$ git qseries -e # arrange the patches in order
18+
$ git qpush # apply the patch
19+
$ git qcommit -a # commit the patch
20+
21+
--
22+
Copyright (C) 2013, MORITA Kazutaka <[email protected]>

bash_completion

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ _git_qpop()
66
return
77
esac
88

9-
__gitcomp "`guilt applied`"
9+
__gitcomp "`git qapplied`"
1010
}
1111

1212
_git_qpush()
@@ -17,7 +17,7 @@ _git_qpush()
1717
return
1818
esac
1919

20-
__gitcomp "`guilt unapplied`"
20+
__gitcomp "`git qunapplied`"
2121
}
2222

2323
_git_qcommit()
@@ -80,10 +80,10 @@ _git_qinit()
8080

8181
_git_qshow()
8282
{
83-
__gitcomp "`guilt series`"
83+
__gitcomp "`git qseries`"
8484
}
8585

8686
_git_qrename()
8787
{
88-
__gitcomp "`guilt series`"
88+
__gitcomp "`git qseries`"
8989
}

git-qapplied

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
#!/bin/bash
2+
#
3+
# Copyright (C) 2013 MORITA Kazutaka <[email protected]>
4+
#
5+
# This code is based on guilt-applied from Guilt (Git Quilt):
6+
# Copyright (c) Josef "Jeff" Sipek, 2006-2011
7+
#
28

3-
guilt applied $@
9+
. git-qsh-setup
10+
11+
USAGE="[-c]"
12+
13+
case $# in
14+
0)
15+
# just output the regular series-style applied list
16+
cat "$applied"
17+
;;
18+
19+
1)
20+
if [ "$1" != "-c" ]; then
21+
usage
22+
fi
23+
24+
for pname in $(cat "$applied"); do
25+
git show-ref refs/patches/$branch/$pname | sed -e "s,refs/patches/$branch/,,"
26+
done
27+
;;
28+
29+
*)
30+
usage
31+
;;
32+
esac

git-qcommit

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
#!/bin/bash
2+
#
3+
# Copyright (C) 2013 MORITA Kazutaka <[email protected]>
4+
#
5+
# This code is based on guilt-commit from Guilt (Git Quilt):
6+
# Copyright (c) Josef "Jeff" Sipek, 2008-2011
7+
#
28

3-
set -e
9+
. git-qsh-setup
410

5-
guilt commit $@
11+
USAGE=""
12+
13+
if [ $# -ne 0 ]; then
14+
usage
15+
fi
16+
17+
# if nothing's applied, exit
18+
[ `wc -l < "$applied"` -eq 0 ] && exit 0
19+
20+
# remove patch refs for what's being committed, and update series
21+
for pname in $(sed -n -e "1,\$p" "$applied"); do
22+
grep -v "^$pname$" < "$series" > "$series.tmp"
23+
mv "$series.tmp" "$series"
24+
echo "$pname" | remove_patch_refs
25+
done
26+
27+
truncate -s 0 "$applied"
628

729
# run gseries to cleanup merged patches
830
rest=$(git qseries)

git-qimport

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,52 @@
11
#!/bin/bash
2+
#
3+
# Copyright (C) 2013 MORITA Kazutaka <[email protected]>
4+
#
5+
# This code is based on guilt-import from Guilt (Git Quilt):
6+
# Copyright (c) Josef "Jeff" Sipek, 2007-2011
7+
#
8+
9+
. git-qsh-setup
10+
11+
USAGE="<file>..."
12+
13+
if [ $# -lt 1 ]; then
14+
usage
15+
fi
16+
17+
_import() {
18+
19+
newname="$1"
20+
oldname="$2"
21+
22+
# make sure that there are no unapplied changes
23+
if ! must_commit_first; then
24+
die "Uncommited changes detected. Refresh first."
25+
fi
26+
27+
if [ ! -e "$oldname" ]; then
28+
die "Specified file does not exist."
29+
fi
30+
31+
if [ -e "$GITQ_DIR/$branch/$newname" ]; then
32+
die "Already tracking a patch under that name."
33+
fi
34+
35+
cp "$oldname" "$GITQ_DIR/$branch/$newname"
36+
37+
# insert the patch into the series file
38+
cp "$series" "$series.tmp"
39+
echo "$newname" >> "$series.tmp"
40+
mv "$series.tmp" "$series"
41+
42+
echo "import $newname"
43+
}
244

345
for f in $@; do
446
name=$(sed ':loop; N; $!b loop; ;s/\n\t/,/g' $f | \
547
grep ^Subject: | \
648
sed -e 's/Subject: \(\[[^]]*\] \)*\[PATCH[^/]*\( \([0-9]*\/\)[0-9]*\)*\] /\3/' | \
749
sed 's/Subject: //' | \
850
tr ' /' '_' | sed 's/[^a-zA-Z0-9_]//g')
9-
guilt import -P $name $f
51+
_import $name $f
1052
done

git-qinit

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
#!/bin/bash
2+
#
3+
# Copyright (C) 2013 MORITA Kazutaka <[email protected]>
4+
#
5+
# This code is based on guilt-init from Guilt (Git Quilt):
6+
# Copyright (c) Josef "Jeff" Sipek, 2006-2011
7+
#
28

3-
guilt init $@
9+
DO_NOT_CHECK_BRANCH_EXISTENCE=1
10+
11+
. git-qsh-setup
12+
13+
USAGE=""
14+
15+
if [ $# -ne 0 ]; then
16+
usage
17+
fi
18+
19+
if [ -d "$GITQ_DIR/$branch" ]; then
20+
die "Branch $branch appears to be already initialized (GIT_DIR=$GIT_DIR)"
21+
fi
22+
23+
[ ! -d "$GITQ_DIR" ] && mkdir "$GITQ_DIR"
24+
mkdir -p "$GITQ_DIR/$branch"
25+
touch "$GITQ_DIR/$branch/series"
26+
touch "$GITQ_DIR/$branch/status"

git-qnext

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) 2013 MORITA Kazutaka <[email protected]>
4+
#
5+
# This code is based on guilt-next from Guilt (Git Quilt):
6+
# Copyright (c) Josef "Jeff" Sipek, 2006-2011
7+
#
8+
9+
. git-qsh-setup
10+
11+
USAGE="[-p|--path]"
12+
13+
while [ $# -ne 0 ]; do
14+
case "$1" in
15+
-p|--path)
16+
path="$GITQ_DIR/$branch/" ;;
17+
*)
18+
usage ;;
19+
esac
20+
shift
21+
done
22+
23+
n=`wc -l < "$applied"`
24+
n=$(($n + 1))
25+
26+
p=`awk "{ if (NR == $n) print \\$0}" "$series"`
27+
28+
if [ -n "$p" ]; then
29+
echo $path$p
30+
fi

git-qpick

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#!/bin/bash
2+
#
3+
# Copyright (C) 2013 MORITA Kazutaka <[email protected]>
4+
#
25

3-
set -e
6+
. git-qsh-setup
47

5-
must_commit_first()
6-
{
7-
git update-index --refresh --unmerged -q > /dev/null
8-
[ `git diff-files | wc -l` -eq 0 ] || return $?
9-
[ `git diff-index HEAD | wc -l` -eq 0 ]
10-
return $?
11-
}
8+
USAGE="[<hash> | <since>..[<until>] | ..<until>]"
129

10+
if [ $# -ne 1 ] || [ -z "$1" ]; then
11+
usage
12+
fi
13+
14+
rhash=`munge_hash_range $1`
15+
16+
# make sure that there are no unapplied changes
1317
if ! must_commit_first; then
14-
echo "Uncommited changes detected."
15-
return 1
18+
die "Uncommited changes detected."
1619
fi
1720

1821
DIR=$(mktemp -d)
19-
20-
c=$(git rev-list --no-walk $@)
21-
git format-patch -o $DIR --quiet $c^..$c
22+
git format-patch -o $DIR --quiet $rhash
2223
git qimport $DIR/*
23-
2424
rm -r $DIR

git-qpop

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,101 @@
11
#!/bin/bash
2+
#
3+
# Copyright (C) 2013 MORITA Kazutaka <[email protected]>
4+
#
5+
# This code is based on guilt-pop from Guilt (Git Quilt):
6+
# Copyright (c) Josef "Jeff" Sipek, 2006-2011
7+
#
28

3-
guilt pop $@
9+
. git-qsh-setup
10+
11+
USAGE="[-f] [-a | --all | -n <num> | <patchname>]"
12+
13+
while [ $# -gt 0 ]; do
14+
case "$1" in
15+
-f)
16+
force=t
17+
;;
18+
-a|--all)
19+
all=t
20+
;;
21+
-n)
22+
num=t
23+
;;
24+
*)
25+
break
26+
;;
27+
esac
28+
shift
29+
done
30+
31+
# "git qpop" or "git qpop foo" or "git qpop -n foo"
32+
if [ -z "$all" ] && [ $# -gt 1 ]; then
33+
usage
34+
fi
35+
36+
# "git qpop -n foo"
37+
if [ ! -z "$num" ]; then
38+
if [ $# -gt 1 ] || [ $# -eq 0 ]; then
39+
usage
40+
fi
41+
fi
42+
43+
# "git qpop -a"
44+
if [ ! -z "$all" ] && [ $# -gt 0 ]; then
45+
usage
46+
fi
47+
48+
patch="$1"
49+
[ ! -z "$all" ] && patch="-a"
50+
51+
if [ ! -s "$applied" ]; then
52+
echo "No patches applied."
53+
exit 0
54+
elif [ "$patch" = "-a" ]; then
55+
# we are supposed to pop all patches
56+
57+
sidx=`wc -l < "$applied"`
58+
eidx=0
59+
elif [ ! -z "$num" ]; then
60+
# we are supposed to pop a set number of patches
61+
62+
[ "$patch" -lt 0 ] && die "Invalid number of patches to pop."
63+
64+
sidx=`wc -l < "$applied"`
65+
eidx=`expr $sidx - $patch`
66+
67+
# catch underflow
68+
[ $eidx -lt 0 ] && eidx=0
69+
[ $eidx -eq $sidx ] && die "No patches requested to be removed."
70+
elif [ -z "$patch" ]; then
71+
# we are supposed to pop only the current patch on the stack
72+
73+
sidx=`wc -l < "$applied"`
74+
eidx=`expr $sidx - 1`
75+
else
76+
# we're supposed to pop only up to a patch, make sure the patch is
77+
# in the series
78+
79+
eidx=`cat "$applied" | grep -ne "^$patch$" | cut -d: -f 1`
80+
if [ -z "$eidx" ]; then
81+
die "Patch $patch is not in the series/is not applied"
82+
fi
83+
84+
eidx=`expr $eidx - 1`
85+
sidx=`wc -l < "$applied"`
86+
fi
87+
88+
# make sure that there are no unapplied changes
89+
# if we are forcing the pop, reset first
90+
if [ ! -z "$force" ]; then
91+
git reset --hard
92+
elif ! must_commit_first; then
93+
die "Uncommited changes detected. Refresh first."
94+
fi
95+
96+
l=`awk "BEGIN{n=0}(n==$eidx){print \\$0; exit}{n=n+1}END{}" < "$applied"`
97+
98+
pop_many_patches `git rev-parse refs/patches/$branch/$l^` `expr $sidx - $eidx`
99+
100+
p=`get_top`
101+
[ ! -z "$p" ] && echo "Now at $p." || echo "All patches popped."

0 commit comments

Comments
 (0)