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 - 17 过去 v1.7.11-rc2
|\
| * 3482b14 - 合并 git://github.com/ralfth/git-po-de - 5 过去 v1.7.11-rc2
| |\
| | * d7f22ed - l10n: de.po: 翻译 27 条新消息 - 3 过去 v1.7.11-rc2
| * | 6cb4571 - l10n:更新 po/vi.po 到 v1.7.11.rc2.2.gb694fbb - 3 过去 v1.7.11-rc2
| |/
| * b694fbb - l10n: zh_CN.po: 翻译 27 条新消息 - 2 条过去 v1.7.11-rc2
| * 7256fd7 - l10n:更新 git.pot(27 条新消息,1 条删除消息) - 1 过去 v1.7.11-rc2
* | 73a6e3c - 合并分支 'mm/api-credentials-doc' - 11 过去 v1.7.11-rc2
于 2012-06-12T18:00:20.460 回答