[PATCH] Also parse objects we already have
[alt-git.git] / git-cherry
blobe186363647e2dcf0ecd72efb3cd609dde6a672bf
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano.
6 . git-sh-setup-script || die "Not a git archive."
8 usage="usage: $0 "'[-v] <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 -v) verbose=t; shift ;; esac
34 case "$#,$1" in
35 1,*..*)
36 upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
37 set x "$upstream" "$ours"
38 shift ;;
39 esac
41 case "$#" in
42 1) upstream=`git-rev-parse --verify "$1"` &&
43 ours=`git-rev-parse --verify HEAD` || exit
45 2) upstream=`git-rev-parse --verify "$1"` &&
46 ours=`git-rev-parse --verify "$2"` || exit
48 *) echo >&2 "$usage"; exit 1 ;;
49 esac
51 # Note that these list commits in reverse order;
52 # not that the order in inup matters...
53 inup=`git-rev-list ^$ours $upstream` &&
54 ours=`git-rev-list $ours ^$upstream` || exit
56 tmp=.cherry-tmp$$
57 patch=$tmp-patch
58 mkdir $patch
59 trap "rm -rf $tmp-*" 0 1 2 3 15
61 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
62 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
64 for c in $inup
66 git-diff-tree -p $c
67 done | git-patch-id |
68 while read id name
70 echo $name >>$patch/$id
71 done
73 LF='
77 for c in $ours
79 set x `git-diff-tree -p $c | git-patch-id`
80 if test "$2" != ""
81 then
82 if test -f "$patch/$2"
83 then
84 sign=-
85 else
86 sign=+
88 case "$verbose" in
90 c=$(git-rev-list --pretty=oneline --max-count=1 $c)
91 esac
92 case "$O" in
93 '') O="$sign $c" ;;
94 *) O="$sign $c$LF$O" ;;
95 esac
97 done
98 case "$O" in
99 '') ;;
100 *) echo "$O" ;;
101 esac