summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-18 02:25:06 +0300
committerIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-18 02:25:06 +0300
commit0bd4df4fece44fc90faa7b0d448bf434d796aa42 (patch)
treec53c003425e78c5b70671809e5c39835a0a0713a
parentupdate readme and ignored files (diff)
downloadgitbatch-0bd4df4fece44fc90faa7b0d448bf434d796aa42.tar.gz
better gui refreshing with event dispatcher and minor refacotrs on gui
-rw-r--r--main.go2
-rw-r--r--pkg/git/branch.go2
-rw-r--r--pkg/git/cmd-fetch.go3
-rw-r--r--pkg/git/cmd-merge.go1
-rw-r--r--pkg/git/cmd-pull.go14
-rw-r--r--pkg/git/cmd-status.go42
-rw-r--r--pkg/git/file.go52
-rw-r--r--pkg/git/job.go25
-rw-r--r--pkg/git/repository.go71
-rw-r--r--pkg/gui/authenticationview.go8
-rw-r--r--pkg/gui/commitview.go6
-rw-r--r--pkg/gui/gui.go7
-rw-r--r--pkg/gui/mainview.go67
-rw-r--r--pkg/gui/sideviews.go68
-rw-r--r--pkg/gui/stashview.go6
-rw-r--r--pkg/gui/statusview.go8
-rw-r--r--pkg/gui/util-common.go35
-rw-r--r--pkg/gui/util-queuehandler.go24
-rw-r--r--pkg/gui/util-textstyle.go10
19 files changed, 238 insertions, 213 deletions
diff --git a/main.go b/main.go
index 0a8b5b3..02a6b20 100644
--- a/main.go
+++ b/main.go
@@ -15,7 +15,7 @@ var (
)
func main() {
- kingpin.Version("gitbatch version 0.1.1 (alpha)")
+ kingpin.Version("gitbatch version 0.1.2 (pre-release)")
// parse the command line flag and options
kingpin.Parse()
diff --git a/pkg/git/branch.go b/pkg/git/branch.go
index ace5f79..085ecb1 100644
--- a/pkg/git/branch.go
+++ b/pkg/git/branch.go
@@ -131,7 +131,7 @@ func (entity *RepoEntity) Checkout(branch *Branch) error {
entity.RefreshPushPull()
// make this conditional on global scale
err = entity.Remote.SyncBranches(branch.Name)
- return err
+ return entity.Refresh()
}
// checking the branch if it has any changes from its head revision. Initially
diff --git a/pkg/git/cmd-fetch.go b/pkg/git/cmd-fetch.go
index d1d6abb..73c29d1 100644
--- a/pkg/git/cmd-fetch.go
+++ b/pkg/git/cmd-fetch.go
@@ -90,6 +90,7 @@ func fetchWithGit(entity *RepoEntity, options FetchOptions) (err error) {
log.Warn("Error at git command (fetch)")
return err
}
+ entity.SetState(Success)
// till this step everything should be ok
return entity.Refresh()
}
@@ -145,6 +146,8 @@ func fetchWithGoGit(entity *RepoEntity, options FetchOptions, refspec string) (e
return err
}
}
+
+ entity.SetState(Success)
// till this step everything should be ok
return entity.Refresh()
}
diff --git a/pkg/git/cmd-merge.go b/pkg/git/cmd-merge.go
index 984bc4b..69b21af 100644
--- a/pkg/git/cmd-merge.go
+++ b/pkg/git/cmd-merge.go
@@ -34,6 +34,7 @@ func Merge(entity *RepoEntity, options MergeOptions) error {
log.Warn("Error while merging")
return err
}
+ entity.SetState(Success)
entity.Refresh()
return nil
}
diff --git a/pkg/git/cmd-pull.go b/pkg/git/cmd-pull.go
index a493b19..164d960 100644
--- a/pkg/git/cmd-pull.go
+++ b/pkg/git/cmd-pull.go
@@ -4,6 +4,7 @@ import (
log "github.com/sirupsen/logrus"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
)
@@ -64,6 +65,7 @@ func pullWithGit(entity *RepoEntity, options PullOptions) (err error) {
log.Warn("Error at git command (pull)")
return err
}
+ entity.SetState(Success)
return entity.Refresh()
}
@@ -98,7 +100,17 @@ func pullWithGoGit(entity *RepoEntity, options PullOptions) (err error) {
}
err = w.Pull(opt)
if err != nil {
- return err
+ if err == git.NoErrAlreadyUpToDate {
+ // Already up-to-date
+ log.Warn(err.Error())
+ } else if err == transport.ErrAuthenticationRequired {
+ log.Warn(err.Error())
+ return ErrAuthenticationRequired
+ } else {
+ log.Warn(err.Error())
+ return err
+ }
}
+ entity.SetState(Success)
return entity.Refresh()
}
diff --git a/pkg/git/cmd-status.go b/pkg/git/cmd-status.go
index 508a27c..b7969e6 100644
--- a/pkg/git/cmd-status.go
+++ b/pkg/git/cmd-status.go
@@ -18,38 +18,6 @@ var (
statusCmdModeNative = "go-git"
)
-// File represents the status of a file in an index or work tree
-type File struct {
- Name string
- AbsPath string
- X FileStatus
- Y FileStatus
-}
-
-// FileStatus is the short representation of state of a file
-type FileStatus byte
-
-var (
- // StatusNotupdated says file not updated
- StatusNotupdated FileStatus = ' '
- // StatusModified says file is modifed
- StatusModified FileStatus = 'M'
- // StatusAdded says file is added to index
- StatusAdded FileStatus = 'A'
- // StatusDeleted says file is deleted
- StatusDeleted FileStatus = 'D'
- // StatusRenamed says file is renamed
- StatusRenamed FileStatus = 'R'
- // StatusCopied says file is copied
- StatusCopied FileStatus = 'C'
- // StatusUpdated says file is updated
- StatusUpdated FileStatus = 'U'
- // StatusUntracked says file is untraced
- StatusUntracked FileStatus = '?'
- // StatusIgnored says file is ignored
- StatusIgnored FileStatus = '!'
-)
-
func shortStatus(entity *RepoEntity, option string) string {
args := make([]string, 0)
args = append(args, statusCommand)
@@ -122,13 +90,3 @@ func statusWithGoGit(entity *RepoEntity) ([]*File, error) {
sort.Sort(filesAlphabetical(files))
return files, nil
}
-
-// Diff is a wrapper of "git diff" command for a file to compare with HEAD rev
-func (file *File) Diff() (output string, err error) {
- args := make([]string, 0)
- args = append(args, "diff")
- args = append(args, "HEAD")
- args = append(args, file.Name)
- output, err = GenericGitCommandWithErrorOutput(strings.TrimSuffix(file.AbsPath, file.Name), args)
- return output, err
-}
diff --git a/pkg/git/file.go b/pkg/git/file.go
new file mode 100644
index 0000000..b1e603a
--- /dev/null
+++ b/pkg/git/file.go
@@ -0,0 +1,52 @@
+package git
+
+import (
+ "strings"
+
+ log "github.com/sirupsen/logrus"
+)
+
+// File represents the status of a file in an index or work tree
+type File struct {
+ Name string
+ AbsPath string
+ X FileStatus
+ Y FileStatus
+}
+
+// FileStatus is the short representation of state of a file
+type FileStatus byte
+
+var (
+ // StatusNotupdated says file not updated
+ StatusNotupdated FileStatus = ' '
+ // StatusModified says file is modifed
+ StatusModified FileStatus = 'M'
+ // StatusAdded says file is added to index
+ StatusAdded FileStatus = 'A'
+ // StatusDeleted says file is deleted
+ StatusDeleted FileStatus = 'D'
+ // StatusRenamed says file is renamed
+ StatusRenamed FileStatus = 'R'
+ // StatusCopied says file is copied
+ StatusCopied FileStatus = 'C'
+ // StatusUpdated says file is updated
+ StatusUpdated FileStatus = 'U'
+ // StatusUntracked says file is untraced
+ StatusUntracked FileStatus = '?'
+ // StatusIgnored says file is ignored
+ StatusIgnored FileStatus = '!'
+)
+
+// Diff is a wrapper of "git diff" command for a file to compare with HEAD rev
+func (file *File) Diff() (output string, err error) {
+ args := make([]string, 0)
+ args = append(args, "diff")
+ args = append(args, "HEAD")
+ args = append(args, file.Name)
+ output, err = GenericGitCommandWithErrorOutput(strings.TrimSuffix(file.AbsPath, file.Name), args)
+ if err != nil {
+ log.Warn(err)
+ }
+ return output, err
+}
diff --git a/pkg/git/job.go b/pkg/git/job.go
index 7dc4126..4889fc0 100644
--- a/pkg/git/job.go
+++ b/pkg/git/job.go
@@ -26,7 +26,7 @@ const (
// starts the job
func (job *Job) start() error {
- job.Entity.State = Working
+ job.Entity.SetState(Working)
// TODO: Handle errors?
// TOOD: Better implementation required
switch mode := job.JobType; mode {
@@ -40,39 +40,32 @@ func (job *Job) start() error {
}
}
if err := Fetch(job.Entity, opts); err != nil {
- job.Entity.State = Fail
+ job.Entity.SetState(Fail)
return err
}
case PullJob:
- var opts FetchOptions
+ var opts PullOptions
if job.Options != nil {
- opts = job.Options.(FetchOptions)
+ opts = job.Options.(PullOptions)
} else {
- opts = FetchOptions{
+ opts = PullOptions{
RemoteName: job.Entity.Remote.Name,
}
}
- if err := Fetch(job.Entity, opts); err != nil {
- job.Entity.State = Fail
+ if err := Pull(job.Entity, opts); err != nil {
+ job.Entity.SetState(Fail)
return err
}
- if err := Merge(job.Entity, MergeOptions{
- BranchName: job.Entity.Remote.Branch.Name,
- }); err != nil {
- job.Entity.State = Fail
- return nil
- }
case MergeJob:
if err := Merge(job.Entity, MergeOptions{
BranchName: job.Entity.Remote.Branch.Name,
}); err != nil {
- job.Entity.State = Fail
+ job.Entity.SetState(Fail)
return nil
}
default:
- job.Entity.State = Available
+ job.Entity.SetState(Available)
return nil
}
- job.Entity.State = Success
return nil
}
diff --git a/pkg/git/repository.go b/pkg/git/repository.go
index f37c813..3debe44 100644
--- a/pkg/git/repository.go
+++ b/pkg/git/repository.go
@@ -3,6 +3,7 @@ package git
import (
"errors"
"os"
+ "sync"
"time"
"github.com/isacikgoz/gitbatch/pkg/helpers"
@@ -26,7 +27,20 @@ type RepoEntity struct {
Commit *Commit
Commits []*Commit
Stasheds []*StashedItem
- State RepoState
+ state RepoState
+
+ mutex *sync.RWMutex
+ listeners map[string][]RepositoryListener
+}
+
+// RepositoryListener is a type for listeners
+type RepositoryListener func(event *RepositoryEvent) error
+
+// RepositoryEvent is used to transfer event-related data.
+// It is passed to listeners when Emit() is called
+type RepositoryEvent struct {
+ Name string
+ Data interface{}
}
// RepoState is the state of the repository for an operation
@@ -45,6 +59,9 @@ const (
Success RepoState = 4
// Fail is the unexpected outcome of the operation
Fail RepoState = 5
+
+ // This is the repository updated topic
+ RepositoryUpdated = "repository.updated"
)
// InitializeRepo initializes a RepoEntity struct with its belongings.
@@ -53,6 +70,7 @@ func InitializeRepo(directory string) (entity *RepoEntity, err error) {
if err != nil {
return nil, err
}
+
// after we intiate the struct we can fill its values
entity.loadLocalBranches()
entity.loadCommits()
@@ -106,16 +124,62 @@ func FastInitializeRepo(directory string) (entity *RepoEntity, err error) {
}).Trace("Cannot open directory as a git repository")
return nil, err
}
+ // initialize entity with minimum viable fields
entity = &RepoEntity{RepoID: helpers.RandomString(8),
Name: fileInfo.Name(),
AbsPath: directory,
ModTime: fileInfo.ModTime(),
Repository: *r,
- State: Available,
+ state: Available,
+ mutex: &sync.RWMutex{},
+ listeners: make(map[string][]RepositoryListener),
}
return entity, nil
}
+// On adds new listener.
+// listener is a callback function that will be called when event emits
+func (entity *RepoEntity) On(event string, listener RepositoryListener) {
+ entity.mutex.Lock()
+ defer entity.mutex.Unlock()
+
+ entity.listeners[event] = append(entity.listeners[event], listener)
+}
+
+// Emit notifies listeners about the event
+func (entity *RepoEntity) Emit(eventName string, data interface{}) error {
+ entity.mutex.RLock()
+ defer entity.mutex.RUnlock()
+
+ listeners, ok := entity.listeners[eventName]
+ if !ok {
+ return nil
+ }
+
+ for i := range listeners {
+ event := &RepositoryEvent{
+ Name: eventName,
+ Data: data,
+ }
+ if err := listeners[i](event); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// State returns the state of the repository such as queued, failed etc.
+func (entity *RepoEntity) State() RepoState {
+ return entity.state
+}
+
+// SetState sets the state of repository and sends repository updated event
+func (entity *RepoEntity) SetState(state RepoState) {
+ entity.state = state
+ // we could send an event data but we don't need for this topic
+ entity.Emit(RepositoryUpdated, nil)
+}
+
// Refresh the belongings of a repositoriy, this function is called right after
// fetch/pull/merge operations
func (entity *RepoEntity) Refresh() error {
@@ -147,5 +211,6 @@ func (entity *RepoEntity) Refresh() error {
return err
}
err = entity.loadStashedItems()
- return err
+ // we could send an event data but we don't need for this topic
+ return entity.Emit(RepositoryUpdated, nil)
}
diff --git a/pkg/gui/authenticationview.go b/pkg/gui/authenticationview.go
index 9c830cd..b644b6b 100644
--- a/pkg/gui/authenticationview.go
+++ b/pkg/gui/authenticationview.go
@@ -37,7 +37,7 @@ func (gui *Gui) openAuthenticationView(g *gocui.Gui, jobQueue *git.JobQueue, job
return err
}
jobRequiresAuth = job
- if job.Entity.State != git.Fail {
+ if job.Entity.State() != git.Fail {
if err := jobQueue.RemoveFromQueue(job.Entity); err != nil {
log.Fatal(err.Error())
return err
@@ -96,7 +96,7 @@ func (gui *Gui) submitAuthenticationView(g *gocui.Gui, v *gocui.View) error {
}
case git.PullJob:
// we handle pull as fetch&merge so same rule applies
- jobRequiresAuth.Options = git.FetchOptions{
+ jobRequiresAuth.Options = git.PullOptions{
RemoteName: jobRequiresAuth.Entity.Remote.Name,
Credentials: git.Credentials{
User: creduser,
@@ -104,14 +104,12 @@ func (gui *Gui) submitAuthenticationView(g *gocui.Gui, v *gocui.View) error {
},
}
}
- jobRequiresAuth.Entity.State = git.Queued
+ jobRequiresAuth.Entity.SetState(git.Queued)
// add this job to the last of the queue
err = gui.State.Queue.AddJob(jobRequiresAuth)
if err != nil {
return err
}
- // refresh views with the updates
- gui.refreshMain(g)
gui.closeAuthenticationView(g, v)
v_return, err := g.View(authenticationReturnView)
gui.startQueue(g, v_return)
diff --git a/pkg/gui/commitview.go b/pkg/gui/commitview.go
index 94ef574..0f22091 100644
--- a/pkg/gui/commitview.go
+++ b/pkg/gui/commitview.go
@@ -174,12 +174,6 @@ func (gui *Gui) closeCommitMessageView(g *gocui.Gui, v *gocui.View) error {
return err
}
}
- if err := gui.refreshMain(g); err != nil {
- return err
- }
- if err := gui.refreshViews(g, entity); err != nil {
- return err
- }
if err := refreshAllStatusView(g, entity, true); err != nil {
return err
}
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 1fb94ad..2e1f2b2 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -2,6 +2,7 @@ package gui
import (
"fmt"
+ "sync"
"github.com/isacikgoz/gitbatch/pkg/git"
"github.com/jroimartin/gocui"
@@ -14,6 +15,7 @@ type Gui struct {
g *gocui.Gui
KeyBindings []*KeyBinding
State guiState
+ mutex *sync.Mutex
}
// guiState struct holds the repositories, directiories, mode and queue of the
@@ -81,6 +83,7 @@ func NewGui(mode string, directoies []string) (*Gui, error) {
}
gui := &Gui{
State: initialState,
+ mutex: &sync.Mutex{},
}
for _, m := range modes {
if string(m.ModeID) == mode {
@@ -121,6 +124,10 @@ func (gui *Gui) Run() error {
return
}
g_ui.State.Repositories = rs
+ // add gui's repositoryUpdated func as an observer to repositories
+ for _, repo := range rs {
+ repo.On(git.RepositoryUpdated, gui.repositoryUpdated)
+ }
gui.fillMain(g)
}(gui)
diff --git a/pkg/gui/mainview.go b/pkg/gui/mainview.go
index 389d66d..6bd55d9 100644
--- a/pkg/gui/mainview.go
+++ b/pkg/gui/mainview.go
@@ -16,9 +16,7 @@ func (gui *Gui) fillMain(g *gocui.Gui) error {
if err != nil {
return err
}
- for _, r := range gui.State.Repositories {
- fmt.Fprintln(v, gui.displayString(r))
- }
+ // if there is still a loading screen we better get rid of it
err = g.DeleteView(loadingViewFeature.Name)
if err != nil {
return err
@@ -26,19 +24,22 @@ func (gui *Gui) fillMain(g *gocui.Gui) error {
if _, err = gui.setCurrentViewOnTop(g, mainViewFeature.Name); err != nil {
return err
}
+ // Sort by name is default behavior as expected, so it handles redrwaing
+ // the main view
if err = gui.sortByName(g, v); err != nil {
return err
}
- entity := gui.getSelectedRepository()
- gui.refreshViews(g, entity)
return nil
})
return nil
}
// refresh the main view and re-render the repository representations
-func (gui *Gui) refreshMain(g *gocui.Gui) error {
- mainView, err := g.View(mainViewFeature.Name)
+func (gui *Gui) refreshMain() error {
+ gui.mutex.Lock()
+ defer gui.mutex.Unlock()
+
+ mainView, err := gui.g.View(mainViewFeature.Name)
if err != nil {
return err
}
@@ -46,6 +47,16 @@ func (gui *Gui) refreshMain(g *gocui.Gui) error {
for _, r := range gui.State.Repositories {
fmt.Fprintln(mainView, gui.displayString(r))
}
+ // while refreshing, refresh sideViews for selected entity, something may
+ // be changed?
+ return gui.refreshSideViews(gui.getSelectedRepository())
+}
+
+// listens the event -> "repository.updated"
+func (gui *Gui) repositoryUpdated(event *git.RepositoryEvent) error {
+ gui.g.Update(func(g *gocui.Gui) error {
+ return gui.refreshMain()
+ })
return nil
}
@@ -62,18 +73,12 @@ func (gui *Gui) cursorDown(g *gocui.Gui, v *gocui.View) error {
return nil
}
if err := v.SetCursor(cx, cy+1); err != nil {
-
if err := v.SetOrigin(ox, oy+1); err != nil {
return err
}
}
- entity := gui.getSelectedRepository()
- if err := gui.refreshMain(g); err != nil {
- return err
- }
- gui.refreshViews(g, entity)
}
- return nil
+ return gui.refreshMain()
}
// moves the cursor upwards for the main view
@@ -86,13 +91,8 @@ func (gui *Gui) cursorUp(g *gocui.Gui, v *gocui.View) error {
return err
}
}
- entity := gui.getSelectedRepository()
- if err := gui.refreshMain(g); err != nil {
- return err
- }
- gui.refreshViews(g, entity)
}
- return nil
+ return gui.refreshMain()
}
// returns the entity at cursors position by taking its position in the gui's
@@ -129,7 +129,7 @@ func (gui *Gui) addToQueue(entity *git.RepoEntity) error {
if err != nil {
return err
}
- entity.State = git.Queued
+ entity.SetState(git.Queued)
return nil
}
@@ -139,7 +139,7 @@ func (gui *Gui) removeFromQueue(entity *git.RepoEntity) error {
if err != nil {
return err
}
- entity.State = git.Available
+ entity.SetState(git.Available)
return nil
}
@@ -148,18 +148,17 @@ func (gui *Gui) removeFromQueue(entity *git.RepoEntity) error {
func (gui *Gui) markRepository(g *gocui.Gui, v *gocui.View) error {
r := gui.getSelectedRepository()
// maybe, failed entities may be added to queue again
- if r.State == git.Available || r.State == git.Success || r.State == git.Paused {
+ if r.State() == git.Available || r.State() == git.Success || r.State() == git.Paused {
if err := gui.addToQueue(r); err != nil {
return err
}
- } else if r.State == git.Queued {
+ } else if r.State() == git.Queued {
if err := gui.removeFromQueue(r); err != nil {
return err
}
} else {
return nil
}
- gui.refreshMain(g)
return nil
}
@@ -167,7 +166,7 @@ func (gui *Gui) markRepository(g *gocui.Gui, v *gocui.View) error {
// current state into account before adding it
func (gui *Gui) markAllRepositories(g *gocui.Gui, v *gocui.View) error {
for _, r := range gui.State.Repositories {
- if r.State == git.Available || r.State == git.Success {
+ if r.State() == git.Available || r.State() == git.Success {
if err := gui.addToQueue(r); err != nil {
return err
}
@@ -175,7 +174,6 @@ func (gui *Gui) markAllRepositories(g *gocui.Gui, v *gocui.View) error {
continue
}
}
- gui.refreshMain(g)
return nil
}
@@ -183,7 +181,7 @@ func (gui *Gui) markAllRepositories(g *gocui.Gui, v *gocui.View) error {
// current state into account before removing it
func (gui *Gui) unmarkAllRepositories(g *gocui.Gui, v *gocui.View) error {
for _, r := range gui.State.Repositories {
- if r.State == git.Queued {
+ if r.State() == git.Queued {
if err := gui.removeFromQueue(r); err != nil {
return err
}
@@ -191,14 +189,13 @@ func (gui *Gui) unmarkAllRepositories(g *gocui.Gui, v *gocui.View) error {
continue
}
}
- gui.refreshMain(g)
return nil
}
// sortByName sorts the repositories by A to Z order
func (gui *Gui) sortByName(g *gocui.Gui, v *gocui.View) error {
sort.Sort(git.Alphabetical(gui.State.Repositories))
- gui.refreshAfterSort(g)
+ gui.refreshMain()
return nil
}
@@ -206,14 +203,6 @@ func (gui *Gui) sortByName(g *gocui.Gui, v *gocui.View) error {
// the top element will be the last modified
func (gui *Gui) sortByMod(g *gocui.Gui, v *gocui.View) error {
sort.Sort(git.LastModified(gui.State.Repositories))
- gui.refreshAfterSort(g)
- return nil
-}
-
-// utility function that refreshes main and side views after that
-func (gui *Gui) refreshAfterSort(g *gocui.Gui) error {
- gui.refreshMain(g)
- entity := gui.getSelectedRepository()
- gui.refreshViews(g, entity)
+ gui.refreshMain()
return nil
}
diff --git a/pkg/gui/sideviews.go b/pkg/gui/sideviews.go
index 86aa3cb..b963391 100644
--- a/pkg/gui/sideviews.go
+++ b/pkg/gui/sideviews.go
@@ -12,10 +12,28 @@ var (
sideViews = []viewFeature{remoteViewFeature, remoteBranchViewFeature, branchViewFeature, commitViewFeature}
)
+// refreshes the side views of the application for given git.RepoEntity struct
+func (gui *Gui) refreshSideViews(entity *git.RepoEntity) error {
+ var err error
+ if err = gui.updateRemotes(entity); err != nil {
+ return err
+ }
+ if err = gui.updateBranch(entity); err != nil {
+ return err
+ }
+ if err = gui.updateRemoteBranches(entity); err != nil {
+ return err
+ }
+ if err = gui.updateCommits(entity); err != nil {
+ return err
+ }
+ return err
+}
+
// updates the remotesview for given entity
-func (gui *Gui) updateRemotes(g *gocui.Gui, entity *git.RepoEntity) error {
+func (gui *Gui) updateRemotes(entity *git.RepoEntity) error {
var err error
- out, err := g.View(remoteViewFeature.Name)
+ out, err := gui.g.View(remoteViewFeature.Name)
if err != nil {
return err
}
@@ -43,9 +61,9 @@ func (gui *Gui) updateRemotes(g *gocui.Gui, entity *git.RepoEntity) error {
}
// updates the remotebranchview for given entity
-func (gui *Gui) updateRemoteBranches(g *gocui.Gui, entity *git.RepoEntity) error {
+func (gui *Gui) updateRemoteBranches(entity *git.RepoEntity) error {
var err error
- out, err := g.View(remoteBranchViewFeature.Name)
+ out, err := gui.g.View(remoteBranchViewFeature.Name)
if err != nil {
return err
}
@@ -73,9 +91,9 @@ func (gui *Gui) updateRemoteBranches(g *gocui.Gui, entity *git.RepoEntity) error
}
// updates the branchview for given entity
-func (gui *Gui) updateBranch(g *gocui.Gui, entity *git.RepoEntity) error {
+func (gui *Gui) updateBranch(entity *git.RepoEntity) error {
var err error
- out, err := g.View(branchViewFeature.Name)
+ out, err := gui.g.View(branchViewFeature.Name)
if err != nil {
return err
}
@@ -96,9 +114,9 @@ func (gui *Gui) updateBranch(g *gocui.Gui, entity *git.RepoEntity) error {
}
// updates the commitsview for given entity
-func (gui *Gui) updateCommits(g *gocui.Gui, entity *git.RepoEntity) error {
+func (gui *Gui) updateCommits(entity *git.RepoEntity) error {
var err error
- out, err := g.View(commitViewFeature.Name)
+ out, err := gui.g.View(commitViewFeature.Name)
if err != nil {
return err
}
@@ -136,12 +154,12 @@ func (gui *Gui) sideViewsNextItem(g *gocui.Gui, v *gocui.View) error {
if err = entity.Remote.NextRemoteBranch(); err != nil {
return err
}
- err = gui.updateRemoteBranches(g, entity)
+ err = gui.updateRemoteBranches(entity)
case remoteViewFeature.Name:
if err = entity.NextRemote(); err != nil {
return err
}
- err = gui.remoteChangeFollowUp(g, entity)
+ err = gui.remoteChangeFollowUp(entity)
case branchViewFeature.Name:
if err = entity.Checkout(entity.NextBranch()); err != nil {
err = gui.openErrorView(g, err.Error(),
@@ -149,12 +167,12 @@ func (gui *Gui) sideViewsNextItem(g *gocui.Gui, v *gocui.View) error {
branchViewFeature.Name)
return err
}
- err = gui.checkoutFollowUp(g, entity)
+ err = gui.checkoutFollowUp(entity)
case commitViewFeature.Name:
if err = entity.NextCommit(); err != nil {
return err
}
- err = gui.updateCommits(g, entity)
+ err = gui.updateCommits(entity)
}
return err
}
@@ -167,12 +185,12 @@ func (gui *Gui) sideViewsPreviousItem(g *gocui.Gui, v *gocui.View) error {
if err = entity.Remote.PreviousRemoteBranch(); err != nil {
return err
}
- err = gui.updateRemoteBranches(g, entity)
+ err = gui.updateRemoteBranches(entity)
case remoteViewFeature.Name:
if err = entity.PreviousRemote(); err != nil {
return err
}
- err = gui.remoteChangeFollowUp(g, entity)
+ err = gui.remoteChangeFollowUp(entity)
case branchViewFeature.Name:
if err = entity.Checkout(entity.PreviousBranch()); err != nil {
err = gui.openErrorView(g, err.Error(),
@@ -180,12 +198,12 @@ func (gui *Gui) sideViewsPreviousItem(g *gocui.Gui, v *gocui.View) error {
branchViewFeature.Name)
return err
}
- err = gui.checkoutFollowUp(g, entity)
+ err = gui.checkoutFollowUp(entity)
case commitViewFeature.Name:
if err = entity.PreviousCommit(); err != nil {
return err
}
- err = gui.updateCommits(g, entity)
+ err = gui.updateCommits(entity)
}
return err
}
@@ -208,7 +226,7 @@ func (gui *Gui) syncRemoteBranch(g *gocui.Gui, v *gocui.View) error {
// some time need to fix, movement aint bad huh?
gui.sideViewsNextItem(g, vr)
gui.sideViewsPreviousItem(g, vr)
- err = gui.updateRemoteBranches(g, entity)
+ err = gui.updateRemoteBranches(entity)
return err
}
@@ -247,7 +265,6 @@ func (gui *Gui) confirmSetUpstreamToBranch(g *gocui.Gui, v *gocui.View) error {
return err
}
entity.Refresh()
- gui.refreshMain(g)
return gui.closeConfirmationView(g, v)
}
@@ -259,25 +276,24 @@ func (gui *Gui) closeConfirmationView(g *gocui.Gui, v *gocui.View) error {
}
// after checkout a remote some refreshments needed
-func (gui *Gui) remoteChangeFollowUp(g *gocui.Gui, entity *git.RepoEntity) (err error) {
- if err = gui.updateRemotes(g, entity); err != nil {
+func (gui *Gui) remoteChangeFollowUp(entity *git.RepoEntity) (err error) {
+ if err = gui.updateRemotes(entity); err != nil {
return err
}
- err = gui.updateRemoteBranches(g, entity)
+ err = gui.updateRemoteBranches(entity)
return err
}
// after checkout a branch some refreshments needed
-func (gui *Gui) checkoutFollowUp(g *gocui.Gui, entity *git.RepoEntity) (err error) {
- if err = gui.updateBranch(g, entity); err != nil {
+func (gui *Gui) checkoutFollowUp(entity *git.RepoEntity) (err error) {
+ if err = gui.updateBranch(entity); err != nil {
return err
}
- if err = gui.updateCommits(g, entity); err != nil {
+ if err = gui.updateCommits(entity); err != nil {
return err
}
- if err = gui.updateRemoteBranches(g, entity); err != nil {
+ if err = gui.updateRemoteBranches(entity); err != nil {
return err
}
- err = gui.refreshMain(g)
return err
}
diff --git a/pkg/gui/stashview.go b/pkg/gui/stashview.go
index 24b4f3c..6011df9 100644
--- a/pkg/gui/stashview.go
+++ b/pkg/gui/stashview.go
@@ -55,9 +55,9 @@ func (gui *Gui) popStash(g *gocui.Gui, v *gocui.View) error {
return err
}
}
- if err := entity.Refresh(); err != nil {
- return err
- }
+ // since the pop is a func of stashed item, we need to refresh entity here
+ entity.Refresh()
+
err = refreshAllStatusView(g, entity, true)
return err
}
diff --git a/pkg/gui/statusview.go b/pkg/gui/statusview.go
index 82df459..798b760 100644
--- a/pkg/gui/statusview.go
+++ b/pkg/gui/statusview.go
@@ -121,13 +121,7 @@ func (gui *Gui) closeStatusView(g *gocui.Gui, v *gocui.View) error {
}
stagedFiles = make([]*git.File, 0)
unstagedFiles = make([]*git.File, 0)
- entity := gui.getSelectedRepository()
- if err := gui.refreshMain(g); err != nil {
- return err
- }
- if err := gui.refreshViews(g, entity); err != nil {
- return err
- }
+
return gui.closeViewCleanup(mainViewFeature.Name)
}
diff --git a/pkg/gui/util-common.go b/pkg/gui/util-common.go
index f203bbf..3f6be1a 100644
--- a/pkg/gui/util-common.go
+++ b/pkg/gui/util-common.go
@@ -1,30 +1,11 @@
package gui
import (
- "github.com/isacikgoz/gitbatch/pkg/git"
"github.com/isacikgoz/gitbatch/pkg/helpers"
"github.com/jroimartin/gocui"
log "github.com/sirupsen/logrus"
)
-// refreshes the side views of the application for given git.RepoEntity struct
-func (gui *Gui) refreshViews(g *gocui.Gui, entity *git.RepoEntity) error {
- var err error
- if err = gui.updateRemotes(g, entity); err != nil {
- return err
- }
- if err = gui.updateBranch(g, entity); err != nil {
- return err
- }
- if err = gui.updateRemoteBranches(g, entity); err != nil {
- return err
- }
- if err = gui.updateCommits(g, entity); err != nil {
- return err
- }
- return err
-}
-
// focus to next view
func (gui *Gui) nextViewOfGroup(g *gocui.Gui, v *gocui.View, group []viewFeature) error {
var focusedViewName string
@@ -77,22 +58,6 @@ func (gui *Gui) previousViewOfGroup(g *gocui.Gui, v *gocui.View, group []viewFea
return nil
}
-// siwtch the app mode
-func (gui *Gui) switchMode(g *gocui.Gui, v *gocui.View) error {
- for i, mode := range modes {
- if mode == gui.State.Mode {
- if i == len(modes)-1 {
- gui.State.Mode = modes[0]
- break
- }
- gui.State.Mode = modes[i+1]
- break
- }
- }
- gui.updateKeyBindingsView(g, mainViewFeature.Name)
- return nil
-}
-
// siwtch the app's mode to fetch
func (gui *Gui) switchToFetchMode(g *gocui.Gui, v *gocui.View) error {
gui.State.Mode = fetchMode
diff --git a/pkg/gui/util-queuehandler.go b/pkg/gui/util-queuehandler.go
index a814c47..e303825 100644
--- a/pkg/gui/util-queuehandler.go
+++ b/pkg/gui/util-queuehandler.go
@@ -12,17 +12,11 @@ func (gui *Gui) startQueue(g *gocui.Gui, v *gocui.View) error {
go func(gui_go *Gui, g_go *gocui.Gui) {
for {
job, finished, err := gui_go.State.Queue.StartNext()
- // for each job execution we better refresh the main
- // it would be nice if we can also refresh side views
- g_go.Update(func(gu *gocui.Gui) error {
- gui_go.refreshMain(gu)
- return nil
- })
if err != nil {
if err == git.ErrAuthenticationRequired {
// pause the job, so it will be indicated to being blocking
- job.Entity.State = git.Paused
+ job.Entity.SetState(git.Paused)
err := gui_go.openAuthenticationView(g, gui_go.State.Queue, job, v.Name())
if err != nil {
log.Warn(err.Error())
@@ -36,23 +30,7 @@ func (gui *Gui) startQueue(g *gocui.Gui, v *gocui.View) error {
if finished {
return
}
- selectedEntity := gui_go.getSelectedRepository()
- if job.Entity == selectedEntity {
- gui_go.refreshViews(g, job.Entity)
- }
}
}(gui, g)
return nil
}
-
-// flashes the keybinding view's backgroun with green color to indicate that
-// the queue is started
-func indicateQueueStarted(g *gocui.Gui) error {
- v, err := g.View(keybindingsViewFeature.Name)
- if err != nil {
- return err
- }
- v.BgColor = gocui.ColorGreen
- v.FgColor = gocui.ColorBlack
- return nil
-}
diff --git a/pkg/gui/util-textstyle.go b/pkg/gui/util-textstyle.go
index 7c36263..d303d9c 100644
--- a/pkg/gui/util-textstyle.go
+++ b/pkg/gui/util-textstyle.go
@@ -86,7 +86,7 @@ func (gui *Gui) displayString(entity *git.RepoEntity) string {
}
// rendering the satus according to repository's state
- if entity.State == git.Queued {
+ if entity.State() == git.Queued {
if inQueue, ty := gui.State.Queue.IsInTheQueue(entity); inQueue {
switch mode := ty; mode {
case git.FetchJob:
@@ -100,14 +100,14 @@ func (gui *Gui) displayString(entity *git.RepoEntity) string {
}
}
return prefix + repoName + ws + suffix
- } else if entity.State == git.Working {
+ } else if entity.State() == git.Working {
// TODO: maybe the type of the job can be written while its working?
return prefix + repoName + ws + green.Sprint(workingSymbol)
- } else if entity.State == git.Success {
+ } else if entity.State() == git.Success {
return prefix + repoName + ws + green.Sprint(successSymbol)
- } else if entity.State == git.Paused {
+ } else if entity.State() == git.Paused {
return prefix + repoName + ws + yellow.Sprint(pauseSymbol)
- } else if entity.State == git.Fail {
+ } else if entity.State() == git.Fail {
return prefix + repoName + ws + red.Sprint(failSymbol)
} else {
return prefix + repoName