36
36
shift
37
37
done
38
38
39
- base=$1 url=$2 head=${3-HEAD} status=0 branch_name=
40
-
41
- headref=$( git symbolic-ref -q " $head " )
42
- if git show-ref -q --verify " $headref "
43
- then
44
- branch_name=${headref# refs/ heads/ }
45
- if test " z$branch_name " = " z$headref " ||
46
- ! git config " branch.$branch_name .description" > /dev/null
47
- then
48
- branch_name=
49
- fi
50
- fi
51
-
52
- tag_name=$( git describe --exact " $head ^0" 2> /dev/null)
39
+ base=$1 url=$2 status=0
53
40
54
41
test -n " $base " && test -n " $url " || usage
55
42
59
46
die " fatal: Not a valid revision: $base "
60
47
fi
61
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
+ #
54
+ local=${3%:* }
55
+ local=${local:- HEAD}
56
+ remote=${3#*: }
57
+ pretty_remote=${remote# refs/ }
58
+ pretty_remote=${pretty_remote# heads/ }
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 " )}
62
+
63
+ # None of the above? Bad.
64
+ test -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..
62
68
headrev=$( git rev-parse --verify --quiet " $head " ^0)
63
- if test -z " $headrev "
69
+ test -z " $headrev " && die " fatal: Ambiguous revision: $local "
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
64
75
then
65
- die " fatal: Not a valid revision: $head "
76
+ branch_name=
66
77
fi
67
78
68
79
merge_base=$( git merge-base $baserev $headrev ) ||
69
80
die " fatal: No commits in common between $base and $head "
70
81
71
- # $head is the token given from the command line, and $tag_name, if
72
- # exists, is the tag we are going to show the commit information for.
73
- # If that tag exists at the remote and it points at the commit, use it.
74
- # Otherwise, if a branch with the same name as $head exists at the remote
75
- # and their values match, use that instead.
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.
76
85
#
77
86
# Otherwise find a random ref that matches $headrev.
78
87
find_matching_ref='
79
- sub abbr {
80
- my $ref = shift;
81
- if ($ref =~ s|^refs/heads/|| || $ref =~ s|^refs/tags/|tags/|) {
82
- return $ref;
83
- } else {
84
- return $ref;
85
- }
86
- }
88
+ my ($head,$headrev) = (@ARGV);
89
+ my ($found);
87
90
88
- my ($tagged, $branch, $found);
89
91
while (<STDIN>) {
90
- my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
91
- next unless ($sha1 eq $ARGV[1]);
92
- $found = abbr($ref);
93
- if ($deref && $ref eq "tags/$ARGV[2]") {
94
- $tagged = $found;
95
- last;
92
+ chomp;
93
+ my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
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;
96
103
}
97
- if ($ref =~ m|/\Q$ARGV[0]\E$| ) {
98
- $exact = $found ;
104
+ if ($sha1 eq $head ) {
105
+ $found = $sha1 ;
99
106
}
100
107
}
101
- if ($tagged) {
102
- print "$tagged\n";
103
- } elsif ($exact) {
104
- print "$exact\n";
105
- } elsif ($found) {
108
+ if ($found) {
106
109
print "$found\n";
107
110
}
108
111
'
109
112
110
- ref=$( git ls-remote " $url " | @@PERL@@ -e " $find_matching_ref " " $head " " $headrev " " $tag_name " )
113
+ ref=$( git ls-remote " $url " | @@PERL@@ -e " $find_matching_ref " " ${remote:- HEAD} " " $headrev " )
114
+
115
+ if test -z " $ref "
116
+ then
117
+ echo " warn: No match for commit $headrev found at $url " >&2
118
+ echo " warn: Are you sure you pushed '${remote:- HEAD} ' there?" >&2
119
+ status=1
120
+ fi
111
121
112
122
url=$( git ls-remote --get-url " $url " )
113
123
@@ -117,47 +127,31 @@ git show -s --format='The following changes since commit %H:
117
127
118
128
are available in the git repository at:
119
129
' $merge_base &&
120
- echo " $url ${ref+ $ref } " &&
130
+ echo " $url $pretty_remote " &&
121
131
git show -s --format='
122
132
for you to fetch changes up to %H:
123
133
124
134
%s (%ci)
125
135
126
136
----------------------------------------------------------------' $headrev &&
127
137
128
- if test -n " $branch_name "
138
+ if test $( git cat-file -t " $head " ) = tag
129
139
then
130
- echo " (from the branch description for $branch_name local branch)"
131
- echo
132
- git config " branch.$branch_name .description"
133
- fi &&
134
-
135
- if test -n " $tag_name "
136
- then
137
- if test -z " $ref " || test " $ref " ! = " tags/$tag_name "
138
- then
139
- echo >&2 " warn: You locally have $tag_name but it does not (yet)"
140
- echo >&2 " warn: appear to be at $url "
141
- echo >&2 " warn: Do you want to push it there, perhaps?"
142
- fi
143
- git cat-file tag " $tag_name " |
140
+ git cat-file tag " $head " |
144
141
sed -n -e ' 1,/^$/d' -e ' /^-----BEGIN PGP /q' -e p
145
142
echo
143
+ echo " ----------------------------------------------------------------"
146
144
fi &&
147
145
148
- if test -n " $branch_name " || test -n " $tag_name "
146
+ if test -n " $branch_name "
149
147
then
148
+ echo " (from the branch description for $branch_name local branch)"
149
+ echo
150
+ git config " branch.$branch_name .description"
150
151
echo " ----------------------------------------------------------------"
151
152
fi &&
152
153
153
154
git shortlog ^$baserev $headrev &&
154
155
git diff -M --stat --summary $patch $merge_base ..$headrev || status=1
155
156
156
- if test -z " $ref "
157
- then
158
- echo " warn: No branch of $url is at:" >&2
159
- git show -s --format=' warn: %h: %s' $headrev >&2
160
- echo " warn: Are you sure you pushed '$head ' there?" >&2
161
- status=1
162
- fi
163
157
exit $status
0 commit comments