From cb15c94eab59536dd128fcbc15f9cd762101edd0 Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Wed, 8 Jul 2015 17:58:12 +0200 Subject: [PATCH 1/5] Alter options to git log. Remove pipe --- bin/git-effort | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-effort b/bin/git-effort index 8ada5a8..28600b0 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -9,7 +9,7 @@ color= # date() { - git log --pretty='format: %ai' $1 | cut -d ' ' -f 2 + git log --pretty='format: %ad' --date=short $1 } # From 73973049d60fa91b1f44b4a4d522ef040ee6c5dd Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Wed, 8 Jul 2015 18:45:41 +0200 Subject: [PATCH 2/5] Parallelize git-effort with xargs --- bin/git-effort | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/git-effort b/bin/git-effort index 28600b0..32cdf54 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -62,12 +62,12 @@ color_for() { # effort() { - for file in "$@"; do + file=$1 commits=`git log --oneline "$file" | wc -l` color='90' # ignore <= --above - test $commits -le $above && continue + test $commits -le $above && exit 0 # commits color_for $commits @@ -79,13 +79,13 @@ effort() { i=$(($i+1)) done - printf " \033[${color}m%s %-10d" $f_dot $commits + msg=$(printf " \033[${color}m%s %-10d" $f_dot $commits) # active days active=`active_days "$file"` color_for $active - printf "\033[${color}m %d\033[0m\n" $active - done + msg="$msg $(printf "\033[${color}m %d\033[0m\n" $active)" + echo "$msg" } # @@ -134,11 +134,18 @@ fi hide_cursor trap show_cursor_and_cleanup INT -# loop files +# export functions so subshells can call them +export -f effort +export -f color_for +export -f active_days +export -f date +export above heading +# send files to effort +printf "%s\0" "${files[@]}" | xargs -0 -n 1 -P 4 -I % bash -c "effort \"%\"" | tee $tmp -effort "${files[@]}" | tee $tmp +# if more than one file, sort and print test "$(wc -l $tmp | awk '{print $1}')" -gt 1 && sort_effort echo From 203b7649a2ef569f8de9cd70163f614d1001ba04 Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Wed, 8 Jul 2015 18:52:51 +0200 Subject: [PATCH 3/5] perf: reduce calls to git log --- bin/git-effort | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bin/git-effort b/bin/git-effort index 32cdf54..c678fe8 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -36,10 +36,7 @@ show_cursor_and_cleanup() { # active_days() { - date $1 | uniq | awk ' - { sum += 1 } - END { print sum } - ' + uniq <(echo "$1") | wc -l } # @@ -63,7 +60,8 @@ color_for() { effort() { file=$1 - commits=`git log --oneline "$file" | wc -l` + local commit_dates=`date $file` + commits=`echo "$commit_dates" | wc -l` color='90' # ignore <= --above @@ -82,7 +80,7 @@ effort() { msg=$(printf " \033[${color}m%s %-10d" $f_dot $commits) # active days - active=`active_days "$file"` + active=`active_days "$commit_dates"` color_for $active msg="$msg $(printf "\033[${color}m %d\033[0m\n" $active)" echo "$msg" From 39238ded46ac572f353bd20a582b7c4b8b4be02e Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Wed, 8 Jul 2015 18:56:00 +0200 Subject: [PATCH 4/5] Remove unnecessary call to cat --- bin/git-effort | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-effort b/bin/git-effort index c678fe8..7f992dd 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -104,7 +104,7 @@ sort_effort() { clear echo heading - cat $tmp | sort -rn -k 2 + < $tmp sort -rn -k 2 } # --above From 935c5a37b36866ae18c686a769a3cc6fa485e9c7 Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Wed, 8 Jul 2015 18:59:10 +0200 Subject: [PATCH 5/5] Avoid spawning subshell --- bin/git-effort | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-effort b/bin/git-effort index 7f992dd..47524f1 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -61,7 +61,7 @@ color_for() { effort() { file=$1 local commit_dates=`date $file` - commits=`echo "$commit_dates" | wc -l` + commits=`wc -l <<<"$(echo "$commit_dates")"` color='90' # ignore <= --above