LoginSignup
5
5

More than 5 years have passed since last update.

リポジトリを横断してコミットメッセージを眺めるツールgglogを使ってみた

Posted at

はじめに

コミットメッセージを英語で書いていると、こういうときのコミットメッセージって前に書いたことがあったはずなんだけど、ということがちょくちょくあったりします。
そういうときは、過去のコミットログを漁っては参考にしたり、あるいはそのままコピペしたりするわけですが、参加しているプロジェクトが多岐に渡っていたりするような場合には、どのリポジトリにコミットときのものかそもそもあまりよく覚えていなかったりして、効率良くないなぁということがありました。

横断的にコミットメッセージを検索できたりすると良いですね、というわけですが、そういうものはすでにあってGroongaの公式サイトの利用例で紹介されているのが、gglogです。

gglogは全文検索エンジンGroongaとそのRubyバインディングであるRroongaを使っているソフトウェアです。

今回はそのgglogを簡単に紹介してみます。

gglogをインストールする

まずはインストールしてみましょう。gglogはgemとして公開されているので導入も簡単です。

gglogはRroongaを使っているので、まだインストールしていなければ、一緒にインストールされます。Rroongaのインストールは環境によって時間がかかるので、インストール時間を短縮したい場合には
rroongaを最速でインストールするには
も合わせて参照しておくといいでしょう。

% gem install gglog
Fetching: rugged-0.19.0.gem (100%)
Building native extensions.  This could take a while...
Successfully installed rugged-0.19.0
Fetching: rainbow-1.1.4.gem (100%)
Successfully installed rainbow-1.1.4
Fetching: pager-1.0.1.gem (100%)
Successfully installed pager-1.0.1
Fetching: gglog-0.0.3.gem (100%)
Successfully installed gglog-0.0.3
4 gems installed
  20.56s user 1.70s system 40% cpu 54.671 total

インストールができたら実行してみましょう。gglogのヘルプが表示されます。

% gglog
Commands:
  gglog help [COMMAND]                # Describe available commands or one specific command
  gglog list                          # List git repositories of gglog target
  gglog register [CLONE URL]          # Register git repository on clone url to gglog target
  gglog search [WORDS]                # Search commit message
  gglog show [REPOSITORY_NAME] [SHA]  # Show commit message
  gglog sync                          # Sync git repositories of gglog target

gglogにリポジトリを登録する

インストールが完了したら、次は検索対象となるリポジトリを登録します。
登録にはgglog registerコマンドを使います。試しにgroongaとmroongaのリポジトリを登録してみましょう。

% gglog register https://github.com/groonga/groonga.git
gglog register https://github.com/groonga/groonga.git  5.47s user 1.20s system 50% cpu 13.273 total
% gglog register https://github.com/mroonga/mroonga.git

登録が成功したか、gglog listで確認してみましょう。

% gglog list
groonga
mroonga

gglogで検索する

登録ができたら、実際に検索してみましょう。
検索するにはgglog searchを使います。
たとえば、語彙表などの文脈でよく使われる、lexiconで検索してみましょう。

% gglog search lexicon

検索結果はこんな感じになります。
実際のコミットメッセージの一部とそのコミット先のリポジトリ、ハッシュが表示されてます。

  * lib/ii.c (lexicon_delete): disabled.                                   groonga 4272075b20a3b3f7c904a62f6e3ae498cf98e7a3
  Fixed a problem in test_mroonga_index(). key_type for lexicon tabl ...   groonga a2c4b2756ad2e2c7f2842efd40984517eebe4850
  GRN_TABLE_NO_KEY type table can be used as lexicon.                      groonga 23db40415deebbea0d6db3e238dc8cac00e3d208
  doc en: fixes failed execution example for creating a lexicon table      groonga d482edb21c89767282af3b6d1b360b3ba0af1a7d
  Support using existing table as lexicon                                  mroonga e60b4a67e2e5a357ec6ed5c8091029963c826e72
  Support using existing table as lexicon for normal "INDEX"               mroonga f816161cc85a366b8c2c84d2bad2fbdd0869165d
  [wrapper] fix lexicon key type.                                          mroonga f628ca186cae52581abad86d4a652dc7b9e3ae53
  fix log message for creating lexicon table.                              mroonga 94024c48d58c2c64086d89b9bce4f0efe52b5eaa
  fixed table_flags for lexicon table to specify NORMALIZE. #627           mroonga 065bb05a8f19b06cc4cc141233e082d4c723f04f
  use NULL path for lexicon table.                                         mroonga ad8fb44ded428be6a1ddc772acaa3fafc173a6f6

個別のコミットログの詳細を確認するときは、gglog showを使います。
リポジトリとハッシュを追加で指定することで省略されている部分を確認することができます。

gglog show groonga a2c4b2756ad2e2c7f2842efd40984517eebe4850

実行すると次のようにコミットの内容が表示されます。

commit a2c4b2756ad2e2c7f2842efd40984517eebe4850
Author: mori <daijiro.mori@gmail.com>
Date:   Mon Jun 15 14:37:29 2009 +0900

    Fixed a problem in test_mroonga_index(). key_type for lexicon table must be assigned.

diff --git a/lib/db.c b/lib/db.c
index e831f29..b469126 100644
--- a/lib/db.c
+++ b/lib/db.c
@@ -5151,7 +5151,7 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr)
           if (x->header.domain == y->header.domain &&
               x->header.type == y->header.type &&
               GRN_BULK_VSIZE(x) == GRN_BULK_VSIZE(y) &&
-              !memcpy(GRN_BULK_HEAD(x), GRN_BULK_HEAD(y), GRN_BULK_VSIZE(x))) {
+              !memcmp(GRN_BULK_HEAD(x), GRN_BULK_HEAD(y), GRN_BULK_VSIZE(x))) {
             GRN_INT32_SET(ctx, res, 1);
           } else {
             GRN_INT32_SET(ctx, res, 0);
diff --git a/test/unit/core/test-expr.c b/test/unit/core/test-expr.c
index d433805..524e2fc 100644
...

リポジトリを同期するには、gglog syncを使います。

% gglog sync
Updating bd1f232..a6ac666
Fast-forward
 lib/ctx_impl.h                | 16 +++++++++++-----
 lib/ctx_impl_mrb.c            |  4 ++++
 lib/mrb/mrb_accessor.c        |  7 ++++---
 lib/mrb/mrb_column.c          | 39 +++++++++++++++++++++++++++++++++++++++
 lib/mrb/mrb_column.h          | 34 ++++++++++++++++++++++++++++++++++
 lib/mrb/mrb_ctx.c             | 38 ++++++++++++++++++++++++++++++++++++++
 lib/mrb/mrb_ctx.h             | 34 ++++++++++++++++++++++++++++++++++
 lib/mrb/mrb_obj.c             |  6 ++++--
 lib/mrb/scripts/expression.rb |  2 +-
 lib/mrb/sources.am            |  4 ++++
 10 files changed, 173 insertions(+), 11 deletions(-)
 create mode 100644 lib/mrb/mrb_column.c
 create mode 100644 lib/mrb/mrb_column.h
 create mode 100644 lib/mrb/mrb_ctx.c
 create mode 100644 lib/mrb/mrb_ctx.h
Updating 8fd9076..a145ebb
Fast-forward
 ha_mroonga.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

実行すると登録済みのリポジトリをすべて更新しているのがわかります。

まとめ

今回は、全文検索エンジンGroongaを使ったコミットメッセージの横断検索ツールであるgglogを紹介してみました。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5