diff --git a/.gitignore b/.gitignore index 48dffc2a7..5583d74d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ development.log commands.log +extra/lgit.rb diff --git a/branches_panel.go b/branches_panel.go index 75408f266..3ff79afda 100644 --- a/branches_panel.go +++ b/branches_panel.go @@ -1,18 +1,6 @@ -// lots of this has been directly ported from one of the example files, will brush up later - -// Copyright 2014 The gocui Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - package main import ( - - // "io" - // "io/ioutil" - - // "strings" - "fmt" "github.com/jroimartin/gocui" @@ -41,34 +29,36 @@ func getSelectedBranch(v *gocui.View) Branch { return state.Branches[lineNumber] } +// may want to standardise how these select methods work func handleBranchSelect(g *gocui.Gui, v *gocui.View) error { renderString(g, "options", "space: checkout, f: force checkout") if len(state.Branches) == 0 { return renderString(g, "main", "No branches for this repo") } - // may want to standardise how these select methods work - lineNumber := getItemPosition(v) - branch := state.Branches[lineNumber] - diff, _ := getBranchDiff(branch.Name, branch.BaseBranch) - if err := renderString(g, "main", diff); err != nil { - return err - } + go func() { + lineNumber := getItemPosition(v) + branch := state.Branches[lineNumber] + diff, _ := getBranchDiff(branch.Name, branch.BaseBranch) + renderString(g, "main", diff) + }() return nil } // refreshStatus is called at the end of this because that's when we can // be sure there is a state.Branches array to pick the current branch from func refreshBranches(g *gocui.Gui) error { - v, err := g.View("branches") - if err != nil { - panic(err) - } - state.Branches = getGitBranches() - v.Clear() - for _, branch := range state.Branches { - fmt.Fprintln(v, branch.DisplayString) - } - resetOrigin(v) - refreshStatus(g) + g.Update(func(g *gocui.Gui) error { + v, err := g.View("branches") + if err != nil { + panic(err) + } + state.Branches = getGitBranches() + v.Clear() + for _, branch := range state.Branches { + fmt.Fprintln(v, branch.DisplayString) + } + resetOrigin(v) + return refreshStatus(g) + }) return nil } diff --git a/commit_panel.go b/commit_panel.go index b31bcb25a..a3d5d9b68 100644 --- a/commit_panel.go +++ b/commit_panel.go @@ -1,9 +1,3 @@ -// lots of this has been directly ported from one of the example files, will brush up later - -// Copyright 2014 The gocui Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - package main import ( @@ -13,7 +7,6 @@ import ( ) func handleCommitPress(g *gocui.Gui, currentView *gocui.View) error { - devLog(stagedFiles(state.GitFiles)) if len(stagedFiles(state.GitFiles)) == 0 { return createSimpleConfirmationPanel(g, currentView, "Nothing to Commit", "There are no staged files to commit (esc)") } @@ -40,7 +33,6 @@ func handleCommitSubmit(g *gocui.Gui, v *gocui.View) error { // for whatever reason, a successful commit returns an error, so we're not // going to check for an error here if err := gitCommit(message); err != nil { - devLog(err) panic(err) } refreshFiles(g) diff --git a/commits_panel.go b/commits_panel.go index f1ca7fc99..ec7681b3a 100644 --- a/commits_panel.go +++ b/commits_panel.go @@ -1,9 +1,3 @@ -// lots of this has been directly ported from one of the example files, will brush up later - -// Copyright 2014 The gocui Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - package main import ( diff --git a/files_panel.go b/files_panel.go index 7d64106e6..66d0acb34 100644 --- a/files_panel.go +++ b/files_panel.go @@ -1,9 +1,3 @@ -// lots of this has been directly ported from one of the example files, will brush up later - -// Copyright 2014 The gocui Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - package main import ( diff --git a/gitcommands.go b/gitcommands.go index 640349569..3cadaa08f 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -1,7 +1,3 @@ -// Go has various value types including strings, -// integers, floats, booleans, etc. Here are a few -// basic examples. - package main import ( @@ -11,6 +7,7 @@ import ( "os" "os/exec" "strings" + "time" "github.com/fatih/color" ) @@ -52,7 +49,7 @@ func colorLog(colour color.Attribute, objects ...interface{}) { func commandLog(objects ...interface{}) { localLog(color.FgWhite, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/commands.log", objects...) - localLog(color.FgWhite, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/development.log", objects...) + // localLog(color.FgWhite, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/development.log", objects...) } func localLog(colour color.Attribute, path string, objects ...interface{}) { @@ -100,8 +97,12 @@ func mergeGitStatusFiles(oldGitFiles, newGitFiles []GitFile) []GitFile { } func runDirectCommand(command string) (string, error) { + timeStart := time.Now() + commandLog(command) cmdOut, err := exec.Command("bash", "-c", command).CombinedOutput() + devLog("run direct command time for command: ", command, time.Now().Sub(timeStart)) + return string(cmdOut), err } @@ -158,18 +159,12 @@ func getGitBranches() []Branch { for i, line := range branchLines { branches = append(branches, branchFromLine(line, i)) } - devLog(branches) return branches } func getGitStatusFiles() []GitFile { statusOutput, _ := getGitStatus() statusStrings := splitLines(statusOutput) - devLog(statusStrings) - // a file can have both staged and unstaged changes - // I'll probably end up ignoring the unstaged flag for now but might revisit - // tracked, staged, unstaged - gitFiles := make([]GitFile, 0) for _, statusString := range statusStrings { @@ -199,9 +194,11 @@ func gitCheckout(branch string, force bool) (string, error) { } func runCommand(command string) (string, error) { + startTime := time.Now() commandLog(command) splitCmd := strings.Split(command, " ") cmdOut, err := exec.Command(splitCmd[0], splitCmd[1:]...).CombinedOutput() + devLog("run command time: ", time.Now().Sub(startTime)) return string(cmdOut), err } @@ -245,7 +242,9 @@ func getCommits() []Commit { } func getLog() string { - result, err := runDirectCommand("git log --oneline") + // currently limiting to 30 for performance reasons + // TODO: add lazyloading when you scroll down + result, err := runDirectCommand("git log --oneline -30") if err != nil { // assume if there is an error there are no commits yet for this branch return "" diff --git a/gui.go b/gui.go index bb07bb789..c16fc1cd5 100644 --- a/gui.go +++ b/gui.go @@ -1,9 +1,3 @@ -// lots of this has been directly ported from one of the example files, will brush up later - -// Copyright 2014 The gocui Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - package main import ( @@ -11,7 +5,6 @@ import ( // "io" // "io/ioutil" - "fmt" "log" // "strings" @@ -181,26 +174,6 @@ func handleLogState(g *gocui.Gui, v *gocui.View) error { return nil } -func refreshStatus(g *gocui.Gui) error { - v, err := g.View("status") - if err != nil { - return err - } - v.Clear() - up, down := gitUpstreamDifferenceCount() - devLog(up, down) - fmt.Fprint(v, "↑"+up+"↓"+down) - branches := state.Branches - if len(branches) == 0 { - return nil - } - branch := branches[0] - // utilising the fact these all have padding to only grab the name - // from the display string with the existing coloring applied - fmt.Fprint(v, " "+branch.DisplayString[4:]) - return nil -} - func layout(g *gocui.Gui) error { width, height := g.Size() leftSideWidth := width / 3 diff --git a/main.go b/main.go index 10272d56b..66f9686b3 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,15 @@ package main -import "github.com/fatih/color" +import ( + "time" +) + +// StartTime : The starting time of the app +var StartTime time.Time func main() { - verifyInGitRepo() - a, b := gitUpstreamDifferenceCount() - colorLog(color.FgRed, a, b) devLog("\n\n\n\n\n\n\n\n\n\n") + StartTime = time.Now() + verifyInGitRepo() run() } diff --git a/status_panel.go b/status_panel.go new file mode 100644 index 000000000..5172f19f8 --- /dev/null +++ b/status_panel.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "time" + + "github.com/fatih/color" + "github.com/jroimartin/gocui" +) + +func refreshStatus(g *gocui.Gui) error { + v, err := g.View("status") + if err != nil { + return err + } + v.Clear() + up, down := gitUpstreamDifferenceCount() + fmt.Fprint(v, "↑"+up+"↓"+down) + branches := state.Branches + if len(branches) == 0 { + return nil + } + branch := branches[0] + // utilising the fact these all have padding to only grab the name + // from the display string with the existing coloring applied + fmt.Fprint(v, " "+branch.DisplayString[4:]) + + colorLog(color.FgCyan, time.Now().Sub(StartTime)) + return nil +} diff --git a/view_helpers.go b/view_helpers.go index b8acb524b..912063ca5 100644 --- a/view_helpers.go +++ b/view_helpers.go @@ -9,6 +9,7 @@ package main import ( "fmt" "strings" + "time" "github.com/jroimartin/gocui" ) @@ -97,6 +98,7 @@ func correctCursor(v *gocui.View) error { func renderString(g *gocui.Gui, viewName, s string) error { g.Update(func(*gocui.Gui) error { + timeStart := time.Now() v, err := g.View(viewName) if err != nil { panic(err) @@ -104,6 +106,7 @@ func renderString(g *gocui.Gui, viewName, s string) error { v.Clear() fmt.Fprint(v, s) v.Wrap = true + devLog("render time: ", time.Now().Sub(timeStart)) return nil }) return nil