diff options
| author | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2019-01-04 10:47:22 +0300 |
|---|---|---|
| committer | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2019-01-04 10:47:22 +0300 |
| commit | ba246669df4f6c80fcba7445ae7e56fbc2d92541 (patch) | |
| tree | dcdbcaa1c86ac3bd580331774dcb721feab3b75d /gui | |
| parent | refactor on var name (diff) | |
| download | gitbatch-ba246669df4f6c80fcba7445ae7e56fbc2d92541.tar.gz | |
add state to repository and some renaming
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/authenticationview.go | 10 | ||||
| -rw-r--r-- | gui/diffview.go | 4 | ||||
| -rw-r--r-- | gui/mainview.go | 16 | ||||
| -rw-r--r-- | gui/sideviews.go | 30 | ||||
| -rw-r--r-- | gui/util-textstyle.go | 33 |
5 files changed, 49 insertions, 44 deletions
diff --git a/gui/authenticationview.go b/gui/authenticationview.go index 97a214e..2faa3b7 100644 --- a/gui/authenticationview.go +++ b/gui/authenticationview.go @@ -41,7 +41,7 @@ func (gui *Gui) openAuthenticationView(g *gocui.Gui, jobQueue *job.JobQueue, job return err } jobRequiresAuth = job - if job.Repository.State() != git.Fail { + if job.Repository.WorkStatus() != git.Fail { if err := jobQueue.RemoveFromQueue(job.Repository); err != nil { log.Fatal(err.Error()) return err @@ -53,7 +53,7 @@ func (gui *Gui) openAuthenticationView(g *gocui.Gui, jobQueue *job.JobQueue, job if err != gocui.ErrUnknownView { return err } - fmt.Fprintln(v, keySymbol+selectionIndicator+red.Sprint(jobRequiresAuth.Repository.Remote.URL[0])) + fmt.Fprintln(v, keySymbol+selectionIndicator+red.Sprint(jobRequiresAuth.Repository.State.Remote.URL[0])) } g.Cursor = true if err := gui.openUserView(g); err != nil { @@ -104,7 +104,7 @@ func (gui *Gui) submitAuthenticationView(g *gocui.Gui, v *gocui.View) error { switch mode := jobRequiresAuth.JobType; mode { case job.FetchJob: jobRequiresAuth.Options = command.FetchOptions{ - RemoteName: jobRequiresAuth.Repository.Remote.Name, + RemoteName: jobRequiresAuth.Repository.State.Remote.Name, Credentials: git.Credentials{ User: creduser, Password: credpswd, @@ -113,14 +113,14 @@ func (gui *Gui) submitAuthenticationView(g *gocui.Gui, v *gocui.View) error { case job.PullJob: // we handle pull as fetch&merge so same rule applies jobRequiresAuth.Options = command.PullOptions{ - RemoteName: jobRequiresAuth.Repository.Remote.Name, + RemoteName: jobRequiresAuth.Repository.State.Remote.Name, Credentials: git.Credentials{ User: creduser, Password: credpswd, }, } } - jobRequiresAuth.Repository.SetState(git.Queued) + jobRequiresAuth.Repository.SetWorkStatus(git.Queued) // add this job to the last of the queue if err := gui.State.Queue.AddJob(jobRequiresAuth); err != nil { diff --git a/gui/diffview.go b/gui/diffview.go index 3bf9b05..9f49456 100644 --- a/gui/diffview.go +++ b/gui/diffview.go @@ -35,10 +35,10 @@ func (gui *Gui) prepareDiffView(g *gocui.Gui, v *gocui.View, display []string) ( // called from commitview, so initial view is commitview func (gui *Gui) openCommitDiffView(g *gocui.Gui, v *gocui.View) (err error) { r := gui.getSelectedRepository() - commit := r.Commit + commit := r.State.Commit commitDetail := []string{("Hash: " + cyan.Sprint(commit.Hash) + "\n" + "Author: " + commit.Author + "\n" + commit.Time + "\n" + "\n" + "\t\t" + commit.Message + "\n")} - diff, err := command.Diff(r, r.Commit.Hash) + diff, err := command.Diff(r, r.State.Commit.Hash) if err != nil { return err } diff --git a/gui/mainview.go b/gui/mainview.go index f12a26c..6cdaf61 100644 --- a/gui/mainview.go +++ b/gui/mainview.go @@ -192,7 +192,7 @@ func (gui *Gui) addToQueue(r *git.Repository) error { if err != nil { return err } - r.SetState(git.Queued) + r.SetWorkStatus(git.Queued) return nil } @@ -202,7 +202,7 @@ func (gui *Gui) removeFromQueue(r *git.Repository) error { if err != nil { return err } - r.SetState(git.Available) + r.SetWorkStatus(git.Available) return nil } @@ -214,7 +214,7 @@ func (gui *Gui) startQueue(g *gocui.Gui, v *gocui.View) error { gui_go.State.Queue = job.CreateJobQueue() for j, err := range fails { if err == gerr.ErrAuthenticationRequired { - j.Repository.SetState(git.Paused) + j.Repository.SetWorkStatus(git.Paused) gui_go.State.FailoverQueue.AddJob(j) } } @@ -224,7 +224,7 @@ func (gui *Gui) startQueue(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) submitCredentials(g *gocui.Gui, v *gocui.View) error { if is, j := gui.State.FailoverQueue.IsInTheQueue(gui.getSelectedRepository()); is { - if j.Repository.State() == git.Paused { + if j.Repository.WorkStatus() == git.Paused { gui.State.FailoverQueue.RemoveFromQueue(j.Repository) err := gui.openAuthenticationView(g, gui.State.Queue, j, v.Name()) if err != nil { @@ -244,11 +244,11 @@ func (gui *Gui) submitCredentials(g *gocui.Gui, v *gocui.View) 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().Ready { + if r.WorkStatus().Ready { if err := gui.addToQueue(r); err != nil { return err } - } else if r.State() == git.Queued { + } else if r.WorkStatus() == git.Queued { if err := gui.removeFromQueue(r); err != nil { return err } @@ -260,7 +260,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().Ready { + if r.WorkStatus().Ready { if err := gui.addToQueue(r); err != nil { return err } @@ -275,7 +275,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.WorkStatus() == git.Queued { if err := gui.removeFromQueue(r); err != nil { return err } diff --git a/gui/sideviews.go b/gui/sideviews.go index 5a3adc7..1a910cf 100644 --- a/gui/sideviews.go +++ b/gui/sideviews.go @@ -47,7 +47,7 @@ func (gui *Gui) renderRemotes(r *git.Repository) error { if totalRemotes > 0 { for i, rm := range r.Remotes { _, shortURL := trimRemoteURL(rm.URL[0]) - if rm.Name == r.Remote.Name { + if rm.Name == r.State.Remote.Name { currentindex = i fmt.Fprintln(out, selectionIndicator+rm.Name+": "+shortURL) continue @@ -70,10 +70,10 @@ func (gui *Gui) renderRemoteBranches(r *git.Repository) error { } out.Clear() currentindex := 0 - trb := len(r.Remote.Branches) + trb := len(r.State.Remote.Branches) if trb > 0 { - for i, rm := range r.Remote.Branches { - if rm.Name == r.Remote.Branch.Name { + for i, rm := range r.State.Remote.Branches { + if rm.Name == r.State.Remote.Branch.Name { currentindex = i fmt.Fprintln(out, selectionIndicator+rm.Name) continue @@ -98,7 +98,7 @@ func (gui *Gui) renderBranch(r *git.Repository) error { currentindex := 0 totalbranches := len(r.Branches) for i, b := range r.Branches { - if b.Name == r.Branch.Name { + if b.Name == r.State.Branch.Name { currentindex = i fmt.Fprintln(out, selectionIndicator+b.Name) continue @@ -120,7 +120,7 @@ func (gui *Gui) renderCommits(r *git.Repository) error { currentindex := 0 totalcommits := len(r.Commits) for i, c := range r.Commits { - if c.Hash == r.Commit.Hash { + if c.Hash == r.State.Commit.Hash { currentindex = i fmt.Fprintln(out, selectionIndicator+commitLabel(c)) continue @@ -136,7 +136,7 @@ func (gui *Gui) sideViewsNextItem(g *gocui.Gui, v *gocui.View) error { r := gui.getSelectedRepository() switch viewName := v.Name(); viewName { case remoteBranchViewFeature.Name: - return r.Remote.NextRemoteBranch(r) + return r.State.Remote.NextRemoteBranch(r) case remoteViewFeature.Name: return r.NextRemote() case branchViewFeature.Name: @@ -159,7 +159,7 @@ func (gui *Gui) sideViewsPreviousItem(g *gocui.Gui, v *gocui.View) error { r := gui.getSelectedRepository() switch viewName := v.Name(); viewName { case remoteBranchViewFeature.Name: - return r.Remote.PreviousRemoteBranch(r) + return r.State.Remote.PreviousRemoteBranch(r) case remoteViewFeature.Name: return r.PreviousRemote() case branchViewFeature.Name: @@ -180,7 +180,7 @@ func (gui *Gui) sideViewsPreviousItem(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) syncRemoteBranch(g *gocui.Gui, v *gocui.View) error { r := gui.getSelectedRepository() return command.Fetch(r, command.FetchOptions{ - RemoteName: r.Remote.Name, + RemoteName: r.State.Remote.Name, Prune: true, }) } @@ -195,8 +195,8 @@ func (gui *Gui) setUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { if err != gocui.ErrUnknownView { return err } - fmt.Fprintln(v, "branch."+r.Branch.Name+"."+"remote"+"="+r.Remote.Name) - fmt.Fprintln(v, "branch."+r.Branch.Name+"."+"merge"+"="+r.Branch.Reference.Name().String()) + fmt.Fprintln(v, "branch."+r.State.Branch.Name+"."+"remote"+"="+r.State.Remote.Name) + fmt.Fprintln(v, "branch."+r.State.Branch.Name+"."+"merge"+"="+r.State.Branch.Reference.Name().String()) } return gui.focusToView(confirmationViewFeature.Name) } @@ -206,17 +206,17 @@ func (gui *Gui) confirmSetUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { var err error r := gui.getSelectedRepository() if err = command.AddConfig(r, command.ConfigOptions{ - Section: "branch." + r.Branch.Name, + Section: "branch." + r.State.Branch.Name, Option: "remote", Site: command.ConfigSiteLocal, - }, r.Remote.Name); err != nil { + }, r.State.Remote.Name); err != nil { return err } if err = command.AddConfig(r, command.ConfigOptions{ - Section: "branch." + r.Branch.Name, + Section: "branch." + r.State.Branch.Name, Option: "merge", Site: command.ConfigSiteLocal, - }, r.Branch.Reference.Name().String()); err != nil { + }, r.State.Branch.Reference.Name().String()); err != nil { return err } r.Refresh() diff --git a/gui/util-textstyle.go b/gui/util-textstyle.go index 01a24c3..d699acf 100644 --- a/gui/util-textstyle.go +++ b/gui/util-textstyle.go @@ -54,12 +54,13 @@ var ( func (gui *Gui) repositoryLabel(r *git.Repository) string { var prefix string - if r.Branch.Pushables != "?" { - prefix = prefix + pushable + ws + r.Branch.Pushables + - ws + pullable + ws + r.Branch.Pullables + b := r.State.Branch + if b.Pushables != "?" { + prefix = prefix + pushable + ws + b.Pushables + + ws + pullable + ws + b.Pullables } else { - prefix = prefix + pushable + ws + yellow.Sprint(r.Branch.Pushables) + - ws + pullable + ws + yellow.Sprint(r.Branch.Pullables) + prefix = prefix + pushable + ws + yellow.Sprint(b.Pushables) + + ws + pullable + ws + yellow.Sprint(b.Pullables) } var repoName string @@ -73,10 +74,10 @@ func (gui *Gui) repositoryLabel(r *git.Repository) string { } // some branch names can be really long, in that times I hope the first // characters are important and meaningful - branch := adjustTextLength(r.Branch.Name, maxBranchLength) + branch := adjustTextLength(b.Name, maxBranchLength) prefix = prefix + string(cyan.Sprint(branch)) - if !r.Branch.Clean { + if !b.Clean { prefix = prefix + ws + dirty + ws } else { prefix = prefix + ws @@ -84,7 +85,7 @@ func (gui *Gui) repositoryLabel(r *git.Repository) string { var suffix string // rendering the satus according to repository's state - if r.State() == git.Queued { + if r.WorkStatus() == git.Queued { if inQueue, j := gui.State.Queue.IsInTheQueue(r); inQueue { switch mode := j.JobType; mode { case job.FetchJob: @@ -98,15 +99,15 @@ func (gui *Gui) repositoryLabel(r *git.Repository) string { } } return prefix + repoName + ws + suffix - } else if r.State() == git.Working { + } else if r.WorkStatus() == git.Working { // TODO: maybe the type of the job can be written while its working? return prefix + repoName + ws + green.Sprint(workingSymbol) - } else if r.State() == git.Success { + } else if r.WorkStatus() == git.Success { return prefix + repoName + ws + green.Sprint(successSymbol) - } else if r.State() == git.Paused { + } else if r.WorkStatus() == git.Paused { return prefix + repoName + ws + yellow.Sprint("authentication required (u)") - } else if r.State() == git.Fail { - return prefix + repoName + ws + red.Sprint(failSymbol) + ws + red.Sprint(r.Message) + } else if r.WorkStatus() == git.Fail { + return prefix + repoName + ws + red.Sprint(failSymbol) + ws + red.Sprint(r.State.Message) } return prefix + repoName } @@ -119,7 +120,11 @@ func commitLabel(c *git.Commit) string { case git.LocalCommit: body = blue.Sprint(c.Hash[:hashLength]) + " " + c.Message case git.RemoteCommit: - body = yellow.Sprint(c.Hash[:hashLength]) + " " + c.Message + if len(c.Hash) > hashLength { + body = yellow.Sprint(c.Hash[:hashLength]) + " " + c.Message + } else { + body = yellow.Sprint(c.Hash[:len(c.Hash)]) + " " + c.Message + } default: body = c.Hash[:hashLength] + " " + c.Message } |
