mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
logging durations and more stuff
This commit is contained in:
parent
a555a75565
commit
103a6fd219
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
development.log
|
||||
commands.log
|
||||
extra/lgit.rb
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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 (
|
||||
|
@ -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 (
|
||||
|
@ -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 ""
|
||||
|
27
gui.go
27
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
|
||||
|
12
main.go
12
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()
|
||||
}
|
||||
|
30
status_panel.go
Normal file
30
status_panel.go
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user