From 0c7bf665f228edd3fba8c2b54b8ede0898697dea Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Sat, 29 Aug 2015 13:09:42 +0200 Subject: [PATCH 1/4] Fix typo in variable name --- bin/git-effort | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-effort b/bin/git-effort index 6ee45bb..f7ebe99 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -180,7 +180,7 @@ else save_ifs=$IFS IFS=`echo -en "\n\b"` paths=(`git ls-files`) - IFS=$safe_ifs + IFS=$save_ifs unset save_ifs fi From 86e1a7014cd2effe1b8260b760b3b6c5a738ac8f Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Sat, 29 Aug 2015 15:14:26 +0200 Subject: [PATCH 2/4] effort: More robust argument parsing Why: * The old way of handling arguments could make it difficult to make non-breaking changes because to be able to handle more arguments than the '--above' argument, the logic would need to be heavily refactored and demand restrictions on argument order. This change addresses the need by: * Parse arguments in a cleaner way * Make the command more future proof with respect to arguments Notable change is the synopsis. Please the see man page. --- bin/git-effort | 76 ++++++++++++++++----------------------------- man/git-effort.1 | 56 +++++++++++++++++++++------------ man/git-effort.html | 43 ++++++++++++++++--------- man/git-effort.md | 38 +++++++++++++++-------- 4 files changed, 116 insertions(+), 97 deletions(-) diff --git a/bin/git-effort b/bin/git-effort index f7ebe99..7d0be16 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -115,41 +115,32 @@ sort_effort() { < $tmp sort -rn -k 2 } -above_index=0 -has_above=false -next_is_above=false -num_paths=0 +declare -a paths=() +while [ "${#}" -ge 1 ] ; do -# Some implementations of `seq` gives "1\n0" for seq 0 -if [ $# -gt 0 ] ; then - for i in `seq ${#@}` - do - cur="${!i}" + case "$1" in + --above) + shift + above=$1 + ;; + --) + shift + args_to_git_log=$(printf " %q" "${@:1}") + break + ;; + --*) + echo 1>&2 "error: unknown argument $1" + echo 1>&2 "error: if that argument was meant for git-log," + echo 1>&2 "error: please put it after two dashes ( -- )." + exit 1 + ;; + *) + paths+=( "$1" ) + ;; + esac - if "$next_is_above" ; then - above="$cur" - next_is_above=false - continue - fi - - case "$cur" in - --above) - if "$has_above" ; then - echo "error: --above can only be specified one time" 1>&2 - exit 1 - fi - next_is_above=true - has_above=true - above_index=$(( i - 1 )) - ;; - --*) - ;; - *) - num_paths=$(( num_paths + 1 )) - ;; - esac - done -fi + shift +done # Exit if above-value is not an int if [ -z "${above##*[!0-9]*}" ] ; then @@ -157,26 +148,13 @@ if [ -z "${above##*[!0-9]*}" ] ; then exit 1 fi -args_before_above=`printf " %q" "${@:1:$above_index}"` - -num_args=$(( i - num_paths )) -if $has_above ; then offset=2 ; else offset=0 ; fi -from=$(( 1 + above_index + offset )) -len=$(( num_args - $(( above_index + offset)) )) -args_after_above=`printf " %q" "${@:$from:$len}"` - -args_to_git_log="${args_before_above#\ \'\'}${args_after_above#\ \'\'}" - -shift $num_args - +# remove empty quotes that appear when there are no arguments +args_to_git_log="${args_to_git_log#\ \'\'}" export args_to_git_log # [path ...] -declare -a paths=() -if test $# -ge 1; then - paths=("$@") -else +if test "${#paths}" -eq 0; then save_ifs=$IFS IFS=`echo -en "\n\b"` paths=(`git ls-files`) diff --git a/man/git-effort.1 b/man/git-effort.1 index ce9afef..a300974 100644 --- a/man/git-effort.1 +++ b/man/git-effort.1 @@ -1,13 +1,13 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-EFFORT" "1" "August 2015" "" "Git Extras" +.TH "GIT\-EFFORT" "1" "September 2015" "" "Git Extras" . .SH "NAME" \fBgit\-effort\fR \- Show effort statistics on file(s) . .SH "SYNOPSIS" -\fBgit\-effort\fR [\-\-above ] [] [[\-\-] \.\.\.] +\fBgit\-effort\fR [\-\-above ] [\.\.\.] [\-\- [\.\.\.]] . .SH "DESCRIPTION" Shows effort statistics about files in the repository\. @@ -28,23 +28,20 @@ Display includes: Ignore files with commits <= a value\. . .P -Run -. -.br -man \-P \'less +/Commit\e Limiting\' git\-log -. -.br -to read about options to limit which commits are counted\. -. -.P -Note: \fBgit\-effort\fR does not accept commit ranges\. -. -.P -[\-\-] \.\.\. +\.\.\. . .P Only count commits that touches the given paths\. . +.P +Note: \fBgit\-effort\fR does not accept revision ranges, but the underlying \fBgit log\fR does (See the examples)\. +. +.P +\.\.\. +. +.P +Options for \fBgit log\fR\. Note that you must use \fB\-\-\fR to separate options to \fBgit log\fR from options to \fBgit effort\fR\. This makes it possible to only count commits you are interested in\. Not all options are relevant in the context of \fBgit\-effort\fR, but those that are is listed under the "Commit Limiting" section on the \fBgit\-log\fR manpages\. +. .SH "EXAMPLES" Note: Output will first appear unsorted, then the screen is cleared and the sorted list is output\. The initial unsorted list is not shown in the examples for brevity\. . @@ -70,7 +67,7 @@ $ git effort \-\-above 5 git\-repl 7 5 -$ git effort \-\-after="one year ago" \-\-above 5 \-\-author="Leila Muhtasib" +$ git effort \-\-above 5 bin/* \-\- \-\-after="one year ago" \-\-author="Leila Muhtasib" file commits active days @@ -86,18 +83,37 @@ $ git effort \-\-after="one year ago" \-\-above 5 \-\-author="Leila Muhtasib" .IP "" 0 . .P -Showing statistics on directories is also possible +Showing statistics on directories is also possible: . .IP "" 4 . .nf -$ git effort bin man +$ git effort bin man \-\- \-\-after="one year ago" file commits active days - bin\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. 406 232 - man\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. 118 80 + bin\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. 406 232 + man\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. 118 80 +. +.fi +. +.IP "" 0 +. +.P +Only count commits in the specified revision range: +. +.P +$ git effort \-\- master\.\.feature +. +.IP "" 4 +. +.nf + + file commits active days + + bin/git\-effort\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. 3 2 + man/git\-effort\.md\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. 1 1 . .fi . diff --git a/man/git-effort.html b/man/git-effort.html index f9d2a8f..5a9408f 100644 --- a/man/git-effort.html +++ b/man/git-effort.html @@ -76,7 +76,7 @@

SYNOPSIS

-

git-effort [--above <value>] [<options>] [[--] <path>...]

+

git-effort [--above <value>] [<path>...] [-- [<log options>...]]

DESCRIPTION

@@ -92,16 +92,19 @@

Ignore files with commits <= a value.

-

Run
- man -P 'less +/Commit\ Limiting' git-log
- to read about options to limit which commits are counted.

- -

Note: git-effort does not accept commit ranges.

- -

[--] <path>...

+

<path>...

Only count commits that touches the given paths.

+

Note: git-effort does not accept revision ranges, but the underlying git log does (See the examples).

+ +

<log options>...

+ +

Options for git log. Note that you must use -- to separate options to git log + from options to git effort. + This makes it possible to only count commits you are interested in. + Not all options are relevant in the context of git-effort, but those that are is listed under the "Commit Limiting" section on the git-log manpages.

+

EXAMPLES

Note: Output will first appear unsorted, then the screen is cleared and the sorted @@ -124,7 +127,7 @@ git-repl 7 5 -$ git effort --after="one year ago" --above 5 --author="Leila Muhtasib" +$ git effort --above 5 bin/* -- --after="one year ago" --author="Leila Muhtasib" file commits active days @@ -136,19 +139,29 @@ $ git effort --after="one year ago" --above 5 --author="Leila Muhtasib" git-graft 2 2 -

Showing statistics on directories is also possible

+

Showing statistics on directories is also possible:

-
$ git effort bin man
+
$ git effort bin man -- --after="one year ago"
 
   file                                          commits    active days
 
-  bin.......................................... 406         232
-  man.......................................... 118         80
+  bin.......................................... 406        232
+  man.......................................... 118        80
+
+ +

Only count commits in the specified revision range:

+ +

$ git effort -- master..feature

+ +
  file                                          commits    active days
+
+  bin/git-effort............................... 3          2
+  man/git-effort.md............................ 1          1
 

AUTHOR

-

Written by Leila Muhtasib <muhtasib@gmail.com>

+

Written by Leila Muhtasib <muhtasib@gmail.com>

REPORTING BUGS

@@ -161,7 +174,7 @@ $ git effort --after="one year ago" --above 5 --author="Leila Muhtasib"
  1. -
  2. August 2015
  3. +
  4. September 2015
  5. git-effort(1)
diff --git a/man/git-effort.md b/man/git-effort.md index da031be..90fb9c3 100644 --- a/man/git-effort.md +++ b/man/git-effort.md @@ -3,7 +3,7 @@ git-effort(1) -- Show effort statistics on file(s) ## SYNOPSIS -`git-effort` [--above <value>] [<options>] [[--] <path>...] +`git-effort` [--above <value>] [<path>...] [-- [<log options>...]] ## DESCRIPTION @@ -19,16 +19,19 @@ git-effort(1) -- Show effort statistics on file(s) Ignore files with commits <= a value. - Run - man -P 'less +/Commit\ Limiting' git-log - to read about options to limit which commits are counted. - - Note: `git-effort` does not accept commit ranges. - - [--] <path>... + <path>... Only count commits that touches the given paths. + Note: `git-effort` does not accept revision ranges, but the underlying `git log` does (See the examples). + + <log options>... + + Options for `git log`. Note that you must use `--` to separate options to `git log` + from options to `git effort`. + This makes it possible to only count commits you are interested in. + Not all options are relevant in the context of `git-effort`, but those that are is listed under the "Commit Limiting" section on the `git-log` manpages. + ## EXAMPLES Note: Output will first appear unsorted, then the screen is cleared and the sorted @@ -51,7 +54,7 @@ git-effort(1) -- Show effort statistics on file(s) git-repl 7 5 - $ git effort --after="one year ago" --above 5 --author="Leila Muhtasib" + $ git effort --above 5 bin/* -- --after="one year ago" --author="Leila Muhtasib" file commits active days @@ -62,14 +65,23 @@ git-effort(1) -- Show effort statistics on file(s) git-changelog 3 2 git-graft 2 2 - Showing statistics on directories is also possible + Showing statistics on directories is also possible: - $ git effort bin man + $ git effort bin man -- --after="one year ago" file commits active days - bin.......................................... 406 232 - man.......................................... 118 80 + bin.......................................... 406 232 + man.......................................... 118 80 + + Only count commits in the specified revision range: + + $ git effort -- master..feature + + file commits active days + + bin/git-effort............................... 3 2 + man/git-effort.md............................ 1 1 ## AUTHOR From e91fd9623f4570ec235b312403717c4e423e5a8a Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Sun, 13 Sep 2015 23:56:56 +0200 Subject: [PATCH 3/4] effort: add usage message --- bin/git-effort | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/git-effort b/bin/git-effort index 7d0be16..46e3547 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -4,6 +4,13 @@ tmp=$(git_extra_mktemp) above=0 color= +# +# print usage message +# +usage() { + echo 1>&2 "usage: git effort [--above ] [...] [-- [...]]" +} + # # get dates for the given # @@ -129,6 +136,7 @@ while [ "${#}" -ge 1 ] ; do break ;; --*) + usage echo 1>&2 "error: unknown argument $1" echo 1>&2 "error: if that argument was meant for git-log," echo 1>&2 "error: please put it after two dashes ( -- )." From 80f060b213cc27e7b0fd35816bf5d180864f29ac Mon Sep 17 00:00:00 2001 From: Nicolai Skogheim Date: Mon, 14 Sep 2015 00:00:39 +0200 Subject: [PATCH 4/4] effort: change order of arguments to function This makes git effort less prone to failing if someone passes formatting options --- bin/git-effort | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-effort b/bin/git-effort index 46e3547..3281b55 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -15,7 +15,7 @@ usage() { # get dates for the given # dates() { - eval "git log --pretty='format: %ad' --date=short $args_to_git_log \"$1\"" + eval "git log $args_to_git_log --pretty='format: %ad' --date=short \"$1\"" } #