[PATCH v2 29/44] ruby: request-pull: use native commit info

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---

Notes:
    We could use a bit more of the internal parsing in C, or we could export more,
    but there's no need to, parse_buffer() is relatively simple in Ruby.

 git-request-pull.rb | 47 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/git-request-pull.rb b/git-request-pull.rb
index 869f160..5f40901 100755
--- a/git-request-pull.rb
+++ b/git-request-pull.rb
@@ -1,5 +1,7 @@
 #!git ruby
 
+require 'date'
+
 ENV['GIT_PAGER'] =
 
 patch = ''
@@ -58,6 +60,25 @@ def get_ref(transport, head_ref, head_id, tag_name)
   return found
 end
 
+def parse_buffer(buffer)
+  summary = []
+  date = msg = nil
+  header, body = buffer.split("\n\n", 2)
+  header.each_line do |line|
+    case line
+    when /^committer ([^<>]+) <(\S+)> (.+)$/
+      date = DateTime.strptime($3, '%s %z')
+    end
+  end
+  body.each_line do |l|
+    break if (l.strip.empty?)
+    summary << l.chomp
+  end
+  summary = summary.join(' ')
+  date = date.strftime('%F %T %z')
+  return [summary, date]
+end
+
 until ARGV.empty?
   case ARGV.first
   when '-p'
@@ -103,7 +124,8 @@ head_commit = Git::Commit.get(head_id)
 merge_bases = get_merge_bases([base_commit, head_commit], 0);
 die "No commits in common between #{base} and #{head}" unless merge_bases
 
-merge_base = sha1_to_hex(merge_bases.first.sha1)
+merge_base_id = merge_bases.first.sha1
+merge_base_commit = Git::Commit.get(merge_base_id)
 
 remote = remote_get(url)
 transport = transport_get(remote, nil)
@@ -111,20 +133,25 @@ transport = transport_get(remote, nil)
 ref = get_ref(transport, head_ref != "HEAD" ? head_ref : nil, head_id, tag_name)
 url = remote.url.first
 
+merge_base_summary, merge_base_date = parse_buffer(merge_base_commit.buffer)
+head_summary, head_date = parse_buffer(head_commit.buffer)
+
 begin
-  run(%[git show -s --format='The following changes since commit %H:
+  puts "The following changes since commit %s:
 
-  %s (%ci)
+  %s (%s)
 
 are available in the git repository at:
-' #{merge_base}])
+
+" % [merge_base_commit, merge_base_summary, merge_base_date]
   puts "  #{url}" + (ref ? " #{ref}" : "")
-  run(%[git show -s --format='
-for you to fetch changes up to %H:
+  puts "
+for you to fetch changes up to %s:
 
-  %s (%ci)
+  %s (%s)
 
-----------------------------------------------------------------' #{head_commit}])
+----------------------------------------------------------------
+" % [head_commit, head_summary, head_date]
 
   if branch_name
     puts "(from the branch description for #{branch_name} local branch)"
@@ -147,11 +174,11 @@ for you to fetch changes up to %H:
   end
 
   run(%[git shortlog ^#{base} #{head}])
-  run(%[git diff -M --stat --summary #{patch} ^#{merge_base} #{head}])
+  run(%[git diff -M --stat --summary #{patch} ^#{merge_base_commit} #{head}])
 
   if ! ref
     $stderr.puts "warn: No branch of #{url} is at:"
-    run("git show -s --format='warn:   %h: %s' #{head} >&2")
+    $stderr.puts "warn:   %s: %s'" % [find_unique_abbrev(head_id, DEFAULT_ABBREV), head_summary]
     $stderr.puts "warn: Are you sure you pushed '#{abbr(head_ref)}' there?"
     status = 1
   end
-- 
1.8.4-fc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]