diff options
| author | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2019-01-04 04:17:28 +0300 |
|---|---|---|
| committer | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2019-01-04 04:17:28 +0300 |
| commit | bb0d2ee079a0f56e18de9f88b3b9f1c068b0798d (patch) | |
| tree | a974716226a9686a5ae52b72a184a110066b9ab0 | |
| parent | huge refactor, package layour re-organized (diff) | |
| download | gitbatch-bb0d2ee079a0f56e18de9f88b3b9f1c068b0798d.tar.gz | |
refactor on var name
| -rw-r--r-- | core/command/cmd-add.go | 18 | ||||
| -rw-r--r-- | core/command/cmd-commit.go | 24 | ||||
| -rw-r--r-- | core/command/cmd-config.go | 24 | ||||
| -rw-r--r-- | core/command/cmd-diff.go | 18 | ||||
| -rw-r--r-- | core/command/cmd-fetch.go | 36 | ||||
| -rw-r--r-- | core/command/cmd-merge.go | 8 | ||||
| -rw-r--r-- | core/command/cmd-pull.go | 32 | ||||
| -rw-r--r-- | core/command/cmd-reset.go | 22 | ||||
| -rw-r--r-- | core/command/cmd-status.go | 22 | ||||
| -rw-r--r-- | core/git/branch.go | 52 | ||||
| -rw-r--r-- | core/git/commit.go | 46 | ||||
| -rw-r--r-- | core/git/remote.go | 34 | ||||
| -rw-r--r-- | core/git/remotebranch.go | 34 | ||||
| -rw-r--r-- | core/git/repository.go | 134 | ||||
| -rw-r--r-- | core/git/sort.go | 8 | ||||
| -rw-r--r-- | core/git/stash.go | 20 | ||||
| -rw-r--r-- | core/job/job-queue.go | 10 | ||||
| -rw-r--r-- | core/job/job.go | 32 | ||||
| -rw-r--r-- | core/load/load.go | 6 | ||||
| -rw-r--r-- | gui/authenticationview.go | 12 | ||||
| -rw-r--r-- | gui/commitview.go | 16 | ||||
| -rw-r--r-- | gui/diffview.go | 12 | ||||
| -rw-r--r-- | gui/gui.go | 8 | ||||
| -rw-r--r-- | gui/mainview.go | 24 | ||||
| -rw-r--r-- | gui/sideviews.go | 108 | ||||
| -rw-r--r-- | gui/stagedview.go | 14 | ||||
| -rw-r--r-- | gui/stashview.go | 24 | ||||
| -rw-r--r-- | gui/statusview.go | 26 | ||||
| -rw-r--r-- | gui/unstagedview.go | 12 | ||||
| -rw-r--r-- | gui/util-textstyle.go | 38 |
30 files changed, 437 insertions, 437 deletions
diff --git a/core/command/cmd-add.go b/core/command/cmd-add.go index 2addb23..5ad8774 100644 --- a/core/command/cmd-add.go +++ b/core/command/cmd-add.go @@ -26,31 +26,31 @@ type AddOptions struct { } // Add is a wrapper function for "git add" command -func Add(e *git.RepoEntity, file *File, option AddOptions) error { +func Add(r *git.Repository, file *File, option AddOptions) error { addCmdMode = addCmdModeNative if option.Update || option.Force || option.DryRun { addCmdMode = addCmdModeLegacy } switch addCmdMode { case addCmdModeLegacy: - err := addWithGit(e, file, option) + err := addWithGit(r, file, option) return err case addCmdModeNative: - err := addWithGoGit(e, file) + err := addWithGoGit(r, file) return err } return errors.New("Unhandled add operation") } // AddAll function is the wrapper of "git add ." command -func AddAll(e *git.RepoEntity, option AddOptions) error { +func AddAll(r *git.Repository, option AddOptions) error { args := make([]string, 0) args = append(args, addCommand) if option.DryRun { args = append(args, "--dry-run") } args = append(args, ".") - out, err := GenericGitCommandWithOutput(e.AbsPath, args) + out, err := GenericGitCommandWithOutput(r.AbsPath, args) if err != nil { log.Warn("Error while add command") return errors.New(out + "\n" + err.Error()) @@ -58,7 +58,7 @@ func AddAll(e *git.RepoEntity, option AddOptions) error { return nil } -func addWithGit(e *git.RepoEntity, file *File, option AddOptions) error { +func addWithGit(r *git.Repository, file *File, option AddOptions) error { args := make([]string, 0) args = append(args, addCommand) args = append(args, file.Name) @@ -71,7 +71,7 @@ func addWithGit(e *git.RepoEntity, file *File, option AddOptions) error { if option.DryRun { args = append(args, "--dry-run") } - out, err := GenericGitCommandWithOutput(e.AbsPath, args) + out, err := GenericGitCommandWithOutput(r.AbsPath, args) if err != nil { log.Warn("Error while add command") return errors.New(out + "\n" + err.Error()) @@ -79,8 +79,8 @@ func addWithGit(e *git.RepoEntity, file *File, option AddOptions) error { return nil } -func addWithGoGit(e *git.RepoEntity, file *File) error { - w, err := e.Repository.Worktree() +func addWithGoGit(r *git.Repository, file *File) error { + w, err := r.Repo.Worktree() if err != nil { return err } diff --git a/core/command/cmd-commit.go b/core/command/cmd-commit.go index d81942e..bf81a25 100644 --- a/core/command/cmd-commit.go +++ b/core/command/cmd-commit.go @@ -29,22 +29,22 @@ type CommitOptions struct { } // CommitCommand defines which commit command to use. -func CommitCommand(e *git.RepoEntity, options CommitOptions) (err error) { +func CommitCommand(r *git.Repository, options CommitOptions) (err error) { // here we configure commit operation // default mode is go-git (this may be configured) commitCmdMode = commitCmdModeNative switch commitCmdMode { case commitCmdModeLegacy: - return commitWithGit(e, options) + return commitWithGit(r, options) case commitCmdModeNative: - return commitWithGoGit(e, options) + return commitWithGoGit(r, options) } return errors.New("Unhandled commit operation") } // commitWithGit is simply a bare git commit -m <msg> command which is flexible -func commitWithGit(e *git.RepoEntity, options CommitOptions) (err error) { +func commitWithGit(r *git.Repository, options CommitOptions) (err error) { args := make([]string, 0) args = append(args, commitCommand) args = append(args, "-m") @@ -52,18 +52,18 @@ func commitWithGit(e *git.RepoEntity, options CommitOptions) (err error) { if len(options.CommitMsg) > 0 { args = append(args, options.CommitMsg) } - if err := GenericGitCommand(e.AbsPath, args); err != nil { + if err := GenericGitCommand(r.AbsPath, args); err != nil { log.Warn("Error at git command (commit)") - e.Refresh() + r.Refresh() return err } // till this step everything should be ok - return e.Refresh() + return r.Refresh() } // commitWithGoGit is the primary commit method -func commitWithGoGit(e *git.RepoEntity, options CommitOptions) (err error) { - config, err := e.Repository.Config() +func commitWithGoGit(r *git.Repository, options CommitOptions) (err error) { + config, err := r.Repo.Config() if err != nil { return err } @@ -77,16 +77,16 @@ func commitWithGoGit(e *git.RepoEntity, options CommitOptions) (err error) { }, } - w, err := e.Repository.Worktree() + w, err := r.Repo.Worktree() if err != nil { return err } _, err = w.Commit(options.CommitMsg, opt) if err != nil { - e.Refresh() + r.Refresh() return err } // till this step everything should be ok - return e.Refresh() + return r.Refresh() } diff --git a/core/command/cmd-config.go b/core/command/cmd-config.go index c580ff6..35eff23 100644 --- a/core/command/cmd-config.go +++ b/core/command/cmd-config.go @@ -37,22 +37,22 @@ const ( ) // Config adds or reads config of a repository -func Config(e *git.RepoEntity, options ConfigOptions) (value string, err error) { +func Config(r *git.Repository, options ConfigOptions) (value string, err error) { // here we configure config operation // default mode is go-git (this may be configured) configCmdMode = configCmdModeLegacy switch configCmdMode { case configCmdModeLegacy: - return configWithGit(e, options) + return configWithGit(r, options) case configCmdModeNative: - return configWithGoGit(e, options) + return configWithGoGit(r, options) } return value, errors.New("Unhandled config operation") } // configWithGit is simply a bare git commit -m <msg> command which is flexible -func configWithGit(e *git.RepoEntity, options ConfigOptions) (value string, err error) { +func configWithGit(r *git.Repository, options ConfigOptions) (value string, err error) { args := make([]string, 0) args = append(args, configCommand) if len(string(options.Site)) > 0 { @@ -61,7 +61,7 @@ func configWithGit(e *git.RepoEntity, options ConfigOptions) (value string, err args = append(args, "--get") args = append(args, options.Section+"."+options.Option) // parse options to command line arguments - out, err := GenericGitCommandWithOutput(e.AbsPath, args) + out, err := GenericGitCommandWithOutput(r.AbsPath, args) if err != nil { return out, err } @@ -70,9 +70,9 @@ func configWithGit(e *git.RepoEntity, options ConfigOptions) (value string, err } // commitWithGoGit is the primary commit method -func configWithGoGit(e *git.RepoEntity, options ConfigOptions) (value string, err error) { +func configWithGoGit(r *git.Repository, options ConfigOptions) (value string, err error) { // TODO: add global search - config, err := e.Repository.Config() + config, err := r.Repo.Config() if err != nil { return value, err } @@ -80,13 +80,13 @@ func configWithGoGit(e *git.RepoEntity, options ConfigOptions) (value string, er } // AddConfig adds an entry on the ConfigOptions field. -func AddConfig(e *git.RepoEntity, options ConfigOptions, value string) (err error) { - return addConfigWithGit(e, options, value) +func AddConfig(r *git.Repository, options ConfigOptions, value string) (err error) { + return addConfigWithGit(r, options, value) } // addConfigWithGit is simply a bare git config --add <option> command which is flexible -func addConfigWithGit(e *git.RepoEntity, options ConfigOptions, value string) (err error) { +func addConfigWithGit(r *git.Repository, options ConfigOptions, value string) (err error) { args := make([]string, 0) args = append(args, configCommand) if len(string(options.Site)) > 0 { @@ -97,10 +97,10 @@ func addConfigWithGit(e *git.RepoEntity, options ConfigOptions, value string) (e if len(value) > 0 { args = append(args, value) } - if err := GenericGitCommand(e.AbsPath, args); err != nil { + if err := GenericGitCommand(r.AbsPath, args); err != nil { log.Warn("Error at git command (config)") return err } // till this step everything should be ok - return e.Refresh() + return r.Refresh() } diff --git a/core/command/cmd-diff.go b/core/command/cmd-diff.go index 120037a..89d17be 100644 --- a/core/command/cmd-diff.go +++ b/core/command/cmd-diff.go @@ -19,36 +19,36 @@ var ( // Diff is a wrapper function for "git diff" command // Diff function returns the diff to previous commit detail of the given has // of a specific commit -func Diff(e *git.RepoEntity, hash string) (diff string, err error) { +func Diff(r *git.Repository, hash string) (diff string, err error) { diffCmdMode = diffCmdModeNative switch diffCmdMode { case diffCmdModeLegacy: - return diffWithGit(e, hash) + return diffWithGit(r, hash) case diffCmdModeNative: - return diffWithGoGit(e, hash) + return diffWithGoGit(r, hash) } return diff, errors.New("Unhandled diff operation") } -func diffWithGit(e *git.RepoEntity, hash string) (diff string, err error) { +func diffWithGit(r *git.Repository, hash string) (diff string, err error) { return diff, nil } -func diffWithGoGit(e *git.RepoEntity, hash string) (diff string, err error) { +func diffWithGoGit(r *git.Repository, hash string) (diff string, err error) { currentCommitIndex := 0 - for i, cs := range e.Commits { + for i, cs := range r.Commits { if cs.Hash == hash { currentCommitIndex = i } } - if len(e.Commits)-currentCommitIndex <= 1 { + if len(r.Commits)-currentCommitIndex <= 1 { return "there is no diff", nil } // maybe we dont need to log the repo again? - commits, err := e.Repository.Log(&gogit.LogOptions{ - From: plumbing.NewHash(e.Commit.Hash), + commits, err := r.Repo.Log(&gogit.LogOptions{ + From: plumbing.NewHash(r.Commit.Hash), Order: gogit.LogOrderCommitterTime, }) if err != nil { diff --git a/core/command/cmd-fetch.go b/core/command/cmd-fetch.go index 3d60fe9..6415651 100644 --- a/core/command/cmd-fetch.go +++ b/core/command/cmd-fetch.go @@ -44,7 +44,7 @@ type FetchOptions struct { // Fetch branches refs from one or more other repositories, along with the // objects necessary to complete their histories -func Fetch(e *git.RepoEntity, options FetchOptions) (err error) { +func Fetch(r *git.Repository, options FetchOptions) (err error) { // here we configure fetch operation // default mode is go-git (this may be configured) fetchCmdMode = fetchCmdModeNative @@ -55,18 +55,18 @@ func Fetch(e *git.RepoEntity, options FetchOptions) (err error) { } switch fetchCmdMode { case fetchCmdModeLegacy: - err = fetchWithGit(e, options) + err = fetchWithGit(r, options) return err case fetchCmdModeNative: // this should be the refspec as default, let's give it a try // TODO: Fix for quick mode, maybe better read config file var refspec string - if e.Branch == nil { + if r.Branch == nil { refspec = "+refs/heads/*:refs/remotes/origin/*" } else { - refspec = "+" + "refs/heads/" + e.Branch.Name + ":" + "/refs/remotes/" + e.Remote.Branch.Name + refspec = "+" + "refs/heads/" + r.Branch.Name + ":" + "/refs/remotes/" + r.Remote.Branch.Name } - err = fetchWithGoGit(e, options, refspec) + err = fetchWithGoGit(r, options, refspec) return err } return nil @@ -75,7 +75,7 @@ func Fetch(e *git.RepoEntity, options FetchOptions) (err error) { // fetchWithGit is simply a bare git fetch <remote> command which is flexible // for complex operations, but on the other hand, it ties the app to another // tool. To avoid that, using native implementation is preferred. -func fetchWithGit(e *git.RepoEntity, options FetchOptions) (err error) { +func fetchWithGit(r *git.Repository, options FetchOptions) (err error) { args := make([]string, 0) args = append(args, fetchCommand) // parse options to command line arguments @@ -91,12 +91,12 @@ func fetchWithGit(e *git.RepoEntity, options FetchOptions) (err error) { if options.DryRun { args = append(args, "--dry-run") } - if out, err := GenericGitCommandWithOutput(e.AbsPath, args); err != nil { + if out, err := GenericGitCommandWithOutput(r.AbsPath, args); err != nil { return gerr.ParseGitError(out, err) } - e.SetState(git.Success) + r.SetState(git.Success) // till this step everything should be ok - return e.Refresh() + return r.Refresh() } // fetchWithGoGit is the primary fetch method and refspec is the main feature. @@ -105,7 +105,7 @@ func fetchWithGit(e *git.RepoEntity, options FetchOptions) (err error) { // pattern for references on the remote side and <dst> is where those references // will be written locally. The + tells Git to update the reference even if it // isn’t a fast-forward. -func fetchWithGoGit(e *git.RepoEntity, options FetchOptions, refspec string) (err error) { +func fetchWithGoGit(r *git.Repository, options FetchOptions, refspec string) (err error) { opt := &gogit.FetchOptions{ RemoteName: options.RemoteName, RefSpecs: []config.RefSpec{config.RefSpec(refspec)}, @@ -113,7 +113,7 @@ func fetchWithGoGit(e *git.RepoEntity, options FetchOptions, refspec string) (er } // if any credential is given, let's add it to the git.FetchOptions if len(options.Credentials.User) > 0 { - protocol, err := git.AuthProtocol(e.Remote) + protocol, err := git.AuthProtocol(r.Remote) if err != nil { return err } @@ -130,34 +130,34 @@ func fetchWithGoGit(e *git.RepoEntity, options FetchOptions, refspec string) (er opt.Progress = os.Stdout } - if err := e.Repository.Fetch(opt); err != nil { + if err := r.Repo.Fetch(opt); err != nil { if err == gogit.NoErrAlreadyUpToDate { // Already up-to-date log.Warn(err.Error()) // TODO: submit a PR for this kind of error, this type of catch is lame } else if strings.Contains(err.Error(), "couldn't find remote ref") { // we dont have remote ref, so lets pull other things.. maybe it'd be useful - rp := e.Remote.RefSpecs[0] + rp := r.Remote.RefSpecs[0] if fetchTryCount < fetchMaxTry { fetchTryCount++ - fetchWithGoGit(e, options, rp) + fetchWithGoGit(r, options, rp) } else { return err } // TODO: submit a PR for this kind of error, this type of catch is lame } else if strings.Contains(err.Error(), "SSH_AUTH_SOCK") { // The env variable SSH_AUTH_SOCK is not defined, maybe git can handle this - return fetchWithGit(e, options) + return fetchWithGit(r, options) } else if err == transport.ErrAuthenticationRequired { log.Warn(err.Error()) return gerr.ErrAuthenticationRequired } else { log.Warn(err.Error()) - return fetchWithGit(e, options) + return fetchWithGit(r, options) } } - e.SetState(git.Success) + r.SetState(git.Success) // till this step everything should be ok - return e.Refresh() + return r.Refresh() } diff --git a/core/command/cmd-merge.go b/core/command/cmd-merge.go index a3c06d1..1bcc90f 100644 --- a/core/command/cmd-merge.go +++ b/core/command/cmd-merge.go @@ -19,7 +19,7 @@ type MergeOptions struct { // Merge incorporates changes from the named commits or branches into the // current branch -func Merge(e *git.RepoEntity, options MergeOptions) error { +func Merge(r *git.Repository, options MergeOptions) error { args := make([]string, 0) args = append(args, mergeCommand) if len(options.BranchName) > 0 { @@ -31,9 +31,9 @@ func Merge(e *git.RepoEntity, options MergeOptions) error { if options.NoStat { args = append(args, "-n") } - if out, err := GenericGitCommandWithOutput(e.AbsPath, args); err != nil { + if out, err := GenericGitCommandWithOutput(r.AbsPath, args); err != nil { return gerr.ParseGitError(out, err) } - e.SetState(git.Success) - return e.Refresh() + r.SetState(git.Success) + return r.Refresh() } diff --git a/core/command/cmd-pull.go b/core/command/cmd-pull.go index 237303e..7fbcecc 100644 --- a/core/command/cmd-pull.go +++ b/core/command/cmd-pull.go @@ -42,7 +42,7 @@ type PullOptions struct { } // Pull ncorporates changes from a remote repository into the current branch. -func Pull(e *git.RepoEntity, options PullOptions) (err error) { +func Pull(r *git.Repository, options PullOptions) (err error) { // here we configure pull operation // default mode is go-git (this may be configured) pullCmdMode = pullCmdModeNative @@ -50,16 +50,16 @@ func Pull(e *git.RepoEntity, options PullOptions) (err error) { switch pullCmdMode { case pullCmdModeLegacy: - err = pullWithGit(e, options) + err = pullWithGit(r, options) return err case pullCmdModeNative: - err = pullWithGoGit(e, options) + err = pullWithGoGit(r, options) return err } return nil } -func pullWithGit(e *git.RepoEntity, options PullOptions) (err error) { +func pullWithGit(r *git.Repository, options PullOptions) (err error) { args := make([]string, 0) args = append(args, pullCommand) // parse options to command line arguments @@ -69,14 +69,14 @@ func pullWithGit(e *git.RepoEntity, options PullOptions) (err error) { if options.Force { args = append(args, "-f") } - if out, err := GenericGitCommandWithOutput(e.AbsPath, args); err != nil { + if out, err := GenericGitCommandWithOutput(r.AbsPath, args); err != nil { return gerr.ParseGitError(out, err) } - e.SetState(git.Success) - return e.Refresh() + r.SetState(git.Success) + return r.Refresh() } -func pullWithGoGit(e *git.RepoEntity, options PullOptions) (err error) { +func pullWithGoGit(r *git.Repository, options PullOptions) (err error) { opt := &gogit.PullOptions{ RemoteName: options.RemoteName, SingleBranch: options.SingleBranch, @@ -88,7 +88,7 @@ func pullWithGoGit(e *git.RepoEntity, options PullOptions) (err error) { } // if any credential is given, let's add it to the git.PullOptions if len(options.Credentials.User) > 0 { - protocol, err := git.AuthProtocol(e.Remote) + protocol, err := git.AuthProtocol(r.Remote) if err != nil { return err } @@ -104,7 +104,7 @@ func pullWithGoGit(e *git.RepoEntity, options PullOptions) (err error) { if options.Progress { opt.Progress = os.Stdout } - w, err := e.Repository.Worktree() + w, err := r.Repo.Worktree() if err != nil { return err } @@ -118,24 +118,24 @@ func pullWithGoGit(e *git.RepoEntity, options PullOptions) (err error) { } else if err == memory.ErrRefHasChanged && pullTryCount < pullMaxTry { pullTryCount++ log.Error("trying to fetch") - if err := Fetch(e, FetchOptions{ + if err := Fetch(r, FetchOptions{ RemoteName: options.RemoteName, }); err != nil { return err } - return Pull(e, options) + return Pull(r, options) } else if strings.Contains(err.Error(), "SSH_AUTH_SOCK") { // The env variable SSH_AUTH_SOCK is not defined, maybe git can handle this - return pullWithGit(e, options) + return pullWithGit(r, options) } else if err == transport.ErrAuthenticationRequired { log.Warn(err.Error()) return gerr.ErrAuthenticationRequired } else { log.Warn(err.Error()) - return pullWithGit(e, options) + return pullWithGit(r, options) } } - e.SetState(git.Success) - return e.Refresh() + r.SetState(git.Success) + return r.Refresh() } diff --git a/core/command/cmd-reset.go b/core/command/cmd-reset.go index d8e36ab..d97d82f 100644 --- a/core/command/cmd-reset.go +++ b/core/command/cmd-reset.go @@ -53,12 +53,12 @@ const ( ) // Reset is the wrapper of "git reset" command -func Reset(e *git.RepoEntity, file *File, option ResetOptions) error { +func Reset(r *git.Repository, file *File, option ResetOptions) error { resetCmdMode = resetCmdModeLegacy switch resetCmdMode { case resetCmdModeLegacy: - err := resetWithGit(e, file, option) + err := resetWithGit(r, file, option) return err case resetCmdModeNative: @@ -66,7 +66,7 @@ func Reset(e *git.RepoEntity, file *File, option ResetOptions) error { return errors.New("Unhandled reset operation") } -func resetWithGit(e *git.RepoEntity, file *File, option ResetOptions) error { +func resetWithGit(r *git.Repository, file *File, option ResetOptions) error { args := make([]string, 0) args = append(args, resetCommand) @@ -75,7 +75,7 @@ func resetWithGit(e *git.RepoEntity, file *File, option ResetOptions) error { if len(option.Rtype) > 0 { args = append(args, "--"+string(option.Rtype)) } - out, err := GenericGitCommandWithOutput(e.AbsPath, args) + out, err := GenericGitCommandWithOutput(r.AbsPath, args) if err != nil { log.Warn("Error while reset command") return errors.New(out + "\n" + err.Error()) @@ -84,27 +84,27 @@ func resetWithGit(e *git.RepoEntity, file *File, option ResetOptions) error { } // ResetAll resets the changes in a repository, should be used wise -func ResetAll(e *git.RepoEntity, option ResetOptions) error { +func ResetAll(r *git.Repository, option ResetOptions) error { resetCmdMode = addCmdModeNative switch resetCmdMode { case resetCmdModeLegacy: - err := resetAllWithGit(e, option) + err := resetAllWithGit(r, option) return err case resetCmdModeNative: - err := resetAllWithGoGit(e, option) + err := resetAllWithGoGit(r, option) return err } return errors.New("Unhandled reset operation") } -func resetAllWithGit(e *git.RepoEntity, option ResetOptions) error { +func resetAllWithGit(r *git.Repository, option ResetOptions) error { args := make([]string, 0) args = append(args, resetCommand) if len(option.Rtype) > 0 { args = append(args, "--"+string(option.Rtype)) } - out, err := GenericGitCommandWithOutput(e.AbsPath, args) + out, err := GenericGitCommandWithOutput(r.AbsPath, args) if err != nil { log.Warn("Error while add command") return errors.New(out + "\n" + err.Error()) @@ -112,8 +112,8 @@ func resetAllWithGit(e *git.RepoEntity, option ResetOptions) error { return nil } -func resetAllWithGoGit(e *git.RepoEntity, option ResetOptions) error { - w, err := e.Repository.Worktree() +func resetAllWithGoGit(r *git.Repository, option ResetOptions) error { + w, err := r.Repo.Worktree() if err != nil { return err } diff --git a/core/command/cmd-status.go b/core/command/cmd-status.go index f6a9dc8..f5947d6 100644 --- a/core/command/cmd-status.go +++ b/core/command/cmd-status.go @@ -19,12 +19,12 @@ var ( statusCmdModeNative = "go-git" ) -func shortStatus(e *git.RepoEntity, option string) string { +func shortStatus(r *git.Repository, option string) string { args := make([]string, 0) args = append(args, statusCommand) args = append(args, option) args = append(args, "--short") - out, err := GenericGitCommandWithOutput(e.AbsPath, args) + out, err := GenericGitCommandWithOutput(r.AbsPath, args) if err != nil { log.Warn("Error while status command") return "?" @@ -33,23 +33,23 @@ func shortStatus(e *git.RepoEntity, option string) string { } // Status returns the dirty files -func Status(e *git.RepoEntity) ([]*File, error) { +func Status(r *git.Repository) ([]*File, error) { statusCmdMode = statusCmdModeNative switch statusCmdMode { case statusCmdModeLegacy: - return statusWithGit(e) + return statusWithGit(r) case statusCmdModeNative: - return statusWithGoGit(e) + return statusWithGoGit(r) } return nil, errors.New("Unhandled status operation") } // LoadFiles function simply commands a git status and collects output in a // structured way -func statusWithGit(e *git.RepoEntity) ([]*File, error) { +func statusWithGit(r *git.Repository) ([]*File, error) { files := make([]*File, 0) - output := shortStatus(e, "--untracked-files=all") + output := shortStatus(r, "--untracked-files=all") if len(output) == 0 { return files, nil } @@ -62,7 +62,7 @@ func statusWithGit(e *git.RepoEntity) ([]*File, error) { files = append(files, &File{ Name: path, - AbsPath: e.AbsPath + string(os.PathSeparator) + path, + AbsPath: r.AbsPath + string(os.PathSeparator) + path, X: FileStatus(x), Y: FileStatus(y), }) @@ -71,9 +71,9 @@ func statusWithGit(e *git.RepoEntity) ([]*File, error) { return files, nil } -func statusWithGoGit(e *git.RepoEntity) ([]*File, error) { +func statusWithGoGit(r *git.Repository) ([]*File, error) { files := make([]*File, 0) - w, err := e.Repository.Worktree() + w, err := r.Repo.Worktree() if err != nil { return files, err } @@ -84,7 +84,7 @@ func statusWithGoGit(e *git.RepoEntity) ([]*File, error) { for k, v := range s { files = append(files, &File{ Name: k, - AbsPath: e.AbsPath + string(os.PathSeparator) + k, + AbsPath: r.AbsPath + string(os.PathSeparator) + k, X: FileStatus(v.Staging), Y: FileStatus(v.Worktree), }) diff --git a/core/git/branch.go b/core/git/branch.go index cc29f17..ead250a 100644 --- a/core/git/branch.go +++ b/core/git/branch.go @@ -30,15 +30,15 @@ var ( // search for branches in go-git way. It is useful to do so that checkout and // checkout error handling can be handled by code rather than struggling with // git cammand and its output -func (e *RepoEntity) loadLocalBranches() error { +func (r *Repository) loadLocalBranches() error { lbs := make([]*Branch, 0) - bs, err := e.Repository.Branches() + bs, err := r.Repo.Branches() if err != nil { log.Warn("Cannot load branches " + err.Error()) return err } defer bs.Close() - headRef, err := e.Repository.Head() + headRef, err := r.Repo.Head() if err != nil { return err } @@ -49,7 +49,7 @@ func (e *RepoEntity) loadLocalBranches() error { } var push, pull string - pushables, err := RevList(e, RevListOptions{ + pushables, err := RevList(r, RevListOptions{ Ref1: "@{u}", Ref2: "HEAD", }) @@ -58,7 +58,7 @@ func (e *RepoEntity) loadLocalBranches() error { } else { push = strconv.Itoa(len(pushables)) } - pullables, err := RevList(e, RevListOptions{ + pullables, err := RevList(r, RevListOptions{ Ref1: "HEAD", Ref2: "@{u}", }) @@ -67,7 +67,7 @@ func (e *RepoEntity) loadLocalBranches() error { } else { pull = strconv.Itoa(len(pullables)) } - clean := e.isClean() + clean := r.isClean() branch := &Branch{ Name: b.Name().Short(), Reference: b, @@ -76,7 +76,7 @@ func (e *RepoEntity) loadLocalBranches() error { Clean: clean, } if b.Name() == headRef.Name() { - e.Branch = branch + r.Branch = branch branchFound = true } lbs = append(lbs, branch) @@ -89,30 +89,30 @@ func (e *RepoEntity) loadLocalBranches() error { Reference: headRef, Pushables: "?", Pullables: "?", - Clean: e.isClean(), + Clean: r.isClean(), } lbs = append(lbs, branch) - e.Branch = branch + r.Branch = branch } - e.Branches = lbs + r.Branches = lbs return err } // NextBranch checkouts the next branch -func (e *RepoEntity) NextBranch() *Branch { - return e.Branches[(e.currentBranchIndex()+1)%len(e.Branches)] +func (r *Repository) NextBranch() *Branch { + return r.Branches[(r.currentBranchIndex()+1)%len(r.Branches)] } // PreviousBranch checkouts the previous branch -func (e *RepoEntity) PreviousBranch() *Branch { - return e.Branches[(len(e.Branches)+e.currentBranchIndex()-1)%len(e.Branches)] +func (r *Repository) PreviousBranch() *Branch { + return r.Branches[(len(r.Branches)+r.currentBranchIndex()-1)%len(r.Branches)] } // returns the active branch index -func (e *RepoEntity) currentBranchIndex() int { +func (r *Repository) currentBranchIndex() int { bix := 0 - for i, lbs := range e.Branches { - if lbs.Name == e.Branch.Name { + for i, lbs := range r.Branches { + if lbs.Name == r.Branch.Name { bix = i } } @@ -121,12 +121,12 @@ func (e *RepoEntity) currentBranchIndex() int { // Checkout to given branch. If any errors occur, the method returns it instead // of returning nil -func (e *RepoEntity) Checkout(b *Branch) error { - if b.Name == e.Branch.Name { +func (r *Repository) Checkout(b *Branch) error { + if b.Name == r.Branch.Name { return nil } - w, err := e.Repository.Worktree() + w, err := r.Repo.Worktree() if err != nil { log.Warn("Cannot get work tree " + err.Error()) return err @@ -140,18 +140,18 @@ func (e *RepoEntity) Checkout(b *Branch) error { // make this conditional on global scale // we don't care if this function returns an error - e.Remote.SyncBranches(b.Name) + r.Remote.SyncBranches(b.Name) - return e.Refresh() + return r.Refresh() } // checking the branch if it has any changes from its head revision. Initially // I implemented this with go-git but it was incredibly slow and there is also // an issue about it: https://github.com/src-d/go-git/issues/844 -func (e *RepoEntity) isClean() bool { +func (r *Repository) isClean() bool { args := []string{"status"} cmd := exec.Command("git", args...) - cmd.Dir = e.AbsPath + cmd.Dir = r.AbsPath out, err := cmd.CombinedOutput() if err != nil { return false @@ -183,7 +183,7 @@ type RevListOptions struct { // RevList returns the commit hashes that are links from the given commit(s). // The output is given in reverse chronological order by default. -func RevList(e *RepoEntity, options RevListOptions) ([]string, error) { +func RevList(r *Repository, options RevListOptions) ([]string, error) { args := make([]string, 0) args = append(args, revlistCommand) if len(options.Ref1) > 0 && len(options.Ref2) > 0 { @@ -191,7 +191,7 @@ func RevList(e *RepoEntity, options RevListOptions) ([]string, error) { args = append(args, arg1) } cmd := exec.Command("git", args...) - cmd.Dir = e.AbsPath + cmd.Dir = r.AbsPath out, err := cmd.CombinedOutput() if err != nil { return []string{"?"}, err diff --git a/core/git/commit.go b/core/git/commit.go index fa4e317..6c35778 100644 --- a/core/git/commit.go +++ b/core/git/commit.go @@ -34,20 +34,20 @@ const ( // NextCommit iterates over next commit of a branch // TODO: the commits entites can tied to branch instead ot the repository -func (e *RepoEntity) NextCommit() { - e.Commit = e.Commits[(e.currentCommitIndex()+1)%len(e.Commits)] +func (r *Repository) NextCommit() { + r.Commit = r.Commits[(r.currentCommitIndex()+1)%len(r.Commits)] } // PreviousCommit iterates to opposite direction -func (e *RepoEntity) PreviousCommit() { - e.Commit = e.Commits[(len(e.Commits)+e.currentCommitIndex()-1)%len(e.Commits)] +func (r *Repository) PreviousCommit() { + r.Commit = r.Commits[(len(r.Commits)+r.currentCommitIndex()-1)%len(r.Commits)] } // returns the active commit index -func (e *RepoEntity) currentCommitIndex() int { +func (r *Repository) currentCommitIndex() int { cix := 0 - for i, c := range e.Commits { - if c.Hash == e.Commit.Hash { + for i, c := range r.Commits { + if c.Hash == r.Commit.Hash { cix = i } } @@ -56,16 +56,16 @@ func (e *RepoEntity) currentCommitIndex() int { // loads the local commits by simply using git log way. ALso, gets the upstream // diff commits -func (e *RepoEntity) loadCommits() error { - r := e.Repository - e.Commits = make([]*Commit, 0) - ref, err := r.Head() +func (r *Repository) loadCommits() error { + rp := r.Repo + r.Commits = make([]*Commit, 0) + ref, err := rp.Head() if err != nil { log.Trace("Cannot get HEAD " + err.Error()) return err } // git log first - cIter, err := r.Log(&git.LogOptions{ + cIter, err := rp.Log(&git.LogOptions{ From: ref.Hash(), Order: git.LogOrderCommitterTime, }) @@ -75,11 +75,11 @@ func (e *RepoEntity) loadCommits() error { } defer cIter.Close() // find commits that fetched from upstream but not merged commits - rmcs, _ := e.pullDiffsToUpstream() - e.Commits = append(e.Commits, rmcs...) + rmcs, _ := r.pullDiffsToUpstream() + r.Commits = append(r.Commits, rmcs...) // find commits that not pushed to upstream - lcs, _ := e.pushDiffsToUpstream() + lcs, _ := r.pushDiffsToUpstream() // ... just iterates over the commits err = cIter.ForEach(func(c *object.Commit) error { @@ -97,7 +97,7 @@ func (e *RepoEntity) loadCommits() error { Time: c.Author.When.String(), CommitType: cmType, } - e.Commits = append(e.Commits, commit) + r.Commits = append(r.Commits, commit) return nil }) return err @@ -105,9 +105,9 @@ func (e *RepoEntity) loadCommits() error { // this function creates the commit entities according to active branchs diffs // to *its* configured upstream -func (e *RepoEntity) pullDiffsToUpstream() ([]*Commit, error) { +func (r *Repository) pullDiffsToUpstream() ([]*Commit, error) { remoteCommits := make([]*Commit, 0) - pullables, err := RevList(e, RevListOptions{ + pullables, err := RevList(r, RevListOptions{ Ref1: "HEAD", Ref2: "@{u}", }) @@ -118,9 +118,9 @@ func (e *RepoEntity) pullDiffsToUpstream() ([]*Commit, error) { for _, s := range pullables { commit := &Commit{ Hash: s, - Author: gitShowEmail(e.AbsPath, s), - Message: re.ReplaceAllString(gitShowBody(e.AbsPath, s), " "), - Time: gitShowDate(e.AbsPath, s), + Author: gitShowEmail(r.AbsPath, s), + Message: re.ReplaceAllString(gitShowBody(r.AbsPath, s), " "), + Time: gitShowDate(r.AbsPath, s), CommitType: RemoteCommit, } remoteCommits = append(remoteCommits, commit) @@ -131,8 +131,8 @@ func (e *RepoEntity) pullDiffsToUpstream() ([]*Commit, error) { // this function returns the hashes of the commits that are not pushed to the // upstream of the specific branch -func (e *RepoEntity) pushDiffsToUpstream() ([]string, error) { - pushables, err := RevList(e, RevListOptions{ +func (r *Repository) pushDiffsToUpstream() ([]string, error) { + pushables, err := RevList(r, RevListOptions{ Ref1: "@{u}", Ref2: "HEAD", }) diff --git a/core/git/remote.go b/core/git/remote.go index 72c8ddd..a90bb85 100644 --- a/core/git/remote.go +++ b/core/git/remote.go @@ -16,24 +16,24 @@ type Remote struct { } // NextRemote iterates over next branch of a remote -func (e *RepoEntity) NextRemote() error { - e.Remote = e.Remotes[(e.currentRemoteIndex()+1)%len(e.Remotes)] - e.Remote.SyncBranches(e.Branch.Name) - return e.Publish(RepositoryUpdated, nil) +func (r *Repository) NextRemote() error { + r.Remote = r.Remotes[(r.currentRemoteIndex()+1)%len(r.Remotes)] + r.Remote.SyncBranches(r.Branch.Name) + return r.Publish(RepositoryUpdated, nil) } // PreviousRemote iterates over previous branch of a remote -func (e *RepoEntity) PreviousRemote() error { - e.Remote = e.Remotes[(len(e.Remotes)+e.currentRemoteIndex()-1)%len(e.Remotes)] - e.Remote.SyncBranches(e.Branch.Name) - return e.Publish(RepositoryUpdated, nil) +func (r *Repository) PreviousRemote() error { + r.Remote = r.Remotes[(len(r.Remotes)+r.currentRemoteIndex()-1)%len(r.Remotes)] + r.Remote.SyncBranches(r.Branch.Name) + return r.Publish(RepositoryUpdated, nil) } // returns the active remote index -func (e *RepoEntity) currentRemoteIndex() int { +func (r *Repository) currentRemoteIndex() int { cix := 0 - for i, remote := range e.Remotes { - if remote.Name == e.Remote.Name { + for i, remote := range r.Remotes { + if remote.Name == r.Remote.Name { cix = i } } @@ -42,11 +42,11 @@ func (e *RepoEntity) currentRemoteIndex() int { // search for remotes in go-git way. It is the short way to get remotes but it // does not give any insght about remote branches -func (e *RepoEntity) loadRemotes() error { - r := e.Repository - e.Remotes = make([]*Remote, 0) +func (r *Repository) loadRemotes() error { + rp := r.Repo + r.Remotes = make([]*Remote, 0) - rms, err := r.Remotes() + rms, err := rp.Remotes() for _, rm := range rms { rfs := make([]string, 0) for _, rf := range rm.Config().Fetch { @@ -57,11 +57,11 @@ func (e *RepoEntity) loadRemotes() error { URL: rm.Config().URLs, RefSpecs: rfs, } - remote.loadRemoteBranches(e) + remote.loadRemoteBranches(r) if len(remote.Branches) > 0 { remote.Branch = remote.Branches[0] } - e.Remotes = append(e.Remotes, remote) + r.Remotes = append(r.Remotes, remote) } if err != nil { diff --git a/core/git/remotebranch.go b/core/git/remotebranch.go index 337b28b..19f4ec2 100644 --- a/core/git/remotebranch.go +++ b/core/git/remotebranch.go @@ -17,22 +17,22 @@ type RemoteBranch struct { } // NextRemoteBranch iterates to the next remote branch -func (r *Remote) NextRemoteBranch(e *RepoEntity) error { - r.Branch = r.Branches[(r.currentRemoteBranchIndex()+1)%len(r.Branches)] - return e.Publish(RepositoryUpdated, nil) +func (rm *Remote) NextRemoteBranch(r *Repository) error { + rm.Branch = rm.Branches[(rm.currentRemoteBranchIndex()+1)%len(rm.Branches)] + return r.Publish(RepositoryUpdated, nil) } // PreviousRemoteBranch iterates to the previous remote branch -func (r *Remote) PreviousRemoteBranch(e *RepoEntity) error { - r.Branch = r.Branches[(len(r.Branches)+r.currentRemoteBranchIndex()-1)%len(r.Branches)] - return e.Publish(RepositoryUpdated, nil) +func (rm *Remote) PreviousRemoteBranch(r *Repository) error { + rm.Branch = rm.Branches[(len(rm.Branches)+rm.currentRemoteBranchIndex()-1)%len(rm.Branches)] + return r.Publish(RepositoryUpdated, nil) } // returns the active remote branch index -func (r *Remote) currentRemoteBranchIndex() int { +func (rm *Remote) currentRemoteBranchIndex() int { cix := 0 - for i, rb := range r.Branches { - if rb.Reference.Hash() == r.Branch.Reference.Hash() { + for i, rb := range rm.Branches { + if rb.Reference.Hash() == rm.Branch.Reference.Hash() { cix = i } } @@ -41,17 +41,17 @@ func (r *Remote) currentRemoteBranchIndex() int { // search for the remote branches of the remote. It takes the go-git's repo // pointer in order to get storer struct -func (r *Remote) loadRemoteBranches(e *RepoEntity) error { - r.Branches = make([]*RemoteBranch, 0) - bs, err := remoteBranchesIter(e.Repository.Storer) +func (rm *Remote) loadRemoteBranches(r *Repository) error { + rm.Branches = make([]*RemoteBranch, 0) + bs, err := remoteBranchesIter(r.Repo.Storer) if err != nil { log.Warn("Cannot initiate iterator " + err.Error()) return err } defer bs.Close() err = bs.ForEach(func(b *plumbing.Reference) error { - if strings.Split(b.Name().Short(), "/")[0] == r.Name { - r.Branches = append(r.Branches, &RemoteBranch{ + if strings.Split(b.Name().Short(), "/")[0] == rm.Name { + rm.Branches = append(rm.Branches, &RemoteBranch{ Name: b.Name().Short(), Reference: b, }) @@ -79,10 +79,10 @@ func remoteBranchesIter(s storer.ReferenceStorer) (storer.ReferenceIter, error) } // switches to the given remote branch -func (r *Remote) switchRemoteBranch(remoteBranchName string) error { - for _, rb := range r.Branches { +func (rm *Remote) switchRemoteBranch(remoteBranchName string) error { + for _, rb := range rm.Branches { if rb.Name == remoteBranchName { - r.Branch = rb + rm.Branch = rb return nil } } diff --git a/core/git/repository.go b/core/git/repository.go index 31b926d..8470f13 100644 --- a/core/git/repository.go +++ b/core/git/repository.go @@ -10,23 +10,23 @@ import ( git "gopkg.in/src-d/go-git.v4" ) -// RepoEntity is the main entity of the application. The repository name is +// Repository is the main entity of the application. The repository name is // actually the name of its folder in the host's filesystem. It holds the go-git // repository entity along with critic entites such as remote/branches and commits -type RepoEntity struct { - RepoID string - Name string - AbsPath string - ModTime time.Time - Repository git.Repository - Branch *Branch - Branches []*Branch - Remote *Remote - Remotes []*Remote - Commit *Commit - Commits []*Commit - Stasheds []*StashedItem - state RepoState +type Repository struct { + RepoID string + Name string + AbsPath string + ModTime time.Time + Repo git.Repository + Branch *Branch + Branches []*Branch + Remote *Remote + Remotes []*Remote + Commit *Commit + Commits []*Commit + Stasheds []*StashedItem + state RepoState // TODO: move this into state Message string @@ -71,69 +71,69 @@ const ( RepositoryUpdated = "repository.updated" ) -// FastInitializeRepo initializes a RepoEntity struct without its belongings. -func FastInitializeRepo(dir string) (e *RepoEntity, err error) { +// FastInitializeRepo initializes a Repository struct without its belongings. +func FastInitializeRepo(dir string) (r *Repository, err error) { f, err := os.Open(dir) if err != nil { return nil, err } // get status of the file fstat, _ := f.Stat() - r, err := git.PlainOpen(dir) + rp, err := git.PlainOpen(dir) if err != nil { return nil, err } - // initialize RepoEntity with minimum viable fields - e = &RepoEntity{RepoID: RandomString(8), - Name: fstat.Name(), - AbsPath: dir, - ModTime: fstat.ModTime(), - Repository: *r, - state: Available, - mutex: &sync.RWMutex{}, - listeners: make(map[string][]RepositoryListener), + // initialize Repository with minimum viable fields + r = &Repository{RepoID: RandomString(8), + Name: fstat.Name(), + AbsPath: dir, + ModTime: fstat.ModTime(), + Repo: *rp, + state: Available, + mutex: &sync.RWMutex{}, + listeners: make(map[string][]RepositoryListener), } - return e, nil + return r, nil } -// InitializeRepo initializes a RepoEntity struct with its belongings. -func InitializeRepo(dir string) (e *RepoEntity, err error) { - e, err = FastInitializeRepo(dir) +// InitializeRepo initializes a Repository struct with its belongings. +func InitializeRepo(dir string) (r *Repository, err error) { + r, err = FastInitializeRepo(dir) if err != nil { return nil, err } // need nothing extra but loading additional components - return e, e.loadComponents(true) + return r, r.loadComponents(true) } // loadComponents initializes the fields of a repository such as branches, // remotes, commits etc. If reset, reload commit, remote pointers too -func (e *RepoEntity) loadComponents(reset bool) error { - if err := e.loadLocalBranches(); err != nil { +func (r *Repository) loadComponents(reset bool) error { + if err := r.loadLocalBranches(); err != nil { return err } - if err := e.loadCommits(); err != nil { + if err := r.loadCommits(); err != nil { return err } - if err := e.loadRemotes(); err != nil { + if err := r.loadRemotes(); err != nil { return err } - if err := e.loadStashedItems(); err != nil { + if err := r.loadStashedItems(); err != nil { log.Warn("Cannot load stashes") } if reset { // handle if there is no commit, maybe? // set commit pointer for repository - if len(e.Commits) > 0 { + if len(r.Commits) > 0 { // select first commit - e.Commit = e.Commits[0] + r.Commit = r.Commits[0] } // set remote pointer for repository - if len(e.Remotes) > 0 { + if len(r.Remotes) > 0 { // TODO: tend to take origin/master as default - e.Remote = e.Remotes[0] + r.Remote = r.Remotes[0] // if couldn't find, its ok. - e.Remote.SyncBranches(e.Branch.Name) + r.Remote.SyncBranches(r.Branch.Name) } else { // if there is no remote, this project is totally useless actually return errors.New("There is no remote for this repository") @@ -144,46 +144,46 @@ func (e *RepoEntity) loadComponents(reset bool) error { // Refresh the belongings of a repositoriy, this function is called right after // fetch/pull/merge operations -func (e *RepoEntity) Refresh() error { +func (r *Repository) Refresh() error { var err error // error can be ignored since the file already exists when app is loading - // if the RepoEntity is only fast initialized, no need to refresh because + // if the Repository is only fast initialized, no need to refresh because // it won't contain its belongings - if e.Branch == nil { + if r.Branch == nil { return nil } - file, _ := os.Open(e.AbsPath) + file, _ := os.Open(r.AbsPath) fstat, _ := file.Stat() // re-initialize the go-git repository struct after supposed update - r, err := git.PlainOpen(e.AbsPath) + rp, err := git.PlainOpen(r.AbsPath) if err != nil { return err } - e.Repository = *r + r.Repo = *rp // modification date may be changed - e.ModTime = fstat.ModTime() - if err := e.loadComponents(false); err != nil { + r.ModTime = fstat.ModTime() + if err := r.loadComponents(false); err != nil { return err } // we could send an event data but we don't need for this topic - return e.Publish(RepositoryUpdated, nil) + return r.Publish(RepositoryUpdated, nil) } // On adds new listener. // listener is a callback function that will be called when event emits -func (e *RepoEntity) On(event string, listener RepositoryListener) { - e.mutex.Lock() - defer e.mutex.Unlock() +func (r *Repository) On(event string, listener RepositoryListener) { + r.mutex.Lock() + defer r.mutex.Unlock() // add listener to the specific event topic - e.listeners[event] = append(e.listeners[event], listener) + r.listeners[event] = append(r.listeners[event], listener) } // Publish publishes the data to a certain event by its name. -func (e *RepoEntity) Publish(eventName string, data interface{}) error { - e.mutex.RLock() - defer e.mutex.RUnlock() +func (r *Repository) Publish(eventName string, data interface{}) error { + r.mutex.RLock() + defer r.mutex.RUnlock() // let's find listeners for this event topic - listeners, ok := e.listeners[eventName] + listeners, ok := r.listeners[eventName] if !ok { return nil } @@ -201,22 +201,22 @@ func (e *RepoEntity) Publish(eventName string, data interface{}) error { } // State returns the state of the repository such as queued, failed etc. -func (e *RepoEntity) State() RepoState { - return e.state +func (r *Repository) State() RepoState { + return r.state } // SetState sets the state of repository and sends repository updated event -func (e *RepoEntity) SetState(state RepoState) { - e.state = state +func (r *Repository) SetState(state RepoState) { + r.state = state // we could send an event data but we don't need for this topic - if err := e.Publish(RepositoryUpdated, nil); err != nil { + if err := r.Publish(RepositoryUpdated, nil); err != nil { log.Warnf("Cannot publish on %s topic.\n", RepositoryUpdated) } } // SetMessage sets the message of status, it is used if state is Fail -func (e *RepoEntity) SetStateMessage(msg string) { - if e.State() == Fail { - e.Message = msg +func (r *Repository) SetStateMessage(msg string) { + if r.State() == Fail { + r.Message = msg } } diff --git a/core/git/sort.go b/core/git/sort.go index de5f454..b681396 100644 --- a/core/git/sort.go +++ b/core/git/sort.go @@ -4,9 +4,9 @@ import ( "unicode" ) -// Alphabetical slice is the re-ordered *RepoEntity slice that sorted according +// Alphabetical slice is the re-ordered *Repository slice that sorted according // to alphabetical order (A-Z) -type Alphabetical []*RepoEntity +type Alphabetical []*Repository // Len is the interface implementation for Alphabetical sorting function func (s Alphabetical) Len() int { return len(s) } @@ -43,9 +43,9 @@ func (s Alphabetical) Less(i, j int) bool { return false } -// LastModified slice is the re-ordered *RepoEntity slice that sorted according +// LastModified slice is the re-ordered *Repository slice that sorted according // to last modified date of the repository directory -type LastModified []*RepoEntity +type LastModified []*Repository // Len is the interface implementation for LastModified sorting function func (s LastModified) Len() int { return len(s) } diff --git a/core/git/stash.go b/core/git/stash.go index 2d7fab0..1391aed 100644 --- a/core/git/stash.go +++ b/core/git/stash.go @@ -20,9 +20,9 @@ type StashedItem struct { EntityPath string } -func (e *RepoEntity) loadStashedItems() error { - e.Stasheds = make([]*StashedItem, 0) - output := stashGet(e, "list") +func (r *Repository) loadStashedItems() error { + r.Stasheds = make([]*StashedItem, 0) + output := stashGet(r, "list") stashIDRegex := regexp.MustCompile(`stash@{[\d]+}:`) stashIDRegexInt := regexp.MustCompile(`[\d]+`) stashBranchRegex := regexp.MustCompile(`^(.*?): `) @@ -64,23 +64,23 @@ func (e *RepoEntity) loadStashedItems() error { } // trim hash - e.Stasheds = append(e.Stasheds, &StashedItem{ + r.Stasheds = append(r.Stasheds, &StashedItem{ StashID: i, BranchName: branchName, Hash: hash, Description: desc, - EntityPath: e.AbsPath, + EntityPath: r.AbsPath, }) } return nil } -func stashGet(e *RepoEntity, option string) string { +func stashGet(r *Repository, option string) string { args := make([]string, 0) args = append(args, "stash") args = append(args, option) cmd := exec.Command("git", args...) - cmd.Dir = e.AbsPath + cmd.Dir = r.AbsPath output, err := cmd.CombinedOutput() if err != nil { return "?" @@ -115,13 +115,13 @@ func (stashedItem *StashedItem) Show() (string, error) { } // Stash is the wrapper of convetional "git stash" command -func (e *RepoEntity) Stash() (string, error) { +func (r *Repository) Stash() (string, error) { args := make([]string, 0) args = append(args, "stash") cmd := exec.Command("git", args...) - cmd.Dir = e.AbsPath + cmd.Dir = r.AbsPath output, err := cmd.CombinedOutput() - e.Refresh() + r.Refresh() return string(output), err } diff --git a/core/job/job-queue.go b/core/job/job-queue.go index 02f7f0b..e337064 100644 --- a/core/job/job-queue.go +++ b/core/job/job-queue.go @@ -28,7 +28,7 @@ func CreateJobQueue() (jq *JobQueue) { // AddJob adds a job to the queue func (jq *JobQueue) AddJob(j *Job) error { for _, job := range jq.series { - if job.Entity.RepoID == j.Entity.RepoID && job.JobType == j.JobType { + if job.Repository.RepoID == j.Repository.RepoID && job.JobType == j.JobType { return errors.New("Same job already is in the queue") } } @@ -56,10 +56,10 @@ func (jq *JobQueue) StartNext() (j *Job, finished bool, err error) { // RemoveFromQueue deletes the given entity and its job from the queue // TODO: it is not safe if the job has been started -func (jq *JobQueue) RemoveFromQueue(entity *git.RepoEntity) error { +func (jq *JobQueue) RemoveFromQueue(r *git.Repository) error { removed := false for i, job := range jq.series { - if job.Entity.RepoID == entity.RepoID { + if job.Repository.RepoID == r.RepoID { jq.series = append(jq.series[:i], jq.series[i+1:]...) removed = true } @@ -73,10 +73,10 @@ func (jq *JobQueue) RemoveFromQueue(entity *git.RepoEntity) error { // IsInTheQueue function; since the job and entity is not tied with its own // struct, this function returns true if that entity is in the queue along with // the jobs type -func (jq *JobQueue) IsInTheQueue(entity *git.RepoEntity) (inTheQueue bool, j *Job) { +func (jq *JobQueue) IsInTheQueue(r *git.Repository) (inTheQueue bool, j *Job) { inTheQueue = false for _, job := range jq.series { - if job.Entity.RepoID == entity.RepoID { + if job.Repository.RepoID == r.RepoID { inTheQueue = true j = job } diff --git a/core/job/job.go b/core/job/job.go index 6156275..69953b7 100644 --- a/core/job/job.go +++ b/core/job/job.go @@ -9,8 +9,8 @@ import ( type Job struct { // JobType is to select operation type that will be applied to repository JobType JobType - // Entity points to the repository that will be used for operation - Entity *git.RepoEntity + // Repository points to the repository that will be used for operation + Repository *git.Repository // Options is a placeholder for operation options Options interface{} } @@ -31,7 +31,7 @@ const ( // starts the job func (j *Job) start() error { - j.Entity.SetState(git.Working) + j.Repository.SetState(git.Working) // TODO: Handle errors? // TOOD: Better implementation required switch mode := j.JobType; mode { @@ -41,12 +41,12 @@ func (j *Job) start() error { opts = j.Options.(command.FetchOptions) } else { opts = command.FetchOptions{ - RemoteName: j.Entity.Remote.Name, + RemoteName: j.Repository.Remote.Name, } } - if err := command.Fetch(j.Entity, opts); err != nil { - j.Entity.SetState(git.Fail) - j.Entity.SetStateMessage(err.Error()) + if err := command.Fetch(j.Repository, opts); err != nil { + j.Repository.SetState(git.Fail) + j.Repository.SetStateMessage(err.Error()) return err } case PullJob: @@ -55,24 +55,24 @@ func (j *Job) start() error { opts = j.Options.(command.PullOptions) } else { opts = command.PullOptions{ - RemoteName: j.Entity.Remote.Name, + RemoteName: j.Repository.Remote.Name, } } - if err := command.Pull(j.Entity, opts); err != nil { - j.Entity.SetState(git.Fail) - j.Entity.SetStateMessage(err.Error()) + if err := command.Pull(j.Repository, opts); err != nil { + j.Repository.SetState(git.Fail) + j.Repository.SetStateMessage(err.Error()) return err } case MergeJob: - if err := command.Merge(j.Entity, command.MergeOptions{ - BranchName: j.Entity.Remote.Branch.Name, + if err := command.Merge(j.Repository, command.MergeOptions{ + BranchName: j.Repository.Remote.Branch.Name, }); err != nil { - j.Entity.SetState(git.Fail) - j.Entity.SetStateMessage(err.Error()) + j.Repository.SetState(git.Fail) + j.Repository.SetStateMessage(err.Error()) return nil } default: - j.Entity.SetState(git.Available) + j.Repository.SetState(git.Available) return nil } return nil diff --git a/core/load/load.go b/core/load/load.go index 6456f64..c4526ef 100644 --- a/core/load/load.go +++ b/core/load/load.go @@ -13,13 +13,13 @@ import ( ) // AsyncAdd is interface to caller -type AsyncAdd func(e *git.RepoEntity) +type AsyncAdd func(r *git.Repository) // RepositoryEntities initializes the go-git's repository obejcts with given // slice of paths. since this job is done parallel, the order of the directories // is not kept -func RepositoryEntities(directories []string) (entities []*git.RepoEntity, err error) { - entities = make([]*git.RepoEntity, 0) +func RepositoryEntities(directories []string) (entities []*git.Repository, err error) { + entities = make([]*git.Repository, 0) var wg sync.WaitGroup var mu sync.Mutex diff --git a/gui/authenticationview.go b/gui/authenticationview.go index 1b5c98f..97a214e 100644 --- a/gui/authenticationview.go +++ b/gui/authenticationview.go @@ -41,8 +41,8 @@ func (gui *Gui) openAuthenticationView(g *gocui.Gui, jobQueue *job.JobQueue, job return err } jobRequiresAuth = job - if job.Entity.State() != git.Fail { - if err := jobQueue.RemoveFromQueue(job.Entity); err != nil { + if job.Repository.State() != 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.Entity.Remote.URL[0])) + fmt.Fprintln(v, keySymbol+selectionIndicator+red.Sprint(jobRequiresAuth.Repository.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.Entity.Remote.Name, + RemoteName: jobRequiresAuth.Repository.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.Entity.Remote.Name, + RemoteName: jobRequiresAuth.Repository.Remote.Name, Credentials: git.Credentials{ User: creduser, Password: credpswd, }, } } - jobRequiresAuth.Entity.SetState(git.Queued) + jobRequiresAuth.Repository.SetState(git.Queued) // add this job to the last of the queue if err := gui.State.Queue.AddJob(jobRequiresAuth); err != nil { diff --git a/gui/commitview.go b/gui/commitview.go index ad8adee..7acc5ca 100644 --- a/gui/commitview.go +++ b/gui/commitview.go @@ -57,7 +57,7 @@ func (gui *Gui) openCommitMessageView(g *gocui.Gui, v *gocui.View) error { // open an error view to inform user with a message and a useful note func (gui *Gui) openCommitUserNameView(g *gocui.Gui) error { - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() maxX, maxY := g.Size() // first, create the label for user vlabel, err := g.SetView(commitUserNameLabelFeature.Name, maxX/2-30, maxY/2, maxX/2-19, maxY/2+2) @@ -74,7 +74,7 @@ func (gui *Gui) openCommitUserNameView(g *gocui.Gui) error { if err != gocui.ErrUnknownView { return err } - name, err := command.Config(e, command.ConfigOptions{ + name, err := command.Config(r, command.ConfigOptions{ Section: "user", Option: "name", }) @@ -90,7 +90,7 @@ func (gui *Gui) openCommitUserNameView(g *gocui.Gui) error { // open an error view to inform user with a message and a useful note func (gui *Gui) openCommitUserEmailView(g *gocui.Gui) error { - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() maxX, maxY := g.Size() // first, create the label for password vlabel, err := g.SetView(commitUserEmailLabelViewFeature.Name, maxX/2-30, maxY/2+1, maxX/2-19, maxY/2+3) @@ -107,7 +107,7 @@ func (gui *Gui) openCommitUserEmailView(g *gocui.Gui) error { if err != gocui.ErrUnknownView { return err } - email, err := command.Config(e, command.ConfigOptions{ + email, err := command.Config(r, command.ConfigOptions{ Section: "user", Option: "email", }) @@ -123,7 +123,7 @@ func (gui *Gui) openCommitUserEmailView(g *gocui.Gui) error { // close the opened commite mesage view func (gui *Gui) submitCommitMessageView(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() // in order to read buffer of the views, first we need to find'em vMsg, err := g.View(commitMessageViewFeature.Name) @@ -151,7 +151,7 @@ func (gui *Gui) submitCommitMessageView(g *gocui.Gui, v *gocui.View) error { return errors.New("User email needs to be provided") } - err = command.CommitCommand(e, command.CommitOptions{ + err = command.CommitCommand(r, command.CommitOptions{ CommitMsg: msg, User: name, Email: email, @@ -170,7 +170,7 @@ func (gui *Gui) nextCommitView(g *gocui.Gui, v *gocui.View) error { // close the opened commite mesage view func (gui *Gui) closeCommitMessageView(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() g.Cursor = false for _, view := range commitViews { if err := g.DeleteView(view.Name); err != nil { @@ -182,7 +182,7 @@ func (gui *Gui) closeCommitMessageView(g *gocui.Gui, v *gocui.View) error { return err } } - if err := refreshAllStatusView(g, e, true); err != nil { + if err := refreshAllStatusView(g, r, true); err != nil { return err } return gui.closeViewCleanup(commitMesageReturnView) diff --git a/gui/diffview.go b/gui/diffview.go index e78dcaf..3bf9b05 100644 --- a/gui/diffview.go +++ b/gui/diffview.go @@ -34,11 +34,11 @@ func (gui *Gui) prepareDiffView(g *gocui.Gui, v *gocui.View, display []string) ( // open diff view for the selcted commit // called from commitview, so initial view is commitview func (gui *Gui) openCommitDiffView(g *gocui.Gui, v *gocui.View) (err error) { - e := gui.getSelectedRepository() - commit := e.Commit + r := gui.getSelectedRepository() + commit := r.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(e, e.Commit.Hash) + diff, err := command.Diff(r, r.Commit.Hash) if err != nil { return err } @@ -93,13 +93,13 @@ func (gui *Gui) openFileDiffView(g *gocui.Gui, v *gocui.View) (err error) { // called from stashview, so initial view is stashview func (gui *Gui) showStash(g *gocui.Gui, v *gocui.View) (err error) { - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() _, oy := v.Origin() _, cy := v.Cursor() - if len(e.Stasheds) <= 0 { + if len(r.Stasheds) <= 0 { return nil } - stashedItem := e.Stasheds[oy+cy] + stashedItem := r.Stasheds[oy+cy] output, err := stashedItem.Show() if err != nil { if err = gui.openErrorView(g, output, @@ -22,7 +22,7 @@ type Gui struct { // guiState struct holds the repositories, directiories, mode and queue of the // gui object. These values are not static type guiState struct { - Repositories []*git.RepoEntity + Repositories []*git.Repository Directories []string Mode mode Queue *job.JobQueue @@ -131,9 +131,9 @@ func (gui *Gui) Run() error { return nil } -func (gui *Gui) addRepository(e *git.RepoEntity) { - gui.State.Repositories = append(gui.State.Repositories, e) - e.On(git.RepositoryUpdated, gui.repositoryUpdated) +func (gui *Gui) addRepository(r *git.Repository) { + gui.State.Repositories = append(gui.State.Repositories, r) + r.On(git.RepositoryUpdated, gui.repositoryUpdated) gui.repositoryUpdated(nil) } diff --git a/gui/mainview.go b/gui/mainview.go index 288ca8f..f12a26c 100644 --- a/gui/mainview.go +++ b/gui/mainview.go @@ -162,7 +162,7 @@ func (gui *Gui) pageUp(g *gocui.Gui, v *gocui.View) error { // slice of repositories. Since it is not a %100 percent safe methodology it may // rrequire a better implementation or the slice's order must be synchronized // with the views lines -func (gui *Gui) getSelectedRepository() *git.RepoEntity { +func (gui *Gui) getSelectedRepository() *git.Repository { if len(gui.State.Repositories) == 0 { return nil } @@ -173,7 +173,7 @@ func (gui *Gui) getSelectedRepository() *git.RepoEntity { } // adds given entity to job queue -func (gui *Gui) addToQueue(entity *git.RepoEntity) error { +func (gui *Gui) addToQueue(r *git.Repository) error { var jt job.JobType switch mode := gui.State.Mode.ModeID; mode { case FetchMode: @@ -186,23 +186,23 @@ func (gui *Gui) addToQueue(entity *git.RepoEntity) error { return nil } err := gui.State.Queue.AddJob(&job.Job{ - JobType: jt, - Entity: entity, + JobType: jt, + Repository: r, }) if err != nil { return err } - entity.SetState(git.Queued) + r.SetState(git.Queued) return nil } // removes given entity from job queue -func (gui *Gui) removeFromQueue(entity *git.RepoEntity) error { - err := gui.State.Queue.RemoveFromQueue(entity) +func (gui *Gui) removeFromQueue(r *git.Repository) error { + err := gui.State.Queue.RemoveFromQueue(r) if err != nil { return err } - entity.SetState(git.Available) + r.SetState(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.Entity.SetState(git.Paused) + j.Repository.SetState(git.Paused) gui_go.State.FailoverQueue.AddJob(j) } } @@ -224,14 +224,14 @@ 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.Entity.State() == git.Paused { - gui.State.FailoverQueue.RemoveFromQueue(j.Entity) + if j.Repository.State() == git.Paused { + gui.State.FailoverQueue.RemoveFromQueue(j.Repository) err := gui.openAuthenticationView(g, gui.State.Queue, j, v.Name()) if err != nil { log.Warn(err.Error()) return err } - if isnt, _ := gui.State.Queue.IsInTheQueue(j.Entity); !isnt { + if isnt, _ := gui.State.Queue.IsInTheQueue(j.Repository); !isnt { gui.State.FailoverQueue.AddJob(j) } } diff --git a/gui/sideviews.go b/gui/sideviews.go index 1139054..5a3adc7 100644 --- a/gui/sideviews.go +++ b/gui/sideviews.go @@ -13,29 +13,29 @@ var ( sideViews = []viewFeature{remoteViewFeature, remoteBranchViewFeature, branchViewFeature, commitViewFeature} ) -// refreshes the side views of the application for given repository.RepoEntity struct -func (gui *Gui) renderSideViews(e *git.RepoEntity) error { - if e == nil { +// refreshes the side views of the application for given repository.Repository struct +func (gui *Gui) renderSideViews(r *git.Repository) error { + if r == nil { return nil } - if err := gui.renderRemotes(e); err != nil { + if err := gui.renderRemotes(r); err != nil { return err } - if err := gui.renderBranch(e); err != nil { + if err := gui.renderBranch(r); err != nil { return err } - if err := gui.renderRemoteBranches(e); err != nil { + if err := gui.renderRemoteBranches(r); err != nil { return err } - if err := gui.renderCommits(e); err != nil { + if err := gui.renderCommits(r); err != nil { return err } return nil } // updates the remotesview for given entity -func (gui *Gui) renderRemotes(e *git.RepoEntity) error { +func (gui *Gui) renderRemotes(r *git.Repository) error { var err error out, err := gui.g.View(remoteViewFeature.Name) if err != nil { @@ -43,16 +43,16 @@ func (gui *Gui) renderRemotes(e *git.RepoEntity) error { } out.Clear() currentindex := 0 - totalRemotes := len(e.Remotes) + totalRemotes := len(r.Remotes) if totalRemotes > 0 { - for i, r := range e.Remotes { - _, shortURL := trimRemoteURL(r.URL[0]) - if r.Name == e.Remote.Name { + for i, rm := range r.Remotes { + _, shortURL := trimRemoteURL(rm.URL[0]) + if rm.Name == r.Remote.Name { currentindex = i - fmt.Fprintln(out, selectionIndicator+r.Name+": "+shortURL) + fmt.Fprintln(out, selectionIndicator+rm.Name+": "+shortURL) continue } - fmt.Fprintln(out, tab+r.Name+": "+shortURL) + fmt.Fprintln(out, tab+rm.Name+": "+shortURL) } if err = gui.smartAnchorRelativeToLine(out, currentindex, totalRemotes); err != nil { return err @@ -62,7 +62,7 @@ func (gui *Gui) renderRemotes(e *git.RepoEntity) error { } // updates the remotebranchview for given entity -func (gui *Gui) renderRemoteBranches(e *git.RepoEntity) error { +func (gui *Gui) renderRemoteBranches(r *git.Repository) error { var err error out, err := gui.g.View(remoteBranchViewFeature.Name) if err != nil { @@ -70,15 +70,15 @@ func (gui *Gui) renderRemoteBranches(e *git.RepoEntity) error { } out.Clear() currentindex := 0 - trb := len(e.Remote.Branches) + trb := len(r.Remote.Branches) if trb > 0 { - for i, r := range e.Remote.Branches { - if r.Name == e.Remote.Branch.Name { + for i, rm := range r.Remote.Branches { + if rm.Name == r.Remote.Branch.Name { currentindex = i - fmt.Fprintln(out, selectionIndicator+r.Name) + fmt.Fprintln(out, selectionIndicator+rm.Name) continue } - fmt.Fprintln(out, tab+r.Name) + fmt.Fprintln(out, tab+rm.Name) } if err = gui.smartAnchorRelativeToLine(out, currentindex, trb); err != nil { return err @@ -88,7 +88,7 @@ func (gui *Gui) renderRemoteBranches(e *git.RepoEntity) error { } // updates the branchview for given entity -func (gui *Gui) renderBranch(e *git.RepoEntity) error { +func (gui *Gui) renderBranch(r *git.Repository) error { var err error out, err := gui.g.View(branchViewFeature.Name) if err != nil { @@ -96,9 +96,9 @@ func (gui *Gui) renderBranch(e *git.RepoEntity) error { } out.Clear() currentindex := 0 - totalbranches := len(e.Branches) - for i, b := range e.Branches { - if b.Name == e.Branch.Name { + totalbranches := len(r.Branches) + for i, b := range r.Branches { + if b.Name == r.Branch.Name { currentindex = i fmt.Fprintln(out, selectionIndicator+b.Name) continue @@ -110,7 +110,7 @@ func (gui *Gui) renderBranch(e *git.RepoEntity) error { } // updates the commitsview for given entity -func (gui *Gui) renderCommits(e *git.RepoEntity) error { +func (gui *Gui) renderCommits(r *git.Repository) error { var err error out, err := gui.g.View(commitViewFeature.Name) if err != nil { @@ -118,9 +118,9 @@ func (gui *Gui) renderCommits(e *git.RepoEntity) error { } out.Clear() currentindex := 0 - totalcommits := len(e.Commits) - for i, c := range e.Commits { - if c.Hash == e.Commit.Hash { + totalcommits := len(r.Commits) + for i, c := range r.Commits { + if c.Hash == r.Commit.Hash { currentindex = i fmt.Fprintln(out, selectionIndicator+commitLabel(c)) continue @@ -133,22 +133,22 @@ func (gui *Gui) renderCommits(e *git.RepoEntity) error { // cursor down variant for sideviews func (gui *Gui) sideViewsNextItem(g *gocui.Gui, v *gocui.View) error { var err error - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() switch viewName := v.Name(); viewName { case remoteBranchViewFeature.Name: - return e.Remote.NextRemoteBranch(e) + return r.Remote.NextRemoteBranch(r) case remoteViewFeature.Name: - return e.NextRemote() + return r.NextRemote() case branchViewFeature.Name: - if err = e.Checkout(e.NextBranch()); err != nil { + if err = r.Checkout(r.NextBranch()); err != nil { err = gui.openErrorView(g, err.Error(), "You should manually resolve this issue", branchViewFeature.Name) return err } case commitViewFeature.Name: - e.NextCommit() - return gui.renderCommits(e) + r.NextCommit() + return gui.renderCommits(r) } return err } @@ -156,31 +156,31 @@ func (gui *Gui) sideViewsNextItem(g *gocui.Gui, v *gocui.View) error { // cursor up variant for sideviews func (gui *Gui) sideViewsPreviousItem(g *gocui.Gui, v *gocui.View) error { var err error - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() switch viewName := v.Name(); viewName { case remoteBranchViewFeature.Name: - return e.Remote.PreviousRemoteBranch(e) + return r.Remote.PreviousRemoteBranch(r) case remoteViewFeature.Name: - return e.PreviousRemote() + return r.PreviousRemote() case branchViewFeature.Name: - if err = e.Checkout(e.PreviousBranch()); err != nil { + if err = r.Checkout(r.PreviousBranch()); err != nil { err = gui.openErrorView(g, err.Error(), "You should manually resolve this issue", branchViewFeature.Name) return err } case commitViewFeature.Name: - e.PreviousCommit() - return gui.renderCommits(e) + r.PreviousCommit() + return gui.renderCommits(r) } return err } // basically does fetch --prune func (gui *Gui) syncRemoteBranch(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() - return command.Fetch(e, command.FetchOptions{ - RemoteName: e.Remote.Name, + r := gui.getSelectedRepository() + return command.Fetch(r, command.FetchOptions{ + RemoteName: r.Remote.Name, Prune: true, }) } @@ -189,14 +189,14 @@ func (gui *Gui) syncRemoteBranch(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) setUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { maxX, maxY := g.Size() - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() v, err := g.SetView(confirmationViewFeature.Name, maxX/2-30, maxY/2-2, maxX/2+30, maxY/2+2) if err != nil { if err != gocui.ErrUnknownView { return err } - fmt.Fprintln(v, "branch."+e.Branch.Name+"."+"remote"+"="+e.Remote.Name) - fmt.Fprintln(v, "branch."+e.Branch.Name+"."+"merge"+"="+e.Branch.Reference.Name().String()) + fmt.Fprintln(v, "branch."+r.Branch.Name+"."+"remote"+"="+r.Remote.Name) + fmt.Fprintln(v, "branch."+r.Branch.Name+"."+"merge"+"="+r.Branch.Reference.Name().String()) } return gui.focusToView(confirmationViewFeature.Name) } @@ -204,22 +204,22 @@ func (gui *Gui) setUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { // add config for upstream merge func (gui *Gui) confirmSetUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { var err error - e := gui.getSelectedRepository() - if err = command.AddConfig(e, command.ConfigOptions{ - Section: "branch." + e.Branch.Name, + r := gui.getSelectedRepository() + if err = command.AddConfig(r, command.ConfigOptions{ + Section: "branch." + r.Branch.Name, Option: "remote", Site: command.ConfigSiteLocal, - }, e.Remote.Name); err != nil { + }, r.Remote.Name); err != nil { return err } - if err = command.AddConfig(e, command.ConfigOptions{ - Section: "branch." + e.Branch.Name, + if err = command.AddConfig(r, command.ConfigOptions{ + Section: "branch." + r.Branch.Name, Option: "merge", Site: command.ConfigSiteLocal, - }, e.Branch.Reference.Name().String()); err != nil { + }, r.Branch.Reference.Name().String()); err != nil { return err } - e.Refresh() + r.Refresh() return gui.closeConfirmationView(g, v) } diff --git a/gui/stagedview.go b/gui/stagedview.go index 5f68f5a..95b474a 100644 --- a/gui/stagedview.go +++ b/gui/stagedview.go @@ -25,32 +25,32 @@ func (gui *Gui) openStageView(g *gocui.Gui) error { } func (gui *Gui) resetChanges(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() _, cy := v.Cursor() _, oy := v.Origin() if len(stagedFiles) <= 0 || len(stagedFiles) <= cy+oy { return nil } - if err := command.Reset(e, stagedFiles[cy+oy], command.ResetOptions{}); err != nil { + if err := command.Reset(r, stagedFiles[cy+oy], command.ResetOptions{}); err != nil { return err } - return refreshAllStatusView(g, e, true) + return refreshAllStatusView(g, r, true) } func (gui *Gui) resetAllChanges(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() - ref, err := e.Repository.Head() + r := gui.getSelectedRepository() + ref, err := r.Repo.Head() if err != nil { return err } - if err := command.ResetAll(e, command.ResetOptions{ + if err := command.ResetAll(r, command.ResetOptions{ Hash: ref.Hash().String(), Rtype: command.ResetMixed, }); err != nil { return err } - return refreshAllStatusView(g, e, true) + return refreshAllStatusView(g, r, true) } // refresh the main view and re-render the repository representations diff --git a/gui/stashview.go b/gui/stashview.go index 05f0a09..f1ecc48 100644 --- a/gui/stashview.go +++ b/gui/stashview.go @@ -18,15 +18,15 @@ func (gui *Gui) openStashView(g *gocui.Gui) error { } v.Title = stashViewFeature.Title } - e := gui.getSelectedRepository() - err = refreshStashView(g, e) + r := gui.getSelectedRepository() + err = refreshStashView(g, r) return err } // func (gui *Gui) stashChanges(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() - output, err := e.Stash() + r := gui.getSelectedRepository() + output, err := r.Stash() if err != nil { if err = gui.openErrorView(g, output, "You should manually resolve this issue", @@ -34,19 +34,19 @@ func (gui *Gui) stashChanges(g *gocui.Gui, v *gocui.View) error { return err } } - err = refreshAllStatusView(g, e, true) + err = refreshAllStatusView(g, r, true) return err } // func (gui *Gui) popStash(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() _, oy := v.Origin() _, cy := v.Cursor() - if len(e.Stasheds) <= 0 { + if len(r.Stasheds) <= 0 { return nil } - stashedItem := e.Stasheds[oy+cy] + stashedItem := r.Stasheds[oy+cy] output, err := stashedItem.Pop() if err != nil { if err = gui.openErrorView(g, output, @@ -56,15 +56,15 @@ func (gui *Gui) popStash(g *gocui.Gui, v *gocui.View) error { } } // since the pop is a func of stashed item, we need to refresh entity here - if err := e.Refresh(); err != nil { + if err := r.Refresh(); err != nil { return err } - return refreshAllStatusView(g, e, true) + return refreshAllStatusView(g, r, true) } // refresh the main view and re-render the repository representations -func refreshStashView(g *gocui.Gui, e *git.RepoEntity) error { +func refreshStashView(g *gocui.Gui, r *git.Repository) error { stashView, err := g.View(stashViewFeature.Name) if err != nil { return err @@ -72,7 +72,7 @@ func refreshStashView(g *gocui.Gui, e *git.RepoEntity) error { stashView.Clear() _, cy := stashView.Cursor() _, oy := stashView.Origin() - stashedItems := e.Stasheds + stashedItems := r.Stasheds for i, stashedItem := range stashedItems { var prefix string if i == cy+oy { diff --git a/gui/statusview.go b/gui/statusview.go index 1648c4e..7b92e6a 100644 --- a/gui/statusview.go +++ b/gui/statusview.go @@ -64,8 +64,8 @@ func (gui *Gui) statusCursorDown(g *gocui.Gui, v *gocui.View) error { return err } } - e := gui.getSelectedRepository() - return refreshStatusView(v.Name(), g, e, false) + r := gui.getSelectedRepository() + return refreshStatusView(v.Name(), g, r, false) } // moves the cursor upwards for the main view @@ -81,20 +81,20 @@ func (gui *Gui) statusCursorUp(g *gocui.Gui, v *gocui.View) error { return err } } - e := gui.getSelectedRepository() - return refreshStatusView(v.Name(), g, e, false) + r := gui.getSelectedRepository() + return refreshStatusView(v.Name(), g, r, false) } // header og the status layout func (gui *Gui) openStatusHeaderView(g *gocui.Gui) error { maxX, _ := g.Size() - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() v, err := g.SetView(statusHeaderViewFeature.Name, 6, 2, maxX-6, 4) if err != nil { if err != gocui.ErrUnknownView { return err } - fmt.Fprintln(v, e.AbsPath) + fmt.Fprintln(v, r.AbsPath) // v.Frame = false v.Wrap = true } @@ -118,8 +118,8 @@ func (gui *Gui) closeStatusView(g *gocui.Gui, v *gocui.View) error { } // generate file lists by git status command -func populateFileLists(e *git.RepoEntity) error { - files, err := command.Status(e) +func populateFileLists(r *git.Repository) error { + files, err := command.Status(r) if err != nil { return err } @@ -136,9 +136,9 @@ func populateFileLists(e *git.RepoEntity) error { return err } -func refreshStatusView(viewName string, g *gocui.Gui, e *git.RepoEntity, reload bool) error { +func refreshStatusView(viewName string, g *gocui.Gui, r *git.Repository, reload bool) error { if reload { - populateFileLists(e) + populateFileLists(r) } var err error switch viewName { @@ -147,14 +147,14 @@ func refreshStatusView(viewName string, g *gocui.Gui, e *git.RepoEntity, reload case unstageViewFeature.Name: err = refreshUnstagedView(g) case stashViewFeature.Name: - err = refreshStashView(g, e) + err = refreshStashView(g, r) } return err } -func refreshAllStatusView(g *gocui.Gui, e *git.RepoEntity, reload bool) error { +func refreshAllStatusView(g *gocui.Gui, r *git.Repository, reload bool) error { for _, v := range statusViews { - if err := refreshStatusView(v.Name, g, e, reload); err != nil { + if err := refreshStatusView(v.Name, g, r, reload); err != nil { return err } } diff --git a/gui/unstagedview.go b/gui/unstagedview.go index ce19388..f5b6e43 100644 --- a/gui/unstagedview.go +++ b/gui/unstagedview.go @@ -23,27 +23,27 @@ func (gui *Gui) openUnStagedView(g *gocui.Gui) error { } func (gui *Gui) addChanges(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() + r := gui.getSelectedRepository() _, cy := v.Cursor() _, oy := v.Origin() if len(unstagedFiles) <= 0 || len(unstagedFiles) < cy+oy { return nil } - if err := command.Add(e, unstagedFiles[cy+oy], command.AddOptions{}); err != nil { + if err := command.Add(r, unstagedFiles[cy+oy], command.AddOptions{}); err != nil { return err } - return refreshAllStatusView(g, e, true) + return refreshAllStatusView(g, r, true) } func (gui *Gui) addAllChanges(g *gocui.Gui, v *gocui.View) error { - e := gui.getSelectedRepository() - if err := command.AddAll(e, command.AddOptions{}); err != nil { + r := gui.getSelectedRepository() + if err := command.AddAll(r, command.AddOptions{}); err != nil { return err } - return refreshAllStatusView(g, e, true) + return refreshAllStatusView(g, r, true) } // refresh the main view and re-render the repository representations diff --git a/gui/util-textstyle.go b/gui/util-textstyle.go index f14e6c2..01a24c3 100644 --- a/gui/util-textstyle.go +++ b/gui/util-textstyle.go @@ -51,32 +51,32 @@ var ( // this function handles the render and representation of the repository // TODO: cleanup is required, right now it looks too complicated -func (gui *Gui) repositoryLabel(e *git.RepoEntity) string { +func (gui *Gui) repositoryLabel(r *git.Repository) string { var prefix string - if e.Branch.Pushables != "?" { - prefix = prefix + pushable + ws + e.Branch.Pushables + - ws + pullable + ws + e.Branch.Pullables + if r.Branch.Pushables != "?" { + prefix = prefix + pushable + ws + r.Branch.Pushables + + ws + pullable + ws + r.Branch.Pullables } else { - prefix = prefix + pushable + ws + yellow.Sprint(e.Branch.Pushables) + - ws + pullable + ws + yellow.Sprint(e.Branch.Pullables) + prefix = prefix + pushable + ws + yellow.Sprint(r.Branch.Pushables) + + ws + pullable + ws + yellow.Sprint(r.Branch.Pullables) } var repoName string - se := gui.getSelectedRepository() - if se == e { + sr := gui.getSelectedRepository() + if sr == r { prefix = prefix + selectionIndicator - repoName = green.Sprint(e.Name) + repoName = green.Sprint(r.Name) } else { prefix = prefix + ws - repoName = e.Name + repoName = r.Name } // some branch names can be really long, in that times I hope the first // characters are important and meaningful - branch := adjustTextLength(e.Branch.Name, maxBranchLength) + branch := adjustTextLength(r.Branch.Name, maxBranchLength) prefix = prefix + string(cyan.Sprint(branch)) - if !e.Branch.Clean { + if !r.Branch.Clean { prefix = prefix + ws + dirty + ws } else { prefix = prefix + ws @@ -84,8 +84,8 @@ func (gui *Gui) repositoryLabel(e *git.RepoEntity) string { var suffix string // rendering the satus according to repository's state - if e.State() == git.Queued { - if inQueue, j := gui.State.Queue.IsInTheQueue(e); inQueue { + if r.State() == git.Queued { + if inQueue, j := gui.State.Queue.IsInTheQueue(r); inQueue { switch mode := j.JobType; mode { case job.FetchJob: suffix = blue.Sprint(queuedSymbol) @@ -98,15 +98,15 @@ func (gui *Gui) repositoryLabel(e *git.RepoEntity) string { } } return prefix + repoName + ws + suffix - } else if e.State() == git.Working { + } else if r.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 e.State() == git.Success { + } else if r.State() == git.Success { return prefix + repoName + ws + green.Sprint(successSymbol) - } else if e.State() == git.Paused { + } else if r.State() == git.Paused { return prefix + repoName + ws + yellow.Sprint("authentication required (u)") - } else if e.State() == git.Fail { - return prefix + repoName + ws + red.Sprint(failSymbol) + ws + red.Sprint(e.Message) + } else if r.State() == git.Fail { + return prefix + repoName + ws + red.Sprint(failSymbol) + ws + red.Sprint(r.Message) } return prefix + repoName } |
