1#!/bin/sh 2# Copyright 2005, Ryan Anderson <ryan@michonline.com> 3# 4# This file is licensed under the GPL v2, or a later version 5# at the discretion of Linus Torvalds. 6 7USAGE='<start> <url> [<end>]' 8LONG_USAGE='Summarizes the changes between two commits to the standard output, 9and includes the given URL in the generated summary.' 10SUBDIRECTORY_OK='Yes' 11OPTIONS_KEEPDASHDASH= 12OPTIONS_SPEC='git request-pull [options] start url [end] 13-- 14p show patch text as well 15' 16 17. git-sh-setup 18 19GIT_PAGER= 20export GIT_PAGER 21 22patch= 23while case"$#"in0)break;;esac 24do 25case"$1"in 26-p) 27patch=-p;; 28--) 29shift;break;; 30-*) 31 usage ;; 32*) 33break;; 34esac 35shift 36done 37 38base=$1 url=$2 status=0 39 40test -n"$base"&&test -n"$url"|| usage 41 42baserev=$(git rev-parse --verify --quiet "$base"^0) 43iftest -z"$baserev" 44then 45 die "fatal: Not a valid revision:$base" 46fi 47 48# 49# $3 must be a symbolic ref, a unique ref, or 50# a SHA object expression. It can also be of 51# the format 'local-name:remote-name'. 52# 53local=${3%:*} 54local=${local:-HEAD} 55remote=${3#*:} 56head=$(git symbolic-ref -q "$local") 57head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)} 58head=${head:-$(git rev-parse --quiet --verify "$local")} 59 60# None of the above? Bad. 61test -z"$head"&& die "fatal: Not a valid revision:$local" 62 63# This also verifies that the resulting head is unique: 64# "git show-ref" could have shown multiple matching refs.. 65headrev=$(git rev-parse --verify --quiet "$head"^0) 66test -z"$headrev"&& die "fatal: Ambiguous revision:$local" 67 68# Was it a branch with a description? 69branch_name=${head#refs/heads/} 70iftest"z$branch_name"="z$headref"|| 71! git config "branch.$branch_name.description">/dev/null 72then 73 branch_name= 74fi 75 76merge_base=$(git merge-base $baserev $headrev)|| 77die "fatal: No commits in common between$baseand$head" 78 79# $head is the refname from the command line. 80# If a ref with the same name as $head exists at the remote 81# and their values match, use that. 82# 83# Otherwise find a random ref that matches $headrev. 84find_matching_ref=' 85 my ($head,$headrev) = (@ARGV); 86 my ($found); 87 88 while (<STDIN>) { 89 chomp; 90 my ($sha1,$ref,$deref) = /^(\S+)\s+([^^]+)(\S*)$/; 91 my ($pattern); 92 next unless ($sha1eq$headrev); 93 94$pattern="/$head\$"; 95 if ($refeq$head) { 96$found=$ref; 97 } 98 if ($ref=~ /$pattern/) { 99$found=$ref; 100 } 101 if ($sha1eq$head) { 102$found=$sha1; 103 } 104 } 105 if ($found) { 106 print "$found\n"; 107 } 108' 109 110ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev") 111 112iftest -z"$ref" 113then 114echo"warn: No match for commit$headrevfound at$url">&2 115echo"warn: Are you sure you pushed '${remote:-HEAD}' there?">&2 116 status=1 117fi 118 119url=$(git ls-remote --get-url "$url") 120 121git show -s --format='The following changes since commit %H: 122 123 %s (%ci) 124 125are available in the git repository at: 126'$merge_base&& 127echo"$url$remote"&& 128git show -s --format=' 129for you to fetch changes up to %H: 130 131 %s (%ci) 132 133----------------------------------------------------------------'$headrev&& 134 135iftest$(git cat-file -t "$head")= tag 136then 137 git cat-file tag "$head"| 138sed-n -e'1,/^$/d'-e'/^-----BEGIN PGP /q'-e p 139echo 140echo"----------------------------------------------------------------" 141fi&& 142 143iftest -n"$branch_name" 144then 145echo"(from the branch description for$branch_namelocal branch)" 146echo 147 git config "branch.$branch_name.description" 148echo"----------------------------------------------------------------" 149fi&& 150 151git shortlog ^$baserev $headrev&& 152git diff-M --stat --summary$patch $merge_base..$headrev|| status=1 153 154exit$status