9 usage: git request-pull [options] start url [end]
11 -p show patch text as well
17 def read_branch_desc(name)
18 git_config() do |key, value|
19 return value if key == "branch.#{name}.description"
25 for_each_ref() do |name, sha1, flags|
26 next unless name.start_with?('refs/tags/')
27 next unless peel_ref(name) == get_sha1(rev)
28 return name.skip_prefix('refs/tags/')
34 if (ref =~ %r{^refs/heads/(.*)} || ref =~ %r{^refs/(tags/.*)})
40 # $head is the token given from the command line, and $tag_name, if
41 # exists, is the tag we are going to show the commit information for.
42 # If that tag exists at the remote and it points at the commit, use it.
43 # Otherwise, if a branch with the same name as $head exists at the remote
44 # and their values match, use that instead.
46 # Otherwise find a random ref that matches $head_id.
48 def get_ref(transport, head_ref, head_id, tag_name)
50 transport.get_remote_refs().each do |e|
52 next unless sha1 == head_id
53 ref, deref = e.name.scan(/^(\S+?)(\^\{\})?$/).first
55 break if (deref && ref == "refs/tags/#{tag_name}")
56 break if ref == head_ref
61 def parse_buffer(buffer)
64 header, body = buffer.split("\n\n", 2)
65 header.each_line do |line|
67 when /^committer ([^<>]+) <(\S+)> (.+)$/
68 date = DateTime.strptime($3, '%s %z')
72 break if (l.strip.empty?)
75 summary = summary.join(' ')
76 date = date.strftime('%F %T %z')
77 return [summary, date]
80 def show_shortlog(base, head)
81 rev = Git::RevInfo.setup(nil, ['^' + base, head], nil)
85 def show_diff(patch, base, head)
86 rev = Git::RevInfo.setup(nil, ['^' + sha1_to_hex(base), sha1_to_hex(head)], nil)
87 rev.diffopt.stat_width = -1
88 rev.diffopt.stat_graph_width = -1
89 rev.diffopt.output_format = patch ? DIFF_FORMAT_PATCH : DIFF_FORMAT_DIFFSTAT
90 rev.diffopt.output_format |= DIFF_FORMAT_SUMMARY
91 rev.diffopt.detect_rename = DIFF_DETECT_RENAME
92 rev.diffopt.flags |= DIFF_OPT_RECURSIVE
94 diff_tree_sha1(base, head, "", rev.diffopt)
95 log_tree_diff_flush(rev)
115 head = ARGV[2] || 'HEAD'
116 branch_name = branch_desc = nil
118 usage unless base or url
120 _, _, head_ref = dwim_ref(head)
122 if head_ref.start_with?('refs/heads')
123 branch_name = head_ref[11..-1]
124 branch_desc = read_branch_desc(branch_name)
125 branch_name = nil if not branch_desc
128 tag_name = describe(head)
130 base_id = get_sha1("#{base}^0")
131 die "Not a valid revision: #{base}" unless base_id
133 head_id = get_sha1("#{head}^0")
134 die "Not a valid revision: #{head}" unless head_id
136 base_commit = Git::Commit.get(base_id)
137 head_commit = Git::Commit.get(head_id)
139 merge_bases = get_merge_bases([base_commit, head_commit], 0);
140 die "No commits in common between #{base} and #{head}" unless merge_bases
142 merge_base_id = merge_bases.first.sha1
143 merge_base_commit = Git::Commit.get(merge_base_id)
145 remote = remote_get(url)
146 transport = transport_get(remote, nil)
148 ref = get_ref(transport, head_ref != "HEAD" ? head_ref : nil, head_id, tag_name)
149 url = remote.url.first
151 merge_base_summary, merge_base_date = parse_buffer(merge_base_commit.buffer)
152 head_summary, head_date = parse_buffer(head_commit.buffer)
154 puts "The following changes since commit %s:
158 are available in the git repository at:
160 " % [merge_base_commit, merge_base_summary, merge_base_date]
161 puts " #{url}" + (ref ? " #{ref}" : "")
163 for you to fetch changes up to %s:
167 ----------------------------------------------------------------
168 " % [head_commit, head_summary, head_date]
171 puts "(from the branch description for #{branch_name} local branch)"
177 if ref != "tags/#{tag_name}"
178 $stderr.puts "warn: You locally have #{tag_name} but it does not (yet)"
179 $stderr.puts "warn: appear to be at #{url}"
180 $stderr.puts "warn: Do you want to push it there, perhaps?"
182 buffer, _ = read_sha1_file(get_sha1(tag_name))
183 puts buffer.scan(/(?:\n\n)(.+)(?:-----BEGIN PGP )?/m).first
187 if branch_name || tag_name
188 puts "----------------------------------------------------------------"
191 show_shortlog(base, head)
192 show_diff(patch, merge_base_id, head_id)
195 $stderr.puts "warn: No branch of #{url} is at:"
196 $stderr.puts "warn: %s: %s'" % [find_unique_abbrev(head_id, DEFAULT_ABBREV), head_summary]
197 $stderr.puts "warn: Are you sure you pushed '#{abbr(head_ref)}' there?"