IJI-9: modified files sync fix

This commit is contained in:
Dmitriy.Panov
2018-12-08 04:02:38 +03:00
parent 610e9ff0e3
commit b5e6e7acdd
3 changed files with 24 additions and 15 deletions
@@ -38,7 +38,7 @@ private fun listGitTree(
execute(repo, GIT, "pull", "--rebase")
}
catch (e: Exception) {
callSafely {
callSafely(printStackTrace = false) {
execute(repo, GIT, "rebase", "--abort")
}
log("Unable to pull changes for $repo: ${e.message}")
@@ -303,7 +303,7 @@ internal data class CommitInfo(
)
internal fun <T> withUser(repo: File, user: String, email: String, block: () -> T): T {
val (originalUser, originalEmail) = callSafely {
val (originalUser, originalEmail) = callSafely(printStackTrace = false) {
execute(repo, GIT, "config", "user.name").removeSuffix(System.lineSeparator()) to
execute(repo, GIT, "config", "user.email").removeSuffix(System.lineSeparator())
} ?: "" to ""
@@ -14,14 +14,14 @@ internal fun syncDevRepo(context: Context) {
if (context.doSyncDevRepo) {
log("Syncing ${context.devRepoName}:")
syncAdded(context.byDesigners.added, context.icons, context.devRepoDir) { changesToReposMap(it) }
syncModified(context.byDesigners.modified, context.devIcons, context.icons)
syncModified(context.devRepoRoot, context.byDesigners.modified, context.devIcons, context.icons)
if (context.doSyncRemovedIconsInDev) syncRemoved(context.byDesigners.removed, context.devIcons)
}
}
internal fun syncIconsRepo(context: Context, byDev: Changes) {
syncAdded(byDev.added, context.devIcons, context.iconsRepoDir) { context.iconsRepo }
syncModified(byDev.modified, context.icons, context.devIcons)
syncModified(context.iconsRepoDir, byDev.modified, context.icons, context.devIcons)
syncRemoved(byDev.removed, context.icons)
}
@@ -48,19 +48,28 @@ private fun syncAdded(added: MutableCollection<String>,
}
}
private fun syncModified(modified: MutableCollection<String>,
private fun syncModified(targetRoot: File,
modified: MutableCollection<String>,
targetRepoMap: Map<String, GitObject>,
sourceRepoMap: Map<String, GitObject>) {
stageFiles(modified) { file, skip, stage ->
val target = targetRepoMap[file]!!
val source = sourceRepoMap[file]!!
if (target.hash == source.hash) {
log("$file is not modified, skipping")
skip()
}
else {
source.file.copyTo(target.file, overwrite = true)
stage(target.repo, target.path)
if (targetRepoMap.containsKey(file)) {
val target = targetRepoMap[file]!!
if (target.hash == source.hash) {
log("$file is not modified, skipping")
skip()
}
else {
source.file.copyTo(target.file, overwrite = true)
stage(target.repo, target.path)
}
} else{
log("$file should be modified but not exist, creating")
val targetFile = targetRoot.resolve(file)
val repo = changesToReposMap(targetFile)
source.file.copyTo(targetFile)
stage(repo, targetFile.toRelativeString(repo))
}
}
}
@@ -54,11 +54,11 @@ internal fun <T> List<T>.split(eachSize: Int): List<List<T>> {
return result
}
internal fun <T> callSafely(call: () -> T): T? = try {
internal fun <T> callSafely(printStackTrace: Boolean = false, call: () -> T): T? = try {
call()
}
catch (e: Exception) {
log(e.message ?: e::class.java.simpleName)
if (printStackTrace) e.printStackTrace() else log(e.message ?: e::class.java.simpleName)
null
}