git-cherry.shon commit Built git-upload-tar should be ignored. (4acdeaf)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano.
   4#
   5
   6USAGE='[-v] <upstream> [<head>] [<limit>]'
   7LONG_USAGE='             __*__*__*__*__> <upstream>
   8            /
   9  fork-point
  10            \__+__+__+__+__+__+__+__> <head>
  11
  12Each commit between the fork-point (or <limit> if given) and <head> is
  13examined, and compared against the change each commit between the
  14fork-point and <upstream> introduces.  If the change seems to be in
  15the upstream, it is shown on the standard output with prefix "+".
  16Otherwise it is shown with prefix "-".'
  17. git-sh-setup
  18
  19case "$1" in -v) verbose=t; shift ;; esac 
  20
  21case "$#,$1" in
  221,*..*)
  23    upstream=$(expr "z$1" : 'z\(.*\)\.\.') ours=$(expr "z$1" : '.*\.\.\(.*\)$')
  24    set x "$upstream" "$ours"
  25    shift ;;
  26esac
  27
  28case "$#" in
  291) upstream=`git-rev-parse --verify "$1"` &&
  30   ours=`git-rev-parse --verify HEAD` || exit
  31   limit="$upstream"
  32   ;;
  332) upstream=`git-rev-parse --verify "$1"` &&
  34   ours=`git-rev-parse --verify "$2"` || exit
  35   limit="$upstream"
  36   ;;
  373) upstream=`git-rev-parse --verify "$1"` &&
  38   ours=`git-rev-parse --verify "$2"` &&
  39   limit=`git-rev-parse --verify "$3"` || exit
  40   ;;
  41*) usage ;;
  42esac
  43
  44# Note that these list commits in reverse order;
  45# not that the order in inup matters...
  46inup=`git-rev-list ^$ours $upstream` &&
  47ours=`git-rev-list $ours ^$limit` || exit
  48
  49tmp=.cherry-tmp$$
  50patch=$tmp-patch
  51mkdir $patch
  52trap "rm -rf $tmp-*" 0 1 2 3 15
  53
  54_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  55_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
  56
  57for c in $inup
  58do
  59        git-diff-tree -p $c
  60done | git-patch-id |
  61while read id name
  62do
  63        echo $name >>$patch/$id
  64done
  65
  66LF='
  67'
  68
  69O=
  70for c in $ours
  71do
  72        set x `git-diff-tree -p $c | git-patch-id`
  73        if test "$2" != ""
  74        then
  75                if test -f "$patch/$2"
  76                then
  77                        sign=-
  78                else
  79                        sign=+
  80                fi
  81                case "$verbose" in
  82                t)
  83                        c=$(git-rev-list --pretty=oneline --max-count=1 $c)
  84                esac
  85                case "$O" in
  86                '')     O="$sign $c" ;;
  87                *)      O="$sign $c$LF$O" ;;
  88                esac
  89        fi
  90done
  91case "$O" in
  92'') ;;
  93*)  echo "$O" ;;
  94esac