-
-
Save zhang-ning/a8cdb9432b0caa831bc7b039a7e8b64d to your computer and use it in GitHub Desktop.
Revisions
-
overengineer revised this gist
Jul 20, 2022 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ #!/usr/bin/env bash # Caution: It can break # Bash unofficial strict mode set -euo pipefail IFS=$'\n\t' -
overengineer revised this gist
Oct 10, 2021 . 1 changed file with 12 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -32,24 +32,24 @@ define TMPL << 'EOF' } EOF function sanitize () { # strip newlines, strip all whitespace, escape newline sed -E -e ':a' -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' -e 's/^\s+|\s+$//g' -e ':a;N;$!ba;s/\n/\\n/g' \ | sed -E -e 's/%/%%/g' -e 's/"/\\"/g' -e 's/\\\\/\\/g' -e 's/\t/\\t/g' -e 's/\\([^nt"])/\\\\\1/g' -e 's/[\x00-\x1f]//g' | tr -d '\r\0\t' # escape percent sign for template, escape quotes, escape backslash, escape tabs, fix double escapes, delete control characters } function field () { git show -s --format="$1" "$2" | sanitize } git log --pretty=format:'%H' | while IFS='' read -r hash; do TMP="$TMPL" msg=$(field "%B" $hash) author=$(field "%aN" $hash) commiter=$(field "%cN" $hash) TMP="${TMP/MSG/$msg}" TMP="${TMP/AUTHOR/$author}" TMP="${TMP/COMMITER/$commiter}" git show $hash -s --format="$TMP" done -
overengineer revised this gist
Oct 1, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #!/usr/bin/env bash # Bash unofficial strict mode set -euo pipefail -
overengineer revised this gist
Oct 1, 2021 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ # Bash unofficial strict mode set -euo pipefail IFS=$'\n\t' LANG='' -
overengineer revised this gist
Oct 1, 2021 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ set -euo pipefail # http://www.dwheeler.com/essays/filenames-in-shell.html IFS=$'\n\t' LANG='' function define() { IFS='\n' read -r -d '' ${1} || true; } @@ -34,12 +35,12 @@ EOF function strip () { # strip newlines then strip all whitespace sed -e ':a' -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' | sed -E 's/^\s+|\s+$//g' } function sanitize () { # escape newline, escape quotes, escape backslash, escape tabs, fix double escapes, delete invalid characters sed ':a;N;$!ba;s/\n/\\n/g' | sed -e 's/"/\\"/g' -e 's/\\\\/\\/g' -e 's/\t/\\t/g' | sed -E 's/\\([^nt"])/\\\\\1/g' | tr -d '\r\0\t' | sed -E 's/[\x00-\x1f]//g' } function field () { -
overengineer revised this gist
Sep 30, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ function strip () { function sanitize () { # escape newline, escape quotes, escape backslash, escape tabs, fix double escapes, delete invalid characters sed ':a;N;$!ba;s/\n/\\n/g' | sed -e 's/"/\\"/g' -e 's/\\\\/\\/g' -e 's/\t/\\t/g' | sed -E 's/\\([^nt"])/\\\\\1/g' | tr -d '\r\0\t' | sed -E 's/[\x00-\x1f]//g'; } function field () { -
overengineer revised this gist
Sep 30, 2021 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -52,8 +52,4 @@ git log --pretty=format:'%H' | while IFS='' read -r hash; do TMP="${TMP/AUTHOR/$(field "%aN" $hash)}" TMP="${TMP/COMMITER/$(field "%cN" $hash)}" git show $hash -s --format="$TMP" done -
overengineer created this gist
Sep 30, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ #!/bin/bash # Bash unofficial strict mode set -euo pipefail # http://www.dwheeler.com/essays/filenames-in-shell.html IFS=$'\n\t' function define() { IFS='\n' read -r -d '' ${1} || true; } define TMPL << 'EOF' { "commit": "%H", "tree": "%T", "parent": "%P", "refs": "%D", "encoding": "%e", "message": "MSG", "commit_notes": "%N", "verification_flag": "%G?", "signer": "%GS", "signer_key": "%GK", "author": { "name": "AUTHOR", "email": "%aE", "date": "%ai" }, "commiter": { "name": "COMMITER", "email": "%cE", "date": "%ci" } } EOF function strip () { # strip newlines then strip all whitespace sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' | sed -E 's/^\s+|\s+$//g' } function sanitize () { # escape newline, escape quotes, escape backslash, escape tabs, fix double escapes, delete invalid characters sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/"/\\"/g' | sed 's/\\\\/\\/g' | sed 's/\t/\\t/g' | sed -E 's/\\([^nt"])/\\\\\1/g' | tr -d '\r\0\t' | sed -E 's/[\x00-\x1f]//g'; } function field () { git show -s --format="$1" "$2" | strip | sanitize } git log --pretty=format:'%H' | while IFS='' read -r hash; do TMP="$TMPL" TMP="${TMP/MSG/$(field "%B" $hash)}" TMP="${TMP/AUTHOR/$(field "%aN" $hash)}" TMP="${TMP/COMMITER/$(field "%cN" $hash)}" git show $hash -s --format="$TMP" done # | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\x0\x0\x0/\0\0\n/g' | sed 's/\"/\\\"/g' | sed 's/\x0\x0/"/g' | sed 's/\x0/" "/g' | tr -d '\000' \ # | xargs printf '{"commit": "%s","abbreviated_commit": "%s","tree": "%s","abbreviated_tree": "%s","parent": "%s","abbreviated_parent": "%s","refs": "%s","encoding": "%s","subject": "%s","sanitized_subject_line": "%s","body": "%s","commit_notes": "%s","verification_flag": "%s","signer": "%s","signer_key": "%s","author": {"name": "%s","email": "%s","date": "%s"},"commiter": {"name": "%s","email": "%s","date": "%s"}}\n' # | sed "$ s/,$//" | sed ':a;N;$!ba;s/\r\n\([^{]\)/\\n\1/g'| awk 'BEGIN { print("[") } { print(%s) } END { print("]") }' | sed ':a;N;$!ba;s/\n/ /g'