diff --git a/commands/command_version.go b/commands/command_version.go index 62bece48..bde27cd1 100644 --- a/commands/command_version.go +++ b/commands/command_version.go @@ -1,7 +1,7 @@ package commands import ( - "github.com/git-lfs/git-lfs/httputil" + "github.com/git-lfs/git-lfs/lfsapi" "github.com/spf13/cobra" ) @@ -10,7 +10,7 @@ var ( ) func versionCommand(cmd *cobra.Command, args []string) { - Print(httputil.UserAgent) + Print(lfsapi.UserAgent) if lovesComics { Print("Nothing may see Gah Lak Tus and survive!") diff --git a/commands/run.go b/commands/run.go index 45c9026f..de603f56 100644 --- a/commands/run.go +++ b/commands/run.go @@ -3,11 +3,13 @@ package commands import ( "fmt" "os" + "path/filepath" "strings" "sync" + "time" "github.com/git-lfs/git-lfs/config" - "github.com/git-lfs/git-lfs/httputil" + "github.com/git-lfs/git-lfs/lfsapi" "github.com/git-lfs/git-lfs/localstorage" "github.com/spf13/cobra" ) @@ -64,7 +66,7 @@ func Run() { } root.Execute() - httputil.LogHttpStats(cfg) + logHTTPStats(getAPIClient()) } func gitlfsCommand(cmd *cobra.Command, args []string) { @@ -103,3 +105,28 @@ func printHelp(commandName string) { fmt.Fprintf(os.Stderr, "Sorry, no usage text found for %q\n", commandName) } } + +func logHTTPStats(c *lfsapi.Client) { + if !c.LoggingStats { + return + } + + file, err := statsLogFile() + if err != nil { + fmt.Fprintf(os.Stderr, "Error logging http stats: %s\n", err) + return + } + + defer file.Close() + c.LogStats(file) +} + +func statsLogFile() (*os.File, error) { + logBase := filepath.Join(config.LocalLogDir, "http") + if err := os.MkdirAll(logBase, 0755); err != nil { + return nil, err + } + + logFile := fmt.Sprintf("http-%d.log", time.Now().Unix()) + return os.Create(filepath.Join(logBase, logFile)) +} diff --git a/test/test-custom-transfers.sh b/test/test-custom-transfers.sh index e1ebd079..63b97317 100755 --- a/test/test-custom-transfers.sh +++ b/test/test-custom-transfers.sh @@ -102,7 +102,8 @@ begin_test "custom-transfer-upload-download" grep "xfer: started custom adapter process" fetchcustom.log grep "xfer\[lfstest-customadapter\]:" fetchcustom.log grep "11 of 11 files" fetchcustom.log - [ `find .git/lfs/objects -type f | wc -l` = 11 ] + objectlist=`find .git/lfs/objects -type f` + [ "$(echo "$objectlist" | wc -l)" -eq 11 ] ) end_test