From b5e6e7acdd9345efc06d618881bb9895462c20b8 Mon Sep 17 00:00:00 2001 From: "Dmitriy.Panov" Date: Sat, 8 Dec 2018 04:02:38 +0300 Subject: [PATCH] IJI-9: modified files sync fix --- .../intellij/build/images/sync/gitUtils.kt | 4 +-- .../intellij/build/images/sync/syncIcons.kt | 31 ++++++++++++------- .../intellij/build/images/sync/utils.kt | 4 +-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/gitUtils.kt b/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/gitUtils.kt index 81e7663daebe..181c6a1cf42e 100644 --- a/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/gitUtils.kt +++ b/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/gitUtils.kt @@ -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 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 "" diff --git a/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/syncIcons.kt b/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/syncIcons.kt index a404c6e85068..d6b6ceeec171 100644 --- a/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/syncIcons.kt +++ b/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/syncIcons.kt @@ -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, } } -private fun syncModified(modified: MutableCollection, +private fun syncModified(targetRoot: File, + modified: MutableCollection, targetRepoMap: Map, sourceRepoMap: Map) { 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)) } } } diff --git a/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/utils.kt b/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/utils.kt index 31c6ebeba4c8..13bb3fbad8e2 100644 --- a/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/utils.kt +++ b/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/sync/utils.kt @@ -54,11 +54,11 @@ internal fun List.split(eachSize: Int): List> { return result } -internal fun callSafely(call: () -> T): T? = try { +internal fun 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 }