Skip to content

Commit 954bdfc

Browse files
committed
Fixed #4
1 parent 9fac3b4 commit 954bdfc

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,34 @@ Code churn has several definitions, the one that to me provides the most value a
99

1010
Solutions that I've found online looked at changes to files irrespective whether these are new changes or edits to existing lines of code (LOC) within existing files. Hence this solution that segments line-of-code edits (churn) with new code changes (contribution).
1111

12+
*Tested with Python version 3.5.3 and Git version 2.20.1*
13+
1214
# How it works
1315
This script looks at a range of commits per author. For each commit it bookkeeps the files that were changed along with the LOC for each file. LOC are kept in a sparse structure and changes per LOC are taken into account as the program loops. When a change to the same LOC is detected it updates this separately to bookkeep the true code churn.
1416
Result is a print with aggregated contribution and churn per author for a given time period.
1517

16-
Tested with Python version 3.5.3 and Git version 2.20.1
18+
***Note:*** This includes the `--no-merges` flag as it assumes that merge commits with or without merge conflicts are not indicative of churn.
1719

1820
# Usage
21+
Positional (required) arguments:
22+
- **after**        after a certain date, in YYYY[-MM[-DD]] format
23+
- **before**     before a certain date, in YYYY[-MM[-DD]] format
24+
- **author**     author string (not committer)
25+
- **dir**            include Git repository directory
26+
27+
Optional arguments:
28+
- **-h, --h, --help**    show this help message and exit
29+
- **-exdir**                   exclude Git repository subdirectory
30+
31+
## Example
1932
```bash
20-
python ./gitcodechurn.py before="2019-03-01" after="2018-11-29" author="an author" dir="/Users/myname/myrepo" -exdir="excluded-directory"
33+
python ./gitcodechurn.py after="2018-11-29" before="2019-03-01" author="an author" dir="/Users/myname/myrepo" -exdir="excluded-directory"
2134
```
22-
# Output
35+
## Output
2336
```bash
24-
contribution: 844
25-
churn: -28
37+
author: an author
38+
contribution: 844
39+
churn: -28
2640
```
2741
Outputs can be used as part of a pipeline that generates bar charts for reports:
2842
![contribution vs churn example chart](/chart.png)

gitcodechurn.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@
3535
def main():
3636
parser = argparse.ArgumentParser(
3737
description = 'Compute true git code churn to understand tech debt.',
38-
usage = 'python [*/]gitcodechurn.py before="YYYY-MM-DD" after="YYYY-MM-DD" author="flacle" dir="[*/]path" [-exdir="[*/]path"] [-h]',
38+
usage = 'python [*/]gitcodechurn.py after="YYYY[-MM[-DD]]" before="YYYY[-MM[-DD]]" author="flacle" dir="[*/]path" [-exdir="[*/]path"]',
3939
epilog = 'Feel free to fork at or contribute on: https://github.com/flacle/truegitcodechurn'
4040
)
4141
parser.add_argument(
42-
'before',
42+
'after',
4343
type = str,
44-
help = 'before a certain date, in YYYY-MM-DD format'
44+
help = 'after a certain date, in YYYY[-MM[-DD]] format'
4545
)
4646
parser.add_argument(
47-
'after',
47+
'before',
4848
type = str,
49-
help = 'after a certain date, in YYYY-MM-DD format'
49+
help = 'before a certain date, in YYYY[-MM[-DD]] format'
5050
)
5151
parser.add_argument(
5252
'author',
@@ -68,17 +68,17 @@ def main():
6868
)
6969
args = parser.parse_args()
7070

71-
before = args.before
7271
after = args.after
72+
before = args.before
7373
author = args.author
7474
dir = args.dir
7575
# exdir is optional
7676
exdir = args.exdir
7777

7878
# for the positionals we remove the prefixes
7979
# TODO not sure why this is happening
80-
before = remove_prefix(before, 'before=')
8180
after = remove_prefix(after, 'after=')
81+
before = remove_prefix(before, 'before=')
8282
author = remove_prefix(author, 'author=')
8383
# dir is already handled in dir_path()
8484

@@ -100,8 +100,9 @@ def main():
100100
exdir
101101
)
102102

103-
print('contribution: ', contribution)
104-
print('churn: ', -churn)
103+
print('author: \t', author)
104+
print('contribution: \t', contribution)
105+
print('churn: \t\t', -churn)
105106
# print files in case more granular results are needed
106107
#print('files: ', files)
107108

@@ -220,7 +221,7 @@ def dir_path(path):
220221
if os.path.isdir(path):
221222
return path
222223
else:
223-
raise argparse.ArgumentTypeError("Directory "+path+" is not a valid path.")
224+
raise argparse.ArgumentTypeError(path + " is not a valid path.")
224225

225226
#https://stackoverflow.com/a/16891418
226227
def remove_prefix(text, prefix):

0 commit comments

Comments
 (0)