cg-log cleanups and enhancements
PATCH 1/1 cg-log cleanups and enhancements
The patchset contains the following 10 patches:
[PATCH 1/10] Cleanup conversion to human readable date [PATCH 2/10] Separate handling of tree and parent in commit headers [PATCH 3/10] Separate handling of author and committer in commit headers [PATCH 4/10] First parse all commit header entries then print them [PATCH 5/10] Move printing of the commit info line inside the loop [PATCH 6/10] Remove the catch all rule
[PATCH 7/10] Move log printing to separate function
[PATCH 8/10] Move the username matching inside the loop [PATCH 9/10] Move file matching inside the loop.
[PATCH 10/10] Add -s option to show log summary
Signature · 1 line
Jonas Fonseca
PATCH 1/10 Cleanup conversion to human readable date
Simplify the date substitution to reduce code duplication.
---
cg-log | 8 ++------ cg-mkpatch | 7 ++----- 2 files changed, 4 insertions(+), 11 deletions(-)
cg-log +2 -6
@@ -188,12 +188,8 @@ $revls | $revsort | while read time comm date=(${rest#*> }) pdate="$(showdate $date)" - if [ "$pdate" ]; then - echo -n $color$key $rest | sed "s/>.*/> $pdate/" - echo $coldefault - else - echo $color$key $rest $coldefault - fi + [ "$pdate" ] && rest="${rest%> *}> $pdate" + echo $color$key $rest $coldefault ;; "tree"|"parent") if [ -z $tree1 ]; then
cg-mkpatch +2 -5
@@ -53,11 +53,8 @@ showpatch () { "author"|"committer") date=(${rest#*> }) pdate="$(showdate $date)" - if [ "$pdate" ]; then - echo $key $rest | sed "s/>.*/> $pdate/" >>$header - else - echo $key $rest >>$header - fi + [ "$pdate" ] && rest="${rest%> *}> $pdate" + echo $key $rest >>$header ;; "") cat
Signature · 1 line
Jonas Fonseca
PATCH 2/10 Separate handling of tree and parent in commit headers
In reply to Jonas FonsecaParse tree and parent commit header entries separately so the logic for deciding where to save the IDs can be removed. Save all parents in an array.
---
cg-log | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)
cg-log +9 -9
@@ -162,8 +162,8 @@ fi $revls | $revsort | while read time commit parents; do trap exit SIGPIPE - tree1= - tree2= + tree= + parents=() [ "$revfmt" = "git-rev-list" ] && commit="$time" if [ $# -ne 0 ]; then parent=$(git-cat-file commit $commit | sed -n '2s/parent //p;2Q')
@@ -191,17 +191,17 @@ $revls | $revsort | while read time comm [ "$pdate" ] && rest="${rest%> *}> $pdate" echo $color$key $rest $coldefault ;; - "tree"|"parent") - if [ -z $tree1 ]; then - tree1=$rest - elif [ -z $tree2 ]; then - tree2=$rest - fi + "tree") + tree="$rest" + echo $colheader$key $tree $coldefault + ;; + "parent") + parents[${#parents[@]}]="$rest" echo $colheader$key $rest $coldefault ;; "") if [ -n "$list_files" ]; then - list_commit_files "$tree1" "$tree2" + list_commit_files "$tree" "${parents[0]}" fi echo; sed -re ' / *Signed-off-by:.*/Is//'$colsignoff'&'$coldefault'/
Signature · 1 line
Jonas Fonseca
PATCH 3/10 Separate handling of author and committer in commit headers
In reply to Jonas FonsecaParse and print the author and committer header entries so the color logic can be removed.
---
cg-log | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
cg-log +14 -10
@@ -162,6 +162,8 @@ fi $revls | $revsort | while read time commit parents; do trap exit SIGPIPE + author= + committer= tree= parents=() [ "$revfmt" = "git-rev-list" ] && commit="$time"
@@ -179,17 +181,19 @@ $revls | $revsort | while read time comm while read key rest; do trap exit SIGPIPE case "$key" in - "author"|"committer") - if [ "$key" = "author" ]; then - color="$colauthor" - else - color="$colcommitter" - fi - - date=(${rest#*> }) + "author") + author="$rest" + date=(${author#*> }) + pdate="$(showdate $date)" + [ "$pdate" ] && author="${author%> *}> $pdate" + echo $colauthor$key $author $coldefault + ;; + "committer") + committer="$rest" + date=(${committer#*> }) pdate="$(showdate $date)" - [ "$pdate" ] && rest="${rest%> *}> $pdate" - echo $color$key $rest $coldefault + [ "$pdate" ] && committer="${committer%> *}> $pdate" + echo $colcommitter$key $committer $coldefault ;; "tree") tree="$rest"
Signature · 1 line
Jonas Fonseca
PATCH 4/10 First parse all commit header entries then print them
In reply to Jonas FonsecaChange the main loop to first parse all header entries before printing them. Makes the cg-log output more independent of the order of the git commit header.
---
cg-log | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-)
cg-log +16 -10
@@ -183,27 +183,33 @@ $revls | $revsort | while read time comm case "$key" in "author") author="$rest" - date=(${author#*> }) - pdate="$(showdate $date)" - [ "$pdate" ] && author="${author%> *}> $pdate" - echo $colauthor$key $author $coldefault ;; "committer") committer="$rest" - date=(${committer#*> }) - pdate="$(showdate $date)" - [ "$pdate" ] && committer="${committer%> *}> $pdate" - echo $colcommitter$key $committer $coldefault ;; "tree") tree="$rest" - echo $colheader$key $tree $coldefault ;; "parent") parents[${#parents[@]}]="$rest" - echo $colheader$key $rest $coldefault ;; "") + echo ${colheader}tree $tree $coldefault + + for parent in "${parents[@]}"; do + echo ${colheader}parent $parent $coldefault + done + + date=(${author#*> }) + pdate="$(showdate $date)" + [ "$pdate" ] && author="${author%> *}> $pdate" + echo ${colauthor}author $author $coldefault + + date=(${committer#*> }) + pdate="$(showdate $date)" + [ "$pdate" ] && committer="${committer%> *}> $pdate" + echo ${colcommitter}committer $committer $coldefault + if [ -n "$list_files" ]; then list_commit_files "$tree" "${parents[0]}" fi
Signature · 1 line
Jonas Fonseca
PATCH 5/10 Move printing of the commit info line inside the loop
In reply to Jonas FonsecaPrinting of all the log headers are now handled the same place.
---
cg-log | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
cg-log +1 -1
@@ -176,7 +176,6 @@ $revls | $revsort | while read time comm if [ "$user" ]; then git-cat-file commit $commit | grep -e '^author ' -e '^committer ' | grep -qi "$user" || continue fi - echo $colheader""commit ${commit%:*} $coldefault; git-cat-file commit $commit | \ while read key rest; do trap exit SIGPIPE
@@ -194,6 +193,7 @@ $revls | $revsort | while read time comm parents[${#parents[@]}]="$rest" ;; "") + echo ${colheader}commit ${commit%:*} $coldefault echo ${colheader}tree $tree $coldefault for parent in "${parents[@]}"; do
Signature · 1 line
Jonas Fonseca
PATCH 6/10 Remove the catch all rule
In reply to Jonas FonsecaAll commit header entries are already be handled so no need for a default case pattern.
---
cg-log | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
cg-log +0 -4
@@ -219,11 +219,7 @@ $revls | $revsort | while read time comm s/./ &/ ' ;; - *) - echo $colheader$key $rest $coldefault - ;; esac - done echo done | pager
Signature · 1 line
Jonas Fonseca
PATCH 7/10 Move log printing to separate function
In reply to Jonas FonsecaEach commit log is now handled in the new print_commit_log() function.
---
cg-log | 30 ++++++++++++++++++------------ 1 files changed, 18 insertions(+), 12 deletions(-)
cg-log +18 -12
@@ -160,22 +160,13 @@ else revfmt="git-rev-list" fi -$revls | $revsort | while read time commit parents; do - trap exit SIGPIPE +print_commit_log() { + commit="$1" author= committer= tree= parents=() - [ "$revfmt" = "git-rev-list" ] && commit="$time" - if [ $# -ne 0 ]; then - parent=$(git-cat-file commit $commit | sed -n '2s/parent //p;2Q') - diff_ops= - [ "$parent" ] || diff_ops=--root - [ "$(git-diff-tree -r $diff_ops $commit $parent "$@")" ] || continue - fi - if [ "$user" ]; then - git-cat-file commit $commit | grep -e '^author ' -e '^committer ' | grep -qi "$user" || continue - fi + git-cat-file commit $commit | \ while read key rest; do trap exit SIGPIPE
@@ -221,5 +212,20 @@ $revls | $revsort | while read time comm ;; esac done +} + +$revls | $revsort | while read time commit parents; do + trap exit SIGPIPE + [ "$revfmt" = "git-rev-list" ] && commit="$time" + if [ $# -ne 0 ]; then + parent=$(git-cat-file commit $commit | sed -n '2s/parent //p;2Q') + diff_ops= + [ "$parent" ] || diff_ops=--root + [ "$(git-diff-tree -r $diff_ops $commit $parent "$@")" ] || continue + fi + if [ "$user" ]; then + git-cat-file commit $commit | grep -e '^author ' -e '^committer ' | grep -qi "$user" || continue + fi + print_commit_log $commit echo done | pager
Signature · 1 line
Jonas Fonseca
PATCH 8/10 Move the username matching inside the loop
In reply to Jonas FonsecaBy handling -u in the commit parsing loop no extra git-cat-file call is necessary. Keep the line-based matching scheme so that it is still possible to restrict searches by using prefixing the search string with either 'author' or 'committer' (e.g. -u'author.*miciah').
This change also magically removes trailing empty lines from commit logs.
---
cg-log | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
cg-log +8 -4
@@ -184,6 +184,10 @@ print_commit_log() { parents[${#parents[@]}]="$rest" ;; "") + if [ "$user" ]; then + echo -e "author $author\ncommitter $committer" \ + | grep -qi "$user" || return + fi echo ${colheader}commit ${commit%:*} $coldefault echo ${colheader}tree $tree $coldefault
@@ -223,9 +227,9 @@ $revls | $revsort | while read time comm [ "$parent" ] || diff_ops=--root [ "$(git-diff-tree -r $diff_ops $commit $parent "$@")" ] || continue fi - if [ "$user" ]; then - git-cat-file commit $commit | grep -e '^author ' -e '^committer ' | grep -qi "$user" || continue + log="$(print_commit_log $commit)" + if [ "$log" ]; then + echo "$log" + echo fi - print_commit_log $commit - echo done | pager
Signature · 1 line
Jonas Fonseca
PATCH 9/10 Move file matching inside the loop.
In reply to Jonas FonsecaHandling of -f is done inide the loop so no extra git-cat-file call is necessary. Store file arguments to cg-log in an array to make them easier to access from print_commit_log().
---
cg-log | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)
cg-log +8 -6
@@ -73,6 +73,7 @@ log_start= log_end= user= mergebase= +files=() while [ "$1" ]; do case "$1" in
@@ -107,6 +108,7 @@ while [ "$1" ]; do mergebase=1 ;; *) + files=("$@") break ;; esac
@@ -184,6 +186,12 @@ print_commit_log() { parents[${#parents[@]}]="$rest" ;; "") + if [ "$files" ]; then + parent="${parents[0]}" + diff_ops= + [ "$parent" ] || diff_ops=--root + [ "$(git-diff-tree -r $diff_ops $commit $parent "${files[@]}")" ] || return 1 + fi if [ "$user" ]; then echo -e "author $author\ncommitter $committer" \ | grep -qi "$user" || return
@@ -221,12 +229,6 @@ print_commit_log() { $revls | $revsort | while read time commit parents; do trap exit SIGPIPE [ "$revfmt" = "git-rev-list" ] && commit="$time" - if [ $# -ne 0 ]; then - parent=$(git-cat-file commit $commit | sed -n '2s/parent //p;2Q') - diff_ops= - [ "$parent" ] || diff_ops=--root - [ "$(git-diff-tree -r $diff_ops $commit $parent "$@")" ] || continue - fi log="$(print_commit_log $commit)" if [ "$log" ]; then echo "$log"
Signature · 1 line
Jonas Fonseca
PATCH 10/10 Add -s option to show log summary
In reply to Jonas FonsecaWhen passing -s to cg-log each log entry is summarized in one line. The line carries info about commit date, author, first log line and the commit id. It will look something like the following (with only:
2005-05-20 11:46 Linus Torvalds sparse cleanup e99d59ff0bff349ef20...
The result ends up being 130 chars wide however the commit id is placed so that it can easily be hidden if line wrapping in the pager is enabled.
---
cg-Xlib | 4 +++- cg-log | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 10 deletions(-)
cg-Xlib +3 -1
@@ -47,10 +47,12 @@ mktemp () { showdate () { date="$1" + format="$2" + [ "$format" ] || format=-R sec=${date[0]}; tz=${date[1]} dtz=${tz/+/} lsec=$(expr $dtz / 100 \* 3600 + $dtz % 100 \* 60 + $sec) - pdate="$(date -Rud "1970-01-01 UTC + $lsec sec" 2>/dev/null)" + pdate="$(date -ud "1970-01-01 UTC + $lsec sec" "$format" 2>/dev/null)" echo "${pdate/+0000/$tz}" }
cg-log +44 -9
102 lines not on this page · raw message
Signature · 1 line
Jonas Fonseca