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 /core/git | |
| parent | huge refactor, package layour re-organized (diff) | |
| download | gitbatch-bb0d2ee079a0f56e18de9f88b3b9f1c068b0798d.tar.gz | |
refactor on var name
Diffstat (limited to 'core/git')
| -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 |
7 files changed, 164 insertions, 164 deletions
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 } |
