diff --git a/bin/git-effort b/bin/git-effort index 6ee45bb..3281b55 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -4,11 +4,18 @@ tmp=$(git_extra_mktemp) above=0 color= +# +# print usage message +# +usage() { + echo 1>&2 "usage: git effort [--above ] [...] [-- [...]]" +} + # # 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\"" } # @@ -115,41 +122,33 @@ 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 + ;; + --*) + 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 ( -- )." + 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,30 +156,17 @@ 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`) - IFS=$safe_ifs + IFS=$save_ifs unset save_ifs fi 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