Skip to content

Commit 4282c4f

Browse files
author
Junio C Hamano
committed
Teach format-patch, rebase and cherry a..b format
Although these commands take only begin and end, not necessarily generic SHA1 expressions rev-parse supports, supporting a..b notation is good for consistency. This commit adds such without breaking backward compatibility. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32173e6 commit 4282c4f

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

git-cherry

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Copyright (c) 2005 Junio C Hamano.
44
#
55

6+
. git-sh-setup-script || die "Not a git archive."
7+
68
usage="usage: $0 "'<upstream> [<head>]
79
810
__*__*__*__*__> <upstream>
@@ -18,29 +20,36 @@ upstream, it is shown on the standard output.
1820
The output is intended to be used as:
1921
2022
OLD_HEAD=$(git-rev-parse HEAD)
21-
git-rev-parse linus >${GIT_DIR-.}/HEAD
22-
git-cherry linus OLD_HEAD |
23+
git-rev-parse upstream >${GIT_DIR-.}/HEAD
24+
git-cherry upstream $OLD_HEAD |
2325
while read commit
2426
do
2527
GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p "$commit" &&
2628
git-commit-script -C "$commit"
2729
done
2830
'
2931

32+
case "$#,$1" in
33+
1,*..*)
34+
upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
35+
set x "$upstream" "$ours"
36+
shift ;;
37+
esac
38+
3039
case "$#" in
31-
1) linus=`git-rev-parse --verify "$1"` &&
32-
junio=`git-rev-parse --verify HEAD` || exit
40+
1) upstream=`git-rev-parse --verify "$1"` &&
41+
ours=`git-rev-parse --verify HEAD` || exit
3342
;;
34-
2) linus=`git-rev-parse --verify "$1"` &&
35-
junio=`git-rev-parse --verify "$2"` || exit
43+
2) upstream=`git-rev-parse --verify "$1"` &&
44+
ours=`git-rev-parse --verify "$2"` || exit
3645
;;
3746
*) echo >&2 "$usage"; exit 1 ;;
3847
esac
3948

4049
# Note that these list commits in reverse order;
4150
# not that the order in inup matters...
42-
inup=`git-rev-list ^$junio $linus` &&
43-
ours=`git-rev-list $junio ^$linus` || exit
51+
inup=`git-rev-list ^$ours $upstream` &&
52+
ours=`git-rev-list $ours ^$upstream` || exit
4453

4554
tmp=.cherry-tmp$$
4655
patch=$tmp-patch

git-format-patch-script

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Copyright (c) 2005 Junio C Hamano
44
#
55

6+
. git-sh-setup-script || die "Not a git archive."
7+
68
usage () {
79
echo >&2 "usage: $0"' [-n] [-o dir] [--mbox] [--check] [-<diff options>...] upstream [ our-head ]
810
@@ -60,13 +62,20 @@ do
6062
shift
6163
done
6264

65+
revpair=
6366
case "$#" in
64-
2) linus="$1" junio="$2" ;;
65-
1) linus="$1" junio=HEAD ;;
66-
*) usage ;;
67+
2)
68+
revpair="$1..$2" ;;
69+
1)
70+
case "$1" in
71+
*..*)
72+
revpair="$1";;
73+
*)
74+
revpair="$1..HEAD";;
75+
esac ;;
76+
*)
77+
usage ;;
6778
esac
68-
junio=`git-rev-parse --verify "$junio"`
69-
linus=`git-rev-parse --verify "$linus"`
7079

7180
me=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'`
7281

@@ -108,7 +117,7 @@ _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
108117
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
109118
stripCommitHead='/^'"$_x40"' (from '"$_x40"')$/d'
110119

111-
git-rev-list --merge-order "$junio" "^$linus" >$series
120+
git-rev-list --merge-order $(git-rev-parse --revs-only "$revpair") >$series
112121
total=`wc -l <$series | tr -dc "[0-9]"`
113122
i=$total
114123
while read commit

git-rebase-script

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,40 @@
33
# Copyright (c) 2005 Junio C Hamano.
44
#
55

6+
. git-sh-setup-script || die "Not a git archive."
7+
68
usage="usage: $0 "'<upstream> [<head>]
79
810
Uses output from git-cherry to rebase local commits to the new head of
911
upstream tree.'
1012

11-
: ${GIT_DIR=.git}
13+
case "$#,$1" in
14+
1,*..*)
15+
upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
16+
set x "$upstream" "$ours"
17+
shift ;;
18+
esac
1219

1320
case "$#" in
14-
1) linus=`git-rev-parse --verify "$1"` &&
15-
junio=`git-rev-parse --verify HEAD` || exit
21+
1) upstream=`git-rev-parse --verify "$1"` &&
22+
ours=`git-rev-parse --verify HEAD` || exit
1623
;;
17-
2) linus=`git-rev-parse --verify "$1"` &&
18-
junio=`git-rev-parse --verify "$2"` || exit
24+
2) upstream=`git-rev-parse --verify "$1"` &&
25+
ours=`git-rev-parse --verify "$2"` || exit
1926
;;
2027
*) echo >&2 "$usage"; exit 1 ;;
2128
esac
2229

23-
git-read-tree -m -u $junio $linus &&
24-
echo "$linus" >"$GIT_DIR/HEAD" || exit
30+
git-read-tree -m -u $ours $upstream &&
31+
echo "$upstream" >"$GIT_DIR/HEAD" || exit
2532

2633
tmp=.rebase-tmp$$
2734
fail=$tmp-fail
2835
trap "rm -rf $tmp-*" 0 1 2 3 15
2936

3037
>$fail
3138

32-
git-cherry $linus $junio |
39+
git-cherry $upstream $ours |
3340
while read sign commit
3441
do
3542
case "$sign" in

0 commit comments

Comments
 (0)