From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6E35F202BB for ; Tue, 12 Mar 2019 04:00:46 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 01/13] git: add "commit_title" method Date: Tue, 12 Mar 2019 04:00:34 +0000 Message-Id: <20190312040046.4619-2-e@80x24.org> In-Reply-To: <20190312040046.4619-1-e@80x24.org> References: <20190312040046.4619-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This will be useful for extracting titles/subjects from commit objects when displaying commits. --- lib/PublicInbox/Git.pm | 7 +++++++ t/solver_git.t | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index a756684..265c3fb 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 8de6398..6f0ce77 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: $!"; -- EW