Paste: diffstat
Author: | piranha |
Mode: | factor |
Date: | Fri, 16 Jan 2009 15:54:39 |
Plain Text |
IN: diffstat
USING: assocs combinators io kernel math namespaces sequences splitting ;
SYMBOL: stats
SYMBOL: fname
SYMBOL: curstats
: isstart ( seq subseq -- bool ) swap start 0 = ;
: is-diffstart-line ( line -- bool ) "diff" isstart ;
: is-plus-line ( line -- bool ) [ "+++" isstart not ] [ "+" isstart ] bi and ;
: is-minus-line ( line -- bool ) [ "---" isstart not ] [ "-" isstart ] bi and ;
: fname-git ( line -- fname )
" " split third 2 swap dup length swap subseq ;
: fname-uni ( line -- fname ) " " split 5 tail " " join ;
: determine-fname ( line -- fname ) [ dup "--git" start ]
[ fname-git ]
[ fname-uni ]
if ;
: inc-curstats ( n -- )
curstats get 2dup nth
1 + -rot set-nth ;
: finish-count ( -- ) curstats get fname get stats get set-at
{ 0 0 } clone curstats set
f fname set ;
: diffstat* ( line -- ) {
{ [ dup is-diffstart-line ] [
fname get [ finish-count ] when
determine-fname fname set ] }
{ [ dup is-plus-line ] [ 0 inc-curstats drop ] }
{ [ dup is-minus-line ] [ 1 inc-curstats drop ] }
[ drop ]
} cond ;
: diffstat ( stream -- stream diffstat )
H{ } clone stats set
{ 0 0 } clone curstats set
[ readln dup ] [ diffstat* ] [ drop ] while
finish-count stats get ;
Author: | piranha |
Mode: | factor |
Date: | Fri, 16 Jan 2009 19:38:24 |
Plain Text |
--- Data stack:
"diff --git a/hgext/churn.py b/hgext/churn.py"
R! diff --git a/(.*) b/(.*)!
( scratchpad ) (match) captured-groups>>
--- Data stack:
H{ ~array~ ~array~ }
( scratchpad ) .
H{
{
1
T{ slice
{ from 13 }
{ to 13 }
{ seq
"diff --git a/hgext/churn.py b/hgext/churn.py"
}
}
}
{
2
T{ slice
{ from 30 }
{ to 30 }
{ seq
"diff --git a/hgext/churn.py b/hgext/churn.py"
}
}
}
}
New Annotation