summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-10-08 17:54:40 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-10-08 18:30:57 +0200
commit9d55d71fdd310886cc178a4416a9d743d8f34a03 (patch)
tree4245f7fe41445a1314ab1a6b52f492675f9bac95
parentcc9a20c4abc850e94352cf04f7484bf0ba381780 (diff)
Add GetItemOperation/SetItemOperation/ClearItemOperation to IStateAccessor
Not used by anything yet; committing this separately in the interest of having smaller independent commits.
-rw-r--r--pkg/gui/gui.go30
-rw-r--r--pkg/gui/types/common.go21
2 files changed, 51 insertions, 0 deletions
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 2ded4a5c5..33a2e3d02 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -110,6 +110,12 @@ type Gui struct {
// lazygit was opened in, or if we'll retain the one we're currently in.
RetainOriginalDir bool
+ // stores long-running operations associated with items (e.g. when a branch
+ // is being pushed). At the moment the rule is to use an item operation when
+ // we need to talk to the remote.
+ itemOperations map[string]types.ItemOperation
+ itemOperationsMutex *deadlock.Mutex
+
PrevLayout PrevLayout
// this is the initial dir we are in upon opening lazygit. We hold onto this
@@ -180,6 +186,27 @@ func (self *StateAccessor) SetRetainOriginalDir(value bool) {
self.gui.RetainOriginalDir = value
}
+func (self *StateAccessor) GetItemOperation(item types.HasUrn) types.ItemOperation {
+ self.gui.itemOperationsMutex.Lock()
+ defer self.gui.itemOperationsMutex.Unlock()
+
+ return self.gui.itemOperations[item.URN()]
+}
+
+func (self *StateAccessor) SetItemOperation(item types.HasUrn, operation types.ItemOperation) {
+ self.gui.itemOperationsMutex.Lock()
+ defer self.gui.itemOperationsMutex.Unlock()
+
+ self.gui.itemOperations[item.URN()] = operation
+}
+
+func (self *StateAccessor) ClearItemOperation(item types.HasUrn) {
+ self.gui.itemOperationsMutex.Lock()
+ defer self.gui.itemOperationsMutex.Unlock()
+
+ delete(self.gui.itemOperations, item.URN())
+}
+
// we keep track of some stuff from one render to the next to see if certain
// things have changed
type PrevLayout struct {
@@ -473,6 +500,9 @@ func NewGui(
},
InitialDir: initialDir,
afterLayoutFuncs: make(chan func() error, 1000),
+
+ itemOperations: make(map[string]types.ItemOperation),
+ itemOperationsMutex: &deadlock.Mutex{},
}
gui.PopupHandler = popup.NewPopupHandler(
diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go
index 80d960eab..f4fde41c7 100644
--- a/pkg/gui/types/common.go
+++ b/pkg/gui/types/common.go
@@ -265,6 +265,24 @@ type Mutexes struct {
PtyMutex *deadlock.Mutex
}
+// A long-running operation associated with an item. For example, we'll show
+// that a branch is being pushed from so that there's visual feedback about
+// what's happening and so that you can see multiple branches' concurrent
+// operations
+type ItemOperation int
+
+const (
+ ItemOperationNone ItemOperation = iota
+ ItemOperationPushing
+ ItemOperationPulling
+ ItemOperationFastForwarding
+ ItemOperationDeleting
+)
+
+type HasUrn interface {
+ URN() string
+}
+
type IStateAccessor interface {
GetRepoPathStack() *utils.StringStack
GetRepoState() IRepoStateAccessor
@@ -277,6 +295,9 @@ type IStateAccessor interface {
SetShowExtrasWindow(bool)
GetRetainOriginalDir() bool
SetRetainOriginalDir(bool)
+ GetItemOperation(item HasUrn) ItemOperation
+ SetItemOperation(item HasUrn, operation ItemOperation)
+ ClearItemOperation(item HasUrn)
}
type IRepoStateAccessor interface {