about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-02-17 05:09:50 +0000
committerEric Wong <e@80x24.org>2019-04-04 09:13:57 +0000
commitc9890ef809425a3607c2f1108eb19c30aa0f077b (patch)
treec471917fee0160e906a90d68483abda631afccaf
parent2537d9dd897a87f4149fe5dccfd11f6d1f1e2d8e (diff)
downloadpublic-inbox-c9890ef809425a3607c2f1108eb19c30aa0f077b.tar.gz
This will be useful for extracting titles/subjects from
commit objects when displaying commits.
-rw-r--r--lib/PublicInbox/Git.pm7
-rw-r--r--t/solver_git.t9
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index a756684a..265c3fb4 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -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
diff --git a/t/solver_git.t b/t/solver_git.t
index 8de63988..6f0ce777 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -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: $!";