Skip to content

Commit 750c36e

Browse files
Merge pull request #657 from libgit2/arthur/add-commit-summary
Add `Rugged::Commit#summary`
2 parents a202eaa + 4f5b900 commit 750c36e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

ext/rugged/rugged_commit.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ VALUE rb_cRuggedCommit;
1919
* commit.message -> msg
2020
*
2121
* Return the message of this commit. This includes the full body of the
22-
* message, with the short description, detailed descritpion, and any
22+
* message, with the short description, detailed description, and any
2323
* optional footers or signatures after it.
2424
*
2525
* In Ruby 1.9+, the returned string will be encoded with the encoding
@@ -44,6 +44,35 @@ static VALUE rb_git_commit_message_GET(VALUE self)
4444
return rb_enc_str_new(message, strlen(message), encoding);
4545
}
4646

47+
/*
48+
* call-seq:
49+
* commit.summary -> summary
50+
*
51+
* Return the short summary message of this commit.
52+
*
53+
* In Ruby 1.9+, the returned string will be encoded with the encoding
54+
* specified in the +Encoding+ header of the commit, if available.
55+
*
56+
* commit.message #=> "add a lot of RDoc docs\n\nthis includes docs for commit and blob"
57+
* commit.summary #=> "add a lot of RDoc docs"
58+
*/
59+
static VALUE rb_git_commit_summary_GET(VALUE self)
60+
{
61+
git_commit *commit;
62+
rb_encoding *encoding = rb_utf8_encoding();
63+
const char *encoding_name;
64+
const char *summary;
65+
66+
Data_Get_Struct(self, git_commit, commit);
67+
68+
summary = git_commit_summary(commit);
69+
encoding_name = git_commit_message_encoding(commit);
70+
if (encoding_name != NULL)
71+
encoding = rb_enc_find(encoding_name);
72+
73+
return rb_enc_str_new(summary, strlen(summary), encoding);
74+
}
75+
4776
/*
4877
* call-seq:
4978
* commit.committer -> signature
@@ -790,6 +819,7 @@ void Init_rugged_commit(void)
790819
rb_define_singleton_method(rb_cRuggedCommit, "extract_signature", rb_git_commit_extract_signature, -1);
791820

792821
rb_define_method(rb_cRuggedCommit, "message", rb_git_commit_message_GET, 0);
822+
rb_define_method(rb_cRuggedCommit, "summary", rb_git_commit_summary_GET, 0);
793823
rb_define_method(rb_cRuggedCommit, "epoch_time", rb_git_commit_epoch_time_GET, 0);
794824
rb_define_method(rb_cRuggedCommit, "committer", rb_git_commit_committer_GET, 0);
795825
rb_define_method(rb_cRuggedCommit, "author", rb_git_commit_author_GET, 0);

test/commit_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,20 @@ def test_create_with_signature
348348
raw_commit = Rugged::Commit::lookup(@repo, id1).read_raw.data
349349
assert_equal signed_commit, raw_commit
350350
end
351+
352+
def test_commit_summary
353+
person = {:name => 'Scott', :email => '[email protected]', :time => Time.now }
354+
355+
commit_id = Rugged::Commit.create(@repo,
356+
:message => "This is the commit message\n\nThis commit is created from Rugged",
357+
:committer => person,
358+
:author => person,
359+
:parents => [@repo.head.target],
360+
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
361+
362+
commit = Rugged::Commit.lookup(@repo, commit_id)
363+
assert_equal "This is the commit message", commit.summary
364+
end
351365
end
352366

353367
class CommitWriteTest < Rugged::TestCase

0 commit comments

Comments
 (0)