Fix git-fetch-script breakage
[git/gitweb.git] / git-cherry
blobe2a1a2db9fda633c174c25df76d4307ec33ff643
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano.
6 usage="usage: $0 "'<upstream> [<head>]
8 __*__*__*__*__> <upstream>
10 fork-point
11 \__+__+__+__+__+__+__+__> <head>
13 Each commit between the fork-point and <head> is examined, and
14 compared against the change each commit between the fork-point and
15 <upstream> introduces. If the change does not seem to be in the
16 upstream, it is shown on the standard output.
18 The output is intended to be used as:
20 OLD_HEAD=$(git-rev-parse HEAD)
21 git-rev-parse linus >${GIT_DIR-.}/HEAD
22 git-cherry linus OLD_HEAD |
23 while read commit
25 GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p "$commit" &&
26 git-commit-script -m "$commit"
27 done
30 case "$#" in
31 1) linus=`git-rev-parse "$1"` &&
32 junio=`git-rev-parse HEAD` || exit
34 2) linus=`git-rev-parse "$1"` &&
35 junio=`git-rev-parse "$2"` || exit
37 *) echo >&2 "$usage"; exit 1 ;;
38 esac
40 # Note that these list commits in reverse order;
41 # not that the order in inup matters...
42 inup=`git-rev-list ^$junio $linus` &&
43 ours=`git-rev-list $junio ^$linus` || exit
45 tmp=.cherry-tmp$$
46 patch=$tmp-patch
47 mkdir $patch
48 trap "rm -rf $tmp-*" 0 1 2 3 15
50 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
51 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
53 for c in $inup
55 git-diff-tree -p $c
56 done | git-patch-id |
57 while read id name
59 echo $name >>$patch/$id
60 done
62 LF='
66 for c in $ours
68 set x `git-diff-tree -p $c | git-patch-id`
69 if test "$2" != ""
70 then
71 if test -f "$patch/$2"
72 then
73 sign=-
74 else
75 sign=+
77 case "$O" in
78 '') O="$sign $c" ;;
79 *) O="$sign $c$LF$O" ;;
80 esac
82 done
83 case "$O" in
84 '') ;;
85 *) echo "$O" ;;
86 esac