diff options
| author | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2019-01-04 18:07:19 +0300 |
|---|---|---|
| committer | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2019-01-04 18:07:19 +0300 |
| commit | 68be7276b752c2711cc6aac8e29080274b197c47 (patch) | |
| tree | 1bd6738d5016aecbc944f04f0391197541cbd7c3 | |
| parent | sort minimalized (diff) | |
| download | gitbatch-68be7276b752c2711cc6aac8e29080274b197c47.tar.gz | |
cleanup before version increase
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | core/errors/errors.go (renamed from core/errors/util-errors.go) | 0 | ||||
| -rw-r--r-- | core/job/queue.go (renamed from core/job/job-queue.go) | 0 | ||||
| -rw-r--r-- | core/load/load.go | 16 | ||||
| -rw-r--r-- | gui/extensions.go (renamed from gui/util-common.go) | 0 | ||||
| -rw-r--r-- | gui/gui.go | 37 | ||||
| -rw-r--r-- | gui/text-renderer.go (renamed from gui/util-textstyle.go) | 0 | ||||
| -rw-r--r-- | main.go | 2 |
8 files changed, 45 insertions, 19 deletions
@@ -1,10 +1,10 @@ [](https://travis-ci.com/isacikgoz/gitbatch) [](/LICENSE) [](https://goreportcard.com/report/github.com/isacikgoz/gitbatch) ## gitbatch -This tool is being built to make your local repositories synchronized with remotes easily. Although the focus is batch jobs, you can still do de facto micro management of your git repositories (e.g *add/reset, stash, commit etc.*) +I like to use polyrepos. I (*was*) often end up walking on many directories and manually pulling updates etc. To make this routine faster, I created a simple tool to handle this job. Although the focus is batch jobs, you can still do de facto micro management of your git repositories (e.g *add/reset, stash, commit etc.*) Here is the screencast of the app: -[](https://asciinema.org/a/QQPVDWVxUR3bvJhIZY3c4PTuG) +[](https://asciinema.org/a/AiH2y2gwr8sLce40epnIQxRAH) ## Installation To install with go, run the following command; @@ -19,7 +19,7 @@ run the `gitbatch` command from the parent of your git repositories. For start-u For more information see the [wiki pages](https://github.com/isacikgoz/gitbatch/wiki) ## Further goals -- add testing +- **add testing** - add push - full src-d/go-git integration (*having some performance issues in such cases*) - fetch, config, add, reset, commit, status and diff commands are supported but not fully utilized, still using git sometimes @@ -34,7 +34,6 @@ Please refer to [Known issues page](https://github.com/isacikgoz/gitbatch/wiki/K - [logrus](https://github.com/sirupsen/logrus) for logging - [viper](https://github.com/spf13/viper) for configuration management - [color](https://github.com/fatih/color) for colored text -- [lazygit](https://github.com/jesseduffield/lazygit) as app template and reference +- [lazygit](https://github.com/jesseduffield/lazygit) for inspiration - [kingpin](https://github.com/alecthomas/kingpin) for command-line flag&options -I love [lazygit](https://github.com/jesseduffield/lazygit), with that inspiration, decided to build this project to be even more lazy. The rationale was; my daily work is tied to many repositories and I often end up walking on many directories and manually pulling updates etc. To make this routine faster, I created a simple tool to handle this job. I really enjoy working on this project and I hope it will be a useful tool. diff --git a/core/errors/util-errors.go b/core/errors/errors.go index f922617..f922617 100644 --- a/core/errors/util-errors.go +++ b/core/errors/errors.go diff --git a/core/job/job-queue.go b/core/job/queue.go index e337064..e337064 100644 --- a/core/job/job-queue.go +++ b/core/job/queue.go diff --git a/core/load/load.go b/core/load/load.go index c4526ef..c568517 100644 --- a/core/load/load.go +++ b/core/load/load.go @@ -15,10 +15,10 @@ import ( // AsyncAdd is interface to caller type AsyncAdd func(r *git.Repository) -// RepositoryEntities initializes the go-git's repository obejcts with given +// SyncLoad 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.Repository, err error) { +func SyncLoad(directories []string) (entities []*git.Repository, err error) { entities = make([]*git.Repository, 0) var wg sync.WaitGroup @@ -55,8 +55,8 @@ func RepositoryEntities(directories []string) (entities []*git.Repository, err e return entities, nil } -// AddRepositoryEntitiesAsync asynchronously adds to caller -func AddRepositoryEntitiesAsync(directories []string, add AsyncAdd) error { +// AsyncLoad asynchronously adds to AsyncAdd function +func AsyncLoad(directories []string, add AsyncAdd, d chan bool) error { ctx := context.TODO() var ( @@ -65,6 +65,8 @@ func AddRepositoryEntitiesAsync(directories []string, add AsyncAdd) error { ) var mx sync.Mutex + + // Compute the output using up to maxWorkers goroutines at a time. for _, dir := range directories { if err := sem.Acquire(ctx, 1); err != nil { log.Errorf("Failed to acquire semaphore: %v", err) @@ -88,5 +90,11 @@ func AddRepositoryEntitiesAsync(directories []string, add AsyncAdd) error { mx.Unlock() }(dir) } + // Acquire all of the tokens to wait for any remaining workers to finish. + if err := sem.Acquire(ctx, int64(maxWorkers)); err != nil { + return err + } + d <- true + sem = nil return nil } diff --git a/gui/util-common.go b/gui/extensions.go index b25848c..b25848c 100644 --- a/gui/util-common.go +++ b/gui/extensions.go @@ -1,8 +1,9 @@ package gui import ( - "sync" + "fmt" "sort" + "sync" "github.com/isacikgoz/gitbatch/core/git" "github.com/isacikgoz/gitbatch/core/job" @@ -75,6 +76,8 @@ var ( mainViews = []viewFeature{mainViewFeature, remoteViewFeature, remoteBranchViewFeature, branchViewFeature, commitViewFeature} modes = []mode{fetchMode, pullMode, mergeMode} + + loaded = make(chan bool) ) // NewGui creates a Gui opject and fill it's state related entites @@ -110,12 +113,11 @@ func (gui *Gui) Run() error { g.Highlight = true g.SelFgColor = gocui.ColorGreen - // If InputEsc is true, when ESC sequence is in the buffer and it doesn't - // match any known sequence, ESC means KeyEsc. g.InputEsc = true g.SetManagerFunc(gui.layout) - go load.AddRepositoryEntitiesAsync(gui.State.Directories, gui.appendRepo) + // load repositories in background asynchronously + go load.AsyncLoad(gui.State.Directories, gui.loadRepository, loaded) if err := gui.generateKeybindings(); err != nil { log.Error("Keybindings could not be created.") @@ -132,10 +134,8 @@ func (gui *Gui) Run() error { return nil } -func (gui *Gui) appendRepo(r *git.Repository){ +func (gui *Gui) loadRepository(r *git.Repository) { rs := gui.State.Repositories - // lock mutex to avoid multithreading ambigouty - gui.mutex.Lock() // insertion sort implementation index := sort.Search(len(rs), func(i int) bool { return git.Less(r, rs[i]) }) @@ -146,10 +146,29 @@ func (gui *Gui) appendRepo(r *git.Repository){ r.On(git.RepositoryUpdated, gui.repositoryUpdated) // update gui gui.repositoryUpdated(nil) - gui.mutex.Unlock() - + gui.renderTitle() // take pointer back gui.State.Repositories = rs + go func() { + if <-loaded { + v, err := gui.g.View(mainViewFeature.Name) + if err != nil { + log.Warn(err.Error()) + return + } + v.Title = mainViewFeature.Title + fmt.Sprintf("(%d) ", len(gui.State.Repositories)) + } + }() +} + +func (gui *Gui) renderTitle() error { + v, err := gui.g.View(mainViewFeature.Name) + if err != nil { + log.Warn(err.Error()) + return err + } + v.Title = mainViewFeature.Title + fmt.Sprintf("(%d/%d) ", len(gui.State.Repositories), len(gui.State.Directories)) + return nil } // set the layout and create views with their default size, name etc. values diff --git a/gui/util-textstyle.go b/gui/text-renderer.go index d699acf..d699acf 100644 --- a/gui/util-textstyle.go +++ b/gui/text-renderer.go @@ -17,7 +17,7 @@ var ( ) func main() { - kingpin.Version("gitbatch version 0.2.2") + kingpin.Version("gitbatch version 0.3.0") // parse the command line flag and options kingpin.Parse() |
