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