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