Skip to content

Commit 4eae376

Browse files
release: 0.2.1
2 parents fd8e0bb + fe61846 commit 4eae376

File tree

7 files changed

+61
-48
lines changed

7 files changed

+61
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<a href="https://sourcerer.io"><img src=https://user-images.githubusercontent.com/20287615/34189346-d426d4c2-e4ef-11e7-9da4-cc76a1ed111d.png alt="Sourcerer Logo", width=50></a>
44
&nbsp; sourcerer.io
55
</h1>
6-
An intelligent profile for software engineers. Start with your public GitHub at <a href="https://sourcerer.io/start">https://sourcerer.io/start</a>.
6+
A visual profile for software engineers. Start with your public GitHub at <a href="https://sourcerer.io/start">https://sourcerer.io/start</a>. Screenshot below.
77
<br>
88

99
What is it?

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ buildConfig {
3737

3838
// App version.
3939
buildConfigField 'int', 'VERSION_CODE', '6'
40-
buildConfigField 'String', 'VERSION', '0.2.0'
40+
buildConfigField 'String', 'VERSION', '0.2.1'
4141

4242
// Logging.
4343
buildConfigField 'String', 'ENV', project.hasProperty('env') ? env : 'production'
@@ -55,6 +55,11 @@ buildConfig {
5555
// Models storage path.
5656
buildConfigField 'String', 'LIBRARY_MODELS_URL', 'https://storage.googleapis.com/sourcerer-app/library-models/v1/'
5757

58+
// Hashing.
59+
buildConfigField 'boolean', 'COMMIT_HASHER_ENABLED', project.hasProperty('commit-hasher-enabled') ? project.property('commit-hasher-enabled').toString() : 'true'
60+
buildConfigField 'boolean', 'FACT_HASHER_ENABLED', project.hasProperty('fact-hasher-enabled') ? project.property('fact-hasher-enabled').toString() : 'true'
61+
buildConfigField 'boolean', 'LONGEVITY_ENABLED', project.hasProperty('longevity-enabled') ? project.property('longevity-enabled').toString() : 'false'
62+
5863
buildConfig
5964
}
6065

src/main/kotlin/app/extractors/CommonExtractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CommonExtractor : ExtractorInterface {
4040
reversedMap.put("perl", listOf("pl", "PL"))
4141
reversedMap.put("powershell", listOf("ps1", "psm1", "psd1"))
4242
reversedMap.put("processing", listOf("pde"))
43-
reversedMap.put("prolog", listOf("pl", "pro", "P"))
43+
reversedMap.put("prolog", listOf("pl", "P"))
4444
reversedMap.put("puppet", listOf("pp"))
4545
reversedMap.put("r", listOf("r", "R"))
4646
reversedMap.put("rust", listOf("rs"))

src/main/kotlin/app/hashers/CodeLongevity.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -456,22 +456,6 @@ class CodeLongevity(
456456
val newId = diff.getNewId().toObjectId()
457457
Logger.trace { "old: '$oldPath', new: '$newPath'" }
458458

459-
// Skip binary files.
460-
val fileId = if (newPath != DiffEntry.DEV_NULL) newId else oldId
461-
try {
462-
if (RawText.isBinary(repo.open(fileId).openStream())) {
463-
continue
464-
}
465-
} catch (e: Exception) {
466-
continue
467-
//TODO(anatoly): better exception handling.
468-
}
469-
470-
// TODO(alex): does it happen in the wilds?
471-
if (diff.changeType == DiffEntry.ChangeType.COPY) {
472-
continue
473-
}
474-
475459
// File was deleted, initialize the line array in the files map.
476460
if (diff.changeType == DiffEntry.ChangeType.DELETE) {
477461
val fileLoader = repo.open(oldId)

src/main/kotlin/app/hashers/CommitCrawler.kt

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object CommitCrawler {
5757
}
5858

5959
fun fetchRehashesAndAuthors(git: Git):
60-
Pair<LinkedList<String>, HashSet<Author>> {
60+
Triple<LinkedList<String>, HashSet<Author>, HashMap<String, Int>> {
6161
val head: RevCommit = RevWalk(git.repository)
6262
.parseCommit(getDefaultBranchHead(git))
6363

@@ -67,6 +67,7 @@ object CommitCrawler {
6767
val commitsRehashes = LinkedList<String>()
6868
val emails = hashSetOf<String>()
6969
val names = hashMapOf<String, String>()
70+
val commitsCount = hashMapOf<String, Int>()
7071

7172
var commit: RevCommit? = revWalk.next()
7273
while (commit != null) {
@@ -81,6 +82,7 @@ object CommitCrawler {
8182
names[email] = name
8283
}
8384
}
85+
commitsCount[email] = commitsCount.getOrDefault(email, 0) + 1
8486

8587
commit.disposeBody()
8688
commit = revWalk.next()
@@ -90,11 +92,12 @@ object CommitCrawler {
9092
val authors = emails.map { email -> Author(names[email]!!, email) }
9193
.toHashSet()
9294

93-
return Pair(commitsRehashes, authors)
95+
return Triple(commitsRehashes, authors, commitsCount)
9496
}
9597

9698
fun getJGitObservable(git: Git,
9799
totalCommitCount: Int = 0,
100+
filteredEmails: HashSet<String>? = null,
98101
tail : RevCommit? = null) : Observable<JgitPair> =
99102
Observable.create { subscriber ->
100103

@@ -138,8 +141,29 @@ object CommitCrawler {
138141
} else 0.0
139142
Logger.printCommit(commit.shortMessage, commit.name, perc)
140143

144+
val email = commit.authorIdent.emailAddress
145+
if (filteredEmails != null && !filteredEmails.contains(email)) {
146+
commit = parentCommit
147+
continue
148+
}
149+
141150
val diffEntries = df.scan(parentCommit, commit)
142-
val diffEdits = diffEntries.map { diff ->
151+
val diffEdits = diffEntries
152+
.filter { diff ->
153+
diff.changeType != DiffEntry.ChangeType.COPY
154+
}
155+
.filter { diff ->
156+
val fileId =
157+
if (diff.getNewPath() != DiffEntry.DEV_NULL) {
158+
diff.getNewId().toObjectId()
159+
} else {
160+
diff.getOldId().toObjectId()
161+
}
162+
val stream = try { repo.open(fileId).openStream() }
163+
catch (e: Exception) { null }
164+
stream != null && !RawText.isBinary(stream)
165+
}
166+
.map { diff ->
143167
JgitDiff(diff, df.toFileHeader(diff).toEditList())
144168
}
145169
subscriber.onNext(JgitPair(commit, diffEdits))
@@ -180,18 +204,6 @@ object CommitCrawler {
180204
private fun getDiffFiles(jgitRepo: Repository,
181205
jgitDiffs: List<JgitDiff>) : List<DiffFile> {
182206
return jgitDiffs
183-
// Skip binary files.
184-
.filter { (diff, _) ->
185-
val fileId =
186-
if (diff.getNewPath() != DiffEntry.DEV_NULL) {
187-
diff.getNewId().toObjectId()
188-
} else {
189-
diff.getOldId().toObjectId()
190-
}
191-
val stream = try { jgitRepo.open(fileId).openStream() }
192-
catch (e: Exception) { null }
193-
stream != null && !RawText.isBinary(stream)
194-
}
195207
.map { (diff, edits) ->
196208
// TODO(anatoly): Can produce exception for large object.
197209
// Investigate for size.

src/main/kotlin/app/hashers/RepoHasher.kt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package app.hashers
55

6+
import app.BuildConfig
67
import app.Logger
78
import app.api.Api
89
import app.config.Configurator
@@ -56,18 +57,29 @@ class RepoHasher(private val localRepo: LocalRepo, private val api: Api,
5657
Logger.error(e, "Hashing error")
5758
}
5859

60+
// Only code longevity needs to calculate each commit, if it's
61+
// disabled then read only author's emails.
62+
val crawlerEmails = if (!BuildConfig.LONGEVITY_ENABLED) {
63+
filteredEmails
64+
} else null
65+
val jgitObservable = CommitCrawler.getJGitObservable(git,
66+
rehashes.size, crawlerEmails).publish()
67+
val observable = CommitCrawler.getObservable(git,
68+
jgitObservable, serverRepo)
69+
5970
// Hash by all plugins.
60-
val jgitObservable =
61-
CommitCrawler.getJGitObservable(git, rehashes.size).publish()
62-
val observable =
63-
CommitCrawler.getObservable(git, jgitObservable, serverRepo)
64-
65-
CommitHasher(serverRepo, api, rehashes, filteredEmails)
66-
.updateFromObservable(observable, onError)
67-
FactHasher(serverRepo, api, rehashes, filteredEmails)
68-
.updateFromObservable(observable, onError)
69-
CodeLongevity(serverRepo, filteredEmails, git)
70-
.updateFromObservable(jgitObservable, onError, api)
71+
if (BuildConfig.COMMIT_HASHER_ENABLED) {
72+
CommitHasher(serverRepo, api, rehashes, filteredEmails)
73+
.updateFromObservable(observable, onError)
74+
}
75+
if (BuildConfig.FACT_HASHER_ENABLED) {
76+
FactHasher(serverRepo, api, rehashes, filteredEmails)
77+
.updateFromObservable(observable, onError)
78+
}
79+
if (BuildConfig.LONGEVITY_ENABLED) {
80+
CodeLongevity(serverRepo, filteredEmails, git)
81+
.updateFromObservable(jgitObservable, onError, api)
82+
}
7183

7284
// Start and synchronously wait until all subscribers complete.
7385
Logger.print("Stats computation. May take a while...")

src/test/kotlin/test/tests/hashers/ColleaguesTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import kotlin.test.assertNotNull
3232
*/
3333
class ColleaguesTest : Spek({
3434
given("'colleagues #1'") {
35-
val testRepoPath = "../CodeLongevity_colleagues1"
35+
val testRepoPath = "../colleagues1"
3636
val testRepo = TestRepo(testRepoPath)
3737
val testRehash = "rehash_colleagues1"
3838
val fileName = "test1.txt"
@@ -88,9 +88,9 @@ class ColleaguesTest : Spek({
8888
}
8989

9090
given("'colleagues stats'") {
91-
val testRepoPath = "../CodeLongevity_colleagues_stats"
91+
val testRepoPath = "../colleagues_stats"
9292
val testRepo = TestRepo(testRepoPath)
93-
val testRehash = "rehash_lngstats2"
93+
val testRehash = "rehash_colleagues_stats"
9494
val fileName = "test1.txt"
9595
val author1 = Author(testRepo.userName, testRepo.userEmail)
9696
val author2 = Author("Vasya Pupkin", "[email protected]")

0 commit comments

Comments
 (0)