Created
September 30, 2025 05:51
-
-
Save rainbow23/8362f049b6c5abbd07375f1c7ddeab80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 例: 既存のログ生成 → ブロック整形表示 | |
| git log --pretty=format:"%ad %H %an <%ae> %s" --date=format:"%Y-%m-%d %H:%M:%S" --name-status -- \ | |
| | awk ' | |
| # 対象: 「行頭が TARGET/NO_TARGET で、かつ日時 YYYY-MM-DD HH:MM:SS が続く」行だけ | |
| # それ以外の行は捨てる(必要なら {print} に変えてください) | |
| # TARGET 行 | |
| /^TARGET[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/ { | |
| # 日時を取り出す(先頭から2フィールド結合) | |
| tgt_date = $2 " " $3 | |
| # 40桁のコミットIDを抽出 | |
| if (match($0, /[0-9a-f]{40}/, m)) { | |
| tgt_id = m[0] | |
| if (!inblk) { # 新しいブロック開始 | |
| inblk = 1 | |
| start_date = tgt_date | |
| start_id = tgt_id | |
| } else { | |
| # 既にブロック中の追加TARGETは無視(先頭TARGETだけ使う) | |
| # 必要なら最後のTARGETを使うよう変更可 | |
| } | |
| } | |
| next | |
| } | |
| # NO_TARGET 行(ブロック終端) | |
| /^NO_TARGET[[:space:]]+[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/ { | |
| if (inblk) { | |
| no_date = $2 " " $3 | |
| no_id = "" | |
| if (match($0, /[0-9a-f]{40}/, m)) no_id = m[0] | |
| # 要求フォーマットで出力 | |
| print "TARGET " start_date " " start_id | |
| print "NO_TARGET " no_date " " no_id | |
| print "" # ブロック間を空行で区切る | |
| inblk = 0 | |
| start_date = start_id = "" | |
| } | |
| next | |
| } | |
| # それ以外は無視 | |
| { next } | |
| END{ | |
| # 末尾が TARGET のまま終わった場合の保険(NO_TARGETが無いブロック) | |
| if (inblk && start_date != "" && start_id != "") { | |
| print "TARGET " start_date " " start_id | |
| # NO_TARGET が無いので行は出さない(必要なら疑似NO_TARGETを出力する処理を追加) | |
| print "" | |
| } | |
| } | |
| ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment