@@ -39,7 +39,7 @@ class RevCommitLine(val commit: RevCommit, val fileId: AnyObjectId,
39
39
val isDeleted : Boolean ) {
40
40
41
41
val id : String
42
- get() = " ${fileId.getName() } :$line "
42
+ get() = " ${fileId.name } :$line "
43
43
}
44
44
45
45
/* *
@@ -79,13 +79,12 @@ class CodeLine(val repo: Repository,
79
79
}
80
80
return field
81
81
}
82
- set(v) { field = v }
83
82
84
83
/* *
85
84
* The code line text.
86
85
*/
87
86
val text : String
88
- get() = RawText (repo.open(from.fileId).getBytes() ).getString(from.line)
87
+ get() = RawText (repo.open(from.fileId).bytes ).getString(from.line)
89
88
90
89
/* *
91
90
* Email address of the line's author.
@@ -103,7 +102,7 @@ class CodeLine(val repo: Repository,
103
102
* A date when the line was changed.
104
103
*/
105
104
val editDate : Date
106
- get() = Date (to.commit.getCommitTime() .toLong() * 1000 )
105
+ get() = Date (to.commit.commitTime .toLong() * 1000 )
107
106
108
107
/* *
109
108
* True if the line is deleted.
@@ -116,15 +115,15 @@ class CodeLine(val repo: Repository,
116
115
*/
117
116
override fun toString () : String {
118
117
val df = SimpleDateFormat (" yyyy-MM-dd HH:mm z" )
119
- val fd = df.format(Date (from.commit.getCommitTime() .toLong() * 1000 ))
120
- val td = df.format(Date (to.commit.getCommitTime() .toLong() * 1000 ))
121
- val fc = " ${from.commit.getName() } '${from.commit.getShortMessage() } '"
122
- val tc = " ${to.commit.getName() } '${to.commit.getShortMessage() } '"
118
+ val fd = df.format(Date (from.commit.commitTime .toLong() * 1000 ))
119
+ val td = df.format(Date (to.commit.commitTime .toLong() * 1000 ))
120
+ val fc = " ${from.commit.name } '${from.commit.shortMessage } '"
121
+ val tc = " ${to.commit.name } '${to.commit.shortMessage } '"
123
122
val revState = if (isDeleted) " deleted in" else " last known as"
124
123
val state = if (isDeleted) " deleted" else " alive"
125
124
return " Line '$text ' - '${from.file} :${from.line} ' added in $fc $fd \n " +
126
- " ${ revState} '${to.file} :${to.line} ' in $tc $td ,\n " +
127
- " age: ${ age} s - $state "
125
+ " $revState '${to.file} :${to.line} ' in $tc $td ,\n " +
126
+ " age: $age s - $state "
128
127
}
129
128
}
130
129
@@ -153,7 +152,7 @@ class Colleagues(private val serverRepo: Repo) {
153
152
Logger .trace { " collected colleague, age: ${line.age} " }
154
153
val vicinity = dates.getOrPut(month, { line.age })
155
154
if (vicinity > line.age) {
156
- dates.put( month, line.age)
155
+ dates[ month] = line.age
157
156
}
158
157
}
159
158
@@ -162,14 +161,14 @@ class Colleagues(private val serverRepo: Repo) {
162
161
// colleague2 edited colleauge1 code.
163
162
val auxHash = hashSetOf<Pair <String , String >>()
164
163
for ((pair, dates) in map) {
165
- val email1 = pair.first;
166
- val email2 = pair.second;
164
+ val email1 = pair.first
165
+ val email2 = pair.second
167
166
if (auxHash.contains(Pair (email2, email1))) {
168
- continue ;
167
+ continue
169
168
}
170
169
171
170
val min1 = dates.minBy { (_, vicinity) -> vicinity }!!
172
- val dates2 = map.get( Pair (email2, email1));
171
+ val dates2 = map[ Pair (email2, email1)]
173
172
if (dates2 != null ) {
174
173
auxHash.add(Pair (email1, email2))
175
174
@@ -237,7 +236,7 @@ class CodeLineAges : Serializable, Cloneable {
237
236
*/
238
237
var lastingLines: HashMap <String , LineInfo > = hashMapOf()
239
238
240
- override public fun clone (): CodeLineAges {
239
+ public override fun clone (): CodeLineAges {
241
240
val clone = CodeLineAges ()
242
241
aggrAges.forEach { (email, age) ->
243
242
clone.aggrAges[email] = age.copy() }
@@ -276,7 +275,7 @@ class CodeLongevity(
276
275
repoSum + = aggrAge.sum
277
276
repoTotal + = aggrAge.count
278
277
if (emails.contains(email)) {
279
- aggrAges.put( email, aggrAge)
278
+ aggrAges[ email] = aggrAge
280
279
}
281
280
}
282
281
@@ -349,7 +348,7 @@ class CodeLongevity(
349
348
// Update ages.
350
349
getLinesObservable(storedHead, diffObservable, onError).subscribe({
351
350
line ->
352
- Logger .trace { " Scanning: ${ line} " }
351
+ Logger .trace { " Scanning: $line " }
353
352
if (line.isDeleted) {
354
353
if (ageData.lastingLines.contains(line.oldId)) {
355
354
line.age + = ageData.lastingLines.remove(line.oldId)!! .age
@@ -365,15 +364,15 @@ class CodeLongevity(
365
364
if (ageData.lastingLines.contains(line.oldId)) {
366
365
age + = ageData.lastingLines.remove(line.oldId)!! .age
367
366
}
368
- ageData.lastingLines.put( line.newId, CodeLineAges .LineInfo (age,
369
- line.authorEmail) )
367
+ ageData.lastingLines[ line.newId] = CodeLineAges .LineInfo (age,
368
+ line.authorEmail)
370
369
}
371
370
}, onError, {
372
371
// Store ages for subsequent runs.
373
372
try {
374
373
val file = dataPath.toFile()
375
374
val oStream = ObjectOutputStream (FileOutputStream (file))
376
- oStream.writeUTF(head.getName() )
375
+ oStream.writeUTF(head.name )
377
376
oStream.writeObject(ageData)
378
377
}
379
378
catch (e: Exception ) {
@@ -418,24 +417,24 @@ class CodeLongevity(
418
417
Observable .create { subscriber ->
419
418
420
419
val headWalk = TreeWalk (repo)
421
- headWalk.setRecursive( true )
422
- headWalk.addTree(head.getTree() )
420
+ headWalk.isRecursive = true
421
+ headWalk.addTree(head.tree )
423
422
424
423
val files: MutableMap <String , ArrayList <RevCommitLine >> = mutableMapOf ()
425
424
426
425
// Build a map of file names and their code lines.
427
426
while (headWalk.next()) {
428
427
try {
429
- val path = headWalk.getPathString()
428
+ val path = headWalk.pathString
430
429
val fileId = headWalk.getObjectId(0 )
431
430
val fileLoader = repo.open(fileId)
432
431
if (! RawText .isBinary(fileLoader.openStream())) {
433
- val fileText = RawText (fileLoader.getBytes() )
432
+ val fileText = RawText (fileLoader.bytes )
434
433
val lines = ArrayList <RevCommitLine >(fileText.size())
435
- for (idx in 0 .. fileText.size() - 1 ) {
434
+ for (idx in 0 until fileText.size()) {
436
435
lines.add(RevCommitLine (head, fileId, path, idx, false ))
437
436
}
438
- files.put( path, lines)
437
+ files[ path] = lines
439
438
}
440
439
} catch (e: Exception ) {
441
440
// TODO(anatoly): better fix of exceptions.
@@ -450,17 +449,17 @@ class CodeLongevity(
450
449
// renames properly.
451
450
// TODO(alex): cover file renames by tests (see APP-132 issue).
452
451
for ((diff, editList) in diffs.asReversed()) {
453
- val oldPath = diff.getOldPath()
454
- val oldId = diff.getOldId() .toObjectId()
455
- val newPath = diff.getNewPath()
456
- val newId = diff.getNewId() .toObjectId()
452
+ val oldPath = diff.oldPath
453
+ val oldId = diff.oldId .toObjectId()
454
+ val newPath = diff.newPath
455
+ val newId = diff.newId .toObjectId()
457
456
Logger .trace { " old: '$oldPath ', new: '$newPath '" }
458
457
459
458
// File was deleted, initialize the line array in the files map.
460
459
if (diff.changeType == DiffEntry .ChangeType .DELETE ) {
461
460
val fileLoader = repo.open(oldId)
462
- val fileText = RawText (fileLoader.getBytes() )
463
- files.put( oldPath, ArrayList (fileText.size() ))
461
+ val fileText = RawText (fileLoader.bytes )
462
+ files[ oldPath] = ArrayList (fileText.size())
464
463
}
465
464
466
465
// If a file was deleted, then the new path is /dev/null.
@@ -469,33 +468,33 @@ class CodeLongevity(
469
468
} else {
470
469
oldPath
471
470
}
472
- val lines = files.get( path) !!
471
+ val lines = files[ path] !!
473
472
474
473
475
474
// Update the lines array according to diff insertions.
476
475
// Traverse the edit list backwards to keep indices of
477
476
// the edit list and the lines array in sync.
478
477
for (edit in editList.asReversed()) {
479
478
// Insertion case: track the lines.
480
- val insCount = edit.getLengthB()
479
+ val insCount = edit.lengthB
481
480
if (insCount > 0 ) {
482
- val insStart = edit.getBeginB()
483
- val insEnd = edit.getEndB()
481
+ val insStart = edit.beginB
482
+ val insEnd = edit.endB
484
483
Logger .trace { " ins ($insStart , $insEnd )" }
485
484
486
- for (idx in insStart .. insEnd - 1 ) {
485
+ for (idx in insStart until insEnd) {
487
486
val from = RevCommitLine (commit, newId,
488
487
newPath, idx, false )
489
488
try {
490
- val to = lines.get( idx)
489
+ val to = lines[ idx]
491
490
val cl = CodeLine (repo, from, to)
492
- Logger .trace { " Collected: ${cl} " }
491
+ Logger .trace { " Collected: $cl " }
493
492
subscriber.onNext(cl)
494
493
}
495
494
catch (e: IndexOutOfBoundsException ) {
496
- Logger .error(e, " No line at ${ idx} ; commit: " +
497
- " ${commit.getName() } ; " +
498
- " '${commit.getShortMessage() } '" )
495
+ Logger .error(e, " No line at $idx ; commit: " +
496
+ " ${commit.name } ; " +
497
+ " '${commit.shortMessage } '" )
499
498
throw e
500
499
}
501
500
}
@@ -507,14 +506,14 @@ class CodeLongevity(
507
506
for (edit in editList) {
508
507
// Deletion case. Chase down the deleted lines through the
509
508
// history.
510
- val delCount = edit.getLengthA()
509
+ val delCount = edit.lengthA
511
510
if (delCount > 0 ) {
512
- val delStart = edit.getBeginA()
513
- val delEnd = edit.getEndA()
511
+ val delStart = edit.beginA
512
+ val delEnd = edit.endA
514
513
Logger .trace { " del ($delStart , $delEnd )" }
515
514
516
515
val tmpLines = ArrayList <RevCommitLine >(delCount)
517
- for (idx in delStart .. delEnd - 1 ) {
516
+ for (idx in delStart until delEnd) {
518
517
tmpLines.add(RevCommitLine (commit, oldId,
519
518
oldPath, idx, true ))
520
519
}
@@ -524,7 +523,7 @@ class CodeLongevity(
524
523
525
524
// File was renamed, tweak the files map.
526
525
if (diff.changeType == DiffEntry .ChangeType .RENAME ) {
527
- files.set( oldPath, files.remove(newPath)!! )
526
+ files[ oldPath] = files.remove(newPath)!!
528
527
}
529
528
}
530
529
}, onError, {
@@ -534,15 +533,15 @@ class CodeLongevity(
534
533
// caller can update their ages properly.
535
534
if (tail != null ) {
536
535
val tailWalk = TreeWalk (repo)
537
- tailWalk.setRecursive( true )
538
- tailWalk.addTree(tail.getTree() )
536
+ tailWalk.isRecursive = true
537
+ tailWalk.addTree(tail.tree )
539
538
540
539
while (tailWalk.next()) {
541
- val filePath = tailWalk.getPathString()
542
- val lines = files.get( filePath)
540
+ val filePath = tailWalk.pathString
541
+ val lines = files[ filePath]
543
542
if (lines != null ) {
544
543
val fileId = tailWalk.getObjectId(0 )
545
- for (idx in 0 .. lines.size - 1 ) {
544
+ for (idx in 0 until lines.size) {
546
545
val from = RevCommitLine (tail, fileId,
547
546
filePath, idx, false )
548
547
val cl = CodeLine (repo, from, lines[idx])
0 commit comments