Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/git4idea/src/git4idea/index/GitFileStatus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data class GitFileStatus(val index: StatusCode,
fun isUntracked() = isUntracked(index) || isUntracked(workTree)
fun isIgnored() = isIgnored(index) || isIgnored(workTree)
fun isTracked() = !isIgnored(index) && !isUntracked(index)
fun isNotChanged() = index == ' ' && workTree == ' ' && origPath == null

fun getStagedStatus(): FileStatus? = if (isIgnored(index) || isUntracked(index) || isConflicted()) null else getFileStatus(index)
fun getUnStagedStatus(): FileStatus? = if (isIgnored(workTree) || isUntracked(workTree) || isConflicted()) null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class GitStageLineStatusTrackerProvider : LineStatusTrackerContentLoader {
if (!isStagingAreaAvailable(project)) return false
if (!stageLineStatusTrackerRegistryOption().asBoolean()) return false

val repository = GitRepositoryManager.getInstance(project).getRepositoryForFileQuick(file)
return repository != null
GitRepositoryManager.getInstance(project).getRepositoryForFileQuick(file) ?: return false
val status = GitStageTracker.getInstance(project).status(file) ?: return false
return status.isTracked()
}

override fun createTracker(project: Project, file: VirtualFile): LocalLineStatusTracker<*>? {
Expand All @@ -55,27 +56,29 @@ class GitStageLineStatusTrackerProvider : LineStatusTrackerContentLoader {

override fun getContentInfo(project: Project, file: VirtualFile): ContentInfo? {
val repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(file) ?: return null
return StagedContentInfo(repository.currentRevision, file.charset, file)
val status = GitStageTracker.getInstance(project).status(file) ?: return null
return StagedContentInfo(repository.currentRevision, status, file.charset, file)
}

override fun shouldBeUpdated(oldInfo: ContentInfo?, newInfo: ContentInfo): Boolean {
newInfo as StagedContentInfo
return oldInfo == null ||
oldInfo !is StagedContentInfo ||
oldInfo.currentRevision != newInfo.currentRevision ||
oldInfo.charset != newInfo.charset
oldInfo.charset != newInfo.charset ||
oldInfo.status.has(ContentVersion.HEAD) != newInfo.status.has(ContentVersion.HEAD)
}

override fun loadContent(project: Project, info: ContentInfo): TrackerContent? {
info as StagedContentInfo

val file = info.virtualFile
val filePath = VcsUtil.getFilePath(file)
val status = GitStageTracker.getInstance(project).status(file) ?: return null
if (GitContentRevision.getRepositoryIfSubmodule(project, filePath) != null) return null

val repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(file) ?: return null

val status = info.status
val indexFileRefresher = GitIndexFileSystemRefresher.getInstance(project)
val indexFile = indexFileRefresher.createFile(repository.root, status.path(ContentVersion.STAGED)) ?: return null
val indexDocument = runReadAction { FileDocumentManager.getInstance().getDocument(indexFile) } ?: return null
Expand All @@ -92,7 +95,8 @@ class GitStageLineStatusTrackerProvider : LineStatusTrackerContentLoader {
return StagedTrackerContent(correctedText, indexDocument)
}
catch (e: VcsException) {
LOG.warn("Can't load base revision content for ${file.path} with status $status", e)
val message = "Can't load base revision content for ${file.path} with status $status"
if (status.isNotChanged()) LOG.debug(message, e) else LOG.warnWithDebug(message, e)
return null
}
}
Expand All @@ -108,7 +112,11 @@ class GitStageLineStatusTrackerProvider : LineStatusTrackerContentLoader {
tracker.dropBaseRevision()
}

private class StagedContentInfo(val currentRevision: String?, val charset: Charset, val virtualFile: VirtualFile) : ContentInfo
private class StagedContentInfo(
val currentRevision: String?, val status: GitFileStatus,
val charset: Charset, val virtualFile: VirtualFile,
) : ContentInfo

private class StagedTrackerContent(val vcsContent: CharSequence, val stagedDocument: Document) : TrackerContent

companion object {
Expand Down