Skip to content

Commit

Permalink
Merge pull request #391 from nicolaiskogheim/effort-limit-commits
Browse files Browse the repository at this point in the history
[RFC] effort: Allow sending options to log. Fix #326
  • Loading branch information
hemanth committed Jul 25, 2015
2 parents 467d52a + 78de79c commit 651a2ba
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 23 deletions.
69 changes: 55 additions & 14 deletions bin/git-effort
@@ -1,15 +1,14 @@
#!/usr/bin/env bash

tmp=$(git_extra_mktemp)
above='0'
above=0
color=

#
# get date for the given <commit>
# get dates for the given <commit>
#

date() {
git log --pretty='format: %ad' --date=short $1
dates() {
eval "git log --pretty='format: %ad' --date=short $args_to_git_log "$1""
}

#
Expand All @@ -28,7 +27,7 @@ show_cursor_and_cleanup() {
printf '\033[?25h'
printf '\033[m\n'
rm "$tmp" > /dev/null 2>&1
exit 1
exit 0
}

#
Expand Down Expand Up @@ -60,7 +59,9 @@ color_for() {

effort() {
file=$1
local commit_dates=`date $file`
local commit_dates
commit_dates=`dates $file`
[ $? -gt 0 ] && exit 255
commits=`wc -l <<<"$(echo "$commit_dates")"`
color='90'

Expand Down Expand Up @@ -107,12 +108,51 @@ sort_effort() {
< $tmp sort -rn -k 2
}

# --above <n-commits>

if test "$1" = "--above"; then
shift; above=$1
shift
fi
above_index=0
has_above=false
next_is_above=false
num_files=0
for i in `seq ${#@}`
do
cur="${!i}"

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_files=$(( num_files + 1 ))
;;
esac
done

args_before_above=`printf " %q" "${@:1:$above_index}"`

num_args=$(( i - num_files ))
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

export args_to_git_log

# [file ...]

Expand All @@ -136,8 +176,9 @@ trap show_cursor_and_cleanup INT
export -f effort
export -f color_for
export -f active_days
export -f date
export -f dates
export above
export log_args

heading
# send files to effort
Expand Down
13 changes: 12 additions & 1 deletion etc/bash_completion.sh
Expand Up @@ -61,7 +61,18 @@ _git_delete_tag(){
}

_git_effort(){
__gitcomp "--above"
__git_has_doubledash && return

case "$cur" in
--*)
__gitcomp "
--above
$__git_log_common_options
$__git_log_shortlog_options
"
return
;;
esac
}

_git_extras(){
Expand Down
28 changes: 26 additions & 2 deletions 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" "April 2015" "" ""
.TH "GIT\-EFFORT" "1" "July 2015" "" "Git Extras"
.
.SH "NAME"
\fBgit\-effort\fR \- Show effort statistics on file(s)
.
.SH "SYNOPSIS"
\fBgit\-effort\fR [\-\-above <value>] [<filename>]
\fBgit\-effort\fR [\-\-above <value>] [<options>] [<filename>]
.
.SH "DESCRIPTION"
Shows effort statistics about files in the repository\.
Expand All @@ -28,6 +28,18 @@ 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
<filename>
.
.P
Expand All @@ -53,6 +65,18 @@ $ git effort \-\-above 5
git\-summary 8 6
git\-delete\-branch 8 6
git\-repl 7 5


$ git effort \-\-after="one year ago" \-\-above 5 \-\-author="Leila Muhtasib"

file commits active days

git\-extras 15 12
git\-release 6 9
git\-effort 6 2
git\-ignore 4 4
git\-changelog 3 5
git\-graft 2 3
.
.fi
.
Expand Down
26 changes: 22 additions & 4 deletions man/git-effort.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions man/git-effort.md
Expand Up @@ -3,7 +3,7 @@ git-effort(1) -- Show effort statistics on file(s)

## SYNOPSIS

`git-effort` [--above &lt;value&gt;] [&lt;filename&gt;]
`git-effort` [--above &lt;value&gt;] [&lt;options&gt;] [&lt;filename&gt;]

## DESCRIPTION

Expand All @@ -19,6 +19,12 @@ git-effort(1) -- Show effort statistics on file(s)

Ignore files with commits &lt;= 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.

&lt;filename&gt;

Only display effort statistics for a specific filename.
Expand All @@ -42,6 +48,17 @@ git-effort(1) -- Show effort statistics on file(s)
git-repl 7 5


$ git effort --after="one year ago" --above 5 --author="Leila Muhtasib"

file commits active days

git-extras 15 12
git-release 6 9
git-effort 6 2
git-ignore 4 4
git-changelog 3 5
git-graft 2 3

## AUTHOR

Written by Leila Muhtasib &lt;<muhtasib@gmail.com>&gt;
Expand All @@ -52,4 +69,4 @@ Written by Leila Muhtasib &lt;<muhtasib@gmail.com>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;
&lt;<https://github.com/tj/git-extras>&gt;

0 comments on commit 651a2ba

Please sign in to comment.