]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: add "commit_title" method
authorEric Wong <e@80x24.org>
Sun, 17 Feb 2019 05:09:50 +0000 (05:09 +0000)
committerEric Wong <e@80x24.org>
Thu, 4 Apr 2019 09:13:57 +0000 (09:13 +0000)
This will be useful for extracting titles/subjects from
commit objects when displaying commits.

lib/PublicInbox/Git.pm
t/solver_git.t

index a756684a70355b6435b26b753f1dc6593e5481fa..265c3fb4507a1173de3d485d6de5cf332976a335 100644 (file)
@@ -296,6 +296,13 @@ sub pub_urls {
        local_nick($self);
 }
 
+sub commit_title ($$) {
+       my ($self, $oid) = @_; # PublicInbox::Git, $sha1hex
+       my $buf = cat_file($self, $oid) or return;
+       utf8::decode($$buf);
+       ($$buf =~ /\r?\n\r?\n([^\r\n]+)\r?\n?/)[0]
+}
+
 1;
 __END__
 =pod
index 8de63988e9c51ce677a41b2e9752891b8824f2cc..6f0ce777477b65a3a2ccdf41e612dc69095324b2 100644 (file)
@@ -40,7 +40,14 @@ sub deliver_patch ($) {
 
 deliver_patch('t/solve/0001-simple-mod.patch');
 
-$ibx->{-repo_objs} = [ PublicInbox::Git->new($git_dir) ];
+my $git = PublicInbox::Git->new($git_dir);
+is('public-inbox 1.0.0',
+       $git->commit_title('cb7c42b1e15577ed2215356a2bf925aef59cdd8d'),
+       'commit_title works on 1.0.0');
+
+is(undef, $git->commit_title('impossible'), 'undef on impossible object');
+
+$ibx->{-repo_objs} = [ $git ];
 my $res;
 my $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
 open my $log, '+>>', "$mainrepo/solve.log" or die "open: $!";