summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2019-01-04 04:17:28 +0300
committerIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2019-01-04 04:17:28 +0300
commitbb0d2ee079a0f56e18de9f88b3b9f1c068b0798d (patch)
treea974716226a9686a5ae52b72a184a110066b9ab0 /core
parenthuge refactor, package layour re-organized (diff)
downloadgitbatch-bb0d2ee079a0f56e18de9f88b3b9f1c068b0798d.tar.gz
refactor on var name
Diffstat (limited to 'core')
-rw-r--r--core/command/cmd-add.go18
-rw-r--r--core/command/cmd-commit.go24
-rw-r--r--core/command/cmd-config.go24
-rw-r--r--core/command/cmd-diff.go18
-rw-r--r--core/command/cmd-fetch.go36
-rw-r--r--core/command/cmd-merge.go8
-rw-r--r--core/command/cmd-pull.go32
-rw-r--r--core/command/cmd-reset.go22
-rw-r--r--core/command/cmd-status.go22
-rw-r--r--core/git/branch.go52
-rw-r--r--core/git/commit.go46
-rw-r--r--core/git/remote.go34
-rw-r--r--core/git/remotebranch.go34
-rw-r--r--core/git/repository.go134
-rw-r--r--core/git/sort.go8
-rw-r--r--core/git/stash.go20
-rw-r--r--core/job/job-queue.go10
-rw-r--r--core/job/job.go32
-rw-r--r--core/load/load.go6
19 files changed, 290 insertions, 290 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