@@ -52,7 +52,8 @@ var rootCmd = &cobra.Command{
52
52
// if the remote flag is set, clone the repo (using repoPath) into memory
53
53
if remote {
54
54
r , err := git .Clone (memory .NewStorage (), nil , & git.CloneOptions {
55
- URL : repoPath ,
55
+ URL : repoPath ,
56
+ SingleBranch : true ,
56
57
})
57
58
handleError (err )
58
59
repo = r
@@ -70,11 +71,13 @@ var rootCmd = &cobra.Command{
70
71
// TODO (patrickdevivo) at some point this entire scoring logic should be brought out into a subpackage with some tests
71
72
// this could also make it possibe for other projects to import the implementation.
72
73
decayHours := 24 * decayDays
73
- // since := time.Now().Add(-(time.Duration(decayHours) * time.Hour * 10))
74
+
75
+ // this ignores any commits older than 100 half-lives,
76
+ since := time .Now ().Add (- (time .Duration (decayHours ) * time .Hour * 10 ))
74
77
commitIter , err := repo .Log (& git.LogOptions {
75
78
Order : git .LogOrderCommitterTime ,
76
79
FileName : fileName ,
77
- // Since: &since,
80
+ Since : & since ,
78
81
})
79
82
handleError (err )
80
83
defer commitIter .Close ()
@@ -99,15 +102,26 @@ var rootCmd = &cobra.Command{
99
102
}
100
103
101
104
agg := authors [authorEmail ]
105
+ hoursAgo := time .Now ().Sub (commit .Author .When ).Hours ()
102
106
agg .commits ++
103
107
108
+ // TODO this is a bit hacky, we're absorbing any panics that occur
109
+ // in particular, it's meant to capture an index out of range error occurring
110
+ // under some conditions in the underlying git/diff dependency. Maybe another reason to use native git...
111
+ defer func () {
112
+ if err := recover (); err != nil {
113
+ agg .score += math .Exp2 (- hoursAgo / float64 (decayHours ))
114
+ }
115
+ }()
116
+
104
117
fileStats , err := commit .Stats ()
105
118
handleError (err )
106
119
107
120
var additions int
108
121
var deletions int
109
122
for _ , stat := range fileStats {
110
123
// ignore diffs in vendor files
124
+ // TODO perhaps it's worth allowing for the user to supply file path patterns be ignored?
111
125
if enry .IsVendor (stat .Name ) {
112
126
continue
113
127
}
@@ -116,7 +130,6 @@ var rootCmd = &cobra.Command{
116
130
}
117
131
agg .impact += additions + deletions
118
132
119
- hoursAgo := time .Now ().Sub (commit .Author .When ).Hours ()
120
133
agg .score += float64 (additions + deletions ) * math .Exp2 (- hoursAgo / float64 (decayHours ))
121
134
return nil
122
135
})
@@ -126,13 +139,14 @@ var rootCmd = &cobra.Command{
126
139
})
127
140
128
141
w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 3 , ' ' , tabwriter .TabIndent )
129
- fmt .Fprintf (w , "Rank\t Email\t Name\t Score\t Commits \ t Impact\n " )
142
+ fmt .Fprintf (w , "Rank\t Email\t Name\t Score\t Impact\t Commits \n " )
130
143
for rank , authorEmail := range authorEmails {
131
144
agg := authors [authorEmail ]
145
+ // ignore scores less than 0
132
146
if agg .score < 1 {
133
147
continue
134
148
}
135
- fmt .Fprintf (w , "%d\t %s\t %s\t %d\t %d commits \t %d\n " , rank + 1 , authorEmail , agg .name , int (math .Round (agg .score )), agg .commits , agg .impact )
149
+ fmt .Fprintf (w , "%d\t %s\t %s\t %d\t %d\t %d\n " , rank + 1 , authorEmail , agg .name , int (math .Round (agg .score )), agg .impact , agg .commits )
136
150
}
137
151
w .Flush ()
138
152
},
0 commit comments