Teach format-patch, rebase and cherry a..b format
[git.git] / git-cherry
blobf14f017efeacdeef01ff871f4f2ff1949463ee90
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano.
6 . git-sh-setup-script || die "Not a git archive."
8 usage="usage: $0 "'<upstream> [<head>]
10 __*__*__*__*__> <upstream>
12 fork-point
13 \__+__+__+__+__+__+__+__> <head>
15 Each commit between the fork-point and <head> is examined, and
16 compared against the change each commit between the fork-point and
17 <upstream> introduces. If the change does not seem to be in the
18 upstream, it is shown on the standard output.
20 The output is intended to be used as:
22 OLD_HEAD=$(git-rev-parse HEAD)
23 git-rev-parse upstream >${GIT_DIR-.}/HEAD
24 git-cherry upstream $OLD_HEAD |
25 while read commit
27 GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p "$commit" &&
28 git-commit-script -C "$commit"
29 done
32 case "$#,$1" in
33 1,*..*)
34 upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
35 set x "$upstream" "$ours"
36 shift ;;
37 esac
39 case "$#" in
40 1) upstream=`git-rev-parse --verify "$1"` &&
41 ours=`git-rev-parse --verify HEAD` || exit
43 2) upstream=`git-rev-parse --verify "$1"` &&
44 ours=`git-rev-parse --verify "$2"` || exit
46 *) echo >&2 "$usage"; exit 1 ;;
47 esac
49 # Note that these list commits in reverse order;
50 # not that the order in inup matters...
51 inup=`git-rev-list ^$ours $upstream` &&
52 ours=`git-rev-list $ours ^$upstream` || exit
54 tmp=.cherry-tmp$$
55 patch=$tmp-patch
56 mkdir $patch
57 trap "rm -rf $tmp-*" 0 1 2 3 15
59 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
60 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
62 for c in $inup
64 git-diff-tree -p $c
65 done | git-patch-id |
66 while read id name
68 echo $name >>$patch/$id
69 done
71 LF='
75 for c in $ours
77 set x `git-diff-tree -p $c | git-patch-id`
78 if test "$2" != ""
79 then
80 if test -f "$patch/$2"
81 then
82 sign=-
83 else
84 sign=+
86 case "$O" in
87 '') O="$sign $c" ;;
88 *) O="$sign $c$LF$O" ;;
89 esac
91 done
92 case "$O" in
93 '') ;;
94 *) echo "$O" ;;
95 esac