Commit Diff


commit - f980e76321979183bd8dd6cc67f93d08fced21db
commit + ff770dc4d5be7e3ede81e0fccd9df5987c526a13
blob - 632600d4ab0b4ba9d133197386db363c491e6c69
blob + fe82f9165a7f72564bdb819e25bdbbf0b46072d4
--- src/main/kotlin/dev/nezzontli/gotvcs/push/GotOutgoingCommitsProvider.kt
+++ src/main/kotlin/dev/nezzontli/gotvcs/push/GotOutgoingCommitsProvider.kt
@@ -4,6 +4,7 @@ import com.intellij.dvcs.push.OutgoingCommitsProvider
 import com.intellij.dvcs.push.OutgoingResult
 import com.intellij.dvcs.push.PushSpec
 import com.intellij.dvcs.push.VcsError
+import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.vcs.VcsException
 import dev.nezzontli.gotvcs.cli.GotCommandLineWrapper
 import dev.nezzontli.gotvcs.repo.GotRepository
@@ -18,6 +19,8 @@ import java.io.File
 class GotOutgoingCommitsProvider(private val commandLine: GotCommandLineWrapper) :
     OutgoingCommitsProvider<GotRepository, GotPushSource, GotPushTarget>() {
 
+    private val logger = Logger.getInstance(GotOutgoingCommitsProvider::class.java)
+
     override fun getOutgoingCommits(
         repository: GotRepository,
         pushSpec: PushSpec<GotPushSource, GotPushTarget>,
@@ -25,13 +28,20 @@ class GotOutgoingCommitsProvider(private val commandLi
     ): OutgoingResult {
         val workDir = File(repository.root.path)
         val target = pushSpec.target
+        logger.warn("got outgoing commits: workDir=$workDir remote=${target.remoteName} branch=${target.branch}")
         return try {
             val remoteHash = commandLine.remoteBranchHash(workDir, target.remoteName, target.branch)
-            val commits = commandLine.outgoingCommitIds(workDir, remoteHash)
-                .map { id -> GotFullCommitDetails(commandLine.catCommit(workDir, id), repository.root) }
+            logger.warn("got outgoing commits: remoteHash=$remoteHash")
+            val ids = commandLine.outgoingCommitIds(workDir, remoteHash)
+            logger.warn("got outgoing commits: ids=$ids")
+            val commits = ids.map { id -> GotFullCommitDetails(commandLine.catCommit(workDir, id), repository.root) }
             OutgoingResult(commits, emptyList())
         } catch (e: VcsException) {
+            logger.warn("got outgoing commits failed", e)
             OutgoingResult(emptyList(), listOf(VcsError(e.message)))
+        } catch (e: Exception) {
+            logger.error("got outgoing commits failed unexpectedly", e)
+            OutgoingResult(emptyList(), listOf(VcsError(e.message ?: e.toString())))
         }
     }
 }
blob - 5cfb8547432e834d0bab37bc6130158b86a1ac21
blob + a58652ea0902eab47d561a728e0873bdbbdbcb91
--- src/main/kotlin/dev/nezzontli/gotvcs/repo/GotBranchWidget.kt
+++ src/main/kotlin/dev/nezzontli/gotvcs/repo/GotBranchWidget.kt
@@ -2,9 +2,13 @@ package dev.nezzontli.gotvcs.repo
 
 import com.intellij.dvcs.ui.DvcsStatusWidget
 import com.intellij.openapi.project.Project
+import com.intellij.openapi.ui.popup.JBPopup
+import com.intellij.openapi.ui.popup.JBPopupFactory
+import com.intellij.openapi.ui.popup.util.BaseListPopupStep
 import com.intellij.openapi.vfs.VirtualFile
 import com.intellij.openapi.wm.StatusBarWidget
 import com.intellij.openapi.wm.StatusBarWidgetFactory
+import dev.nezzontli.gotvcs.cli.GotLogEntry
 
 private const val WIDGET_ID = "got.branch.widget"
 
@@ -26,6 +30,26 @@ class GotBranchWidget(project: Project) : DvcsStatusWi
 
     override fun rememberRecentRoot(path: String) = Unit
 
+    /**
+     * A quick, non-interactive preview of recent commits (from GotRepository's
+     * precomputed log, itself refreshed off-EDT). The full commit graph is a
+     * separate, larger "Log" tab feature not implemented yet.
+     */
+    override fun getWidgetPopup(project: Project, repository: GotRepository): JBPopup {
+        val entries = repository.getRecentLog()
+        val step = object : BaseListPopupStep<GotLogEntry>("Recent got commits", entries) {
+            override fun getTextFor(value: GotLogEntry): String {
+                val subject = value.message.lineSequence().firstOrNull().orEmpty()
+                return "${value.commitId.take(8)}  ${value.date}  $subject"
+            }
+
+            override fun isSelectable(value: GotLogEntry): Boolean = false
+
+            override fun onChosen(selectedValue: GotLogEntry?, finalChoice: Boolean) = null
+        }
+        return JBPopupFactory.getInstance().createListPopup(step)
+    }
+
     class Factory : StatusBarWidgetFactory {
         override fun getId(): String = WIDGET_ID
 
blob - e2470fa0782c308ca8eb832b2d7afbb219786d40
blob + 226d95b2c840aa45ead845323e905c24a0b15e38
--- src/main/kotlin/dev/nezzontli/gotvcs/repo/GotRepository.kt
+++ src/main/kotlin/dev/nezzontli/gotvcs/repo/GotRepository.kt
@@ -10,8 +10,11 @@ import com.intellij.openapi.vcs.VcsException
 import com.intellij.openapi.vfs.VirtualFile
 import dev.nezzontli.gotvcs.GotVcs
 import dev.nezzontli.gotvcs.cli.GotCommandLineWrapper
+import dev.nezzontli.gotvcs.cli.GotLogEntry
 import java.io.File
 
+private const val RECENT_LOG_SIZE = 15
+
 /**
  * getCurrentBranchName()/getCurrentRevision() are called from UI code (the
  * branch widget, the Push dialog's tree model) that runs on the EDT, so they
@@ -35,6 +38,9 @@ class GotRepository(
     @Volatile
     private var revision: String? = null
 
+    @Volatile
+    private var recentLog: List<GotLogEntry> = emptyList()
+
     init {
         Disposer.register(parentDisposable, this)
         refreshState()
@@ -52,8 +58,16 @@ class GotRepository(
         } catch (e: VcsException) {
             null
         }
+        recentLog = try {
+            commandLine.log(workDir, null, RECENT_LOG_SIZE)
+        } catch (e: VcsException) {
+            emptyList()
+        }
     }
 
+    /** Precomputed off-EDT (see class doc); safe for the branch widget's click popup to read directly. */
+    fun getRecentLog(): List<GotLogEntry> = recentLog
+
     override fun getRoot(): VirtualFile = root
 
     override fun getPresentableUrl(): String = root.presentableUrl