]>
Commit | Line | Data |
---|---|---|
53dfac44 | 1 | #!/bin/sh |
ab421d2c RA |
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 | ||
3eb91bfc SN |
7 | USAGE='<start> <url> [<end>]' |
8 | LONG_USAGE='Summarizes the changes between two commits to the standard output, | |
9 | and includes the given URL in the generated summary.' | |
806f36d4 | 10 | SUBDIRECTORY_OK='Yes' |
50ab6558 | 11 | OPTIONS_KEEPDASHDASH= |
51ba8ce3 | 12 | OPTIONS_STUCKLONG= |
133cfaeb JH |
13 | OPTIONS_SPEC='git request-pull [options] start url [end] |
14 | -- | |
15 | p show patch text as well | |
16 | ' | |
17 | ||
806f36d4 | 18 | . git-sh-setup |
ab421d2c | 19 | |
653a31c1 MM |
20 | GIT_PAGER= |
21 | export GIT_PAGER | |
22 | ||
133cfaeb JH |
23 | patch= |
24 | while case "$#" in 0) break ;; esac | |
25 | do | |
26 | case "$1" in | |
27 | -p) | |
28 | patch=-p ;; | |
29 | --) | |
30 | shift; break ;; | |
31 | -*) | |
32 | usage ;; | |
33 | *) | |
34 | break ;; | |
35 | esac | |
36 | shift | |
37 | done | |
38 | ||
024d34cb | 39 | base=$1 url=$2 status=0 |
d0504645 | 40 | |
3c9f1e7c | 41 | test -n "$base" && test -n "$url" || usage |
ace33bf9 DW |
42 | |
43 | baserev=$(git rev-parse --verify --quiet "$base"^0) | |
44 | if test -z "$baserev" | |
45 | then | |
46 | die "fatal: Not a valid revision: $base" | |
47 | fi | |
48 | ||
024d34cb LT |
49 | # |
50 | # $3 must be a symbolic ref, a unique ref, or | |
dc2eacc5 LT |
51 | # a SHA object expression. It can also be of |
52 | # the format 'local-name:remote-name'. | |
024d34cb | 53 | # |
dc2eacc5 LT |
54 | local=${3%:*} |
55 | local=${local:-HEAD} | |
56 | remote=${3#*:} | |
5aae66bd JH |
57 | pretty_remote=${remote#refs/} |
58 | pretty_remote=${pretty_remote#heads/} | |
dc2eacc5 LT |
59 | head=$(git symbolic-ref -q "$local") |
60 | head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)} | |
61 | head=${head:-$(git rev-parse --quiet --verify "$local")} | |
024d34cb LT |
62 | |
63 | # None of the above? Bad. | |
dc2eacc5 | 64 | test -z "$head" && die "fatal: Not a valid revision: $local" |
024d34cb LT |
65 | |
66 | # This also verifies that the resulting head is unique: | |
67 | # "git show-ref" could have shown multiple matching refs.. | |
ace33bf9 | 68 | headrev=$(git rev-parse --verify --quiet "$head"^0) |
dc2eacc5 | 69 | test -z "$headrev" && die "fatal: Ambiguous revision: $local" |
024d34cb LT |
70 | |
71 | # Was it a branch with a description? | |
72 | branch_name=${head#refs/heads/} | |
73 | if test "z$branch_name" = "z$headref" || | |
74 | ! git config "branch.$branch_name.description" >/dev/null | |
ace33bf9 | 75 | then |
024d34cb | 76 | branch_name= |
ace33bf9 | 77 | fi |
ab421d2c | 78 | |
3c9f1e7c | 79 | merge_base=$(git merge-base $baserev $headrev) || |
ff06c743 SP |
80 | die "fatal: No commits in common between $base and $head" |
81 | ||
024d34cb LT |
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. | |
682853e6 JH |
85 | # |
86 | # Otherwise find a random ref that matches $headrev. | |
fe46fa9d | 87 | find_matching_ref=' |
dc2eacc5 LT |
88 | my ($head,$headrev) = (@ARGV); |
89 | my ($found); | |
fe46fa9d | 90 | |
fe46fa9d | 91 | while (<STDIN>) { |
dc2eacc5 | 92 | chomp; |
024d34cb | 93 | my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/; |
dc2eacc5 LT |
94 | my ($pattern); |
95 | next unless ($sha1 eq $headrev); | |
96 | ||
97 | $pattern="/$head\$"; | |
98 | if ($ref eq $head) { | |
99 | $found = $ref; | |
100 | } | |
101 | if ($ref =~ /$pattern/) { | |
102 | $found = $ref; | |
682853e6 | 103 | } |
dc2eacc5 | 104 | if ($sha1 eq $head) { |
024d34cb | 105 | $found = $sha1; |
fe46fa9d JH |
106 | } |
107 | } | |
dc2eacc5 | 108 | if ($found) { |
fe46fa9d JH |
109 | print "$found\n"; |
110 | } | |
111 | ' | |
112 | ||
dc2eacc5 | 113 | ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev") |
024d34cb LT |
114 | |
115 | if test -z "$ref" | |
116 | then | |
dc2eacc5 LT |
117 | echo "warn: No match for commit $headrev found at $url" >&2 |
118 | echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2 | |
024d34cb LT |
119 | status=1 |
120 | fi | |
fe46fa9d | 121 | |
d952cbb1 JH |
122 | # Special case: turn "for_linus" to "tags/for_linus" when it is correct |
123 | if test "$ref" = "refs/tags/$pretty_remote" | |
124 | then | |
125 | pretty_remote=tags/$pretty_remote | |
126 | fi | |
127 | ||
1a927775 | 128 | url=$(git ls-remote --get-url "$url") |
ff06c743 | 129 | |
10eb0007 | 130 | git show -s --format='The following changes since commit %H: |
ab421d2c | 131 | |
10eb0007 MV |
132 | %s (%ci) |
133 | ||
cf731666 | 134 | are available in the git repository at: |
b7e642ec | 135 | ' $merge_base && |
5aae66bd | 136 | echo " $url $pretty_remote" && |
cf731666 JH |
137 | git show -s --format=' |
138 | for you to fetch changes up to %H: | |
139 | ||
140 | %s (%ci) | |
141 | ||
142 | ----------------------------------------------------------------' $headrev && | |
ab421d2c | 143 | |
4b14ec87 | 144 | if test $(git cat-file -t "$head") = tag |
c0168147 | 145 | then |
4b14ec87 | 146 | git cat-file tag "$head" | |
d0504645 JH |
147 | sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p |
148 | echo | |
4b14ec87 | 149 | echo "----------------------------------------------------------------" |
d0504645 JH |
150 | fi && |
151 | ||
c0168147 | 152 | if test -n "$branch_name" |
d0504645 | 153 | then |
fe46fa9d | 154 | echo "(from the branch description for $branch_name local branch)" |
c0168147 JH |
155 | echo |
156 | git config "branch.$branch_name.description" | |
157 | echo "----------------------------------------------------------------" | |
158 | fi && | |
d0504645 | 159 | |
53dfac44 | 160 | git shortlog ^$baserev $headrev && |
cf731666 JH |
161 | git diff -M --stat --summary $patch $merge_base..$headrev || status=1 |
162 | ||
ff06c743 | 163 | exit $status |