-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[patch] radically reducing the need for custom digger code by smarter…
… use of git cli
- Loading branch information
1 parent
93f597e
commit 6a15f5d
Showing
5 changed files
with
60 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/FindTrunkPath.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.zegreatrob.tools.digger.core | ||
|
||
fun DiggerGitWrapper.findTrunkPath(tagRefs: List<TagRef>, log: List<CommitRef>): List<CommitRef> = allPaths( | ||
log = log, | ||
firstTagCommit = log.first(), | ||
preferredCommitIds = tagRefs.map { it.commitId }.toSet(), | ||
) | ||
.shortestPathWithMostTags(taggedCommitIds = tagRefs.map { it.commitId }.toSet()) | ||
?: log.alwaysLeftParent() | ||
|
||
private fun MutableList<List<CommitRef>>.shortestPathWithMostTags(taggedCommitIds: Set<String>): List<CommitRef>? { | ||
val pathTagCountGroups = groupBy { path -> | ||
path.count { taggedCommitIds.contains(it.id) } | ||
} | ||
return pathTagCountGroups[pathTagCountGroups.keys.max()] | ||
?.minBy { it.size } | ||
} | ||
|
||
fun List<CommitRef>.alwaysLeftParent() = fold(emptyList<CommitRef>()) { acc, commit -> | ||
if (acc.isEmpty()) { | ||
acc + commit | ||
} else if (commit.id == acc.last().parents.firstOrNull()) { | ||
acc + commit | ||
} else { | ||
acc | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters