1

の出力を追加するにはどうすればよいですか

# Get tag distance $(TAGDIST) 
git describe --tags | \
awk '{split($0,TagNameWithTagDist,"-g");
     i=split(TagNameWithTagDist[1],TagDist,"-");
     print(TagDist[i]);}'

次の出力に?

git log --graph --format=format:'%h - %s + $TAGDIST'

ドキュメントの「Pretty Formats」セクションに、この値に対応するプレースホルダーがありません。git-logプレースホルダー%dは、それが作成されたコミットのタグ名のみを示します。

4

1 に答える 1

1

以下のコードを、パス内のディレクトリにある名前のファイルとしてコピーしgit-logtagdistます。git-describeコミットごとに新しいプロセスをフォークするため、実行速度が遅いことに注意してください。実行をバッチ処理することで高速化できgit-describeます。

#! /usr/bin/env perl

use strict;
use warnings;

use Git;

my $repo = Git->repository;

my @logcmd = (
  "log", "--color=always", "--graph",
  "--format=format:%h - %s - !!!DISTANCE!!!",
);

my($fh,$ctx) = $repo->command_output_pipe(@logcmd);

if (-t STDOUT) {
  my(@pager) = $ENV{GIT_PAGER} || $ENV{PAGER} || ("less", "-R");
  open STDOUT, "|-", @pager or die "$0: open: $!";
}

while (<$fh>) {
  # e.g., 797166c - Merge branch 'maint' - !!!DISTANCE!!!
  s<([0-9a-f]{7,})\b(.+ - )!!!DISTANCE!!!> {
    my($sha1,$msg) = ($1,$2);
    my $distance;

    # e.g., v1.7.9.2-334-g797166c
    chomp(my $describe = $repo->command("describe", "--tags", $sha1));
    if ($describe =~ /^(.+?)-([0-9]+)-g/) {
      $distance = "$2 past $1";
    }
    else {
      $distance = "tagged: $describe";
    }

    $sha1 . $msg . $distance;
  }e;

  print;
}

close STDOUT or warn "$0: close: $!";

出力例:

$ git logtagdist
* 9bea2b5 - Git 1.7.11-rc3 - タグ: v1.7.11-rc3
* 3a2c135 - git://github.com/git-l10n/git-po をマージ - v1.7.11-rc2 から 17 年後
|\
| | * 3482b14 - git://github.com/ralfth/git-po-de をマージ - v1.7.11-rc2 から 5 年後
| | |\
| | | | * d7f22ed - l10n: de.po: 27 件の新しいメッセージを翻訳 - v1.7.11-rc2 から 3 件
| | * | | 6cb4571 - l10n: po/vi.po を v1.7.11.rc2.2.gb694fbb に更新 - v1.7.11-rc2 の 3 つ前
| | |/
| | * b694fbb - l10n: zh_CN.po: 27 件の新しいメッセージを翻訳 - v1.7.11-rc2 から 2 件分
| | * 7256fd7 - l10n: git.pot を更新 (27 件の新規メッセージ、1 件の削除メッセージ) - 1 件過去の v1.7.11-rc2
* | | 73a6e3c - ブランチ 'mm/api-credentials-doc' をマージ - v1.7.11-rc2 から 11 年経過
于 2012-06-12T18:00:20.460 に答える