git-request-pull.shon commit git-p4: don't groom exclude path list on every commit (ff8c50e)
   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
   7SUBDIRECTORY_OK='Yes'
   8OPTIONS_KEEPDASHDASH=
   9OPTIONS_STUCKLONG=
  10OPTIONS_SPEC='git request-pull [options] start url [end]
  11--
  12p    show patch text as well
  13'
  14
  15. git-sh-setup
  16
  17GIT_PAGER=
  18export GIT_PAGER
  19
  20patch=
  21while   case "$#" in 0) break ;; esac
  22do
  23        case "$1" in
  24        -p)
  25                patch=-p ;;
  26        --)
  27                shift; break ;;
  28        -*)
  29                usage ;;
  30        *)
  31                break ;;
  32        esac
  33        shift
  34done
  35
  36base=$1 url=$2 status=0
  37
  38test -n "$base" && test -n "$url" || usage
  39
  40baserev=$(git rev-parse --verify --quiet "$base"^0)
  41if test -z "$baserev"
  42then
  43    die "fatal: Not a valid revision: $base"
  44fi
  45
  46#
  47# $3 must be a symbolic ref, a unique ref, or
  48# a SHA object expression. It can also be of
  49# the format 'local-name:remote-name'.
  50#
  51local=${3%:*}
  52local=${local:-HEAD}
  53remote=${3#*:}
  54pretty_remote=${remote#refs/}
  55pretty_remote=${pretty_remote#heads/}
  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/}
  70if test "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 $base and $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 ($sha1 eq $headrev);
  93
  94                $pattern="/$head\$";
  95                if ($ref eq $head) {
  96                        $found = $ref;
  97                }
  98                if ($ref =~ /$pattern/) {
  99                        $found = $ref;
 100                }
 101                if ($sha1 eq $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
 112if test -z "$ref"
 113then
 114        echo "warn: No match for commit $headrev found at $url" >&2
 115        echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
 116        status=1
 117fi
 118
 119# Special case: turn "for_linus" to "tags/for_linus" when it is correct
 120if test "$ref" = "refs/tags/$pretty_remote"
 121then
 122        pretty_remote=tags/$pretty_remote
 123fi
 124
 125url=$(git ls-remote --get-url "$url")
 126
 127git show -s --format='The following changes since commit %H:
 128
 129  %s (%ci)
 130
 131are available in the Git repository at:
 132' $merge_base &&
 133echo "  $url $pretty_remote" &&
 134git show -s --format='
 135for you to fetch changes up to %H:
 136
 137  %s (%ci)
 138
 139----------------------------------------------------------------' $headrev &&
 140
 141if test $(git cat-file -t "$head") = tag
 142then
 143        git cat-file tag "$head" |
 144        sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
 145        echo
 146        echo "----------------------------------------------------------------"
 147fi &&
 148
 149if test -n "$branch_name"
 150then
 151        echo "(from the branch description for $branch_name local branch)"
 152        echo
 153        git config "branch.$branch_name.description"
 154        echo "----------------------------------------------------------------"
 155fi &&
 156
 157git shortlog ^$baserev $headrev &&
 158git diff -M --stat --summary $patch $merge_base..$headrev || status=1
 159
 160exit $status